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:
Thu Aug 14 10:47:27 2014 +0000
Revision:
17:731a47339cb8
Child:
19:72c02acb601d
Added mode indication to modules (allows them to change behavior based on mode changes.  Means you can have a module change state but not commit the change until you leave that state.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vtraveller 17:731a47339cb8 1 #include "mbed.h"
vtraveller 17:731a47339cb8 2 #include "SyncModule.h"
vtraveller 17:731a47339cb8 3 #include "extra_chars.h"
vtraveller 17:731a47339cb8 4
vtraveller 17:731a47339cb8 5 SyncModule::SyncModule
vtraveller 17:731a47339cb8 6 (
vtraveller 17:731a47339cb8 7 Serial & in_cDisplay,
vtraveller 17:731a47339cb8 8 RTclock & in_cPrecisionClock,
vtraveller 17:731a47339cb8 9 RTclock & in_cClock
vtraveller 17:731a47339cb8 10 )
vtraveller 17:731a47339cb8 11 : Module(in_cDisplay)
vtraveller 17:731a47339cb8 12 , m_cPrecisionClock(in_cPrecisionClock)
vtraveller 17:731a47339cb8 13 , m_cClock(in_cClock)
vtraveller 17:731a47339cb8 14 , m_eMode(eModeLast)
vtraveller 17:731a47339cb8 15 , m_bSync(false)
vtraveller 17:731a47339cb8 16 {
vtraveller 17:731a47339cb8 17 }
vtraveller 17:731a47339cb8 18
vtraveller 17:731a47339cb8 19 SyncModule::~SyncModule()
vtraveller 17:731a47339cb8 20 {
vtraveller 17:731a47339cb8 21 }
vtraveller 17:731a47339cb8 22
vtraveller 17:731a47339cb8 23 void SyncModule::change
vtraveller 17:731a47339cb8 24 (
vtraveller 17:731a47339cb8 25 size_t /* in_nIndex */,
vtraveller 17:731a47339cb8 26 bool /* in_bUp */
vtraveller 17:731a47339cb8 27 )
vtraveller 17:731a47339cb8 28 {
vtraveller 17:731a47339cb8 29 m_bSync = (m_bSync) ? false : true;
vtraveller 17:731a47339cb8 30 }
vtraveller 17:731a47339cb8 31
vtraveller 17:731a47339cb8 32 int SyncModule::getCursorOffset(size_t & inout_nIndex)
vtraveller 17:731a47339cb8 33 {
vtraveller 17:731a47339cb8 34 return m_bSync ? 13 : 12;
vtraveller 17:731a47339cb8 35 }
vtraveller 17:731a47339cb8 36
vtraveller 17:731a47339cb8 37 void SyncModule::onModeChange(EModes in_eMode)
vtraveller 17:731a47339cb8 38 {
vtraveller 17:731a47339cb8 39 EModes eOldMode = m_eMode;
vtraveller 17:731a47339cb8 40 m_eMode = in_eMode;
vtraveller 17:731a47339cb8 41
vtraveller 17:731a47339cb8 42 if (eModeChange != eOldMode) return;
vtraveller 17:731a47339cb8 43 if (eModeMenu != m_eMode) return;
vtraveller 17:731a47339cb8 44
vtraveller 17:731a47339cb8 45 if (m_bSync)
vtraveller 17:731a47339cb8 46 {
vtraveller 17:731a47339cb8 47 // Sync the internal mbed clock (stdlib)
vtraveller 17:731a47339cb8 48 m_cPrecisionClock.mapTime();
vtraveller 17:731a47339cb8 49
vtraveller 17:731a47339cb8 50 // Sync the precision clock with the inaccurate RTC
vtraveller 17:731a47339cb8 51 tm sTM;
vtraveller 17:731a47339cb8 52 m_cPrecisionClock.getTime(sTM);
vtraveller 17:731a47339cb8 53 m_cClock.setTime(sTM,true);
vtraveller 17:731a47339cb8 54
vtraveller 17:731a47339cb8 55 m_bSync = false;
vtraveller 17:731a47339cb8 56 }
vtraveller 17:731a47339cb8 57 }
vtraveller 17:731a47339cb8 58
vtraveller 17:731a47339cb8 59 void SyncModule::show(bool /*in_bRefresh*/)
vtraveller 17:731a47339cb8 60 {
vtraveller 17:731a47339cb8 61 switch (m_eMode)
vtraveller 17:731a47339cb8 62 {
vtraveller 17:731a47339cb8 63 case eModeChange:
vtraveller 17:731a47339cb8 64 case eModeSelect:
vtraveller 17:731a47339cb8 65 m_cDisplay.printf("Sync Time? %s ",m_bSync ? "yes" : "no");
vtraveller 17:731a47339cb8 66 break;
vtraveller 17:731a47339cb8 67
vtraveller 17:731a47339cb8 68 default:
vtraveller 17:731a47339cb8 69 m_cDisplay.printf("Sync Time %c ",eRight);
vtraveller 17:731a47339cb8 70 }
vtraveller 17:731a47339cb8 71 }