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:
Sun Aug 10 12:34:44 2014 +0000
Revision:
10:3fcab08717fc
Child:
11:96146db429de
Added module system.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vtraveller 10:3fcab08717fc 1 #include "mbed.h"
vtraveller 10:3fcab08717fc 2 #include "TimeModule.h"
vtraveller 10:3fcab08717fc 3 #include "time_helper.h"
vtraveller 10:3fcab08717fc 4
vtraveller 10:3fcab08717fc 5 #if 0
vtraveller 10:3fcab08717fc 6 tm sTM;
vtraveller 10:3fcab08717fc 7 sTM.tm_sec = 0;
vtraveller 10:3fcab08717fc 8 sTM.tm_min = 0;
vtraveller 10:3fcab08717fc 9 sTM.tm_hour = 18;
vtraveller 10:3fcab08717fc 10 sTM.tm_mday = 9;
vtraveller 10:3fcab08717fc 11 sTM.tm_mon = 8 - 1;
vtraveller 10:3fcab08717fc 12 sTM.tm_year = 2014 - 1900;
vtraveller 10:3fcab08717fc 13 sTM.tm_wday = 6;
vtraveller 10:3fcab08717fc 14
vtraveller 10:3fcab08717fc 15 rtc.SetTime(sTM,true);
vtraveller 10:3fcab08717fc 16 #endif
vtraveller 10:3fcab08717fc 17
vtraveller 10:3fcab08717fc 18
vtraveller 10:3fcab08717fc 19 TimeModule::TimeModule
vtraveller 10:3fcab08717fc 20 (
vtraveller 10:3fcab08717fc 21 Adafruit_RGBLCDShield & in_cLCD,
vtraveller 10:3fcab08717fc 22 RTclock & in_cRTclock
vtraveller 10:3fcab08717fc 23 )
vtraveller 10:3fcab08717fc 24 : Module(in_cLCD)
vtraveller 10:3fcab08717fc 25 , m_cRTclock(in_cRTclock)
vtraveller 10:3fcab08717fc 26 {
vtraveller 10:3fcab08717fc 27 }
vtraveller 10:3fcab08717fc 28
vtraveller 10:3fcab08717fc 29 TimeModule::~TimeModule()
vtraveller 10:3fcab08717fc 30 {
vtraveller 10:3fcab08717fc 31 }
vtraveller 10:3fcab08717fc 32
vtraveller 10:3fcab08717fc 33 int TimeModule::setCursor
vtraveller 10:3fcab08717fc 34 (
vtraveller 10:3fcab08717fc 35 int in_nIndex,
vtraveller 10:3fcab08717fc 36 int in_nCursorX,
vtraveller 10:3fcab08717fc 37 int in_nCursorY
vtraveller 10:3fcab08717fc 38 )
vtraveller 10:3fcab08717fc 39 {
vtraveller 10:3fcab08717fc 40 const int k_aCursor[] = { 0, 1, 3, 4, 6, 7, 10 };
vtraveller 10:3fcab08717fc 41
vtraveller 10:3fcab08717fc 42 int nIndex = in_nIndex;
vtraveller 10:3fcab08717fc 43 if (nIndex < 0) nIndex = 0;
vtraveller 10:3fcab08717fc 44 if (nIndex >= _countof(k_aCursor)) nIndex = _countof(k_aCursor) - 1;
vtraveller 10:3fcab08717fc 45
vtraveller 10:3fcab08717fc 46 int nCursorX = k_aCursor[nIndex];
vtraveller 10:3fcab08717fc 47 m_cLCD.setCursor(in_nCursorX + nCursorX,in_nCursorY);
vtraveller 10:3fcab08717fc 48
vtraveller 10:3fcab08717fc 49 return nIndex;
vtraveller 10:3fcab08717fc 50 }
vtraveller 10:3fcab08717fc 51
vtraveller 10:3fcab08717fc 52 void TimeModule::show()
vtraveller 10:3fcab08717fc 53 {
vtraveller 10:3fcab08717fc 54 tm sTM;
vtraveller 10:3fcab08717fc 55 const char * pUnits = " ";
vtraveller 10:3fcab08717fc 56
vtraveller 10:3fcab08717fc 57 // to get the current time information
vtraveller 10:3fcab08717fc 58 if (m_cRTclock.getTime(sTM))
vtraveller 10:3fcab08717fc 59 {
vtraveller 10:3fcab08717fc 60 // Adjust for 12 hour clock
vtraveller 10:3fcab08717fc 61 if (m_cRTclock.isTwelveHour())
vtraveller 10:3fcab08717fc 62 {
vtraveller 10:3fcab08717fc 63 pUnits = (sTM.tm_hour < 12) ? "am":"pm";
vtraveller 10:3fcab08717fc 64 sTM.tm_hour %= 12;
vtraveller 10:3fcab08717fc 65 }
vtraveller 10:3fcab08717fc 66 }
vtraveller 10:3fcab08717fc 67 else
vtraveller 10:3fcab08717fc 68 {
vtraveller 10:3fcab08717fc 69 // If failed get internal time (as at least that's something
vtraveller 10:3fcab08717fc 70 GetTime(sTM);
vtraveller 10:3fcab08717fc 71 }
vtraveller 10:3fcab08717fc 72
vtraveller 10:3fcab08717fc 73 m_cLCD.printf ("%02i:%02i:%02i %s ", sTM.tm_hour, sTM.tm_min, sTM.tm_sec, pUnits);
vtraveller 10:3fcab08717fc 74 }