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:
Mon Aug 11 19:11:43 2014 +0000
Revision:
13:9641bc42db92
Parent:
12:0fea8ebe6c1a
Child:
15:d1eaddb363be
Created a scrollable menu system based on modules to work against the Adafruit RGB LCD library.; Modules can be created and installed as menu items with display, cursor and edit capabilities.

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 10:3fcab08717fc 15 }
vtraveller 10:3fcab08717fc 16
vtraveller 10:3fcab08717fc 17 DateModule::~DateModule()
vtraveller 10:3fcab08717fc 18 {
vtraveller 10:3fcab08717fc 19 }
vtraveller 11:96146db429de 20
vtraveller 11:96146db429de 21 void DateModule::change
vtraveller 11:96146db429de 22 (
vtraveller 13:9641bc42db92 23 size_t in_nIndex,
vtraveller 11:96146db429de 24 bool in_bUp
vtraveller 11:96146db429de 25 )
vtraveller 11:96146db429de 26 {
vtraveller 11:96146db429de 27 tm sTM;
vtraveller 10:3fcab08717fc 28
vtraveller 11:96146db429de 29 // to get the current time information
vtraveller 11:96146db429de 30 if (!m_cRTclock.getTime(sTM)) GetTime(sTM);
vtraveller 11:96146db429de 31 bool bTwelveHour = m_cRTclock.isTwelveHour();
vtraveller 12:0fea8ebe6c1a 32
vtraveller 12:0fea8ebe6c1a 33 enum ETime
vtraveller 12:0fea8ebe6c1a 34 {
vtraveller 12:0fea8ebe6c1a 35 eWeekDay = 0,
vtraveller 12:0fea8ebe6c1a 36 eDayTen,
vtraveller 12:0fea8ebe6c1a 37 eDaySingle,
vtraveller 12:0fea8ebe6c1a 38 eMonthTen,
vtraveller 12:0fea8ebe6c1a 39 eMonthSingle,
vtraveller 12:0fea8ebe6c1a 40 eYearTen,
vtraveller 12:0fea8ebe6c1a 41 eYearSingle,
vtraveller 12:0fea8ebe6c1a 42 };
vtraveller 11:96146db429de 43
vtraveller 13:9641bc42db92 44 switch (in_nIndex)
vtraveller 11:96146db429de 45 {
vtraveller 12:0fea8ebe6c1a 46 case eWeekDay: sTM.tm_wday += (in_bUp ? 1 : -1); break;
vtraveller 12:0fea8ebe6c1a 47 case eDayTen: sTM.tm_mday += (in_bUp ? 1 : -1) * 10; break;
vtraveller 12:0fea8ebe6c1a 48 case eDaySingle: sTM.tm_mday += (in_bUp ? 1 : -1); break;
vtraveller 12:0fea8ebe6c1a 49 case eMonthTen: sTM.tm_mon += (in_bUp ? 1 : -1) * 10; break;
vtraveller 12:0fea8ebe6c1a 50 case eMonthSingle: sTM.tm_mon += (in_bUp ? 1 : -1); break;
vtraveller 12:0fea8ebe6c1a 51 case eYearTen: sTM.tm_year += (in_bUp ? 1 : -1) * 10; break;
vtraveller 12:0fea8ebe6c1a 52 case eYearSingle: sTM.tm_year += (in_bUp ? 1 : -1); break;
vtraveller 11:96146db429de 53 }
vtraveller 12:0fea8ebe6c1a 54
vtraveller 12:0fea8ebe6c1a 55 if (sTM.tm_wday < 0) sTM.tm_wday = 0;
vtraveller 12:0fea8ebe6c1a 56 if (sTM.tm_wday > 6) sTM.tm_wday = 6;
vtraveller 12:0fea8ebe6c1a 57 if (sTM.tm_mday < 1) sTM.tm_mday = 1;
vtraveller 12:0fea8ebe6c1a 58 if (sTM.tm_mday > 31) sTM.tm_mday = 31;
vtraveller 12:0fea8ebe6c1a 59 if (sTM.tm_mon < 0) sTM.tm_mon = 0;
vtraveller 12:0fea8ebe6c1a 60 if (sTM.tm_mon > 11) sTM.tm_mon = 11;
vtraveller 12:0fea8ebe6c1a 61 if (sTM.tm_year < 2000 - 1900) sTM.tm_year = 2000 - 1900;
vtraveller 12:0fea8ebe6c1a 62 if (sTM.tm_year > 2099 - 1900) sTM.tm_year = 2099 - 1900;
vtraveller 11:96146db429de 63
vtraveller 12:0fea8ebe6c1a 64 if (m_cRTclock.setTime(sTM,bTwelveHour))
vtraveller 12:0fea8ebe6c1a 65 {
vtraveller 12:0fea8ebe6c1a 66 m_cRTclock.mapTime();
vtraveller 12:0fea8ebe6c1a 67 }
vtraveller 12:0fea8ebe6c1a 68 else
vtraveller 12:0fea8ebe6c1a 69 {
vtraveller 12:0fea8ebe6c1a 70 SetTime(sTM);
vtraveller 12:0fea8ebe6c1a 71 }
vtraveller 11:96146db429de 72 }
vtraveller 11:96146db429de 73
vtraveller 13:9641bc42db92 74 int DateModule::getCursorOffset(size_t & inout_nIndex)
vtraveller 10:3fcab08717fc 75 {
vtraveller 12:0fea8ebe6c1a 76 const int k_aCursor[] = { 2, 4, 5, 7, 8, 12, 13 };
vtraveller 10:3fcab08717fc 77
vtraveller 13:9641bc42db92 78 if ((int)inout_nIndex < 0) inout_nIndex = 0;
vtraveller 13:9641bc42db92 79 if (inout_nIndex >= _countof(k_aCursor)) inout_nIndex = _countof(k_aCursor) - 1;
vtraveller 10:3fcab08717fc 80
vtraveller 13:9641bc42db92 81 return k_aCursor[inout_nIndex];
vtraveller 10:3fcab08717fc 82 }
vtraveller 10:3fcab08717fc 83
vtraveller 10:3fcab08717fc 84 void DateModule::show()
vtraveller 10:3fcab08717fc 85 {
vtraveller 10:3fcab08717fc 86 tm sTM;
vtraveller 10:3fcab08717fc 87
vtraveller 10:3fcab08717fc 88 // to get the current time information
vtraveller 10:3fcab08717fc 89 if (!m_cRTclock.getTime(sTM)) GetTime(sTM);
vtraveller 10:3fcab08717fc 90
vtraveller 13:9641bc42db92 91 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 92 }