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

LightString.cpp

Committer:
isonno
Date:
2012-01-16
Revision:
2:965388eecf95
Parent:
0:6da5625a6946

File content as of revision 2:965388eecf95:

//
// Interface to the CuriLights
//

#include "LightString.h"

#include "HoldInterrupts.h"

LightString::LightString( PinName pin, int numLights )
  : fPort( pin, NC ), fUSBPort( NC, USBRX ), fSnoop( numLights )
{
    fNumLights = numLights;
}

void LightString::AttachUSBSerial()
{
    fUSBPort.attach( this, &LightString::HandleUSBToLights, MODSERIAL::RxIrq );
}

void LightString::HandleUSBToLights(MODSERIAL_IRQ_INFO * serialInfo)
{
    while (fUSBPort.readable())
    {
        fPort.putc( fUSBPort.getc() );
    }
}

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 );
}