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:
- 3:0ac64c4ca40f
- Parent:
- 0:6da5625a6946
--- a/LightString.cpp Sun Jan 15 09:07:04 2012 +0000 +++ b/LightString.cpp Tue Jan 17 13:45:17 2012 +0000 @@ -6,46 +6,65 @@ #include "HoldInterrupts.h" -void LightString::AttachUSBSerial() +#include "RGBLED.h" + +LightString::LightString( PinName pin, int numLights ) + : fLightsPort( pin, NC ), fUSBPort( NC, USBRX ), fSnoop( numLights ) { - fUSBPort.attach( this, &LightString::HandleUSBToLights ); + fNumLights = numLights; + fBufferInPos = 0; + fBufferOutPos = 0; + // Attaches the USB port to the light port, so + // data is passed straight through from the host to the lights. + fUSBPort.attach( this, &LightString::HandleIncomingData ); +// fLightsPort.attach( this, &LightString::HandleOutgoingData ); } -void LightString::HandleUSBToLights() +void LightString::HandleIncomingData() { - uint8_t buffer[512]; - int i, count = 0; - while (fUSBPort.readable() && (count < sizeof(buffer))) + while (fUSBPort.readable()) { - buffer[count++] = fUSBPort.getc(); + fBuffer[fBufferInPos] = fUSBPort.getc(); + fBufferInPos++; + if (fBufferInPos >= sizeof( fBuffer )) + fBufferInPos = 0; + if (fBufferInPos == fBufferOutPos) + printf("Buffer overflow\r\n"); } - for (i = 0; i < count; ++i) +} + +void LightString::HandleOutgoingData() +{ + gDebugLED.Set( 700 ); + while ((fBufferOutPos != fBufferInPos) && fLightsPort.writeable()) { - while (! fPort.writeable()) {}; // Spin wait on the output - fPort.putc( buffer[i] ); + fLightsPort.putc( fBuffer[fBufferOutPos++] ); + if (fBufferOutPos >= sizeof( fBuffer )) + fBufferOutPos = 0; } + gDebugLED.Set( (fBufferOutPos == fBufferInPos) ? 0 : 70 ); } void LightString::sendCommand1( uint8_t ch ) { HoldInterrupts noint(); - fPort.putc( ch ); + fLightsPort.putc( ch ); } void LightString::sendCommand2( uint8_t ch1, uint8_t ch2 ) { HoldInterrupts noint(); - fPort.putc( ch1 ); - fPort.putc( ch2 ); + fLightsPort.putc( ch1 ); + fLightsPort.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 ); + fLightsPort.putc( ch1 ); + fLightsPort.putc( ch2 ); + fLightsPort.putc( ch3 ); } void LightString::InitLights( int numLights )