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/afLib.h@1:8818b793d147, 2018-02-23 (annotated)
- Committer:
- Rhyme
- Date:
- Fri Feb 23 07:51:55 2018 +0000
- Revision:
- 1:8818b793d147
- Parent:
- 0:ce97f6d34336
Wrong behavior when one of color sensor is missing has been fixed.
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 | #ifndef AFLIB_H__ |
Rhyme | 0:ce97f6d34336 | 18 | #define AFLIB_H__ |
Rhyme | 0:ce97f6d34336 | 19 | |
Rhyme | 0:ce97f6d34336 | 20 | #include "mbed.h" |
Rhyme | 0:ce97f6d34336 | 21 | #include "iafLib.h" |
Rhyme | 0:ce97f6d34336 | 22 | #include "SPI.h" |
Rhyme | 0:ce97f6d34336 | 23 | #include "Command.h" |
Rhyme | 0:ce97f6d34336 | 24 | #include "StatusCommand.h" |
Rhyme | 0:ce97f6d34336 | 25 | #include "afSPI.h" |
Rhyme | 0:ce97f6d34336 | 26 | // #include "WatchDogWrapper.hpp" |
Rhyme | 0:ce97f6d34336 | 27 | |
Rhyme | 0:ce97f6d34336 | 28 | #define STATE_IDLE 0 |
Rhyme | 0:ce97f6d34336 | 29 | #define STATE_STATUS_SYNC 1 |
Rhyme | 0:ce97f6d34336 | 30 | #define STATE_STATUS_ACK 3 |
Rhyme | 0:ce97f6d34336 | 31 | #define STATE_SEND_BYTES 4 |
Rhyme | 0:ce97f6d34336 | 32 | #define STATE_RECV_BYTES 5 |
Rhyme | 0:ce97f6d34336 | 33 | #define STATE_CMD_COMPLETE 6 |
Rhyme | 0:ce97f6d34336 | 34 | |
Rhyme | 0:ce97f6d34336 | 35 | #define SPI_FRAME_LEN 16 |
Rhyme | 0:ce97f6d34336 | 36 | |
Rhyme | 0:ce97f6d34336 | 37 | #define REQUEST_QUEUE_SIZE 10 |
Rhyme | 0:ce97f6d34336 | 38 | |
Rhyme | 0:ce97f6d34336 | 39 | typedef struct { |
Rhyme | 0:ce97f6d34336 | 40 | uint8_t messageType; |
Rhyme | 0:ce97f6d34336 | 41 | uint16_t attrId; |
Rhyme | 0:ce97f6d34336 | 42 | uint8_t requestId; |
Rhyme | 0:ce97f6d34336 | 43 | uint16_t valueLen; |
Rhyme | 0:ce97f6d34336 | 44 | uint8_t *p_value; |
Rhyme | 0:ce97f6d34336 | 45 | } request_t; |
Rhyme | 0:ce97f6d34336 | 46 | |
Rhyme | 0:ce97f6d34336 | 47 | class afLib : public iafLib { |
Rhyme | 0:ce97f6d34336 | 48 | public: |
Rhyme | 0:ce97f6d34336 | 49 | afLib(PinName mcuInterrupt, isr isrWrapper, |
Rhyme | 0:ce97f6d34336 | 50 | onAttributeSet attrSet, onAttributeSetComplete attrSetComplete, afSPI *theSPI); |
Rhyme | 0:ce97f6d34336 | 51 | //wsugi 20161128 |
Rhyme | 0:ce97f6d34336 | 52 | ~afLib(); |
Rhyme | 0:ce97f6d34336 | 53 | //wsugi 20161128 |
Rhyme | 0:ce97f6d34336 | 54 | |
Rhyme | 0:ce97f6d34336 | 55 | // motoo tanaka 20171116 |
Rhyme | 0:ce97f6d34336 | 56 | virtual int getRequestId(void) ; |
Rhyme | 0:ce97f6d34336 | 57 | // motoo tanaka 20171116 |
Rhyme | 0:ce97f6d34336 | 58 | // motoo tanaka 20171229 |
Rhyme | 0:ce97f6d34336 | 59 | virtual void disable_irq(void) { fco.disable_irq() ; } |
Rhyme | 0:ce97f6d34336 | 60 | virtual void enable_irq(void) { fco.enable_irq() ; } |
Rhyme | 0:ce97f6d34336 | 61 | |
Rhyme | 0:ce97f6d34336 | 62 | virtual void loop(void); |
Rhyme | 0:ce97f6d34336 | 63 | |
Rhyme | 0:ce97f6d34336 | 64 | virtual int getAttribute(const uint16_t attrId); |
Rhyme | 0:ce97f6d34336 | 65 | |
Rhyme | 0:ce97f6d34336 | 66 | virtual int setAttributeBool(const uint16_t attrId, const bool value); |
Rhyme | 0:ce97f6d34336 | 67 | |
Rhyme | 0:ce97f6d34336 | 68 | virtual int setAttribute8(const uint16_t attrId, const int8_t value); |
Rhyme | 0:ce97f6d34336 | 69 | |
Rhyme | 0:ce97f6d34336 | 70 | virtual int setAttribute16(const uint16_t attrId, const int16_t value); |
Rhyme | 0:ce97f6d34336 | 71 | |
Rhyme | 0:ce97f6d34336 | 72 | virtual int setAttribute32(const uint16_t attrId, const int32_t value); |
Rhyme | 0:ce97f6d34336 | 73 | |
Rhyme | 0:ce97f6d34336 | 74 | virtual int setAttribute64(const uint16_t attrId, const int64_t value); |
Rhyme | 0:ce97f6d34336 | 75 | |
Rhyme | 0:ce97f6d34336 | 76 | virtual int setAttribute(const uint16_t attrId, const string &value); |
Rhyme | 0:ce97f6d34336 | 77 | |
Rhyme | 0:ce97f6d34336 | 78 | virtual int setAttribute(const uint16_t attrId, const uint16_t valueLen, const char *value); |
Rhyme | 0:ce97f6d34336 | 79 | |
Rhyme | 0:ce97f6d34336 | 80 | virtual int setAttribute(const uint16_t attrId, const uint16_t valueLen, const uint8_t *value); |
Rhyme | 0:ce97f6d34336 | 81 | |
Rhyme | 0:ce97f6d34336 | 82 | virtual int setAttributeComplete(uint8_t requestId, const uint16_t attrId, const uint16_t valueLen, const uint8_t *value); |
Rhyme | 0:ce97f6d34336 | 83 | |
Rhyme | 0:ce97f6d34336 | 84 | virtual bool isIdle(); |
Rhyme | 0:ce97f6d34336 | 85 | |
Rhyme | 0:ce97f6d34336 | 86 | virtual void mcuISR(); |
Rhyme | 0:ce97f6d34336 | 87 | |
Rhyme | 0:ce97f6d34336 | 88 | private: |
Rhyme | 0:ce97f6d34336 | 89 | Timeout deathWish; |
Rhyme | 0:ce97f6d34336 | 90 | Timer *checkLastSync; |
Rhyme | 0:ce97f6d34336 | 91 | static void kick_the_bucket(); |
Rhyme | 0:ce97f6d34336 | 92 | afSPI *_theSPI; |
Rhyme | 0:ce97f6d34336 | 93 | |
Rhyme | 0:ce97f6d34336 | 94 | //SPISettings _spiSettings; |
Rhyme | 0:ce97f6d34336 | 95 | volatile int _interrupts_pending; |
Rhyme | 0:ce97f6d34336 | 96 | int _state; |
Rhyme | 0:ce97f6d34336 | 97 | uint16_t _bytesToSend; |
Rhyme | 0:ce97f6d34336 | 98 | uint16_t _bytesToRecv; |
Rhyme | 0:ce97f6d34336 | 99 | uint8_t _requestId; |
Rhyme | 0:ce97f6d34336 | 100 | uint16_t _outstandingSetGetAttrId; |
Rhyme | 0:ce97f6d34336 | 101 | |
Rhyme | 0:ce97f6d34336 | 102 | // Application Callbacks. |
Rhyme | 0:ce97f6d34336 | 103 | onAttributeSet _onAttrSet; |
Rhyme | 0:ce97f6d34336 | 104 | onAttributeSetComplete _onAttrSetComplete; |
Rhyme | 0:ce97f6d34336 | 105 | |
Rhyme | 0:ce97f6d34336 | 106 | Command *_writeCmd; |
Rhyme | 0:ce97f6d34336 | 107 | uint16_t _writeBufferLen; |
Rhyme | 0:ce97f6d34336 | 108 | uint8_t *_writeBuffer; |
Rhyme | 0:ce97f6d34336 | 109 | |
Rhyme | 0:ce97f6d34336 | 110 | Command *_readCmd; |
Rhyme | 0:ce97f6d34336 | 111 | uint16_t _readBufferLen; |
Rhyme | 0:ce97f6d34336 | 112 | uint8_t *_readBuffer; |
Rhyme | 0:ce97f6d34336 | 113 | |
Rhyme | 0:ce97f6d34336 | 114 | int _writeCmdOffset; |
Rhyme | 0:ce97f6d34336 | 115 | int _readCmdOffset; |
Rhyme | 0:ce97f6d34336 | 116 | |
Rhyme | 0:ce97f6d34336 | 117 | StatusCommand *_txStatus; |
Rhyme | 0:ce97f6d34336 | 118 | StatusCommand *_rxStatus; |
Rhyme | 0:ce97f6d34336 | 119 | |
Rhyme | 0:ce97f6d34336 | 120 | request_t _request; |
Rhyme | 0:ce97f6d34336 | 121 | request_t _requestQueue[REQUEST_QUEUE_SIZE]; |
Rhyme | 0:ce97f6d34336 | 122 | |
Rhyme | 0:ce97f6d34336 | 123 | #ifdef ATTRIBUTE_CLI |
Rhyme | 0:ce97f6d34336 | 124 | int parseCommand(const char *cmd); |
Rhyme | 0:ce97f6d34336 | 125 | #endif |
Rhyme | 0:ce97f6d34336 | 126 | |
Rhyme | 0:ce97f6d34336 | 127 | void sendCommand(void); |
Rhyme | 0:ce97f6d34336 | 128 | |
Rhyme | 0:ce97f6d34336 | 129 | void runStateMachine(void); |
Rhyme | 0:ce97f6d34336 | 130 | |
Rhyme | 0:ce97f6d34336 | 131 | void printState(int state); |
Rhyme | 0:ce97f6d34336 | 132 | |
Rhyme | 0:ce97f6d34336 | 133 | //void beginSPI(); |
Rhyme | 0:ce97f6d34336 | 134 | |
Rhyme | 0:ce97f6d34336 | 135 | //void endSPI(); |
Rhyme | 0:ce97f6d34336 | 136 | |
Rhyme | 0:ce97f6d34336 | 137 | int exchangeStatus(StatusCommand *tx, StatusCommand *rx); |
Rhyme | 0:ce97f6d34336 | 138 | |
Rhyme | 0:ce97f6d34336 | 139 | bool inSync(StatusCommand *tx, StatusCommand *rx); |
Rhyme | 0:ce97f6d34336 | 140 | |
Rhyme | 0:ce97f6d34336 | 141 | int writeStatus(StatusCommand *c); |
Rhyme | 0:ce97f6d34336 | 142 | |
Rhyme | 0:ce97f6d34336 | 143 | void sendBytes(); |
Rhyme | 0:ce97f6d34336 | 144 | |
Rhyme | 0:ce97f6d34336 | 145 | void recvBytes(); |
Rhyme | 0:ce97f6d34336 | 146 | |
Rhyme | 0:ce97f6d34336 | 147 | void dumpBytes(char *label, int len, uint8_t *bytes); |
Rhyme | 0:ce97f6d34336 | 148 | |
Rhyme | 0:ce97f6d34336 | 149 | void updateIntsPending(int amount); |
Rhyme | 0:ce97f6d34336 | 150 | |
Rhyme | 0:ce97f6d34336 | 151 | void queueInit(void); |
Rhyme | 0:ce97f6d34336 | 152 | |
Rhyme | 0:ce97f6d34336 | 153 | int queuePut(uint8_t messageType, uint8_t requestId, const uint16_t attributeId, uint16_t valueLen, const uint8_t *value); |
Rhyme | 0:ce97f6d34336 | 154 | |
Rhyme | 0:ce97f6d34336 | 155 | int queueGet(uint8_t *messageType, uint8_t *requestId, uint16_t *attributeId, uint16_t *valueLen, uint8_t **value); |
Rhyme | 0:ce97f6d34336 | 156 | |
Rhyme | 0:ce97f6d34336 | 157 | int doGetAttribute(uint8_t requestId, uint16_t attrId); |
Rhyme | 0:ce97f6d34336 | 158 | |
Rhyme | 0:ce97f6d34336 | 159 | int doSetAttribute(uint8_t requestId, uint16_t attrId, uint16_t valueLen, uint8_t *value); |
Rhyme | 0:ce97f6d34336 | 160 | |
Rhyme | 0:ce97f6d34336 | 161 | int doUpdateAttribute(uint8_t requestId, uint16_t attrId, uint8_t status, uint16_t valueLen, uint8_t *value); |
Rhyme | 0:ce97f6d34336 | 162 | |
Rhyme | 0:ce97f6d34336 | 163 | void onStateIdle(void); |
Rhyme | 0:ce97f6d34336 | 164 | void onStateSync(void); |
Rhyme | 0:ce97f6d34336 | 165 | void onStateAck(void); |
Rhyme | 0:ce97f6d34336 | 166 | void onStateSendBytes(void); |
Rhyme | 0:ce97f6d34336 | 167 | void onStateRecvBytes(void); |
Rhyme | 0:ce97f6d34336 | 168 | void onStateCmdComplete(void); |
Rhyme | 0:ce97f6d34336 | 169 | void printTransaction(uint8_t *rbytes, int len); |
Rhyme | 0:ce97f6d34336 | 170 | InterruptIn fco; |
Rhyme | 0:ce97f6d34336 | 171 | }; |
Rhyme | 0:ce97f6d34336 | 172 | |
Rhyme | 0:ce97f6d34336 | 173 | #endif // AFLIB_H__ |