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.
Fork of SX1276_GPS by
Modules/DateModule.cpp
- Committer:
- vtraveller
- Date:
- 2014-08-11
- Revision:
- 13:9641bc42db92
- Parent:
- 12:0fea8ebe6c1a
- Child:
- 15:d1eaddb363be
File content as of revision 13:9641bc42db92:
#include "mbed.h"
#include "DateModule.h"
#include "time_helper.h"
const char * k_aWeekDays[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
DateModule::DateModule
(
Serial & in_cDisplay,
RTclock & in_cRTclock
)
: Module(in_cDisplay)
, m_cRTclock(in_cRTclock)
{
}
DateModule::~DateModule()
{
}
void DateModule::change
(
size_t in_nIndex,
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
{
eWeekDay = 0,
eDayTen,
eDaySingle,
eMonthTen,
eMonthSingle,
eYearTen,
eYearSingle,
};
switch (in_nIndex)
{
case eWeekDay: sTM.tm_wday += (in_bUp ? 1 : -1); break;
case eDayTen: sTM.tm_mday += (in_bUp ? 1 : -1) * 10; break;
case eDaySingle: sTM.tm_mday += (in_bUp ? 1 : -1); break;
case eMonthTen: sTM.tm_mon += (in_bUp ? 1 : -1) * 10; break;
case eMonthSingle: sTM.tm_mon += (in_bUp ? 1 : -1); break;
case eYearTen: sTM.tm_year += (in_bUp ? 1 : -1) * 10; break;
case eYearSingle: sTM.tm_year += (in_bUp ? 1 : -1); break;
}
if (sTM.tm_wday < 0) sTM.tm_wday = 0;
if (sTM.tm_wday > 6) sTM.tm_wday = 6;
if (sTM.tm_mday < 1) sTM.tm_mday = 1;
if (sTM.tm_mday > 31) sTM.tm_mday = 31;
if (sTM.tm_mon < 0) sTM.tm_mon = 0;
if (sTM.tm_mon > 11) sTM.tm_mon = 11;
if (sTM.tm_year < 2000 - 1900) sTM.tm_year = 2000 - 1900;
if (sTM.tm_year > 2099 - 1900) sTM.tm_year = 2099 - 1900;
if (m_cRTclock.setTime(sTM,bTwelveHour))
{
m_cRTclock.mapTime();
}
else
{
SetTime(sTM);
}
}
int DateModule::getCursorOffset(size_t & inout_nIndex)
{
const int k_aCursor[] = { 2, 4, 5, 7, 8, 12, 13 };
if ((int)inout_nIndex < 0) inout_nIndex = 0;
if (inout_nIndex >= _countof(k_aCursor)) inout_nIndex = _countof(k_aCursor) - 1;
return k_aCursor[inout_nIndex];
}
void DateModule::show()
{
tm sTM;
// to get the current time information
if (!m_cRTclock.getTime(sTM)) GetTime(sTM);
m_cDisplay.printf ("%s %02i/%02i/%04i ", k_aWeekDays[sTM.tm_wday], sTM.tm_mday, sTM.tm_mon + 1, 1900 + sTM.tm_year);
}
