Color sensor reset at the end of calibration added. sensor id auto assignment was changed to be a fixed value assignment to avoid sensor id shift when some sensor is absent.
Dependencies: UniGraphic mbed vt100
afLib/iafLib.h@0:ce97f6d34336, 2018-02-23 (annotated)
- Committer:
- Rhyme
- Date:
- Fri Feb 23 05:40:22 2018 +0000
- Revision:
- 0:ce97f6d34336
color sensor reset was added at the end of calibration
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Rhyme | 0:ce97f6d34336 | 1 | /** |
Rhyme | 0:ce97f6d34336 | 2 | * Copyright 2015 Afero, Inc. |
Rhyme | 0:ce97f6d34336 | 3 | * |
Rhyme | 0:ce97f6d34336 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Rhyme | 0:ce97f6d34336 | 5 | * you may not use this file except in compliance with the License. |
Rhyme | 0:ce97f6d34336 | 6 | * You may obtain a copy of the License at |
Rhyme | 0:ce97f6d34336 | 7 | * |
Rhyme | 0:ce97f6d34336 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Rhyme | 0:ce97f6d34336 | 9 | * |
Rhyme | 0:ce97f6d34336 | 10 | * Unless required by applicable law or agreed to in writing, software |
Rhyme | 0:ce97f6d34336 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
Rhyme | 0:ce97f6d34336 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Rhyme | 0:ce97f6d34336 | 13 | * See the License for the specific language governing permissions and |
Rhyme | 0:ce97f6d34336 | 14 | * limitations under the License. |
Rhyme | 0:ce97f6d34336 | 15 | */ |
Rhyme | 0:ce97f6d34336 | 16 | |
Rhyme | 0:ce97f6d34336 | 17 | /** |
Rhyme | 0:ce97f6d34336 | 18 | * afLib public interface |
Rhyme | 0:ce97f6d34336 | 19 | * |
Rhyme | 0:ce97f6d34336 | 20 | * This file defines everything your application should need for commuinicating with the Afero ASR-1 radio module. |
Rhyme | 0:ce97f6d34336 | 21 | * Is there is anything missing from this file, please post a request on the developer forum and we will see what |
Rhyme | 0:ce97f6d34336 | 22 | * we can do. |
Rhyme | 0:ce97f6d34336 | 23 | */ |
Rhyme | 0:ce97f6d34336 | 24 | #ifndef AFLIB_IAFLIB_H |
Rhyme | 0:ce97f6d34336 | 25 | #define AFLIB_IAFLIB_H |
Rhyme | 0:ce97f6d34336 | 26 | |
Rhyme | 0:ce97f6d34336 | 27 | #include "mbed.h" |
Rhyme | 0:ce97f6d34336 | 28 | #include <string> |
Rhyme | 0:ce97f6d34336 | 29 | using namespace std; |
Rhyme | 0:ce97f6d34336 | 30 | #include "afErrors.h" |
Rhyme | 0:ce97f6d34336 | 31 | #include "afSPI.h" |
Rhyme | 0:ce97f6d34336 | 32 | |
Rhyme | 0:ce97f6d34336 | 33 | #if defined (TARGET_TEENSY3_1) |
Rhyme | 0:ce97f6d34336 | 34 | #include "USBSerial.h" |
Rhyme | 0:ce97f6d34336 | 35 | #endif |
Rhyme | 0:ce97f6d34336 | 36 | |
Rhyme | 0:ce97f6d34336 | 37 | #define afMINIMUM_TIME_BETWEEN_REQUESTS 1000 |
Rhyme | 0:ce97f6d34336 | 38 | |
Rhyme | 0:ce97f6d34336 | 39 | #define MAX_ATTRIBUTE_SIZE 255 |
Rhyme | 0:ce97f6d34336 | 40 | |
Rhyme | 0:ce97f6d34336 | 41 | typedef void (*isr)(); |
Rhyme | 0:ce97f6d34336 | 42 | typedef void (*onAttributeSet)(const uint8_t requestId, const uint16_t attributeId, const uint16_t valueLen, const uint8_t *value); |
Rhyme | 0:ce97f6d34336 | 43 | typedef void (*onAttributeSetComplete)(const uint8_t requestId, const uint16_t attributeId, const uint16_t valueLen, const uint8_t *value); |
Rhyme | 0:ce97f6d34336 | 44 | |
Rhyme | 0:ce97f6d34336 | 45 | class iafLib { |
Rhyme | 0:ce97f6d34336 | 46 | public: |
Rhyme | 0:ce97f6d34336 | 47 | /** |
Rhyme | 0:ce97f6d34336 | 48 | * create |
Rhyme | 0:ce97f6d34336 | 49 | * |
Rhyme | 0:ce97f6d34336 | 50 | * Create an instance of the afLib object. The afLib is a singleton. Calling this method multiple |
Rhyme | 0:ce97f6d34336 | 51 | * times will return the same instance. |
Rhyme | 0:ce97f6d34336 | 52 | * |
Rhyme | 0:ce97f6d34336 | 53 | * @param mcuInterrupt The Arduino interrupt to be used (returned from digitalPinToInterrupt) |
Rhyme | 0:ce97f6d34336 | 54 | * @param isrWrapper This is the isr method that must be defined in your sketch |
Rhyme | 0:ce97f6d34336 | 55 | * @param attrSet Callback for notification of attribute set requests |
Rhyme | 0:ce97f6d34336 | 56 | * @param attrSetComplete Callback for notification of attribute set request completions |
Rhyme | 0:ce97f6d34336 | 57 | * @return iafLib * Instance of iafLib |
Rhyme | 0:ce97f6d34336 | 58 | */ |
Rhyme | 0:ce97f6d34336 | 59 | static iafLib * create(PinName mcuInterrupt, isr isrWrapper, |
Rhyme | 0:ce97f6d34336 | 60 | onAttributeSet attrSet, onAttributeSetComplete attrSetComplete, afSPI *theSPI); |
Rhyme | 0:ce97f6d34336 | 61 | |
Rhyme | 0:ce97f6d34336 | 62 | //wsugi 20161128 |
Rhyme | 0:ce97f6d34336 | 63 | static void destroy(); |
Rhyme | 0:ce97f6d34336 | 64 | |
Rhyme | 0:ce97f6d34336 | 65 | /** |
Rhyme | 0:ce97f6d34336 | 66 | * loop |
Rhyme | 0:ce97f6d34336 | 67 | * |
Rhyme | 0:ce97f6d34336 | 68 | * Called by the loop() method in your sketch to give afLib some CPU time |
Rhyme | 0:ce97f6d34336 | 69 | */ |
Rhyme | 0:ce97f6d34336 | 70 | virtual void loop(void) = 0; |
Rhyme | 0:ce97f6d34336 | 71 | |
Rhyme | 0:ce97f6d34336 | 72 | /** |
Rhyme | 0:ce97f6d34336 | 73 | * getAttribute |
Rhyme | 0:ce97f6d34336 | 74 | * |
Rhyme | 0:ce97f6d34336 | 75 | * Request the value of an attribute be returned from the ASR-1. |
Rhyme | 0:ce97f6d34336 | 76 | * Value will be returned in the attrSetComplete callback. |
Rhyme | 0:ce97f6d34336 | 77 | */ |
Rhyme | 0:ce97f6d34336 | 78 | virtual int getAttribute(const uint16_t attrId) = 0; |
Rhyme | 0:ce97f6d34336 | 79 | |
Rhyme | 0:ce97f6d34336 | 80 | /** |
Rhyme | 0:ce97f6d34336 | 81 | * setAttribute |
Rhyme | 0:ce97f6d34336 | 82 | * |
Rhyme | 0:ce97f6d34336 | 83 | * Request setting an attribute. |
Rhyme | 0:ce97f6d34336 | 84 | * For MCU attributes, the attribute value will be updated. |
Rhyme | 0:ce97f6d34336 | 85 | * For IO attributes, the attribute value will be updated, and then onAttrSetComplete will be called. |
Rhyme | 0:ce97f6d34336 | 86 | */ |
Rhyme | 0:ce97f6d34336 | 87 | virtual int setAttributeBool(const uint16_t attrId, const bool value) = 0; |
Rhyme | 0:ce97f6d34336 | 88 | |
Rhyme | 0:ce97f6d34336 | 89 | virtual int setAttribute8(const uint16_t attrId, const int8_t value) = 0; |
Rhyme | 0:ce97f6d34336 | 90 | |
Rhyme | 0:ce97f6d34336 | 91 | virtual int setAttribute16(const uint16_t attrId, const int16_t value) = 0; |
Rhyme | 0:ce97f6d34336 | 92 | |
Rhyme | 0:ce97f6d34336 | 93 | virtual int setAttribute32(const uint16_t attrId, const int32_t value) = 0; |
Rhyme | 0:ce97f6d34336 | 94 | |
Rhyme | 0:ce97f6d34336 | 95 | virtual int setAttribute64(const uint16_t attrId, const int64_t value) = 0; |
Rhyme | 0:ce97f6d34336 | 96 | |
Rhyme | 0:ce97f6d34336 | 97 | virtual int setAttribute(const uint16_t attrId, const string &value) = 0; |
Rhyme | 0:ce97f6d34336 | 98 | |
Rhyme | 0:ce97f6d34336 | 99 | virtual int setAttribute(const uint16_t attrId, const uint16_t valueLen, const char *value) = 0; |
Rhyme | 0:ce97f6d34336 | 100 | |
Rhyme | 0:ce97f6d34336 | 101 | virtual int setAttribute(const uint16_t attrId, const uint16_t valueLen, const uint8_t *value) = 0; |
Rhyme | 0:ce97f6d34336 | 102 | |
Rhyme | 0:ce97f6d34336 | 103 | /** |
Rhyme | 0:ce97f6d34336 | 104 | * setAttributeComplete |
Rhyme | 0:ce97f6d34336 | 105 | * |
Rhyme | 0:ce97f6d34336 | 106 | * Call this in response to an onAttrSet. This lets the ASR-1 know that the set request has been handled. |
Rhyme | 0:ce97f6d34336 | 107 | */ |
Rhyme | 0:ce97f6d34336 | 108 | virtual int setAttributeComplete(uint8_t requestId, const uint16_t attrId, const uint16_t valueLen, const uint8_t *value) = 0; |
Rhyme | 0:ce97f6d34336 | 109 | |
Rhyme | 0:ce97f6d34336 | 110 | /** |
Rhyme | 0:ce97f6d34336 | 111 | * isIdle |
Rhyme | 0:ce97f6d34336 | 112 | * |
Rhyme | 0:ce97f6d34336 | 113 | * Call to find out of the ASR-1 is currently handling a request. |
Rhyme | 0:ce97f6d34336 | 114 | * |
Rhyme | 0:ce97f6d34336 | 115 | * @return true if an operation is in progress |
Rhyme | 0:ce97f6d34336 | 116 | */ |
Rhyme | 0:ce97f6d34336 | 117 | virtual bool isIdle() = 0; |
Rhyme | 0:ce97f6d34336 | 118 | |
Rhyme | 0:ce97f6d34336 | 119 | /** |
Rhyme | 0:ce97f6d34336 | 120 | * mcuISR |
Rhyme | 0:ce97f6d34336 | 121 | * |
Rhyme | 0:ce97f6d34336 | 122 | * Called by your sketch to pass the interrupt along to afLib. |
Rhyme | 0:ce97f6d34336 | 123 | */ |
Rhyme | 0:ce97f6d34336 | 124 | virtual void mcuISR() = 0; |
Rhyme | 0:ce97f6d34336 | 125 | }; |
Rhyme | 0:ce97f6d34336 | 126 | #endif //AFLIB_IAFLIB_H |