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
System Block Diagram
Diff: LightString.cpp
- Revision:
- 0:6da5625a6946
- Child:
- 2:965388eecf95
- Child:
- 3:0ac64c4ca40f
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LightString.cpp Thu Dec 29 01:59:53 2011 +0000 @@ -0,0 +1,83 @@ +// +// Interface to the CuriLights +// + +#include "LightString.h" + +#include "HoldInterrupts.h" + +void LightString::AttachUSBSerial() +{ + fUSBPort.attach( this, &LightString::HandleUSBToLights ); +} + +void LightString::HandleUSBToLights() +{ + uint8_t buffer[512]; + int i, count = 0; + while (fUSBPort.readable() && (count < sizeof(buffer))) + { + buffer[count++] = fUSBPort.getc(); + } + for (i = 0; i < count; ++i) + { + while (! fPort.writeable()) {}; // Spin wait on the output + fPort.putc( buffer[i] ); + } +} + +void LightString::sendCommand1( uint8_t ch ) +{ + HoldInterrupts noint(); + + fPort.putc( ch ); +} + +void LightString::sendCommand2( uint8_t ch1, uint8_t ch2 ) +{ + HoldInterrupts noint(); + fPort.putc( ch1 ); + fPort.putc( ch2 ); +} + +void LightString::sendCommand3( uint8_t ch1, uint8_t ch2, uint8_t ch3 ) +{ + HoldInterrupts noint(); + fPort.putc( ch1 ); + fPort.putc( ch2 ); + fPort.putc( ch3 ); +} + +void LightString::InitLights( int numLights ) +{ + if (numLights) + fNumLights = numLights; + + printf("Init called\n\r"); + sendCommand2( 'I', 0 ); + sendCommand2( 'N', fNumLights ); +} + +void LightString::SetOneColor( int color, uint8_t id ) +{ + uint8_t redBit, c; + + c = colorByte( color, redBit ); + + sendCommand3( 'C', id | redBit, c ); +} + +void LightString::SetAllLights( int color ) +{ + int i; + for (i = 0; i < fNumLights; ++i) + SetOneColor( color, i ); +} + +void LightString::SetColors( const vector<int>& colorList ) +{ + int num = fNumLights < colorList.size() ? fNumLights : colorList.size(); + + for (int i = 0; i < num; ++i) + SetOneColor( colorList[i], i ); +} \ No newline at end of file