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
Diff: spi/AferoCommHndlr.cpp
- Revision:
- 14:b205267fa5f6
- Parent:
- 13:c7d1ef8c57b3
- Child:
- 15:2c2c0a7c50c1
--- a/spi/AferoCommHndlr.cpp Fri Apr 28 10:11:07 2017 +0000 +++ b/spi/AferoCommHndlr.cpp Tue May 16 08:58:26 2017 +0000 @@ -1,35 +1,12 @@ #include "AferoCommHndlr.h" -Necochan *Necochan::ref = NULL; - -Necochan::Necochan() -{ - if(ref==NULL) - { - ref = this; - } - out = new DigitalOut(PTB8,1); -} - -void Necochan::release() -{ - DigitalOut *p = ref->out; - *p = 1; -} - -void Necochan::push() -{ - SERIAL_PRINT_DBG("push meow\n"); - *out = 0; - timeout.attach(&release,1); -} - static AferoCommHndlr *self = NULL; AferoCommHndlr::AferoCommHndlr() : flowControlEnabled(false) { - necochan = new Necochan(); deathWish = new Timeout(); + setAttrCmpDelay = new Timeout(); + _onGetTodoP = &AferoCommHndlr::_onGetTodo; } void @@ -42,10 +19,7 @@ void AferoCommHndlr::loop() { - for (int i=0; i< ((255/16)+3) ; ++i) - { - piafLib->loop(); - } + piafLib->loop(); todoQ->loop(); } @@ -94,15 +68,16 @@ const uint16_t valueLen, const uint8_t *value) { -// uint8_t *buf = new uint8_t[valueLen+1]; -// memset(buf,'\0',valueLen+1); -// memcpy(buf, value, valueLen); -// SERIAL_PRINT_DBG("attr id:%d value:%s\n",attributeId,buf); -// delete[] buf; -// buf = NULL; - - //self->deathWish->attach(&AferoCommHndlr::kick_the_bucket,10); - + self->_myOnAttributeSetComplete(requestId,attributeId,valueLen,value); +} + +void +AferoCommHndlr::_myOnAttributeSetComplete( + const uint8_t requestId, + const uint16_t attributeId, + const uint16_t valueLen, + const uint8_t *value) +{ int32_t sensing_interval; char *buf = NULL; if(attributeId >= 4 && attributeId <= 8) @@ -117,27 +92,27 @@ else if(attributeId==4) { buf = "PREFERENCES::SENSING_INTERVAL[SENSORS::ACCELEROMETER]"; - PREFERENCES::SENSING_INTERVAL[SENSORS::ACCELEROMETER] = self->sanitizeSensingInterval(attributeId,sensing_interval); + PREFERENCES::SENSING_INTERVAL[SENSORS::ACCELEROMETER] = sanitizeSensingInterval(attributeId,sensing_interval); } else if(attributeId==5) { buf = "PREFERENCES::SENSING_INTERVAL[SENSORS::COLOR]"; - PREFERENCES::SENSING_INTERVAL[SENSORS::COLOR] = self->sanitizeSensingInterval(attributeId,sensing_interval); + PREFERENCES::SENSING_INTERVAL[SENSORS::COLOR] = sanitizeSensingInterval(attributeId,sensing_interval); } else if(attributeId==6) { buf = "PREFERENCES::SENSING_INTERVAL[SENSORS::PRESSURE]"; - PREFERENCES::SENSING_INTERVAL[SENSORS::PRESSURE] = self->sanitizeSensingInterval(attributeId,sensing_interval); + PREFERENCES::SENSING_INTERVAL[SENSORS::PRESSURE] = sanitizeSensingInterval(attributeId,sensing_interval); } else if(attributeId==7) { buf = "PREFERENCES::SENSING_INTERVAL[SENSORS::CURRENT_TRANS]"; - PREFERENCES::SENSING_INTERVAL[SENSORS::CURRENT_TRANS] = self->sanitizeSensingInterval(attributeId,sensing_interval); + PREFERENCES::SENSING_INTERVAL[SENSORS::CURRENT_TRANS] = sanitizeSensingInterval(attributeId,sensing_interval); } else if(attributeId==8) { buf = "PREFERENCES::SENSING_INTERVAL[SENSORS::TEMPERATURE]"; - PREFERENCES::SENSING_INTERVAL[SENSORS::TEMPERATURE] = self->sanitizeSensingInterval(attributeId,sensing_interval); + PREFERENCES::SENSING_INTERVAL[SENSORS::TEMPERATURE] = sanitizeSensingInterval(attributeId,sensing_interval); } else if(attributeId==9) { @@ -151,14 +126,14 @@ } else if(attributeId==1024) { - self->necochan->push(); } if(attributeId >= 4 && attributeId <= 8) { SERIAL_PRINT_DBG("%s=%ld\n",buf,sensing_interval); } - + //_onGetTodoP = &AferoCommHndlr::_onGetTodo; + setAttrCmpDelay->attach(&onSetAttrCmpDelay,1); } void @@ -170,9 +145,10 @@ } } -void -AferoCommHndlr::onGetTodo(ToDo *todo) +bool +AferoCommHndlr::_onGetTodo(ToDo *todo) { + _onGetTodoP = &AferoCommHndlr::_onGetTodoFalsy; char buf[255]; memset(buf,'\0',sizeof(buf)); if(todo!=NULL) @@ -181,14 +157,54 @@ { PREFERENCES::_crc32 crc32; todo->toBASE64(buf,&crc32); - self->piafLib->setAttribute(ATTR_ID_SENSE_VAL,strlen(buf),buf) != afSUCCESS ? SERIAL_PRINT_DBG("set attr failed!!\n") : NULL ; - self->piafLib->setAttribute64(3,crc32.ui32) != afSUCCESS ? SERIAL_PRINT_DBG("set attr failed!!\n") : NULL ; + if(piafLib->setAttribute(ATTR_ID_SENSE_VAL,strlen(buf),buf) != afSUCCESS) + { + SERIAL_PRINT_DBG("set attr failed!!\n"); + return false; + } + if(piafLib->setAttribute64(3,crc32.ui32) != afSUCCESS) + { + SERIAL_PRINT_DBG("set attr failed!!\n"); + return false; + } } else { todo->toJSON(buf); - //SERIAL_PRINT_DBG("%s\n",buf); - self->piafLib->setAttribute(ATTR_ID_SENSE_VAL,strlen(buf),buf) != afSUCCESS ? SERIAL_PRINT_DBG("set attr failed!!\n") : NULL ; + int ret = afSUCCESS; + if((ret=piafLib->setAttribute(ATTR_ID_SENSE_VAL,strlen(buf),buf)) != afSUCCESS) + { + SERIAL_PRINT_DBG("set attr failed!! : %d\n", ret); + todo->error_count_inc(); + return false; + } + else + { + SERIAL_PRINT_DBG("set attr success!! : %d\n", ret); + SERIAL_PRINT_DBG("%s\n",buf); + todo->error_count_clear(); + return true; + } } } + return true; } + +bool +AferoCommHndlr::_onGetTodoFalsy(ToDo *todo) +{ + return false; +} + +bool +AferoCommHndlr::onGetTodo(ToDo *todo) +{ + return (self->*(self->_onGetTodoP))(todo); +} + +void +AferoCommHndlr::onSetAttrCmpDelay() +{ + SERIAL_PRINT_DBG("onSetAttrCmpDelay triggered\n"); + self->_onGetTodoP = &AferoCommHndlr::_onGetTodo; +} \ No newline at end of file