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
Revision 4:cfef06d8bb96, committed 2013-02-11
- Comitter:
- isonno
- Date:
- Mon Feb 11 05:04:18 2013 +0000
- Parent:
- 3:0ac64c4ca40f
- Commit message:
- Minor changes to add backlight routines. Not hooked up yet, shouldn't affect build operation.
Changed in this revision
--- a/FATFileSystem.lib Tue Jan 17 13:45:17 2012 +0000 +++ b/FATFileSystem.lib Mon Feb 11 05:04:18 2013 +0000 @@ -1,1 +1,1 @@ -http://mbed.co.uk/projects/libraries/svn/FATFileSystem/trunk@22 \ No newline at end of file +http://mbed.org/users/mbed_unsupported/code/FatFileSystem/#333d6e93e58f
--- a/LightString.h Tue Jan 17 13:45:17 2012 +0000 +++ b/LightString.h Mon Feb 11 05:04:18 2013 +0000 @@ -58,6 +58,8 @@ void FlushOutput() { HandleOutgoingData(); }; + void Debug(); + private: void sendCommand1( uint8_t ch ); void sendCommand2( uint8_t ch1, uint8_t ch2 );
--- a/NokiaLCD.h Tue Jan 17 13:45:17 2012 +0000 +++ b/NokiaLCD.h Mon Feb 11 05:04:18 2013 +0000 @@ -83,7 +83,8 @@ fState = on; fPWM = (!fState) ? 1.0 : 0.0; } - + + bool BacklightOn() const { return fState; } private: bool fState; @@ -129,8 +130,9 @@ void splash(int demo); // Backlight control - void fade_backlight( bool on ) { fBacklight.Fade( on ); } - void switch_backlight( bool on ) { fBacklight.Switch( on ); } + void fade_backlight( bool on ) { fBacklight.Fade( on ); } + void switch_backlight( bool on ){ fBacklight.Switch( on ); } + bool is_backlight_on() const { return fBacklight.BacklightOn(); } // Guts of the sprite/text rendering void draw_sprite( uint32_t fcolor, uint32_t bcolor,
--- a/SettingsMenu.cpp Tue Jan 17 13:45:17 2012 +0000 +++ b/SettingsMenu.cpp Mon Feb 11 05:04:18 2013 +0000 @@ -1,83 +1,108 @@ -// -// Settings menu implementation -// - -#include "SettingsMenu.h" -#include "UserInterface.h" -#include "SystemState.h" - -/* -class SettingsMenu : public UIMenu -{ -public: - SettingsMenu( CheapLCD * lcd, HomeMenu * parent ); - virtual ~SettingsMenu() {}; - -protected: - virtual void KnobPushed(); - virtual void AttachButton( PushButton * button ) - { button->attach( this, &SettingsMenu::KnobPushed ); } - -private: - HomeMenu * fParent; - CheapLCD * fLCD; -}; -*/ - -SettingsMenu::SettingsMenu( CheapLCD * lcd, HomeMenu * parent ) -: UIMenu( lcd, "Settings" ), - fParent( parent ), fLightSensorMenu( lcd, this ) -{ - fLabels.push_back( string( "Light Sensor" ) ); - fLabels.push_back( string( "Motion Sensor" ) ); - fLabels.push_back( string( "Defaults" ) ); - fLabels.push_back( string( "Debug" ) ); - fLabels.push_back( string( "Exit Settings" ) ); -} - -void SettingsMenu::KnobPushed() -{ - switch( SelectedItem() ) - { - case 0: - SwitchTo( &fLightSensorMenu ); - break; - - case 4: - SwitchTo( fParent ); - break; - } -} - -LightSensorMenu::LightSensorMenu( CheapLCD * lcd, SettingsMenu * parent ) -: UIMenu( lcd ), - fParent( parent ) -{ - fLabels.push_back( string( "Enable" ) ); - fLabels.push_back( string( "Disable" ) ); - fLabels.push_back( string( "Exit" ) ); - fLightState = gSystemState.GetLightSensor(); - fHeader = string( fLightState ? "Lt Sens On" : "Lt Sens Off" ); -} - -void LightSensorMenu::KnobPushed() -{ - switch( SelectedItem() ) - { - case 0: - fLightState = 1; - ChangeHeader( "Lt Sens On" ); - break; - - case 1: - fLightState = 0; - ChangeHeader( "Lt Sens Off" ); - break; - - case 2: - gSystemState.SetLightSensor( fLightState ); - SwitchTo( fParent ); - break; - } -} - \ No newline at end of file +// +// Settings menu implementation +// + +#include "SettingsMenu.h" +#include "UserInterface.h" +#include "SystemState.h" + +/* +class SettingsMenu : public UIMenu +{ +public: + SettingsMenu( CheapLCD * lcd, HomeMenu * parent ); + virtual ~SettingsMenu() {}; + +protected: + virtual void KnobPushed(); + virtual void AttachButton( PushButton * button ) + { button->attach( this, &SettingsMenu::KnobPushed ); } + +private: + HomeMenu * fParent; + CheapLCD * fLCD; +}; +*/ + +SettingsMenu::SettingsMenu( CheapLCD * lcd, HomeMenu * parent ) +: UIMenu( lcd, "Settings" ), + fParent( parent ), + fLightSensorMenu( lcd, this ), + fDebugMenu( lcd, this ) +{ + fLabels.push_back( string( "Light Sensor" ) ); + fLabels.push_back( string( "Motion Sensor" ) ); + fLabels.push_back( string( "Defaults" ) ); + fLabels.push_back( string( "Debug" ) ); + fLabels.push_back( string( "Exit Settings" ) ); +} + +void SettingsMenu::KnobPushed() +{ + switch( SelectedItem() ) + { + case 0: + SwitchTo( &fLightSensorMenu ); + break; + + case 3: + SwitchTo( &fDebugMenu ); + break; + + case 4: + SwitchTo( fParent ); + break; + } +} + +LightSensorMenu::LightSensorMenu( CheapLCD * lcd, SettingsMenu * parent ) +: UIMenu( lcd ), + fParent( parent ) +{ + fLabels.push_back( string( "Enable" ) ); + fLabels.push_back( string( "Disable" ) ); + fLabels.push_back( string( "Exit" ) ); + fLightState = gSystemState.GetLightSensor(); + fHeader = string( fLightState ? "Lt Sens On" : "Lt Sens Off" ); +} + +void LightSensorMenu::KnobPushed() +{ + switch( SelectedItem() ) + { + case 0: + fLightState = 1; + ChangeHeader( "Lt Sens On" ); + break; + + case 1: + fLightState = 0; + ChangeHeader( "Lt Sens Off" ); + break; + + case 2: + gSystemState.SetLightSensor( fLightState ); + SwitchTo( fParent ); + break; + } +} + +DebugMenu::DebugMenu( CheapLCD * lcd, SettingsMenu * parent ) +: UIMenu( lcd, "Debug" ), fParent( parent ) +{ + for (int i = 0; i < 5; ++i) + fLabels.push_back( string( "..." )); +} + +void DebugMenu::SetItem( int item, const char * name, int value ) +{ + char label[20]; + sprintf( label, "%s:%d", name, value ); + ChangeItem( item, label ); +} + +void DebugMenu::KnobPushed() +{ + // No matter what's selected, just exit + SwitchTo( fParent ); +}
--- a/SettingsMenu.h Tue Jan 17 13:45:17 2012 +0000 +++ b/SettingsMenu.h Mon Feb 11 05:04:18 2013 +0000 @@ -1,56 +1,58 @@ -#ifndef _SETTINGSMENU_ -#define _SETTINGSMENU_ - -#ifndef _UIMENU_ -#include "UIMenu.h" -#endif - -class HomeMenu; -class SettingsMenu; - -class DebugMenu : public UIMenu -{ -public: - DebugMenu( CheapLCD * lcd, SettingsMenu * parent ); - virtual ~DebugMenu() {}; - -protected: - virtual void KnobPushed(); - SETUP_KNOBPUSH_CALLBACK( DebugMenu ); - -private: - SettingsMenu * parent; -}; - -class LightSensorMenu : public UIMenu -{ -public: - LightSensorMenu( CheapLCD * lcd, SettingsMenu * parent ); - virtual ~LightSensorMenu() {}; - -protected: - virtual void KnobPushed(); - SETUP_KNOBPUSH_CALLBACK( LightSensorMenu ); - -private: - SettingsMenu * fParent; - int fLightState; -}; - -class SettingsMenu : public UIMenu -{ -public: - SettingsMenu( CheapLCD * lcd, HomeMenu * parent ); - virtual ~SettingsMenu() {}; - -protected: - virtual void KnobPushed(); - SETUP_KNOBPUSH_CALLBACK( SettingsMenu ); - -private: - HomeMenu * fParent; - LightSensorMenu fLightSensorMenu; -}; - - -#endif +#ifndef _SETTINGSMENU_ +#define _SETTINGSMENU_ + +#ifndef _UIMENU_ +#include "UIMenu.h" +#endif + +class HomeMenu; +class SettingsMenu; + +class DebugMenu : public UIMenu +{ +public: + DebugMenu( CheapLCD * lcd, SettingsMenu * parent ); + virtual ~DebugMenu() {}; + void SetItem( int item, const char * name, int value ); + +protected: + virtual void KnobPushed(); + SETUP_KNOBPUSH_CALLBACK( DebugMenu ); + +private: + SettingsMenu * fParent; +}; + +class LightSensorMenu : public UIMenu +{ +public: + LightSensorMenu( CheapLCD * lcd, SettingsMenu * parent ); + virtual ~LightSensorMenu() {}; + +protected: + virtual void KnobPushed(); + SETUP_KNOBPUSH_CALLBACK( LightSensorMenu ); + +private: + SettingsMenu * fParent; + int fLightState; +}; + +class SettingsMenu : public UIMenu +{ +public: + SettingsMenu( CheapLCD * lcd, HomeMenu * parent ); + virtual ~SettingsMenu() {}; + +protected: + virtual void KnobPushed(); + SETUP_KNOBPUSH_CALLBACK( SettingsMenu ); + +private: + HomeMenu * fParent; + LightSensorMenu fLightSensorMenu; + DebugMenu fDebugMenu; +}; + + +#endif
--- a/UIMenu.cpp Tue Jan 17 13:45:17 2012 +0000 +++ b/UIMenu.cpp Mon Feb 11 05:04:18 2013 +0000 @@ -69,7 +69,11 @@ fLCD->fade_backlight( false ); gScreenTimer.detach(); } - + +bool PushKnobUI::IsSleeping() const +{ + return ! fLCD->is_backlight_on(); +} //----------------------------------------------------
--- a/UIMenu.h Tue Jan 17 13:45:17 2012 +0000 +++ b/UIMenu.h Mon Feb 11 05:04:18 2013 +0000 @@ -45,6 +45,8 @@ // This gets called any time there's control // activity, it wakes up the LCD backlight. virtual void Wake(); + + virtual bool IsSleeping() const; protected:
--- a/UserInterface.cpp Tue Jan 17 13:45:17 2012 +0000 +++ b/UserInterface.cpp Mon Feb 11 05:04:18 2013 +0000 @@ -360,6 +360,7 @@ void HomeMenu::KnobPushed() { + // BUG: If display is asleep, should just wake it here. switch( SelectedItem() ) { case 0: DoLightController( kPatternSelector ); break;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Feb 11 05:04:18 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/e2ac27c8e93e \ No newline at end of file
--- a/mbed.lib Tue Jan 17 13:45:17 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/projects/libraries/svn/mbed/trunk@26 \ No newline at end of file