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
Revision 11:96146db429de, committed 2014-08-10
- Comitter:
- vtraveller
- Date:
- Sun Aug 10 15:45:03 2014 +0000
- Parent:
- 10:3fcab08717fc
- Child:
- 12:0fea8ebe6c1a
- Commit message:
- Added support for changing time.
Changed in this revision
--- a/Modules/DateModule.cpp Sun Aug 10 12:34:44 2014 +0000
+++ b/Modules/DateModule.cpp Sun Aug 10 15:45:03 2014 +0000
@@ -17,7 +17,31 @@
DateModule::~DateModule()
{
}
+
+void DateModule::change
+(
+ int in_nIndexX,
+ int in_nCursorY,
+ bool in_bUp
+)
+{
+ tm sTM;
+ // to get the current time information
+ if (!m_cRTclock.getTime(sTM)) GetTime(sTM);
+ bool bTwelveHour = m_cRTclock.isTwelveHour();
+
+#if 0
+ switch (in_nIndexX)
+ {
+ case 0: m_nTemp += (in_bUp ? 1 : -1) * 10; break;
+ case 1: m_nTemp += (in_bUp ? 1 : -1); break;
+ }
+#endif
+
+ if (!m_cRTclock.setTime(sTM,bTwelveHour)) SetTime(sTM);
+}
+
int DateModule::setCursor
(
int in_nIndex,
--- a/Modules/DateModule.h Sun Aug 10 12:34:44 2014 +0000
+++ b/Modules/DateModule.h Sun Aug 10 15:45:03 2014 +0000
@@ -15,6 +15,12 @@
);
virtual ~DateModule();
+ virtual void change
+ (
+ int in_nIndexX,
+ int in_nCursorY,
+ bool in_bUp
+ );
virtual int setCursor
(
int in_nIndex,
--- a/Modules/TempModule.cpp Sun Aug 10 12:34:44 2014 +0000
+++ b/Modules/TempModule.cpp Sun Aug 10 15:45:03 2014 +0000
@@ -5,13 +5,37 @@
TempModule::TempModule(Adafruit_RGBLCDShield & in_cLCD)
: Module(in_cLCD)
+ , m_nTemp(28)
{
}
TempModule::~TempModule()
{
}
+
+void TempModule::change
+(
+ int in_nIndexX,
+ int in_nCursorY,
+ bool in_bUp
+)
+{
+ enum ETemp
+ {
+ eTens = 0,
+ eSingles = 1,
+ };
+ switch (in_nIndexX)
+ {
+ case eTens: m_nTemp += (in_bUp ? 1 : -1) * 10; break;
+ case eSingles: m_nTemp += (in_bUp ? 1 : -1); break;
+ }
+
+ if (m_nTemp > 40) m_nTemp = 40;
+ if (m_nTemp < -40) m_nTemp = -40;
+}
+
int TempModule::setCursor
(
int in_nIndex,
@@ -33,5 +57,5 @@
void TempModule::show()
{
- m_cLCD.printf("Room: %i%cC ",28,eDegree);
+ m_cLCD.printf("Room: %i%cC ",m_nTemp,eDegree);
}
--- a/Modules/TempModule.h Sun Aug 10 12:34:44 2014 +0000
+++ b/Modules/TempModule.h Sun Aug 10 15:45:03 2014 +0000
@@ -10,13 +10,22 @@
TempModule(Adafruit_RGBLCDShield & in_cLCD);
virtual ~TempModule();
+ virtual void change
+ (
+ int in_nIndexX,
+ int in_nCursorY,
+ bool in_bUp
+ );
virtual int setCursor
(
int in_nIndex,
int in_nCursorX,
int in_nCursorY
);
- virtual void show();
+ virtual void show();
+
+protected:
+ int m_nTemp;
};
#endif /* __TEMPMODULE_H__ */
--- a/Modules/TimeModule.cpp Sun Aug 10 12:34:44 2014 +0000
+++ b/Modules/TimeModule.cpp Sun Aug 10 15:45:03 2014 +0000
@@ -29,7 +29,77 @@
TimeModule::~TimeModule()
{
}
+
+void TimeModule::change
+(
+ int in_nIndexX,
+ int in_nCursorY,
+ bool in_bUp
+)
+{
+ tm sTM;
+ // to get the current time information
+ if (!m_cRTclock.getTime(sTM)) GetTime(sTM);
+ bool bTwelveHour = m_cRTclock.isTwelveHour();
+
+ enum ETime
+ {
+ eHourTen = 0,
+ eHourSingle,
+ eMinTen,
+ eMinSingle,
+ eSecondTen,
+ eSecondSingle,
+ eAmPm,
+ };
+
+ switch (in_nIndexX)
+ {
+ case eHourTen: sTM.tm_hour += (in_bUp ? 1 : -1) * 10; break;
+ case eHourSingle: sTM.tm_hour += (in_bUp ? 1 : -1); break;
+ case eMinTen: sTM.tm_min += (in_bUp ? 1 : -1) * 10; break;
+ case eMinSingle: sTM.tm_min += (in_bUp ? 1 : -1); break;
+ case eSecondTen: sTM.tm_sec += (in_bUp ? 1 : -1) * 10; break;
+ case eSecondSingle: sTM.tm_sec += (in_bUp ? 1 : -1); break;
+ case eAmPm:
+ if (bTwelveHour)
+ {
+ if (in_bUp)
+ {
+ if (sTM.tm_hour >= 12) bTwelveHour = !bTwelveHour; else sTM.tm_hour += 12;
+ }
+ else
+ {
+ if (sTM.tm_hour >= 12) sTM.tm_hour -= 12; else bTwelveHour = !bTwelveHour;
+ }
+ }
+ else
+ {
+ bTwelveHour = !bTwelveHour;
+ if (in_bUp && sTM.tm_hour >= 12) sTM.tm_hour -= 12;
+ if (!in_bUp && sTM.tm_hour < 12) sTM.tm_hour += 12;
+ }
+ break;
+ }
+
+ if (sTM.tm_hour < 0) sTM.tm_hour = 0;
+ if (sTM.tm_hour > 23) sTM.tm_hour = 23;
+ if (sTM.tm_min < 0) sTM.tm_min = 0;
+ if (sTM.tm_hour > 59) sTM.tm_min = 59;
+ if (sTM.tm_sec < 0) sTM.tm_sec = 0;
+ if (sTM.tm_sec > 59) sTM.tm_sec = 59;
+
+ if (m_cRTclock.setTime(sTM,bTwelveHour))
+ {
+ m_cRTclock.mapTime();
+ }
+ else
+ {
+ SetTime(sTM);
+ }
+}
+
int TimeModule::setCursor
(
int in_nIndex,
--- a/Modules/TimeModule.h Sun Aug 10 12:34:44 2014 +0000
+++ b/Modules/TimeModule.h Sun Aug 10 15:45:03 2014 +0000
@@ -16,6 +16,12 @@
virtual ~TimeModule();
virtual bool canRefresh() { return true; }
+ virtual void change
+ (
+ int in_nIndexX,
+ int in_nCursorY,
+ bool in_bUp
+ );
virtual int setCursor
(
int in_nIndex,
--- a/Modules/TitleModule.cpp Sun Aug 10 12:34:44 2014 +0000
+++ b/Modules/TitleModule.cpp Sun Aug 10 15:45:03 2014 +0000
@@ -9,16 +9,6 @@
TitleModule::~TitleModule()
{
}
-
-int TitleModule::setCursor
-(
- int in_nIndex,
- int in_nCursorX,
- int in_nCursorY
-)
-{
- return -1;
-}
void TitleModule::show()
{
--- a/Modules/TitleModule.h Sun Aug 10 12:34:44 2014 +0000
+++ b/Modules/TitleModule.h Sun Aug 10 15:45:03 2014 +0000
@@ -10,12 +10,6 @@
TitleModule(Adafruit_RGBLCDShield & in_cLCD);
virtual ~TitleModule();
- virtual int setCursor
- (
- int in_nIndex,
- int in_nCursorX,
- int in_nCursorY
- );
virtual void show();
};
--- a/Modules/module.h Sun Aug 10 12:34:44 2014 +0000
+++ b/Modules/module.h Sun Aug 10 15:45:03 2014 +0000
@@ -14,12 +14,20 @@
virtual ~Module();
virtual bool canRefresh() { return false; }
+ virtual void change
+ (
+ int in_nIndexX,
+ int in_nCursorY,
+ bool in_bUp
+ )
+ { ; }
virtual int setCursor
(
- int in_nIndex,
- int in_nCursorX,
- int in_nCursorY
- ) = 0;
+ int in_nIndex,
+ int in_nCursorX,
+ int in_nCursorY
+ )
+ { return -1; }
virtual void show() = 0;
protected:
--- a/main.cpp Sun Aug 10 12:34:44 2014 +0000
+++ b/main.cpp Sun Aug 10 15:45:03 2014 +0000
@@ -26,6 +26,20 @@
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 };
@@ -193,12 +207,21 @@
if ((nCursorY < k_nHeightLCD - 1) && (nKeys & BUTTON_DOWN)) nCursorY++;
if (nKeys & BUTTON_LEFT) nIndexX--;
- if (nKeys & BUTTON_RIGHT) 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;
}
--- a/time_helper.cpp Sun Aug 10 12:34:44 2014 +0000
+++ b/time_helper.cpp Sun Aug 10 15:45:03 2014 +0000
@@ -8,23 +8,11 @@
::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
-)
+void SetTime(const tm & in_sTM)
{
- tm sCurrentTime = { 0 };
- sCurrentTime.tm_year = in_nYear - 1900;
- sCurrentTime.tm_mon = in_nMonth - 1;
- sCurrentTime.tm_mday = in_nDay;
+ tm sTM = { 0 };
+ memcpy(&sTM,&in_sTM,sizeof(sTM));
- sCurrentTime.tm_hour = in_nHour;
- sCurrentTime.tm_min = in_nMin;
-
- time_t nCurrentTime = mktime(&sCurrentTime);
- set_time(nCurrentTime);
+ time_t nTime = mktime(&sTM);
+ set_time(nTime);
}
--- a/time_helper.h Sun Aug 10 12:34:44 2014 +0000 +++ b/time_helper.h Sun Aug 10 15:45:03 2014 +0000 @@ -4,14 +4,6 @@ #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 -); +void SetTime(const tm & in_sTM); #endif /* __TIME_HELPER_H__ */ \ No newline at end of file
