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: AdaFruit_RGBLCDShield MCP23017 mbed RTclock
Fork of MCP_test by
DateModule.cpp
00001 #include "mbed.h" 00002 #include "DateModule.h" 00003 #include "time_helper.h" 00004 00005 const char * k_aWeekDays[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; 00006 00007 DateModule::DateModule 00008 ( 00009 Serial & in_cDisplay, 00010 RTclock & in_cRTclock 00011 ) 00012 : Module(in_cDisplay) 00013 , m_cRTclock(in_cRTclock) 00014 { 00015 ::memset(&m_sLastTM,0,sizeof(m_sLastTM)); 00016 } 00017 00018 DateModule::~DateModule() 00019 { 00020 } 00021 00022 void DateModule::change 00023 ( 00024 size_t in_nIndex, 00025 bool in_bUp 00026 ) 00027 { 00028 tm sTM; 00029 00030 // to get the current time information 00031 if (!m_cRTclock.getTime(sTM)) GetTime(sTM); 00032 bool bTwelveHour = m_cRTclock.isTwelveHour(); 00033 00034 enum ETime 00035 { 00036 eWeekDay = 0, 00037 eDayTen, 00038 eDaySingle, 00039 eMonthTen, 00040 eMonthSingle, 00041 eYearTen, 00042 eYearSingle, 00043 }; 00044 00045 switch (in_nIndex) 00046 { 00047 case eWeekDay: sTM.tm_wday += (in_bUp ? 1 : -1); break; 00048 case eDayTen: sTM.tm_mday += (in_bUp ? 1 : -1) * 10; break; 00049 case eDaySingle: sTM.tm_mday += (in_bUp ? 1 : -1); break; 00050 case eMonthTen: sTM.tm_mon += (in_bUp ? 1 : -1) * 10; break; 00051 case eMonthSingle: sTM.tm_mon += (in_bUp ? 1 : -1); break; 00052 case eYearTen: sTM.tm_year += (in_bUp ? 1 : -1) * 10; break; 00053 case eYearSingle: sTM.tm_year += (in_bUp ? 1 : -1); break; 00054 } 00055 00056 if (sTM.tm_wday < 0) sTM.tm_wday = 0; 00057 if (sTM.tm_wday > 6) sTM.tm_wday = 6; 00058 if (sTM.tm_mday < 1) sTM.tm_mday = 1; 00059 if (sTM.tm_mday > 31) sTM.tm_mday = 31; 00060 if (sTM.tm_mon < 0) sTM.tm_mon = 0; 00061 if (sTM.tm_mon > 11) sTM.tm_mon = 11; 00062 if (sTM.tm_year < 2000 - 1900) sTM.tm_year = 2000 - 1900; 00063 if (sTM.tm_year > 2099 - 1900) sTM.tm_year = 2099 - 1900; 00064 00065 if (m_cRTclock.setTime(sTM,bTwelveHour)) 00066 { 00067 m_cRTclock.mapTime(); 00068 } 00069 else 00070 { 00071 SetTime(sTM); 00072 } 00073 } 00074 00075 int DateModule::getCursorOffset(size_t & inout_nIndex) 00076 { 00077 const int k_aCursor[] = { 2, 4, 5, 7, 8, 12, 13 }; 00078 00079 if ((int)inout_nIndex < 0) inout_nIndex = 0; 00080 if (inout_nIndex >= _countof(k_aCursor)) inout_nIndex = _countof(k_aCursor) - 1; 00081 00082 return k_aCursor[inout_nIndex]; 00083 } 00084 00085 void DateModule::show(bool in_bRefresh) 00086 { 00087 tm sTM; 00088 00089 // to get the current time information 00090 if (!m_cRTclock.getTime(sTM)) GetTime(sTM); 00091 00092 // if refreshing - only update if there's a change 00093 if (in_bRefresh) 00094 { 00095 // Check for change based on day (rest is irrelevant) 00096 if (sTM.tm_mday == m_sLastTM.tm_mday) return; 00097 } 00098 00099 // Ensure internal struct has new TM data 00100 ::memcpy(&m_sLastTM,&sTM,sizeof(m_sLastTM)); 00101 m_cDisplay.printf ("%s %02i/%02i/%04i ", k_aWeekDays[sTM.tm_wday], sTM.tm_mday, sTM.tm_mon + 1, 1900 + sTM.tm_year); 00102 }
Generated on Thu Jul 14 2022 00:55:23 by
1.7.2
