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

UIMenu.h

Committer:
isonno
Date:
2012-01-15
Revision:
1:d1da77023e6a
Parent:
0:6da5625a6946
Child:
3:0ac64c4ca40f

File content as of revision 1:d1da77023e6a:

//
// Click-knob menu implementation
//

#ifndef _UIMENU_
#define _UIMENU_

#include <vector>
#include <string>

#ifndef _ROTARY_ENCODER_
#include "RotaryEncoder.h"
#endif

#ifndef _PUSHBUTTON_
#include "PushButton.h"
#endif

class CheapLCD;

#define SETUP_KNOB_CALLBACKS( className ) \
    virtual void AttachKnob( RotaryEncoder * knob ) { knob->attach( this, &className::KnobMoved ); }\
    virtual void AttachButton( PushButton * button ) { button->attach( this, &className::KnobPushed ); }

// This class manages the input hardware
class PushKnobUI
{
public:
    PushKnobUI( CheapLCD * lcd ) : fKnob( NULL ), fKnobButton( NULL ), fLCD( lcd ) {}
    virtual ~PushKnobUI() {}

    // Call this with pointers to the devices when the menu is active.
    // When another screen is active, pass NULL pointers to de-activate
    // the menu.
    virtual void ConnectDevices( RotaryEncoder * knob, PushButton * button );
    
    // 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 SwitchControl( PushKnobUI * otherDevice );
    
    // This gets called any time there's control
    // activity, it wakes up the LCD backlight.
    virtual void Wake();

protected:

    virtual int32_t KnobMoved( int32_t step );
    virtual void KnobPushed();
    virtual void Sleep();
    
    SETUP_KNOB_CALLBACKS( PushKnobUI )
     
private:
    RotaryEncoder * fKnob;
    PushButton * fKnobButton;
    CheapLCD * fLCD;
};

// This knob implements a basic menu system
class UIMenu : public PushKnobUI
{
public:
    static const int kNoSelection = -1;

    UIMenu( CheapLCD * lcd, const char * header = NULL, bool upMenuItem = false );
    virtual ~UIMenu() {}
    
    // Call to add an item to the menu
    virtual void AddItem( const char * label );
    
    // 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; }
    
    // Force select item (simulates selecting and click it w/ the knob)
    virtual void SelectItem( int i ) { fSelectedItem = i; Display( true ); }
    
    // Change the text of an item (updates display if display is on)
    virtual void ChangeItem( int item, const char * label );
    
protected:
    vector<string> fLabels;
    string fHeader;
    
    virtual int32_t KnobMoved( int32_t step );
    virtual void KnobPushed();

    SETUP_KNOB_CALLBACKS( UIMenu )

private:
    void DrawItem( int item );
    
    bool fDisplayOn;
    bool fUpMenuItem;
    int fSelectedItem;
    CheapLCD * fLCD;
};

#endif