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@6:88cc04eb613a, 2017-03-22 (annotated)
- Committer:
- wataloh
- Date:
- Wed Mar 22 23:39:41 2017 +0000
- Revision:
- 6:88cc04eb613a
- Parent:
- 4:b38e09f24711
- Child:
- 13:c7d1ef8c57b3
New calib vals for LED RGB.
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 | 0:20bce0dcc921 | 45 | piafLib->loop(); |
wataloh | 0:20bce0dcc921 | 46 | todoQ->loop(); |
wataloh | 0:20bce0dcc921 | 47 | } |
wataloh | 0:20bce0dcc921 | 48 | |
wataloh | 0:20bce0dcc921 | 49 | AferoCommHndlr* |
wataloh | 0:20bce0dcc921 | 50 | AferoCommHndlr::create(Timer *timer, mbedSPI *spi) |
wataloh | 0:20bce0dcc921 | 51 | { |
wataloh | 0:20bce0dcc921 | 52 | SERIAL_PRINT_DBG("HELLO\n"); |
wataloh | 0:20bce0dcc921 | 53 | self = new AferoCommHndlr(); |
wataloh | 0:20bce0dcc921 | 54 | self->timer = timer; |
wataloh | 1:b2a9a6f2c30e | 55 | self->piafLib = iafLib::create((PinName)PINS::ASR_1::SPI::SR, |
wataloh | 0:20bce0dcc921 | 56 | AferoCommHndlr::fco_irq_fall, |
wataloh | 0:20bce0dcc921 | 57 | AferoCommHndlr::myOnAttributeSet, |
wataloh | 0:20bce0dcc921 | 58 | AferoCommHndlr::myOnAttributeSetComplete, spi); |
wataloh | 0:20bce0dcc921 | 59 | self->todoQ = ToDoQ::create(AferoCommHndlr::onGetTodo); |
wataloh | 0:20bce0dcc921 | 60 | SERIAL_PRINT_DBG("AferoCommHndlr init done\n"); |
wataloh | 6:88cc04eb613a | 61 | self->piafLib->setAttribute8(1,1) != afSUCCESS ? SERIAL_PRINT_DBG("set attr failed!!\n") : NULL ; |
wataloh | 1:b2a9a6f2c30e | 62 | |
wataloh | 0:20bce0dcc921 | 63 | return self; |
wataloh | 0:20bce0dcc921 | 64 | } |
wataloh | 0:20bce0dcc921 | 65 | |
wataloh | 0:20bce0dcc921 | 66 | void |
wataloh | 0:20bce0dcc921 | 67 | AferoCommHndlr::myOnAttributeSet( |
wataloh | 0:20bce0dcc921 | 68 | const uint8_t requestId, |
wataloh | 0:20bce0dcc921 | 69 | const uint16_t attributeId, |
wataloh | 0:20bce0dcc921 | 70 | const uint16_t valueLen, |
wataloh | 0:20bce0dcc921 | 71 | const uint8_t *value) |
wataloh | 0:20bce0dcc921 | 72 | { |
wataloh | 6:88cc04eb613a | 73 | self->piafLib->setAttributeComplete(requestId, attributeId, valueLen, value) != afSUCCESS ? SERIAL_PRINT_DBG("set attr failed!!\n") : NULL ; |
wataloh | 0:20bce0dcc921 | 74 | } |
wataloh | 0:20bce0dcc921 | 75 | |
wataloh | 4:b38e09f24711 | 76 | int32_t |
wataloh | 4:b38e09f24711 | 77 | AferoCommHndlr::sanitizeSensingInterval(uint16_t attributeId, int32_t interval) |
wataloh | 4:b38e09f24711 | 78 | { |
wataloh | 4:b38e09f24711 | 79 | if(interval < 5) |
wataloh | 4:b38e09f24711 | 80 | { |
wataloh | 4:b38e09f24711 | 81 | interval = 5; |
wataloh | 6:88cc04eb613a | 82 | self->piafLib->setAttribute32(attributeId, interval) != afSUCCESS ? SERIAL_PRINT_DBG("set attr failed!!\n") : NULL ; |
wataloh | 4:b38e09f24711 | 83 | } |
wataloh | 4:b38e09f24711 | 84 | return interval; |
wataloh | 4:b38e09f24711 | 85 | } |
wataloh | 4:b38e09f24711 | 86 | |
wataloh | 0:20bce0dcc921 | 87 | void |
wataloh | 0:20bce0dcc921 | 88 | AferoCommHndlr::myOnAttributeSetComplete( |
wataloh | 0:20bce0dcc921 | 89 | const uint8_t requestId, |
wataloh | 0:20bce0dcc921 | 90 | const uint16_t attributeId, |
wataloh | 0:20bce0dcc921 | 91 | const uint16_t valueLen, |
wataloh | 0:20bce0dcc921 | 92 | const uint8_t *value) |
wataloh | 0:20bce0dcc921 | 93 | { |
wataloh | 2:dfe671e31221 | 94 | // uint8_t *buf = new uint8_t[valueLen+1]; |
wataloh | 2:dfe671e31221 | 95 | // memset(buf,'\0',valueLen+1); |
wataloh | 2:dfe671e31221 | 96 | // memcpy(buf, value, valueLen); |
wataloh | 2:dfe671e31221 | 97 | // SERIAL_PRINT_DBG("attr id:%d value:%s\n",attributeId,buf); |
wataloh | 2:dfe671e31221 | 98 | // delete[] buf; |
wataloh | 2:dfe671e31221 | 99 | // buf = NULL; |
wataloh | 1:b2a9a6f2c30e | 100 | |
wataloh | 6:88cc04eb613a | 101 | //self->deathWish->attach(&AferoCommHndlr::kick_the_bucket,10); |
wataloh | 6:88cc04eb613a | 102 | |
wataloh | 4:b38e09f24711 | 103 | int32_t sensing_interval; |
wataloh | 4:b38e09f24711 | 104 | char *buf = NULL; |
wataloh | 4:b38e09f24711 | 105 | if(attributeId >= 4 && attributeId <= 8) |
wataloh | 4:b38e09f24711 | 106 | { |
wataloh | 4:b38e09f24711 | 107 | sensing_interval = *((int32_t*)value); |
wataloh | 4:b38e09f24711 | 108 | } |
wataloh | 4:b38e09f24711 | 109 | |
wataloh | 2:dfe671e31221 | 110 | if(attributeId==2) |
wataloh | 2:dfe671e31221 | 111 | { |
wataloh | 2:dfe671e31221 | 112 | PREFERENCES::CRC32.ui32 = *((uint32_t*)value); |
wataloh | 2:dfe671e31221 | 113 | } |
wataloh | 2:dfe671e31221 | 114 | else if(attributeId==4) |
wataloh | 2:dfe671e31221 | 115 | { |
wataloh | 4:b38e09f24711 | 116 | buf = "PREFERENCES::SENSING_INTERVAL[SENSORS::ACCELEROMETER]"; |
wataloh | 4:b38e09f24711 | 117 | PREFERENCES::SENSING_INTERVAL[SENSORS::ACCELEROMETER] = self->sanitizeSensingInterval(attributeId,sensing_interval); |
wataloh | 2:dfe671e31221 | 118 | } |
wataloh | 2:dfe671e31221 | 119 | else if(attributeId==5) |
wataloh | 2:dfe671e31221 | 120 | { |
wataloh | 4:b38e09f24711 | 121 | buf = "PREFERENCES::SENSING_INTERVAL[SENSORS::COLOR]"; |
wataloh | 4:b38e09f24711 | 122 | PREFERENCES::SENSING_INTERVAL[SENSORS::COLOR] = self->sanitizeSensingInterval(attributeId,sensing_interval); |
wataloh | 2:dfe671e31221 | 123 | } |
wataloh | 2:dfe671e31221 | 124 | else if(attributeId==6) |
wataloh | 2:dfe671e31221 | 125 | { |
wataloh | 4:b38e09f24711 | 126 | buf = "PREFERENCES::SENSING_INTERVAL[SENSORS::PRESSURE]"; |
wataloh | 4:b38e09f24711 | 127 | PREFERENCES::SENSING_INTERVAL[SENSORS::PRESSURE] = self->sanitizeSensingInterval(attributeId,sensing_interval); |
wataloh | 2:dfe671e31221 | 128 | } |
wataloh | 2:dfe671e31221 | 129 | else if(attributeId==7) |
wataloh | 2:dfe671e31221 | 130 | { |
wataloh | 4:b38e09f24711 | 131 | buf = "PREFERENCES::SENSING_INTERVAL[SENSORS::CURRENT_TRANS]"; |
wataloh | 4:b38e09f24711 | 132 | PREFERENCES::SENSING_INTERVAL[SENSORS::CURRENT_TRANS] = self->sanitizeSensingInterval(attributeId,sensing_interval); |
wataloh | 2:dfe671e31221 | 133 | } |
wataloh | 2:dfe671e31221 | 134 | else if(attributeId==8) |
wataloh | 2:dfe671e31221 | 135 | { |
wataloh | 4:b38e09f24711 | 136 | buf = "PREFERENCES::SENSING_INTERVAL[SENSORS::TEMPERATURE]"; |
wataloh | 4:b38e09f24711 | 137 | PREFERENCES::SENSING_INTERVAL[SENSORS::TEMPERATURE] = self->sanitizeSensingInterval(attributeId,sensing_interval); |
wataloh | 2:dfe671e31221 | 138 | } |
wataloh | 2:dfe671e31221 | 139 | else if(attributeId==9) |
wataloh | 2:dfe671e31221 | 140 | { |
wataloh | 2:dfe671e31221 | 141 | SERIAL_PRINT_DBG("time stamp:%ld\n", *((uint32_t*)value)); |
wataloh | 6:88cc04eb613a | 142 | time_t t; |
wataloh | 6:88cc04eb613a | 143 | RTC_GET_UTC(t); |
wataloh | 6:88cc04eb613a | 144 | if(*((uint32_t*)value) > ((uint32_t)t)) |
wataloh | 6:88cc04eb613a | 145 | { |
wataloh | 6:88cc04eb613a | 146 | RTC_Handler::getInstance()->setUTC(*((uint32_t*)value)); |
wataloh | 6:88cc04eb613a | 147 | } |
wataloh | 2:dfe671e31221 | 148 | } |
wataloh | 2:dfe671e31221 | 149 | else if(attributeId==1024) |
wataloh | 1:b2a9a6f2c30e | 150 | { |
wataloh | 1:b2a9a6f2c30e | 151 | self->necochan->push(); |
wataloh | 1:b2a9a6f2c30e | 152 | } |
wataloh | 4:b38e09f24711 | 153 | |
wataloh | 4:b38e09f24711 | 154 | if(attributeId >= 4 && attributeId <= 8) |
wataloh | 4:b38e09f24711 | 155 | { |
wataloh | 4:b38e09f24711 | 156 | SERIAL_PRINT_DBG("%s=%ld\n",buf,sensing_interval); |
wataloh | 4:b38e09f24711 | 157 | } |
wataloh | 4:b38e09f24711 | 158 | |
wataloh | 0:20bce0dcc921 | 159 | } |
wataloh | 0:20bce0dcc921 | 160 | |
wataloh | 0:20bce0dcc921 | 161 | void |
wataloh | 0:20bce0dcc921 | 162 | AferoCommHndlr::fco_irq_fall() |
wataloh | 0:20bce0dcc921 | 163 | { |
wataloh | 0:20bce0dcc921 | 164 | if(self->piafLib) |
wataloh | 0:20bce0dcc921 | 165 | { |
wataloh | 0:20bce0dcc921 | 166 | self->piafLib->mcuISR(); |
wataloh | 0:20bce0dcc921 | 167 | } |
wataloh | 0:20bce0dcc921 | 168 | } |
wataloh | 0:20bce0dcc921 | 169 | |
wataloh | 0:20bce0dcc921 | 170 | void |
wataloh | 0:20bce0dcc921 | 171 | AferoCommHndlr::onGetTodo(ToDo *todo) |
wataloh | 0:20bce0dcc921 | 172 | { |
wataloh | 0:20bce0dcc921 | 173 | char buf[255]; |
wataloh | 0:20bce0dcc921 | 174 | memset(buf,'\0',sizeof(buf)); |
wataloh | 0:20bce0dcc921 | 175 | if(todo!=NULL) |
wataloh | 0:20bce0dcc921 | 176 | { |
wataloh | 2:dfe671e31221 | 177 | if(PREFERENCES::FLOW_CONTROL==true) |
wataloh | 1:b2a9a6f2c30e | 178 | { |
wataloh | 2:dfe671e31221 | 179 | PREFERENCES::_crc32 crc32; |
wataloh | 2:dfe671e31221 | 180 | todo->toBASE64(buf,&crc32); |
wataloh | 6:88cc04eb613a | 181 | self->piafLib->setAttribute(ATTR_ID_SENSE_VAL,strlen(buf),buf) != afSUCCESS ? SERIAL_PRINT_DBG("set attr failed!!\n") : NULL ; |
wataloh | 6:88cc04eb613a | 182 | self->piafLib->setAttribute64(3,crc32.ui32) != afSUCCESS ? SERIAL_PRINT_DBG("set attr failed!!\n") : NULL ; |
wataloh | 1:b2a9a6f2c30e | 183 | } |
wataloh | 1:b2a9a6f2c30e | 184 | else |
wataloh | 2:dfe671e31221 | 185 | { |
wataloh | 1:b2a9a6f2c30e | 186 | todo->toJSON(buf); |
wataloh | 1:b2a9a6f2c30e | 187 | SERIAL_PRINT_DBG("%s\n",buf); |
wataloh | 6:88cc04eb613a | 188 | self->piafLib->setAttribute(ATTR_ID_SENSE_VAL,strlen(buf),buf) != afSUCCESS ? SERIAL_PRINT_DBG("set attr failed!!\n") : NULL ; |
wataloh | 1:b2a9a6f2c30e | 189 | } |
wataloh | 0:20bce0dcc921 | 190 | } |
wataloh | 0:20bce0dcc921 | 191 | } |