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!

Files at this revision

API Documentation at this revision

Comitter:
vtraveller
Date:
Sun Aug 10 12:34:44 2014 +0000
Parent:
9:1501fb01ded6
Child:
11:96146db429de
Commit message:
Added module system.

Changed in this revision

MCP23017.lib Show annotated file Show diff for this revision Revisions of this file
Modules/DateModule.cpp Show annotated file Show diff for this revision Revisions of this file
Modules/DateModule.h Show annotated file Show diff for this revision Revisions of this file
Modules/TempModule.cpp Show annotated file Show diff for this revision Revisions of this file
Modules/TempModule.h Show annotated file Show diff for this revision Revisions of this file
Modules/TimeModule.cpp Show annotated file Show diff for this revision Revisions of this file
Modules/TimeModule.h Show annotated file Show diff for this revision Revisions of this file
Modules/TitleModule.cpp Show annotated file Show diff for this revision Revisions of this file
Modules/TitleModule.h Show annotated file Show diff for this revision Revisions of this file
Modules/module.cpp Show annotated file Show diff for this revision Revisions of this file
Modules/module.h Show annotated file Show diff for this revision Revisions of this file
RTclock.lib Show annotated file Show diff for this revision Revisions of this file
extra_chars.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
time_helper.cpp Show annotated file Show diff for this revision Revisions of this file
time_helper.h Show annotated file Show diff for this revision Revisions of this file
--- a/MCP23017.lib	Mon Aug 04 11:38:13 2014 +0000
+++ b/MCP23017.lib	Sun Aug 10 12:34:44 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/vtraveller/code/MCP23017/#c8d31c67ac27
+http://mbed.org/users/vtraveller/code/MCP23017/#164d420bcbcf
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Modules/DateModule.cpp	Sun Aug 10 12:34:44 2014 +0000
@@ -0,0 +1,48 @@
+#include "mbed.h"
+#include "DateModule.h"
+#include "time_helper.h"
+
+const char * k_aWeekDays[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
+
+DateModule::DateModule
+(
+    Adafruit_RGBLCDShield & in_cLCD,
+    RTclock & in_cRTclock
+)
+    : Module(in_cLCD)
+    , m_cRTclock(in_cRTclock)
+{
+}
+
+DateModule::~DateModule()
+{
+}
+    
+int DateModule::setCursor
+(
+    int in_nIndex,
+    int in_nCursorX,
+    int in_nCursorY
+)
+{
+    const int k_aCursor[] = { 2, 4, 5, 7, 8, 10, 11, 12, 13 };
+    
+    int nIndex = in_nIndex;
+    if (nIndex < 0) nIndex = 0;
+    if (nIndex >= _countof(k_aCursor)) nIndex = _countof(k_aCursor) - 1;
+       
+    int nCursorX = k_aCursor[nIndex];
+    m_cLCD.setCursor(in_nCursorX + nCursorX,in_nCursorY);
+    
+    return nIndex;
+}
+
+void DateModule::show()
+{
+    tm sTM;
+    
+    // to get the current time information
+    if (!m_cRTclock.getTime(sTM)) GetTime(sTM);
+
+    m_cLCD.printf ("%s %02i/%02i/%04i      ", k_aWeekDays[sTM.tm_wday], sTM.tm_mday, sTM.tm_mon + 1, 1900 + sTM.tm_year);    
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Modules/DateModule.h	Sun Aug 10 12:34:44 2014 +0000
@@ -0,0 +1,30 @@
+#ifndef __DATEMODULE_H__
+#define __DATEMODULE_H__
+
+#include "module.h"
+#include "RTclock.h"
+
+class DateModule
+    : public Module
+{
+public:
+    DateModule
+    (
+        Adafruit_RGBLCDShield & in_cLCD,
+        RTclock & in_cRTclock
+    );
+    virtual ~DateModule();
+    
+    virtual int     setCursor
+                    (
+                        int in_nIndex,
+                        int in_nCursorX,
+                        int in_nCursorY
+                    );
+    virtual void    show();
+    
+protected:
+    RTclock & m_cRTclock;    
+};
+
+#endif /* __DATEMODULE_H__ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Modules/TempModule.cpp	Sun Aug 10 12:34:44 2014 +0000
@@ -0,0 +1,37 @@
+#include "mbed.h"
+#include "TempModule.h"
+
+#include "extra_chars.h"
+
+TempModule::TempModule(Adafruit_RGBLCDShield & in_cLCD)
+    : Module(in_cLCD)
+{
+}
+
+TempModule::~TempModule()
+{
+}
+    
+int TempModule::setCursor
+(
+    int in_nIndex,
+    int in_nCursorX,
+    int in_nCursorY
+)
+{
+    const int k_aCursor[] = { 6, 7 };
+    
+    int nIndex = in_nIndex;
+    if (nIndex < 0) nIndex = 0;
+    if (nIndex >= _countof(k_aCursor)) nIndex = _countof(k_aCursor) - 1;
+       
+    int nCursorX = k_aCursor[nIndex];
+    m_cLCD.setCursor(in_nCursorX + nCursorX,in_nCursorY);
+    
+    return nIndex;
+}
+
+void TempModule::show()
+{
+    m_cLCD.printf("Room: %i%cC     ",28,eDegree);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Modules/TempModule.h	Sun Aug 10 12:34:44 2014 +0000
@@ -0,0 +1,22 @@
+#ifndef __TEMPMODULE_H__
+#define __TEMPMODULE_H__
+
+#include "module.h"
+
+class TempModule
+    : public Module
+{
+public:
+    TempModule(Adafruit_RGBLCDShield & in_cLCD);
+    virtual ~TempModule();
+    
+    virtual int     setCursor
+                    (
+                        int in_nIndex,
+                        int in_nCursorX,
+                        int in_nCursorY
+                    );
+    virtual void    show();    
+};
+
+#endif /* __TEMPMODULE_H__ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Modules/TimeModule.cpp	Sun Aug 10 12:34:44 2014 +0000
@@ -0,0 +1,74 @@
+#include "mbed.h"
+#include "TimeModule.h"
+#include "time_helper.h"
+
+#if 0
+    tm sTM;
+    sTM.tm_sec = 0;
+    sTM.tm_min = 0;
+    sTM.tm_hour = 18;
+    sTM.tm_mday = 9;
+    sTM.tm_mon  = 8 - 1;
+    sTM.tm_year = 2014 - 1900;
+    sTM.tm_wday = 6;
+
+    rtc.SetTime(sTM,true);
+#endif
+
+
+TimeModule::TimeModule
+(
+    Adafruit_RGBLCDShield & in_cLCD,
+    RTclock & in_cRTclock
+)
+    : Module(in_cLCD)
+    , m_cRTclock(in_cRTclock)
+{
+}
+
+TimeModule::~TimeModule()
+{
+}
+    
+int TimeModule::setCursor
+(
+    int in_nIndex,
+    int in_nCursorX,
+    int in_nCursorY
+)
+{
+    const int k_aCursor[] = { 0, 1, 3, 4, 6, 7, 10 };
+    
+    int nIndex = in_nIndex;
+    if (nIndex < 0) nIndex = 0;
+    if (nIndex >= _countof(k_aCursor)) nIndex = _countof(k_aCursor) - 1;
+       
+    int nCursorX = k_aCursor[nIndex];
+    m_cLCD.setCursor(in_nCursorX + nCursorX,in_nCursorY);
+    
+    return nIndex;
+}
+
+void TimeModule::show()
+{
+    tm sTM;
+    const char * pUnits = "  ";
+   
+    // to get the current time information 
+    if (m_cRTclock.getTime(sTM))
+    {
+        // Adjust for 12 hour clock
+        if (m_cRTclock.isTwelveHour())
+        {
+            pUnits = (sTM.tm_hour < 12) ? "am":"pm";
+            sTM.tm_hour %= 12;
+        }
+    }
+    else
+    {
+        // If failed get internal time (as at least that's something
+        GetTime(sTM);
+    }
+
+    m_cLCD.printf ("%02i:%02i:%02i %s   ", sTM.tm_hour, sTM.tm_min, sTM.tm_sec, pUnits);    
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Modules/TimeModule.h	Sun Aug 10 12:34:44 2014 +0000
@@ -0,0 +1,31 @@
+#ifndef __TIMEMODULE_H__
+#define __TIMEMODULE_H__
+
+#include "module.h"
+#include "RTclock.h"
+
+class TimeModule
+    : public Module
+{
+public:
+    TimeModule
+    (
+        Adafruit_RGBLCDShield & in_cLCD,
+        RTclock & in_cRTclock
+    );
+    virtual ~TimeModule();
+    
+    virtual bool    canRefresh() { return true; }
+    virtual int     setCursor
+                    (
+                        int in_nIndex,
+                        int in_nCursorX,
+                        int in_nCursorY
+                    );
+    virtual void    show();
+    
+protected:
+    RTclock & m_cRTclock;
+};
+
+#endif /* __TIMEMODULE_H__ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Modules/TitleModule.cpp	Sun Aug 10 12:34:44 2014 +0000
@@ -0,0 +1,26 @@
+#include "mbed.h"
+#include "TitleModule.h"
+
+TitleModule::TitleModule(Adafruit_RGBLCDShield & in_cLCD)
+    : Module(in_cLCD)
+{
+}
+
+TitleModule::~TitleModule()
+{
+}
+    
+int TitleModule::setCursor
+(
+    int in_nIndex,
+    int in_nCursorX,
+    int in_nCursorY
+)
+{
+    return -1;
+}
+
+void TitleModule::show()
+{
+    m_cLCD.printf("System Running");
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Modules/TitleModule.h	Sun Aug 10 12:34:44 2014 +0000
@@ -0,0 +1,22 @@
+#ifndef __TITLEMODULE_H__
+#define __TITLEMODULE_H__
+
+#include "module.h"
+
+class TitleModule
+    : public Module
+{
+public:
+    TitleModule(Adafruit_RGBLCDShield & in_cLCD);
+    virtual ~TitleModule();
+    
+    virtual int     setCursor
+                    (
+                        int in_nIndex,
+                        int in_nCursorX,
+                        int in_nCursorY
+                    );
+    virtual void    show();    
+};
+
+#endif /* __TITLEMODULE_H__ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Modules/module.cpp	Sun Aug 10 12:34:44 2014 +0000
@@ -0,0 +1,12 @@
+#include "mbed.h"
+#include "Adafruit_RGBLCDShield.h"
+#include "module.h"
+
+Module::Module(Adafruit_RGBLCDShield & in_cLCD)
+    : m_cLCD(in_cLCD)
+{
+}
+
+Module::~Module()
+{
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Modules/module.h	Sun Aug 10 12:34:44 2014 +0000
@@ -0,0 +1,29 @@
+#ifndef __MODULE_H__
+#define __MODULE_H__
+
+#include "Adafruit_RGBLCDShield.h"
+
+#ifndef _countof
+    #define _countof(a) (sizeof(a) / sizeof(a[0]))
+#endif
+
+class Module
+{
+public:
+    Module(Adafruit_RGBLCDShield & in_cLCD);
+    virtual ~Module();
+    
+    virtual bool    canRefresh() { return false; }
+    virtual int     setCursor
+                    (
+                        int in_nIndex,
+                        int in_nCursorX,
+                        int in_nCursorY
+                    ) = 0;
+    virtual void    show() = 0;
+    
+protected:
+    Adafruit_RGBLCDShield & m_cLCD;
+};
+
+#endif /* __MODULE_H__ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RTclock.lib	Sun Aug 10 12:34:44 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/vtraveller/code/RTclock/#3621025e7949
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extra_chars.h	Sun Aug 10 12:34:44 2014 +0000
@@ -0,0 +1,13 @@
+#ifndef __EXTRA_CHARS_H__
+#define __EXTRA_CHARS_H__
+
+enum EExtraChars
+{
+    eUp = 0,
+    eDown,
+    eRight,
+    eLeft,
+    eDegree
+};
+
+#endif /* __EXTRA_CHARS_H__ */
--- a/main.cpp	Mon Aug 04 11:38:13 2014 +0000
+++ b/main.cpp	Sun Aug 10 12:34:44 2014 +0000
@@ -1,33 +1,56 @@
 #include "mbed.h"
 #include "Adafruit_RGBLCDShield.h"
-//#include "MCP23017.h"
+#include "RTclock.h"
+#include "extra_chars.h"
+
+#include "module.h"
+#include "DateModule.h"
+#include "TempModule.h"
+#include "TimeModule.h"
+#include "TitleModule.h"
 
 Serial pc(SERIAL_TX, SERIAL_RX);
 
-MCP23017 mcp23017 = MCP23017(I2C_SDA, I2C_SCL, 0x40);
+MCP23017 mcp23017 = MCP23017(I2C_SDA, I2C_SCL, 0x40, true);
 Adafruit_RGBLCDShield lcd(mcp23017);
+RTclock rtc(I2C_SDA, I2C_SCL);
+
+const int k_nWidthLCD = 16;
+const int k_nHeightLCD = 2;
 
-enum EExtraChars
+enum EModes
 {
-    eUp = 0,
-    eDown,
-    eDegree
+    eModeMenu = 0,
+    eModeSelect,
+    eModeChange,
+    eModeLast
 };
 
 void CreateChars()
 {
-    uint8_t k_aUp[] = { 0x4,0xe,0x1f,0x15,0x4,0x4,0x4,0x4 };
-    uint8_t k_aDown[] = { 0x4,0x4,0x4,0x4,0x15,0x1f,0xe,0x4 };
+    //uint8_t k_aUp[] = { 0x4,0xe,0x1f,0x15,0x4,0x4,0x4,0x4 };
+    //uint8_t k_aDown[] = { 0x4,0x4,0x4,0x4,0x15,0x1f,0xe,0x4 };
+    
+    uint8_t k_aUp[] = { 0x0,0x0,0x4,0xe,0x1f,0x0,0x0 };
+    uint8_t k_aDown[] = { 0x0,0x0,0x1f,0xe,0x4,0x0,0x0 };
+    uint8_t k_aRight[] = { 0x0,0x8,0xc,0xe,0xc,0x8,0x0 };
+    uint8_t k_aLeft[] = { 0x0,0x2,0x6,0xe,0x6,0x2,0x0 };
     uint8_t k_aDegree[] = { 0xc,0x12,0x12,0xc,0x0,0x0,0x0,0x0 };
 
     lcd.createChar(eUp,k_aUp);
     lcd.createChar(eDown,k_aDown);
+    lcd.createChar(eRight,k_aRight);
+    lcd.createChar(eLeft,k_aLeft);    
     lcd.createChar(eDegree,k_aDegree);    
 }
 
 void Initialise()
 {
-    lcd.begin(16,2);
+    // Spin up RTC
+    rtc.mapTime();
+    
+    // Initialise LCD
+    lcd.begin(k_nWidthLCD,k_nHeightLCD);
     CreateChars();
 
     lcd.setCursor(0,0);
@@ -36,138 +59,162 @@
     lcd.setCursor(0,1);
     lcd._putc(eDown);    
 }
-    
-// Allows to set the backlight, if the LCD backpack is used
-void SetBacklight(unsigned char status)
+
+void SetCursor(bool in_bCursor,bool in_bBlink)
 {
-    pc.printf("Backlight: %i\r\n", status);
+    if (in_bCursor) lcd.cursor(); else lcd.noCursor();
+    if (in_bBlink) lcd.blink(); else lcd.noBlink();     
+}
+
+void ShowModules
+(
+    Module **   in_pModuleList,
+    size_t      in_nModuleListSize,
+    size_t      in_nPos,
+    bool        in_bRefresh = false
+)
+{
+    lcd.setCursor(2,0);
     
-    mcp23017.digitalWrite(8, (~(status >> 2) & 0x1));
-    mcp23017.digitalWrite(7, (~(status >> 1) & 0x1));
-    mcp23017.digitalWrite(6, (~status & 0x1));
+    if (in_pModuleList[in_nPos]->canRefresh() || !in_bRefresh) in_pModuleList[in_nPos]->show();
+    
+    size_t nPos = (in_nPos + 1) % in_nModuleListSize;
+    lcd.setCursor(2,1);
+    
+    if (in_pModuleList[nPos]->canRefresh() || !in_bRefresh) in_pModuleList[nPos]->show();
 }
 
-uint8_t CheckKeys()
+void ShowTracking(bool in_bShow)
 {
-    static uint8_t lastButtons = lcd.readButtons();
-    
-    uint8_t buttons = lcd.readButtons();
-
-    if (buttons)
+    if (in_bShow)
     {
-        if (buttons != lastButtons)
-        {
-            lastButtons = buttons;
-        }
-            
-        lcd.setCursor(2,1);
+        lcd.setCursor(1,0);
+        lcd._putc(eLeft);
         
-        if (buttons & BUTTON_UP)
-        {
-            pc.printf("UP ");
-            
-            lcd.printf("UP ");
-        }
+        lcd.setCursor(1,1);
+        lcd._putc(eRight);        
+    }
+    else
+    {
+        lcd.setCursor(1,0);
+        lcd._putc(' ');
         
-        if (buttons & BUTTON_DOWN)
-        {
-            pc.printf("DOWN ");
-            
-            lcd.printf("DOWN ");
-        }
-        
-        if (buttons & BUTTON_LEFT)
-        {
-            pc.printf("LEFT ");
-            
-            lcd.printf("LEFT ");
-        }
+        lcd.setCursor(1,1);
+        lcd._putc(' ');                                       
+    }    
+}
+
+void UpdateDisplay
+(
+    Module **   in_pModuleList,
+    size_t      in_nModuleListSize,
+    size_t      in_nMenuPos,
+    int &       inout_nIndexX,
+    int         in_nCursorX,
+    int &       inout_nCursorY
+)
+{
+    ShowModules(in_pModuleList,in_nModuleListSize,in_nMenuPos);
+    
+    size_t nCurrent = (in_nMenuPos + inout_nCursorY) % in_nModuleListSize;
+    inout_nIndexX = in_pModuleList[nCurrent]->setCursor(inout_nIndexX,in_nCursorX,inout_nCursorY);
+                
+    // If we didn't have anything, move the line
+    if (-1 == inout_nIndexX)
+    {
+        inout_nCursorY = (inout_nCursorY + 1) % k_nHeightLCD;
         
-        if (buttons & BUTTON_RIGHT)
-        {
-            pc.printf("RIGHT ");
-            
-            lcd.printf("RIGHT ");            
-        }
-        
-        if (buttons & BUTTON_SELECT)
-        {
-            pc.printf("SELECT ");
-            
-            lcd.printf("SELECT ");            
-        }
-        
-        lcd.printf("              ");
+        nCurrent = (in_nMenuPos  + inout_nCursorY) % in_nModuleListSize;
+        inout_nIndexX = in_pModuleList[nCurrent]->setCursor(0,in_nCursorX,inout_nCursorY);
     }
     
-    return buttons;
-}
-
-void ShowTemp(int in_nTemp)
-{
-    lcd.setCursor(2,0);
-    lcd.printf("Room: %i%cC     ",in_nTemp,eDegree);    
-}
-
-void SetTime
-(
-    uint8_t     in_nHour,
-    uint8_t     in_nMin,
-    uint8_t     in_nDay,
-    uint8_t     in_nMonth,
-    uint16_t    in_nYear
-)
-{
-    tm sCurrentTime = { 0 };
-    sCurrentTime.tm_year = in_nYear - 1900;
-    sCurrentTime.tm_mon = in_nMonth - 1;
-    sCurrentTime.tm_mday = in_nDay;
-    
-    sCurrentTime.tm_hour = in_nHour;
-    sCurrentTime.tm_min = in_nMin;
-    
-    time_t nCurrentTime = mktime(&sCurrentTime);
-    set_time(nCurrentTime);    
-}
-
-void ShowTime()
-{
-    lcd.setCursor(2,1);
-
-    time_t rawtime = time(0);
-    tm * timeinfo = localtime(&rawtime);        
-    lcd.printf ("%02i:%02i:%02i      ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);    
+    // If nothing to show - hide everything
+    if (-1 == inout_nIndexX) SetCursor(false,false);
 }
 
 int main()
 {        
     pc.printf("\r\nInitialise LCD\r\n");    
     
-    Initialise();
+    Initialise();    
+        
+    EModes eMode = eModeMenu;
+    size_t nMenuPos = 0;
 
-    SetTime(11,48,4,8,2014);
+    // Set up display modules    
+    Module * aModules[] =
+    {
+        new TitleModule(lcd),
+        new TimeModule(lcd,rtc),
+        new DateModule(lcd,rtc),
+        new TempModule(lcd)
+    };
     
-    int nTemp = 28;
-    ShowTemp(nTemp);
-
-    time_t nLast = 0;
+    ShowModules(aModules,_countof(aModules),nMenuPos);
+    
+    int nIndexX = 0;
+    int nCursorY = 0;
+    
     while (true)
     {
-        if (time(0) - nLast > 3)
-        {
-            ShowTime();
-        }
-
-        uint8_t nKeys = CheckKeys();        
+        uint8_t nKeys = lcd.readButtons();
         if (nKeys)
         {
-            if (nKeys & BUTTON_UP) nTemp++;
-            if (nKeys & BUTTON_DOWN) nTemp--;
+            // Change mode based on select
+            if (nKeys & BUTTON_SELECT)
+            {
+                eMode = (EModes)((eMode + 1) % eModeLast);
+                
+                // Start at top corner
+                if (eModeSelect == eMode)
+                {
+                    nIndexX = 0;
+                    nCursorY = 0;
+                }
+            }
+
+            switch (eMode)
+            {                
+                case eModeMenu:
+                    SetCursor(false,false);
+                    ShowTracking(false);
+                                        
+                    if (nKeys & BUTTON_UP) nMenuPos--;
+                    if (nKeys & BUTTON_DOWN) nMenuPos++;
+                    
+                    nMenuPos = nMenuPos % _countof(aModules);                    
+                    break;
+                    
+                case eModeSelect:
+                    SetCursor(true,false);
+                    ShowTracking(true);
+                                                            
+                    if (nCursorY > 0 && (nKeys & BUTTON_UP)) nCursorY--;
+                    if ((nCursorY < k_nHeightLCD - 1) && (nKeys & BUTTON_DOWN)) nCursorY++;
+                                        
+                    if (nKeys & BUTTON_LEFT) nIndexX--;
+                    if (nKeys & BUTTON_RIGHT) nIndexX++;                    
+                    break;
+                    
+                case eModeChange:
+                    SetCursor(false,true);
+                    ShowTracking(true);
+                    break;
+            }
                         
-            ShowTemp(nTemp);            
-            nLast = time(0);
+            UpdateDisplay(aModules,_countof(aModules),nMenuPos,nIndexX,2,nCursorY);
         }
-            
+        else
+        {
+            switch (eMode)
+            {
+                case eModeMenu:
+                    ShowModules(aModules,_countof(aModules),nMenuPos,true);
+                    aModules[nMenuPos]->setCursor(nIndexX,2,nCursorY);
+                    break;
+            }
+        }
+        
         wait(0.2);
-    }    
+    }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/time_helper.cpp	Sun Aug 10 12:34:44 2014 +0000
@@ -0,0 +1,30 @@
+#include "mbed.h"
+#include "time_helper.h"
+
+void GetTime(tm & out_sTM)
+{
+    time_t nTime = time(0);
+    tm * pTM = ::localtime(&nTime);
+    ::memcpy(&out_sTM,pTM,sizeof(out_sTM));
+}
+
+void SetTime
+(
+    uint8_t     in_nHour,
+    uint8_t     in_nMin,
+    uint8_t     in_nDay,
+    uint8_t     in_nMonth,
+    uint16_t    in_nYear
+)
+{
+    tm sCurrentTime = { 0 };
+    sCurrentTime.tm_year = in_nYear - 1900;
+    sCurrentTime.tm_mon = in_nMonth - 1;
+    sCurrentTime.tm_mday = in_nDay;
+    
+    sCurrentTime.tm_hour = in_nHour;
+    sCurrentTime.tm_min = in_nMin;
+    
+    time_t nCurrentTime = mktime(&sCurrentTime);
+    set_time(nCurrentTime);    
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/time_helper.h	Sun Aug 10 12:34:44 2014 +0000
@@ -0,0 +1,17 @@
+#ifndef __TIME_HELPER_H__
+#define __TIME_HELPER_H__
+
+#include <time.h>
+
+void GetTime(tm & out_sTM);
+
+void SetTime
+(
+    uint8_t     in_nHour,
+    uint8_t     in_nMin,
+    uint8_t     in_nDay,
+    uint8_t     in_nMonth,
+    uint16_t    in_nYear
+);
+
+#endif /* __TIME_HELPER_H__ */
\ No newline at end of file