pwm period is now 200us instead of the default 20ms veml6040 config is now AF_BIT | TRIG_BIT
Dependencies: mbed MMA8451Q USBDevice WakeUp vt100
Fork of afero_node_suntory_2017_06_15 by
spi/AferoCommHndlr.cpp@13:c7d1ef8c57b3, 2017-04-28 (annotated)
- Committer:
- wataloh
- Date:
- Fri Apr 28 10:11:07 2017 +0000
- Revision:
- 13:c7d1ef8c57b3
- Parent:
- 6:88cc04eb613a
- Child:
- 14:b205267fa5f6
TEMP01,TEMP02,TEMP03 ---> TEMP04
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wataloh | 0:20bce0dcc921 | 1 | #include "AferoCommHndlr.h" |
wataloh | 0:20bce0dcc921 | 2 | |
wataloh | 1:b2a9a6f2c30e | 3 | Necochan *Necochan::ref = NULL; |
wataloh | 1:b2a9a6f2c30e | 4 | |
wataloh | 1:b2a9a6f2c30e | 5 | Necochan::Necochan() |
wataloh | 1:b2a9a6f2c30e | 6 | { |
wataloh | 1:b2a9a6f2c30e | 7 | if(ref==NULL) |
wataloh | 1:b2a9a6f2c30e | 8 | { |
wataloh | 1:b2a9a6f2c30e | 9 | ref = this; |
wataloh | 1:b2a9a6f2c30e | 10 | } |
wataloh | 1:b2a9a6f2c30e | 11 | out = new DigitalOut(PTB8,1); |
wataloh | 1:b2a9a6f2c30e | 12 | } |
wataloh | 1:b2a9a6f2c30e | 13 | |
wataloh | 1:b2a9a6f2c30e | 14 | void Necochan::release() |
wataloh | 1:b2a9a6f2c30e | 15 | { |
wataloh | 1:b2a9a6f2c30e | 16 | DigitalOut *p = ref->out; |
wataloh | 1:b2a9a6f2c30e | 17 | *p = 1; |
wataloh | 1:b2a9a6f2c30e | 18 | } |
wataloh | 1:b2a9a6f2c30e | 19 | |
wataloh | 1:b2a9a6f2c30e | 20 | void Necochan::push() |
wataloh | 1:b2a9a6f2c30e | 21 | { |
wataloh | 1:b2a9a6f2c30e | 22 | SERIAL_PRINT_DBG("push meow\n"); |
wataloh | 1:b2a9a6f2c30e | 23 | *out = 0; |
wataloh | 1:b2a9a6f2c30e | 24 | timeout.attach(&release,1); |
wataloh | 1:b2a9a6f2c30e | 25 | } |
wataloh | 1:b2a9a6f2c30e | 26 | |
wataloh | 0:20bce0dcc921 | 27 | static AferoCommHndlr *self = NULL; |
wataloh | 0:20bce0dcc921 | 28 | |
wataloh | 1:b2a9a6f2c30e | 29 | AferoCommHndlr::AferoCommHndlr() : flowControlEnabled(false) |
wataloh | 0:20bce0dcc921 | 30 | { |
wataloh | 1:b2a9a6f2c30e | 31 | necochan = new Necochan(); |
wataloh | 6:88cc04eb613a | 32 | deathWish = new Timeout(); |
wataloh | 6:88cc04eb613a | 33 | } |
wataloh | 6:88cc04eb613a | 34 | |
wataloh | 6:88cc04eb613a | 35 | void |
wataloh | 6:88cc04eb613a | 36 | AferoCommHndlr::kick_the_bucket() |
wataloh | 6:88cc04eb613a | 37 | { |
wataloh | 6:88cc04eb613a | 38 | SERIAL_PRINT_DBG("bucket kicked!!\n"); |
wataloh | 6:88cc04eb613a | 39 | wtd.kick_the_bucket(); |
wataloh | 0:20bce0dcc921 | 40 | } |
wataloh | 0:20bce0dcc921 | 41 | |
wataloh | 0:20bce0dcc921 | 42 | void |
wataloh | 0:20bce0dcc921 | 43 | AferoCommHndlr::loop() |
wataloh | 0:20bce0dcc921 | 44 | { |
wataloh | 13:c7d1ef8c57b3 | 45 | for (int i=0; i< ((255/16)+3) ; ++i) |
wataloh | 13:c7d1ef8c57b3 | 46 | { |
wataloh | 13:c7d1ef8c57b3 | 47 | piafLib->loop(); |
wataloh | 13:c7d1ef8c57b3 | 48 | } |
wataloh | 0:20bce0dcc921 | 49 | todoQ->loop(); |
wataloh | 0:20bce0dcc921 | 50 | } |
wataloh | 0:20bce0dcc921 | 51 | |
wataloh | 0:20bce0dcc921 | 52 | AferoCommHndlr* |
wataloh | 0:20bce0dcc921 | 53 | AferoCommHndlr::create(Timer *timer, mbedSPI *spi) |
wataloh | 0:20bce0dcc921 | 54 | { |
wataloh | 0:20bce0dcc921 | 55 | SERIAL_PRINT_DBG("HELLO\n"); |
wataloh | 0:20bce0dcc921 | 56 | self = new AferoCommHndlr(); |
wataloh | 0:20bce0dcc921 | 57 | self->timer = timer; |
wataloh | 1:b2a9a6f2c30e | 58 | self->piafLib = iafLib::create((PinName)PINS::ASR_1::SPI::SR, |
wataloh | 0:20bce0dcc921 | 59 | AferoCommHndlr::fco_irq_fall, |
wataloh | 0:20bce0dcc921 | 60 | AferoCommHndlr::myOnAttributeSet, |
wataloh | 0:20bce0dcc921 | 61 | AferoCommHndlr::myOnAttributeSetComplete, spi); |
wataloh | 0:20bce0dcc921 | 62 | self->todoQ = ToDoQ::create(AferoCommHndlr::onGetTodo); |
wataloh | 0:20bce0dcc921 | 63 | SERIAL_PRINT_DBG("AferoCommHndlr init done\n"); |
wataloh | 6:88cc04eb613a | 64 | self->piafLib->setAttribute8(1,1) != afSUCCESS ? SERIAL_PRINT_DBG("set attr failed!!\n") : NULL ; |
wataloh | 1:b2a9a6f2c30e | 65 | |
wataloh | 0:20bce0dcc921 | 66 | return self; |
wataloh | 0:20bce0dcc921 | 67 | } |
wataloh | 0:20bce0dcc921 | 68 | |
wataloh | 0:20bce0dcc921 | 69 | void |
wataloh | 0:20bce0dcc921 | 70 | AferoCommHndlr::myOnAttributeSet( |
wataloh | 0:20bce0dcc921 | 71 | const uint8_t requestId, |
wataloh | 0:20bce0dcc921 | 72 | const uint16_t attributeId, |
wataloh | 0:20bce0dcc921 | 73 | const uint16_t valueLen, |
wataloh | 0:20bce0dcc921 | 74 | const uint8_t *value) |
wataloh | 0:20bce0dcc921 | 75 | { |
wataloh | 6:88cc04eb613a | 76 | self->piafLib->setAttributeComplete(requestId, attributeId, valueLen, value) != afSUCCESS ? SERIAL_PRINT_DBG("set attr failed!!\n") : NULL ; |
wataloh | 0:20bce0dcc921 | 77 | } |
wataloh | 0:20bce0dcc921 | 78 | |
wataloh | 4:b38e09f24711 | 79 | int32_t |
wataloh | 4:b38e09f24711 | 80 | AferoCommHndlr::sanitizeSensingInterval(uint16_t attributeId, int32_t interval) |
wataloh | 4:b38e09f24711 | 81 | { |
wataloh | 4:b38e09f24711 | 82 | if(interval < 5) |
wataloh | 4:b38e09f24711 | 83 | { |
wataloh | 4:b38e09f24711 | 84 | interval = 5; |
wataloh | 6:88cc04eb613a | 85 | self->piafLib->setAttribute32(attributeId, interval) != afSUCCESS ? SERIAL_PRINT_DBG("set attr failed!!\n") : NULL ; |
wataloh | 4:b38e09f24711 | 86 | } |
wataloh | 4:b38e09f24711 | 87 | return interval; |
wataloh | 4:b38e09f24711 | 88 | } |
wataloh | 4:b38e09f24711 | 89 | |
wataloh | 0:20bce0dcc921 | 90 | void |
wataloh | 0:20bce0dcc921 | 91 | AferoCommHndlr::myOnAttributeSetComplete( |
wataloh | 0:20bce0dcc921 | 92 | const uint8_t requestId, |
wataloh | 0:20bce0dcc921 | 93 | const uint16_t attributeId, |
wataloh | 0:20bce0dcc921 | 94 | const uint16_t valueLen, |
wataloh | 0:20bce0dcc921 | 95 | const uint8_t *value) |
wataloh | 0:20bce0dcc921 | 96 | { |
wataloh | 2:dfe671e31221 | 97 | // uint8_t *buf = new uint8_t[valueLen+1]; |
wataloh | 2:dfe671e31221 | 98 | // memset(buf,'\0',valueLen+1); |
wataloh | 2:dfe671e31221 | 99 | // memcpy(buf, value, valueLen); |
wataloh | 2:dfe671e31221 | 100 | // SERIAL_PRINT_DBG("attr id:%d value:%s\n",attributeId,buf); |
wataloh | 2:dfe671e31221 | 101 | // delete[] buf; |
wataloh | 2:dfe671e31221 | 102 | // buf = NULL; |
wataloh | 1:b2a9a6f2c30e | 103 | |
wataloh | 6:88cc04eb613a | 104 | //self->deathWish->attach(&AferoCommHndlr::kick_the_bucket,10); |
wataloh | 6:88cc04eb613a | 105 | |
wataloh | 4:b38e09f24711 | 106 | int32_t sensing_interval; |
wataloh | 4:b38e09f24711 | 107 | char *buf = NULL; |
wataloh | 4:b38e09f24711 | 108 | if(attributeId >= 4 && attributeId <= 8) |
wataloh | 4:b38e09f24711 | 109 | { |
wataloh | 4:b38e09f24711 | 110 | sensing_interval = *((int32_t*)value); |
wataloh | 4:b38e09f24711 | 111 | } |
wataloh | 4:b38e09f24711 | 112 | |
wataloh | 2:dfe671e31221 | 113 | if(attributeId==2) |
wataloh | 2:dfe671e31221 | 114 | { |
wataloh | 2:dfe671e31221 | 115 | PREFERENCES::CRC32.ui32 = *((uint32_t*)value); |
wataloh | 2:dfe671e31221 | 116 | } |
wataloh | 2:dfe671e31221 | 117 | else if(attributeId==4) |
wataloh | 2:dfe671e31221 | 118 | { |
wataloh | 4:b38e09f24711 | 119 | buf = "PREFERENCES::SENSING_INTERVAL[SENSORS::ACCELEROMETER]"; |
wataloh | 4:b38e09f24711 | 120 | PREFERENCES::SENSING_INTERVAL[SENSORS::ACCELEROMETER] = self->sanitizeSensingInterval(attributeId,sensing_interval); |
wataloh | 2:dfe671e31221 | 121 | } |
wataloh | 2:dfe671e31221 | 122 | else if(attributeId==5) |
wataloh | 2:dfe671e31221 | 123 | { |
wataloh | 4:b38e09f24711 | 124 | buf = "PREFERENCES::SENSING_INTERVAL[SENSORS::COLOR]"; |
wataloh | 4:b38e09f24711 | 125 | PREFERENCES::SENSING_INTERVAL[SENSORS::COLOR] = self->sanitizeSensingInterval(attributeId,sensing_interval); |
wataloh | 2:dfe671e31221 | 126 | } |
wataloh | 2:dfe671e31221 | 127 | else if(attributeId==6) |
wataloh | 2:dfe671e31221 | 128 | { |
wataloh | 4:b38e09f24711 | 129 | buf = "PREFERENCES::SENSING_INTERVAL[SENSORS::PRESSURE]"; |
wataloh | 4:b38e09f24711 | 130 | PREFERENCES::SENSING_INTERVAL[SENSORS::PRESSURE] = self->sanitizeSensingInterval(attributeId,sensing_interval); |
wataloh | 2:dfe671e31221 | 131 | } |
wataloh | 2:dfe671e31221 | 132 | else if(attributeId==7) |
wataloh | 2:dfe671e31221 | 133 | { |
wataloh | 4:b38e09f24711 | 134 | buf = "PREFERENCES::SENSING_INTERVAL[SENSORS::CURRENT_TRANS]"; |
wataloh | 4:b38e09f24711 | 135 | PREFERENCES::SENSING_INTERVAL[SENSORS::CURRENT_TRANS] = self->sanitizeSensingInterval(attributeId,sensing_interval); |
wataloh | 2:dfe671e31221 | 136 | } |
wataloh | 2:dfe671e31221 | 137 | else if(attributeId==8) |
wataloh | 2:dfe671e31221 | 138 | { |
wataloh | 4:b38e09f24711 | 139 | buf = "PREFERENCES::SENSING_INTERVAL[SENSORS::TEMPERATURE]"; |
wataloh | 4:b38e09f24711 | 140 | PREFERENCES::SENSING_INTERVAL[SENSORS::TEMPERATURE] = self->sanitizeSensingInterval(attributeId,sensing_interval); |
wataloh | 2:dfe671e31221 | 141 | } |
wataloh | 2:dfe671e31221 | 142 | else if(attributeId==9) |
wataloh | 2:dfe671e31221 | 143 | { |
wataloh | 2:dfe671e31221 | 144 | SERIAL_PRINT_DBG("time stamp:%ld\n", *((uint32_t*)value)); |
wataloh | 6:88cc04eb613a | 145 | time_t t; |
wataloh | 6:88cc04eb613a | 146 | RTC_GET_UTC(t); |
wataloh | 6:88cc04eb613a | 147 | if(*((uint32_t*)value) > ((uint32_t)t)) |
wataloh | 6:88cc04eb613a | 148 | { |
wataloh | 6:88cc04eb613a | 149 | RTC_Handler::getInstance()->setUTC(*((uint32_t*)value)); |
wataloh | 6:88cc04eb613a | 150 | } |
wataloh | 2:dfe671e31221 | 151 | } |
wataloh | 2:dfe671e31221 | 152 | else if(attributeId==1024) |
wataloh | 1:b2a9a6f2c30e | 153 | { |
wataloh | 1:b2a9a6f2c30e | 154 | self->necochan->push(); |
wataloh | 1:b2a9a6f2c30e | 155 | } |
wataloh | 4:b38e09f24711 | 156 | |
wataloh | 4:b38e09f24711 | 157 | if(attributeId >= 4 && attributeId <= 8) |
wataloh | 4:b38e09f24711 | 158 | { |
wataloh | 4:b38e09f24711 | 159 | SERIAL_PRINT_DBG("%s=%ld\n",buf,sensing_interval); |
wataloh | 4:b38e09f24711 | 160 | } |
wataloh | 4:b38e09f24711 | 161 | |
wataloh | 0:20bce0dcc921 | 162 | } |
wataloh | 0:20bce0dcc921 | 163 | |
wataloh | 0:20bce0dcc921 | 164 | void |
wataloh | 0:20bce0dcc921 | 165 | AferoCommHndlr::fco_irq_fall() |
wataloh | 0:20bce0dcc921 | 166 | { |
wataloh | 0:20bce0dcc921 | 167 | if(self->piafLib) |
wataloh | 0:20bce0dcc921 | 168 | { |
wataloh | 0:20bce0dcc921 | 169 | self->piafLib->mcuISR(); |
wataloh | 0:20bce0dcc921 | 170 | } |
wataloh | 0:20bce0dcc921 | 171 | } |
wataloh | 0:20bce0dcc921 | 172 | |
wataloh | 0:20bce0dcc921 | 173 | void |
wataloh | 0:20bce0dcc921 | 174 | AferoCommHndlr::onGetTodo(ToDo *todo) |
wataloh | 0:20bce0dcc921 | 175 | { |
wataloh | 0:20bce0dcc921 | 176 | char buf[255]; |
wataloh | 0:20bce0dcc921 | 177 | memset(buf,'\0',sizeof(buf)); |
wataloh | 0:20bce0dcc921 | 178 | if(todo!=NULL) |
wataloh | 0:20bce0dcc921 | 179 | { |
wataloh | 2:dfe671e31221 | 180 | if(PREFERENCES::FLOW_CONTROL==true) |
wataloh | 1:b2a9a6f2c30e | 181 | { |
wataloh | 2:dfe671e31221 | 182 | PREFERENCES::_crc32 crc32; |
wataloh | 2:dfe671e31221 | 183 | todo->toBASE64(buf,&crc32); |
wataloh | 6:88cc04eb613a | 184 | self->piafLib->setAttribute(ATTR_ID_SENSE_VAL,strlen(buf),buf) != afSUCCESS ? SERIAL_PRINT_DBG("set attr failed!!\n") : NULL ; |
wataloh | 6:88cc04eb613a | 185 | self->piafLib->setAttribute64(3,crc32.ui32) != afSUCCESS ? SERIAL_PRINT_DBG("set attr failed!!\n") : NULL ; |
wataloh | 1:b2a9a6f2c30e | 186 | } |
wataloh | 1:b2a9a6f2c30e | 187 | else |
wataloh | 2:dfe671e31221 | 188 | { |
wataloh | 1:b2a9a6f2c30e | 189 | todo->toJSON(buf); |
wataloh | 13:c7d1ef8c57b3 | 190 | //SERIAL_PRINT_DBG("%s\n",buf); |
wataloh | 6:88cc04eb613a | 191 | self->piafLib->setAttribute(ATTR_ID_SENSE_VAL,strlen(buf),buf) != afSUCCESS ? SERIAL_PRINT_DBG("set attr failed!!\n") : NULL ; |
wataloh | 1:b2a9a6f2c30e | 192 | } |
wataloh | 0:20bce0dcc921 | 193 | } |
wataloh | 0:20bce0dcc921 | 194 | } |