Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SX1276Lib AdaFruit_RGBLCD MCP23017 mbed
Fork of AdaFruit_RGBLCD by
Diff: main.cpp
- Revision:
- 13:9641bc42db92
- Parent:
- 11:96146db429de
- Child:
- 17:731a47339cb8
--- a/main.cpp Sun Aug 10 16:01:43 2014 +0000
+++ b/main.cpp Mon Aug 11 19:11:43 2014 +0000
@@ -1,243 +1,38 @@
#include "mbed.h"
+
#include "Adafruit_RGBLCDShield.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, true);
-Adafruit_RGBLCDShield lcd(mcp23017);
-RTclock rtc(I2C_SDA, I2C_SCL);
-
-const int k_nWidthLCD = 16;
-const int k_nHeightLCD = 2;
-
-enum EModes
-{
- eModeMenu = 0,
- eModeSelect,
- eModeChange,
- eModeLast
-};
-
-void ChangeModule
-(
- Module ** in_pModuleList,
- size_t in_nModuleListSize,
- size_t in_nMenuPos,
- int in_nIndexX,
- int in_nCursorY,
- bool in_bUp
-)
-{
- size_t nModule = (in_nMenuPos + in_nCursorY) % in_nModuleListSize;
- in_pModuleList[nModule]->change(in_nIndexX,in_nCursorY,in_bUp);
-}
-
-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[] = { 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()
-{
- // Spin up RTC
- rtc.mapTime();
-
- // Initialise LCD
- lcd.begin(k_nWidthLCD,k_nHeightLCD);
- CreateChars();
-
- lcd.setCursor(0,0);
- lcd._putc(eUp);
-
- lcd.setCursor(0,1);
- lcd._putc(eDown);
-}
+#include "MenuManager.h"
-void SetCursor(bool in_bCursor,bool in_bBlink)
-{
- 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);
-
- 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();
-}
-
-void ShowTracking(bool in_bShow)
-{
- if (in_bShow)
- {
- lcd.setCursor(1,0);
- lcd._putc(eLeft);
-
- lcd.setCursor(1,1);
- lcd._putc(eRight);
- }
- else
- {
- lcd.setCursor(1,0);
- lcd._putc(' ');
-
- 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;
-
- nCurrent = (in_nMenuPos + inout_nCursorY) % in_nModuleListSize;
- inout_nIndexX = in_pModuleList[nCurrent]->setCursor(0,in_nCursorX,inout_nCursorY);
- }
-
- // If nothing to show - hide everything
- if (-1 == inout_nIndexX) SetCursor(false,false);
-}
+//Serial cPC(SERIAL_TX, SERIAL_RX);
int main()
-{
- pc.printf("\r\nInitialise LCD\r\n");
+{
+ MCP23017 cMCP23017 = MCP23017(I2C_SDA, I2C_SCL, 0x40, true);
+ Adafruit_RGBLCDShield cLCD(cMCP23017);
+ RTclock cRTclock(I2C_SDA, I2C_SCL);
+
+ // Spin up RTC
+ cRTclock.mapTime();
- Initialise();
-
- EModes eMode = eModeMenu;
- size_t nMenuPos = 0;
-
// Set up display modules
Module * aModules[] =
{
- new TitleModule(lcd),
- new TimeModule(lcd,rtc),
- new DateModule(lcd,rtc),
- new TempModule(lcd)
+ new TitleModule(cLCD),
+ new TimeModule(cLCD,cRTclock),
+ new DateModule(cLCD,cRTclock),
+ new TempModule(cLCD),
};
-
- ShowModules(aModules,_countof(aModules),nMenuPos);
-
- int nIndexX = 0;
- int nCursorY = 0;
-
- while (true)
- {
- uint8_t nKeys = lcd.readButtons();
- if (nKeys)
- {
- // 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);
-
- if (nKeys & (BUTTON_UP | BUTTON_DOWN))
- {
- bool bUp = (nKeys & BUTTON_UP) ? true : false;
- ChangeModule(aModules,_countof(aModules),nMenuPos,nIndexX,nCursorY,bUp);
- }
-
- if (nKeys & BUTTON_LEFT) nIndexX--;
- if (nKeys & BUTTON_RIGHT) nIndexX++;
- break;
- }
-
- 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);
- }
+ // Set up the menu manager
+ MenuManager cMenuManager(aModules,_countof(aModules),cLCD);
+
+ // Start menu manager loop
+ cMenuManager.loop();
}
