Source code for the Curilights Controller. See http://www.saccade.com/writing/projects/CuriController/ for details.

Dependencies:   FatFileSystem mbed

This is the source code for the Curilights controller. This lets you interactively control a string of Curilights. It provides a simple click-wheel user interface for changing colors, brightness and behavior. It responds to movement and lighting.

Finished Controller

/media/uploads/isonno/nxp3872_controllerclose.jpg

System Block Diagram

/media/uploads/isonno/blockdiagram.png

Files at this revision

API Documentation at this revision

Comitter:
isonno
Date:
Mon Jan 16 06:33:34 2012 +0000
Parent:
1:d1da77023e6a
Commit message:
Experiment with MODSERIAL - just hung....

Changed in this revision

LightString.cpp Show annotated file Show diff for this revision Revisions of this file
LightString.h Show annotated file Show diff for this revision Revisions of this file
MODSERIAL.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/LightString.cpp	Sun Jan 15 09:07:04 2012 +0000
+++ b/LightString.cpp	Mon Jan 16 06:33:34 2012 +0000
@@ -6,43 +6,42 @@
 
 #include "HoldInterrupts.h"
 
-void LightString::AttachUSBSerial()
+LightString::LightString( PinName pin, int numLights )
+  : fPort( pin, NC ), fUSBPort( NC, USBRX ), fSnoop( numLights )
 {
-    fUSBPort.attach( this, &LightString::HandleUSBToLights );
+    fNumLights = numLights;
 }
 
-void LightString::HandleUSBToLights()
+void LightString::AttachUSBSerial()
 {
-    uint8_t buffer[512];
-    int i, count = 0;
-    while (fUSBPort.readable() && (count < sizeof(buffer)))
+    fUSBPort.attach( this, &LightString::HandleUSBToLights, MODSERIAL::RxIrq );
+}
+
+void LightString::HandleUSBToLights(MODSERIAL_IRQ_INFO * serialInfo)
+{
+    while (fUSBPort.readable())
     {
-        buffer[count++] = fUSBPort.getc();
-    }
-    for (i = 0; i < count; ++i)
-    {
-        while (! fPort.writeable()) {};  // Spin wait on the output
-        fPort.putc( buffer[i] );
+        fPort.putc( fUSBPort.getc() );
     }
 }
 
 void LightString::sendCommand1( uint8_t ch )
 {
-    HoldInterrupts noint();
+//    HoldInterrupts noint();
     
     fPort.putc( ch );
 }
 
 void LightString::sendCommand2( uint8_t ch1,  uint8_t ch2 )
 {
-    HoldInterrupts noint();
+//    HoldInterrupts noint();
     fPort.putc( ch1 );
     fPort.putc( ch2 );
 }
 
 void LightString::sendCommand3( uint8_t ch1,  uint8_t ch2, uint8_t ch3 )
 {
-    HoldInterrupts noint();
+//    HoldInterrupts noint();
     fPort.putc( ch1 );
     fPort.putc( ch2 );
     fPort.putc( ch3 );
--- a/LightString.h	Sun Jan 15 09:07:04 2012 +0000
+++ b/LightString.h	Mon Jan 16 06:33:34 2012 +0000
@@ -9,6 +9,14 @@
 #include "mbed.h"
 #endif
 
+// Use ModSerial, Andy Kirkham's interrupt based serial library.
+#ifndef MODSERIAL_H
+// For a 128 light string, setting all colors requires 3*127=384
+#define MODSERIAL_DEFAULT_RX_BUFFER_SIZE    384
+#define MODSERIAL_DEFAULT_TX_BUFFER_SIZE    128
+#include <MODSERIAL.h>
+#endif
+
 #ifndef __LIGHTSNOOP__
 #include "LightSnoop.h"
 #endif
@@ -21,11 +29,7 @@
 
     // Note: We rely on the default serial configuration of 9600 8N1,
     // this matches the CuriLights serial parameters.
-    LightString( PinName pin, int numLights )
-     : fPort( pin, NC ), fUSBPort( NC, USBRX ), fSnoop( numLights )
-    {
-        fNumLights = numLights;
-    }
+    LightString( PinName pin, int numLights );
 
     // This sends an initialization to the string and configures it.
     // If numLights is non-zero, the length of the light string is reset
@@ -69,7 +73,7 @@
     void sendCommand2( uint8_t ch1, uint8_t ch2 );
     void sendCommand3( uint8_t ch1, uint8_t ch2, uint8_t ch3 );
     
-    void HandleUSBToLights();
+    void HandleUSBToLights(MODSERIAL_IRQ_INFO * serialInfo);
     
     // Note the top red bit is stripped off to fit in the byte, other
     // code must manually add it back to the top bit if the light ID
@@ -87,8 +91,8 @@
         return color( rgb[0] - '0', rgb[1] - '0', rgb[2] - '0' );
     }
 */    
-    Serial fPort;
-    Serial fUSBPort;
+    MODSERIAL fPort;
+    MODSERIAL fUSBPort;
     int fNumLights;
     LightSnoop fSnoop;
 };
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MODSERIAL.lib	Mon Jan 16 06:33:34 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/AjK/libraries/MODSERIAL/lqybn0
\ No newline at end of file
--- a/main.cpp	Sun Jan 15 09:07:04 2012 +0000
+++ b/main.cpp	Mon Jan 16 06:33:34 2012 +0000
@@ -183,9 +183,14 @@
     ZMotionDetector mdetect( p28, p27 );    
     mdetect.SetExtendedRange( true );
 
+leds[0] = leds[1] = leds[2] = leds[3] = 0;
+leds[0] = 1;
     LightString curiLights( p9, 58 );
+leds[1] = 1;
     curiLights.InitLights();
+leds[2] = 1;
     curiLights.AttachUSBSerial();
+leds[3] = 1;
     
     RotaryEncoder knob( p17, p18 );
     PushButton knobButton( p30, "Knob" );