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

Revision:
1:b2a9a6f2c30e
Parent:
0:20bce0dcc921
Child:
2:dfe671e31221
diff -r 20bce0dcc921 -r b2a9a6f2c30e spi/AferoCommHndlr.cpp
--- a/spi/AferoCommHndlr.cpp	Tue Dec 20 01:51:02 2016 +0000
+++ b/spi/AferoCommHndlr.cpp	Thu Jan 19 09:17:16 2017 +0000
@@ -1,9 +1,34 @@
 #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()
+AferoCommHndlr::AferoCommHndlr() : flowControlEnabled(false)
 {
+    necochan = new Necochan();
 }
 
 void
@@ -19,12 +44,14 @@
      SERIAL_PRINT_DBG("HELLO\n");
      self = new AferoCommHndlr();
      self->timer = timer;
-     self->piafLib = iafLib::create(SPI_SLAVE_INT,
+     self->piafLib = iafLib::create((PinName)PINS::ASR_1::SPI::SR,
        AferoCommHndlr::fco_irq_fall,
        AferoCommHndlr::myOnAttributeSet,
        AferoCommHndlr::myOnAttributeSetComplete, spi);
      self->todoQ = ToDoQ::create(AferoCommHndlr::onGetTodo);
      SERIAL_PRINT_DBG("AferoCommHndlr init done\n");
+     self->piafLib->setAttribute8(1,1);
+     
      return self;
 }
 
@@ -45,6 +72,18 @@
     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;
+    
+    if(attributeId==1024)
+    {
+        self->necochan->push();
+    }
+    
     if(attributeId==ATTR_ID_SENSING_INTERVAL)
     {
         
@@ -72,22 +111,15 @@
     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);
+        if(self->flowControlEnabled==true)
+        {
+            
+        }
+        else
+        {    
+            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);
-    }
-}
-*/
\ No newline at end of file