projectwerk

Dependencies:   NeoPixelString SimplyLog

Fork of NeoPixelI2cSlave by Nico De Witte

Revision:
3:02931c2b1e82
Parent:
2:e0269262d1f2
--- a/neopixel_i2c_daemon.cpp	Sun Oct 25 11:36:21 2015 +0000
+++ b/neopixel_i2c_daemon.cpp	Sat Jan 09 13:10:19 2016 +0000
@@ -1,38 +1,31 @@
 #include "neopixel_i2c_daemon.h"
-
+#include "strobe.h"
 #define DEBUG_MODE 1
 #include "log.h"
-
 NeoPixelI2cDaemon::NeoPixelI2cDaemon(I2cDevice * i2c, PinName alive_pin) : alive(alive_pin) {
     this->i2c = i2c;
     cAlive = 0;
 }
-
 void NeoPixelI2cDaemon::attachPixelString(NeoPixelString * pixelstring) {
     pixelstrings.push_back(pixelstring);   
 }
-
 void NeoPixelI2cDaemon::allOff(void) {
     for (unsigned int i = 0; i < pixelstrings.size(); i++) {
         pixelstrings[i]->update(Colors::Black);
     }   
 }
-
 void NeoPixelI2cDaemon::allSingleColor(neopixel::Pixel singlecolor) {
     for (unsigned int i = 0; i < pixelstrings.size(); i++) {
         pixelstrings[i]->update(singlecolor);
     }   
 }
-
 void NeoPixelI2cDaemon::diagnoseAll(void) {
     for (unsigned int i = 0; i < pixelstrings.size(); i++) {
         pixelstrings[i]->diagnose();
     }   
 }
-
 void NeoPixelI2cDaemon::listen(bool blocking=false) {
     char buffer[10];
-
     while (blocking) {
         // Check for i2c message
         int i = i2c->receive();
@@ -40,22 +33,18 @@
             // ReadAddressed - the master has requested a read from this slave
             // WriteAddressed - the master is writing to this slave
             // WriteGeneral - the master is writing to all slave
-
         switch (i) {
-
             case I2cDevice::ReadAddressed:
                 char sendbuffer[1];
                 sendbuffer[0] = pixelstrings.size();
                 int result = i2c->write(sendbuffer, sizeof(sendbuffer));
                 i2c->stop();
-
                 if (!result) {     // 0 on success, non-0 otherwise
                     SimplyLog::Log::i("Send info to master successfully\r\n");
                 } else {
                     SimplyLog::Log::w("Send info to master failed\r\n");
                 }
                 break;
-
             case I2cDevice::WriteAddressed:
             {
                 // First we read the command byte
@@ -68,15 +57,15 @@
                         i2c->stop();    // Necessary !! Otherwise write will fail on master end
                         SimplyLog::Log::i("Killing all neopixel leds\r\n");
                         allOff();
+                        
                         break;
-
                     case DIAGNOSTIC:
                         i2c->stop();    // Necessary !! Otherwise write will fail on master end
                         SimplyLog::Log::i("Executing diagnostic of neopixel strings\r\n");
                         diagnoseAll();
                         SimplyLog::Log::i("Diagnostic finished\r\n");
+                        
                         break;
-
                     case SINGLE_COLOR:
                         // Expect 3 more bytes [red green blue]
                         if(!i2c->read(buffer, 3)) {      //0 on success, non-0 otherwise
@@ -85,11 +74,20 @@
                             color.green = buffer[1];
                             color.blue = buffer[2];
                             allSingleColor(color);
-
                             SimplyLog::Log::i("Setting single color [r,g,b] = [%d,%d,%d]\r\n", color.red, color.green, color.blue);
                         } else {
                             SimplyLog::Log::w("Single color set received with missing params\r\n");
                         }
+                        
+                        break;
+                        
+                    
+                    case STROBO:
+                        i2c->stop();
+                        SimplyLog::Log::w("We gaan een ticker aanroepen\r\n");
+                        hanzi= new Strobe(this);
+                        hanzi->strstart();    
+                        SimplyLog::Log::w("Single color set received with missing params\r\n");
                         break;
                     
                     default:
@@ -98,7 +96,6 @@
                 }
             }
         }
-
         for(int i = 0; i < 10; i++) {
             buffer[i] = 0;    // Clear buffer
         }
@@ -108,5 +105,7 @@
         if (!cAlive) {
             alive = !alive;
         }
+        
+        hanzi->execute();
     }
 }
\ No newline at end of file