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

spi/AferoCommHndlr.cpp

Committer:
wataloh
Date:
2016-12-20
Revision:
0:20bce0dcc921
Child:
1:b2a9a6f2c30e

File content as of revision 0:20bce0dcc921:

#include "AferoCommHndlr.h"

static AferoCommHndlr *self = NULL;

AferoCommHndlr::AferoCommHndlr()
{
}

void
AferoCommHndlr::loop()
{
    piafLib->loop();
    todoQ->loop();
}

AferoCommHndlr*
AferoCommHndlr::create(Timer *timer, mbedSPI *spi)
{
     SERIAL_PRINT_DBG("HELLO\n");
     self = new AferoCommHndlr();
     self->timer = timer;
     self->piafLib = iafLib::create(SPI_SLAVE_INT,
       AferoCommHndlr::fco_irq_fall,
       AferoCommHndlr::myOnAttributeSet,
       AferoCommHndlr::myOnAttributeSetComplete, spi);
     self->todoQ = ToDoQ::create(AferoCommHndlr::onGetTodo);
     SERIAL_PRINT_DBG("AferoCommHndlr init done\n");
     return self;
}

void
AferoCommHndlr::myOnAttributeSet(
    const uint8_t requestId,
    const uint16_t attributeId,
    const uint16_t valueLen,
    const uint8_t *value)
{
    self->piafLib->setAttributeComplete(requestId, attributeId, valueLen, value);
}

void
AferoCommHndlr::myOnAttributeSetComplete(
    const uint8_t requestId,
    const uint16_t attributeId,
    const uint16_t valueLen,
    const uint8_t *value)
{
    if(attributeId==ATTR_ID_SENSING_INTERVAL)
    {
        
    }
    else if(attributeId==ATTR_ID_SENSE_VAL)
    {
        //self->timeoutUpload.attach(&AferoCommHndlr::updateToAferoCloud,1);
    }
}

void
AferoCommHndlr::fco_irq_fall()
{
    if(self->piafLib)
    {
        self->piafLib->mcuISR();
    }
}

void
AferoCommHndlr::onGetTodo(ToDo *todo)
{
    SERIAL_PRINT_DBG("AferoCommHndlr::onGetTodo()\n");
    char buf[255];
    memset(buf,'\0',sizeof(buf));
    if(todo!=NULL)
    {
        todo->toJSON(buf);
        SERIAL_PRINT_DBG("%s\n",buf);
        self->piafLib->setAttribute(ATTR_ID_SENSE_VAL,strlen(buf),buf);
    }
}
/*
void
AferoCommHndlr::onGetTodo(ToDo *todo)
{
    char buf[255];
    memset(buf,'\0',sizeof(buf));
    if(todo!=NULL)
    {
        todo->toJSON(buf);
        SERIAL_PRINT_DBG("%s\n",buf);
        self->piafLib->setAttribute(ATTR_ID_SENSE_VAL,strlen(buf),buf);
    }
}
*/