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:
Sun Jan 15 09:07:04 2012 +0000
Parent:
0:6da5625a6946
Child:
2:965388eecf95
Child:
3:0ac64c4ca40f
Commit message:
Add SettingsMenu functionality.

Changed in this revision

SettingsMenu.cpp Show annotated file Show diff for this revision Revisions of this file
SettingsMenu.h Show annotated file Show diff for this revision Revisions of this file
UIMenu.cpp Show annotated file Show diff for this revision Revisions of this file
UIMenu.h Show annotated file Show diff for this revision Revisions of this file
UserInterface.cpp Show annotated file Show diff for this revision Revisions of this file
UserInterface.h 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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SettingsMenu.cpp	Sun Jan 15 09:07:04 2012 +0000
@@ -0,0 +1,45 @@
+//
+// Settings menu implementation
+//
+
+#include "SettingsMenu.h"
+#include "UserInterface.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" ),
+  fLCD( lcd ), fParent( parent )
+{
+    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 4:
+        SwitchTo( fParent );
+        break;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SettingsMenu.h	Sun Jan 15 09:07:04 2012 +0000
@@ -0,0 +1,42 @@
+#ifndef _SETTINGSMENU_
+#define _SETTINGSMENU_
+
+#ifndef _UIMENU_
+#include "UIMenu.h"
+#endif
+
+class HomeMenu;
+
+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:
+    CheapLCD * fLCD;
+    HomeMenu * fParent;
+};
+
+class DebugMenu : public UIMenu
+{
+public:
+    DebugMenu( CheapLCD * lcd, SettingsMenu * parent );
+    virtual ~DebugMenu() {};
+
+protected:
+    virtual void KnobPushed();
+    virtual void AttachButton( PushButton * button )
+        { button->attach( this, &DebugMenu::KnobPushed ); }
+        
+private:
+    CheapLCD * fLCD;
+    SettingsMenu * parent;
+};
+
+#endif
--- a/UIMenu.cpp	Thu Dec 29 01:59:53 2011 +0000
+++ b/UIMenu.cpp	Sun Jan 15 09:07:04 2012 +0000
@@ -37,7 +37,7 @@
     }
 }
 
-void PushKnobUI::SwitchTo( PushKnobUI * other )
+void PushKnobUI::SwitchControl( PushKnobUI * other )
 {
     other->ConnectDevices( fKnob, fKnobButton );
     fKnob = NULL;
@@ -128,6 +128,13 @@
     Wake();
     printf("Selected %s\n\r", fLabels[fSelectedItem].c_str() );
 }
+
+void UIMenu::SwitchTo( UIMenu * nextMenu )
+{
+    Display( false );
+    SwitchControl( nextMenu );
+    nextMenu->Display( true );
+}
     
 // Parameters controlling the display layout
 const int kLineSpace = 20;
@@ -157,6 +164,7 @@
     if (on)
     {
         fDisplayOn = true;
+        fLCD->clear( BLACK, 0, 0, 131, kLineSpace + kTopGap );
         fLCD->clear( GRAY, 0, kLineSpace + kTopGap-1, 131, kLineSpace + kTopGap );
         if (! fHeader.empty())
             fLCD->draw_glyph_text( WHITE, BLACK, 2, kLineSpace-2, fHeader.c_str() );
--- a/UIMenu.h	Thu Dec 29 01:59:53 2011 +0000
+++ b/UIMenu.h	Sun Jan 15 09:07:04 2012 +0000
@@ -37,7 +37,7 @@
     // Hands over the control from one control item to another
     // (e.g., from a menu to a submenu).  Control actions are routed
     // to the other item)
-    virtual void SwitchTo( PushKnobUI * otherDevice );
+    virtual void SwitchControl( PushKnobUI * otherDevice );
     
     // This gets called any time there's control
     // activity, it wakes up the LCD backlight.
@@ -69,8 +69,12 @@
     // Call to add an item to the menu
     virtual void AddItem( const char * label );
     
-    // Turn on the display of the menu
+    // Turn on / check status the display of the menu
     virtual void Display( bool on );
+    virtual bool IsDisplayOn() const { return fDisplayOn; }
+    
+    // Switch to another menu
+    virtual void SwitchTo( UIMenu * nextMenu );
     
     // Returns the currently selected item
     virtual int SelectedItem() { return fSelectedItem; }
--- a/UserInterface.cpp	Thu Dec 29 01:59:53 2011 +0000
+++ b/UserInterface.cpp	Sun Jan 15 09:07:04 2012 +0000
@@ -6,6 +6,7 @@
 #include "UserInterface.h"
 #include "LightString.h"
 #include "SystemState.h"
+#include "SettingsMenu.h"
 
 #include "SDFileSystem.h"
 #include <string>
@@ -315,15 +316,16 @@
     Wake();
     Display( false );
     fLCD->erase();
+    SwitchControl( fParent );
     fParent->Display( true );
-    SwitchTo( fParent );
 }
     
 //================================================
 
 HomeMenu::HomeMenu( CheapLCD * lcd, LightString * lights ) 
 : UIMenu( lcd, "CuriLights" ), 
-  fLightController( this, lcd, lights )
+  fLightController( this, lcd, lights ),
+  fSettingsMenu( lcd, this )
 {
     fForcedOff = false;
     fLabels.push_back( string( "Patterns" ) );
@@ -352,7 +354,7 @@
 {
     Display( false );
     fLightController.SetSelector( sel );
-    SwitchTo( &fLightController );
+    SwitchControl( &fLightController );
     fLightController.Display( true );
 }
 
@@ -361,13 +363,17 @@
     switch( SelectedItem() )
     {
     case 0: DoLightController( kPatternSelector ); break;
-    case 1: DoLightController( kColorSelector ); break;
-    case 2: DoLightController( kWhiteSelector ); break;
+    case 1: DoLightController( kColorSelector );   break;
+    case 2: DoLightController( kWhiteSelector );   break;
+    
     case 3: DoToggleLightsOn(); 
             // The ForcedOff state can only be set via the menu
             fForcedOff = !fLightController.AreLightsOn();
             break;
             
+    case 4: SwitchTo( &fSettingsMenu );
+            break;
+            
     default: UIMenu::KnobPushed(); break;
     }
 }
--- a/UserInterface.h	Thu Dec 29 01:59:53 2011 +0000
+++ b/UserInterface.h	Sun Jan 15 09:07:04 2012 +0000
@@ -9,6 +9,10 @@
 #include "UIMenu.h"
 #endif
 
+#ifndef _SETTINGSMENU_
+#include "SettingsMenu.h"
+#endif
+
 class HomeMenu;
 class LightString;
 
@@ -35,6 +39,7 @@
     bool fLightsOn;
 };
 
+// PatternSelector lets you choose patterns stored on the SD card
 typedef vector<uint32_t> Pattern;
 
 class PatternSelector : public ControllerUI
@@ -148,6 +153,7 @@
     virtual void AttachButton( PushButton * button ) { button->attach( this, &HomeMenu::KnobPushed ); }
     
     LightController fLightController;
+    SettingsMenu fSettingsMenu;
 
 private:
     bool fForcedOff;
--- a/main.cpp	Thu Dec 29 01:59:53 2011 +0000
+++ b/main.cpp	Sun Jan 15 09:07:04 2012 +0000
@@ -15,6 +15,7 @@
 #include "PushButton.h"
 #include "SystemState.h"
 #include "UserInterface.h"
+#include "SettingsMenu.h"
 
 #include "RGBLED.h"