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 Orefatoi

Committer:
wataloh
Date:
Thu Jan 19 09:17:16 2017 +0000
Revision:
1:b2a9a6f2c30e
Parent:
0:20bce0dcc921
Child:
2:dfe671e31221
simplified

Who changed what in which revision?

UserRevisionLine numberNew 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 0:20bce0dcc921 32 }
wataloh 0:20bce0dcc921 33
wataloh 0:20bce0dcc921 34 void
wataloh 0:20bce0dcc921 35 AferoCommHndlr::loop()
wataloh 0:20bce0dcc921 36 {
wataloh 0:20bce0dcc921 37 piafLib->loop();
wataloh 0:20bce0dcc921 38 todoQ->loop();
wataloh 0:20bce0dcc921 39 }
wataloh 0:20bce0dcc921 40
wataloh 0:20bce0dcc921 41 AferoCommHndlr*
wataloh 0:20bce0dcc921 42 AferoCommHndlr::create(Timer *timer, mbedSPI *spi)
wataloh 0:20bce0dcc921 43 {
wataloh 0:20bce0dcc921 44 SERIAL_PRINT_DBG("HELLO\n");
wataloh 0:20bce0dcc921 45 self = new AferoCommHndlr();
wataloh 0:20bce0dcc921 46 self->timer = timer;
wataloh 1:b2a9a6f2c30e 47 self->piafLib = iafLib::create((PinName)PINS::ASR_1::SPI::SR,
wataloh 0:20bce0dcc921 48 AferoCommHndlr::fco_irq_fall,
wataloh 0:20bce0dcc921 49 AferoCommHndlr::myOnAttributeSet,
wataloh 0:20bce0dcc921 50 AferoCommHndlr::myOnAttributeSetComplete, spi);
wataloh 0:20bce0dcc921 51 self->todoQ = ToDoQ::create(AferoCommHndlr::onGetTodo);
wataloh 0:20bce0dcc921 52 SERIAL_PRINT_DBG("AferoCommHndlr init done\n");
wataloh 1:b2a9a6f2c30e 53 self->piafLib->setAttribute8(1,1);
wataloh 1:b2a9a6f2c30e 54
wataloh 0:20bce0dcc921 55 return self;
wataloh 0:20bce0dcc921 56 }
wataloh 0:20bce0dcc921 57
wataloh 0:20bce0dcc921 58 void
wataloh 0:20bce0dcc921 59 AferoCommHndlr::myOnAttributeSet(
wataloh 0:20bce0dcc921 60 const uint8_t requestId,
wataloh 0:20bce0dcc921 61 const uint16_t attributeId,
wataloh 0:20bce0dcc921 62 const uint16_t valueLen,
wataloh 0:20bce0dcc921 63 const uint8_t *value)
wataloh 0:20bce0dcc921 64 {
wataloh 0:20bce0dcc921 65 self->piafLib->setAttributeComplete(requestId, attributeId, valueLen, value);
wataloh 0:20bce0dcc921 66 }
wataloh 0:20bce0dcc921 67
wataloh 0:20bce0dcc921 68 void
wataloh 0:20bce0dcc921 69 AferoCommHndlr::myOnAttributeSetComplete(
wataloh 0:20bce0dcc921 70 const uint8_t requestId,
wataloh 0:20bce0dcc921 71 const uint16_t attributeId,
wataloh 0:20bce0dcc921 72 const uint16_t valueLen,
wataloh 0:20bce0dcc921 73 const uint8_t *value)
wataloh 0:20bce0dcc921 74 {
wataloh 1:b2a9a6f2c30e 75 uint8_t *buf = new uint8_t[valueLen+1];
wataloh 1:b2a9a6f2c30e 76 memset(buf,'\0',valueLen+1);
wataloh 1:b2a9a6f2c30e 77 memcpy(buf, value, valueLen);
wataloh 1:b2a9a6f2c30e 78 SERIAL_PRINT_DBG("attr id:%d value:%s\n",attributeId,buf);
wataloh 1:b2a9a6f2c30e 79 delete[] buf;
wataloh 1:b2a9a6f2c30e 80 buf = NULL;
wataloh 1:b2a9a6f2c30e 81
wataloh 1:b2a9a6f2c30e 82 if(attributeId==1024)
wataloh 1:b2a9a6f2c30e 83 {
wataloh 1:b2a9a6f2c30e 84 self->necochan->push();
wataloh 1:b2a9a6f2c30e 85 }
wataloh 1:b2a9a6f2c30e 86
wataloh 0:20bce0dcc921 87 if(attributeId==ATTR_ID_SENSING_INTERVAL)
wataloh 0:20bce0dcc921 88 {
wataloh 0:20bce0dcc921 89
wataloh 0:20bce0dcc921 90 }
wataloh 0:20bce0dcc921 91 else if(attributeId==ATTR_ID_SENSE_VAL)
wataloh 0:20bce0dcc921 92 {
wataloh 0:20bce0dcc921 93 //self->timeoutUpload.attach(&AferoCommHndlr::updateToAferoCloud,1);
wataloh 0:20bce0dcc921 94 }
wataloh 0:20bce0dcc921 95 }
wataloh 0:20bce0dcc921 96
wataloh 0:20bce0dcc921 97 void
wataloh 0:20bce0dcc921 98 AferoCommHndlr::fco_irq_fall()
wataloh 0:20bce0dcc921 99 {
wataloh 0:20bce0dcc921 100 if(self->piafLib)
wataloh 0:20bce0dcc921 101 {
wataloh 0:20bce0dcc921 102 self->piafLib->mcuISR();
wataloh 0:20bce0dcc921 103 }
wataloh 0:20bce0dcc921 104 }
wataloh 0:20bce0dcc921 105
wataloh 0:20bce0dcc921 106 void
wataloh 0:20bce0dcc921 107 AferoCommHndlr::onGetTodo(ToDo *todo)
wataloh 0:20bce0dcc921 108 {
wataloh 0:20bce0dcc921 109 SERIAL_PRINT_DBG("AferoCommHndlr::onGetTodo()\n");
wataloh 0:20bce0dcc921 110 char buf[255];
wataloh 0:20bce0dcc921 111 memset(buf,'\0',sizeof(buf));
wataloh 0:20bce0dcc921 112 if(todo!=NULL)
wataloh 0:20bce0dcc921 113 {
wataloh 1:b2a9a6f2c30e 114 if(self->flowControlEnabled==true)
wataloh 1:b2a9a6f2c30e 115 {
wataloh 1:b2a9a6f2c30e 116
wataloh 1:b2a9a6f2c30e 117 }
wataloh 1:b2a9a6f2c30e 118 else
wataloh 1:b2a9a6f2c30e 119 {
wataloh 1:b2a9a6f2c30e 120 todo->toJSON(buf);
wataloh 1:b2a9a6f2c30e 121 SERIAL_PRINT_DBG("%s\n",buf);
wataloh 1:b2a9a6f2c30e 122 self->piafLib->setAttribute(ATTR_ID_SENSE_VAL,strlen(buf),buf);
wataloh 1:b2a9a6f2c30e 123 }
wataloh 0:20bce0dcc921 124 }
wataloh 0:20bce0dcc921 125 }