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:
Tue Aug 12 04:25:08 2014 +0000
Revision:
15:d1eaddb363be
Parent:
13:9641bc42db92
Child:
16:9e1edf28393f
Added refresh parameter to show().; Updated time and date to only refresh if there's a change.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vtraveller 10:3fcab08717fc 1 #include "mbed.h"
vtraveller 10:3fcab08717fc 2 #include "DateModule.h"
vtraveller 10:3fcab08717fc 3 #include "time_helper.h"
vtraveller 10:3fcab08717fc 4
vtraveller 10:3fcab08717fc 5 const char * k_aWeekDays[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
vtraveller 10:3fcab08717fc 6
vtraveller 10:3fcab08717fc 7 DateModule::DateModule
vtraveller 10:3fcab08717fc 8 (
vtraveller 13:9641bc42db92 9 Serial & in_cDisplay,
vtraveller 13:9641bc42db92 10 RTclock & in_cRTclock
vtraveller 10:3fcab08717fc 11 )
vtraveller 13:9641bc42db92 12 : Module(in_cDisplay)
vtraveller 10:3fcab08717fc 13 , m_cRTclock(in_cRTclock)
vtraveller 10:3fcab08717fc 14 {
vtraveller 15:d1eaddb363be 15 ::memset(&m_sLastTM,0,sizeof(m_sLastTM));
vtraveller 10:3fcab08717fc 16 }
vtraveller 10:3fcab08717fc 17
vtraveller 10:3fcab08717fc 18 DateModule::~DateModule()
vtraveller 10:3fcab08717fc 19 {
vtraveller 10:3fcab08717fc 20 }
vtraveller 11:96146db429de 21
vtraveller 11:96146db429de 22 void DateModule::change
vtraveller 11:96146db429de 23 (
vtraveller 13:9641bc42db92 24 size_t in_nIndex,
vtraveller 11:96146db429de 25 bool in_bUp
vtraveller 11:96146db429de 26 )
vtraveller 11:96146db429de 27 {
vtraveller 11:96146db429de 28 tm sTM;
vtraveller 10:3fcab08717fc 29
vtraveller 11:96146db429de 30 // to get the current time information
vtraveller 11:96146db429de 31 if (!m_cRTclock.getTime(sTM)) GetTime(sTM);
vtraveller 11:96146db429de 32 bool bTwelveHour = m_cRTclock.isTwelveHour();
vtraveller 12:0fea8ebe6c1a 33
vtraveller 12:0fea8ebe6c1a 34 enum ETime
vtraveller 12:0fea8ebe6c1a 35 {
vtraveller 12:0fea8ebe6c1a 36 eWeekDay = 0,
vtraveller 12:0fea8ebe6c1a 37 eDayTen,
vtraveller 12:0fea8ebe6c1a 38 eDaySingle,
vtraveller 12:0fea8ebe6c1a 39 eMonthTen,
vtraveller 12:0fea8ebe6c1a 40 eMonthSingle,
vtraveller 12:0fea8ebe6c1a 41 eYearTen,
vtraveller 12:0fea8ebe6c1a 42 eYearSingle,
vtraveller 12:0fea8ebe6c1a 43 };
vtraveller 11:96146db429de 44
vtraveller 13:9641bc42db92 45 switch (in_nIndex)
vtraveller 11:96146db429de 46 {
vtraveller 12:0fea8ebe6c1a 47 case eWeekDay: sTM.tm_wday += (in_bUp ? 1 : -1); break;
vtraveller 12:0fea8ebe6c1a 48 case eDayTen: sTM.tm_mday += (in_bUp ? 1 : -1) * 10; break;
vtraveller 12:0fea8ebe6c1a 49 case eDaySingle: sTM.tm_mday += (in_bUp ? 1 : -1); break;
vtraveller 12:0fea8ebe6c1a 50 case eMonthTen: sTM.tm_mon += (in_bUp ? 1 : -1) * 10; break;
vtraveller 12:0fea8ebe6c1a 51 case eMonthSingle: sTM.tm_mon += (in_bUp ? 1 : -1); break;
vtraveller 12:0fea8ebe6c1a 52 case eYearTen: sTM.tm_year += (in_bUp ? 1 : -1) * 10; break;
vtraveller 12:0fea8ebe6c1a 53 case eYearSingle: sTM.tm_year += (in_bUp ? 1 : -1); break;
vtraveller 11:96146db429de 54 }
vtraveller 12:0fea8ebe6c1a 55
vtraveller 12:0fea8ebe6c1a 56 if (sTM.tm_wday < 0) sTM.tm_wday = 0;
vtraveller 12:0fea8ebe6c1a 57 if (sTM.tm_wday > 6) sTM.tm_wday = 6;
vtraveller 12:0fea8ebe6c1a 58 if (sTM.tm_mday < 1) sTM.tm_mday = 1;
vtraveller 12:0fea8ebe6c1a 59 if (sTM.tm_mday > 31) sTM.tm_mday = 31;
vtraveller 12:0fea8ebe6c1a 60 if (sTM.tm_mon < 0) sTM.tm_mon = 0;
vtraveller 12:0fea8ebe6c1a 61 if (sTM.tm_mon > 11) sTM.tm_mon = 11;
vtraveller 12:0fea8ebe6c1a 62 if (sTM.tm_year < 2000 - 1900) sTM.tm_year = 2000 - 1900;
vtraveller 12:0fea8ebe6c1a 63 if (sTM.tm_year > 2099 - 1900) sTM.tm_year = 2099 - 1900;
vtraveller 11:96146db429de 64
vtraveller 12:0fea8ebe6c1a 65 if (m_cRTclock.setTime(sTM,bTwelveHour))
vtraveller 12:0fea8ebe6c1a 66 {
vtraveller 12:0fea8ebe6c1a 67 m_cRTclock.mapTime();
vtraveller 12:0fea8ebe6c1a 68 }
vtraveller 12:0fea8ebe6c1a 69 else
vtraveller 12:0fea8ebe6c1a 70 {
vtraveller 12:0fea8ebe6c1a 71 SetTime(sTM);
vtraveller 12:0fea8ebe6c1a 72 }
vtraveller 11:96146db429de 73 }
vtraveller 11:96146db429de 74
vtraveller 13:9641bc42db92 75 int DateModule::getCursorOffset(size_t & inout_nIndex)
vtraveller 10:3fcab08717fc 76 {
vtraveller 12:0fea8ebe6c1a 77 const int k_aCursor[] = { 2, 4, 5, 7, 8, 12, 13 };
vtraveller 10:3fcab08717fc 78
vtraveller 13:9641bc42db92 79 if ((int)inout_nIndex < 0) inout_nIndex = 0;
vtraveller 13:9641bc42db92 80 if (inout_nIndex >= _countof(k_aCursor)) inout_nIndex = _countof(k_aCursor) - 1;
vtraveller 10:3fcab08717fc 81
vtraveller 13:9641bc42db92 82 return k_aCursor[inout_nIndex];
vtraveller 10:3fcab08717fc 83 }
vtraveller 10:3fcab08717fc 84
vtraveller 15:d1eaddb363be 85 void DateModule::show(bool in_bRefresh)
vtraveller 10:3fcab08717fc 86 {
vtraveller 10:3fcab08717fc 87 tm sTM;
vtraveller 10:3fcab08717fc 88
vtraveller 10:3fcab08717fc 89 // to get the current time information
vtraveller 10:3fcab08717fc 90 if (!m_cRTclock.getTime(sTM)) GetTime(sTM);
vtraveller 15:d1eaddb363be 91
vtraveller 15:d1eaddb363be 92 // if refreshing - only update if there's a change
vtraveller 15:d1eaddb363be 93 if (in_bRefresh)
vtraveller 15:d1eaddb363be 94 {
vtraveller 15:d1eaddb363be 95 if (0 == ::memcmp(&sTM,&m_sLastTM,sizeof(sTM))) return;
vtraveller 15:d1eaddb363be 96 }
vtraveller 15:d1eaddb363be 97
vtraveller 15:d1eaddb363be 98 // Ensure internal struct has new TM data
vtraveller 15:d1eaddb363be 99 ::memcpy(&m_sLastTM,&sTM,sizeof(m_sLastTM));
vtraveller 15:d1eaddb363be 100 m_cDisplay.printf ("%s %02i/%02i/%04i ", k_aWeekDays[sTM.tm_wday], sTM.tm_mday, sTM.tm_mon + 1, 1900 + sTM.tm_year);
vtraveller 10:3fcab08717fc 101 }