Example of how to use an Ada Fruit RGB LCD with the Ada Fruit RGB LCD Shield Library

Dependencies:   AdaFruit_RGBLCDShield MCP23017 mbed RTclock

Dependents:   SX1276_GPS

Fork of MCP_test by Wim Huiskamp

Updated the Adafruit RGB LCD Shield test app with a module system.

It pulls in RTclock which is another library I did for controlling the DS1307 RTC in a sane way (marries stdlib time and the RTC together cleanly). You don't need an RTC to run the example, it'll just use stdlib time instead. This class also maps RTC to system time, so if you loose the RTC the mbed will free run.

Four modules are defined in the modules folder plus the module base class. These examples provide:

  • title menu item
  • time menu item (updates automatically)
  • date menu item
  • fake temp menu item

Press select to switch modes: menu->cursor->change

Menu switches menu items going up/down. Cursor allows you to move around editable fields using the cursor keys / marker. Change allows you to move left/right on a particular line and change values by using up/down on an item with the blink box.

Custom fonts are defined for UI arrows and degree character.

If you want a menu item to update over time then you need to implement the canRefresh() member function in any child module you derive from class Module. Make it return true to receive update requests in your show() member function. Date and time both check when refreshing to see if anything has changed, then update.

main() registers a table of modules with the MenuManager. Others can be added easily by creating children derived from the Module base class..

Depending on what you want to do you may need to adjust the loop wait time in MenuManager::loop(). If you don't balance this based on work you need to do then the key presses may get a little lively. I may adjust the key checking to be fixed to 200ms regardless of loop wait time, however the catch there is that you'll consume more power the more loops you do so the wait is still important.

Happy coding!

Committer:
vtraveller
Date:
Fri Oct 10 11:10:56 2014 +0000
Revision:
28:fbcd3bac0cd7
Parent:
25:24654d08a99a
Reduced write delay - faster LCD response

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vtraveller 25:24654d08a99a 1 #ifndef __MENUMANAGER_H__
vtraveller 25:24654d08a99a 2 #define __MENUMANAGER_H__
vtraveller 25:24654d08a99a 3
vtraveller 25:24654d08a99a 4 #include "lcd.h"
vtraveller 25:24654d08a99a 5 #include "keys.h"
vtraveller 25:24654d08a99a 6
vtraveller 25:24654d08a99a 7 class MenuManager
vtraveller 25:24654d08a99a 8 {
vtraveller 25:24654d08a99a 9 public:
vtraveller 25:24654d08a99a 10 MenuManager
vtraveller 25:24654d08a99a 11 (
vtraveller 25:24654d08a99a 12 Module ** in_pModules,
vtraveller 25:24654d08a99a 13 size_t in_nModules,
vtraveller 25:24654d08a99a 14 LCD & in_cLCD,
vtraveller 25:24654d08a99a 15 Keys & in_cKeys
vtraveller 25:24654d08a99a 16 );
vtraveller 25:24654d08a99a 17 void loop();
vtraveller 25:24654d08a99a 18
vtraveller 25:24654d08a99a 19 protected:
vtraveller 25:24654d08a99a 20 void changeModule(bool in_bUp);
vtraveller 25:24654d08a99a 21 void createChars();
vtraveller 25:24654d08a99a 22 void initialise();
vtraveller 25:24654d08a99a 23 void processKeys(uint8_t in_nKeys);
vtraveller 25:24654d08a99a 24 void setCursor
vtraveller 25:24654d08a99a 25 (
vtraveller 25:24654d08a99a 26 bool in_bCursor,
vtraveller 25:24654d08a99a 27 bool in_bBlink
vtraveller 25:24654d08a99a 28 );
vtraveller 25:24654d08a99a 29 void setMode(Module::EModes in_eMode);
vtraveller 25:24654d08a99a 30 void showModules(bool in_bRefresh = false);
vtraveller 25:24654d08a99a 31 void showTracking(bool in_bShow);
vtraveller 25:24654d08a99a 32 void updateDisplay();
vtraveller 25:24654d08a99a 33
vtraveller 25:24654d08a99a 34 protected:
vtraveller 25:24654d08a99a 35 Module ** m_pModules;
vtraveller 25:24654d08a99a 36 size_t m_nModules;
vtraveller 25:24654d08a99a 37 LCD & m_cLCD;
vtraveller 25:24654d08a99a 38 Keys & m_cKeys;
vtraveller 25:24654d08a99a 39 Module::EModes m_eMode;
vtraveller 25:24654d08a99a 40 size_t m_nMenuPos;
vtraveller 25:24654d08a99a 41 size_t m_nIndex;
vtraveller 25:24654d08a99a 42 int m_nCursorX, m_nCursorY;
vtraveller 25:24654d08a99a 43 };
vtraveller 25:24654d08a99a 44
vtraveller 25:24654d08a99a 45 #endif /* __MENUMANAGER_H__ */