Updated hours bug
This commit is contained in:
+10
-2
@@ -64,16 +64,24 @@ class Clock
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
enum mode
|
||||||
|
{
|
||||||
|
TEN_BEFORE_HALF,
|
||||||
|
TWENTY_OVER
|
||||||
|
};
|
||||||
|
|
||||||
Clock();
|
Clock(Clock::mode mode);
|
||||||
|
|
||||||
void generateWordlist(list<string>* wordlist);
|
void generateWordlist(list<string>* wordlist);
|
||||||
|
|
||||||
time_t getTime(void);
|
time_t getTime(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
Clock::mode clockmode;
|
||||||
time_t currentTime;
|
time_t currentTime;
|
||||||
|
|
||||||
|
|
||||||
string toNumbers[20] {"zero", "one", "two", "three", "four",
|
string toNumbers[20] {"zero", "one", "two", "three", "four",
|
||||||
"five", "six", "seven", "eight",
|
"five", "six", "seven", "eight",
|
||||||
"nine", "ten", "eleven", "twelve",
|
"nine", "ten", "eleven", "twelve",
|
||||||
@@ -82,7 +90,7 @@ class Clock
|
|||||||
"nineteen"};
|
"nineteen"};
|
||||||
|
|
||||||
// void toString(TimeStructure* timestructure);
|
// void toString(TimeStructure* timestructure);
|
||||||
int calculateHours(int hour);
|
int calculateHours(struct tm time);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -210,7 +210,7 @@ extern "C" void app_main(void)
|
|||||||
Wifi wifi;
|
Wifi wifi;
|
||||||
wifi.start_client();
|
wifi.start_client();
|
||||||
|
|
||||||
Clock clock;
|
Clock clock(Clock::mode::TEN_BEFORE_HALF);
|
||||||
|
|
||||||
countdown(200);
|
countdown(200);
|
||||||
|
|
||||||
|
|||||||
+16
-127
@@ -52,10 +52,12 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
Clock::Clock()
|
Clock::Clock(Clock::mode mode)
|
||||||
{
|
{
|
||||||
Clock::currentTime = 0;
|
Clock::currentTime = 0;
|
||||||
|
|
||||||
|
Clock::clockmode = mode;
|
||||||
|
|
||||||
// Start NTP
|
// Start NTP
|
||||||
setenv("TZ", "CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00", 1);
|
setenv("TZ", "CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00", 1);
|
||||||
tzset();
|
tzset();
|
||||||
@@ -77,7 +79,7 @@ void Clock::generateWordlist(list<string>* wordlist)
|
|||||||
wordlist->clear();
|
wordlist->clear();
|
||||||
wordlist->push_back("it");
|
wordlist->push_back("it");
|
||||||
wordlist->push_back("is");
|
wordlist->push_back("is");
|
||||||
wordlist->push_back(toNumbers[calculateHours(tm.tm_hour)]);
|
wordlist->push_back(toNumbers[calculateHours(tm)]);
|
||||||
|
|
||||||
if (tm.tm_min < 4)
|
if (tm.tm_min < 4)
|
||||||
{
|
{
|
||||||
@@ -159,136 +161,23 @@ time_t Clock::getTime(void)
|
|||||||
return currentTime;
|
return currentTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Clock::TimeStructure Clock::updateTime(void)
|
|
||||||
//{
|
|
||||||
// struct tm tm;
|
|
||||||
// time(¤tTime);
|
|
||||||
//// currentTime += 10;
|
|
||||||
// localtime_r(¤tTime, &tm);
|
|
||||||
//
|
|
||||||
// LOGGER_INFO("%lld\n\r", currentTime);
|
|
||||||
// LOGGER_INFO("%02i:%02i:%02i\n\r", tm.tm_hour, tm.tm_min, tm.tm_sec);
|
|
||||||
//
|
|
||||||
// // Construct the time structure
|
|
||||||
// TimeStructure timeStructure;
|
|
||||||
// // Show the prefix
|
|
||||||
// timeStructure.prefix = true;
|
|
||||||
//
|
|
||||||
// if (tm.tm_min < 4)
|
|
||||||
// {
|
|
||||||
// timeStructure.fifths = None_FifthIndication;
|
|
||||||
// timeStructure.beforeAfter = None_BeforeAfter;
|
|
||||||
// timeStructure.half = false;
|
|
||||||
// timeStructure.hours = calculateHours(tm.tm_hour);
|
|
||||||
// timeStructure.hourPostfix = true;
|
|
||||||
// }
|
|
||||||
// else if (tm.tm_min < 9)
|
|
||||||
// {
|
|
||||||
// timeStructure.fifths = Five;
|
|
||||||
// timeStructure.beforeAfter = After;
|
|
||||||
// timeStructure.half = false;
|
|
||||||
// timeStructure.hours = calculateHours(tm.tm_hour);
|
|
||||||
// timeStructure.hourPostfix = false;
|
|
||||||
// }
|
|
||||||
// else if (tm.tm_min < 14)
|
|
||||||
// {
|
|
||||||
// timeStructure.fifths = Ten;
|
|
||||||
// timeStructure.beforeAfter = After;
|
|
||||||
// timeStructure.half = false;
|
|
||||||
// timeStructure.hours = calculateHours(tm.tm_hour);
|
|
||||||
// timeStructure.hourPostfix = false;
|
|
||||||
// }
|
|
||||||
// else if (tm.tm_min < 19)
|
|
||||||
// {
|
|
||||||
// timeStructure.fifths = Quarter;
|
|
||||||
// timeStructure.beforeAfter = After;
|
|
||||||
// timeStructure.half = false;
|
|
||||||
// timeStructure.hours = calculateHours(tm.tm_hour);
|
|
||||||
// timeStructure.hourPostfix = false;
|
|
||||||
// }
|
|
||||||
// else if (tm.tm_min < 24)
|
|
||||||
// {
|
|
||||||
// timeStructure.fifths = Ten;
|
|
||||||
// timeStructure.beforeAfter = Before;
|
|
||||||
// timeStructure.half = true;
|
|
||||||
// timeStructure.hours = calculateHours(tm.tm_hour + 1);
|
|
||||||
// timeStructure.hourPostfix = false;
|
|
||||||
// }
|
|
||||||
// else if (tm.tm_min < 29)
|
|
||||||
// {
|
|
||||||
// timeStructure.fifths = Five;
|
|
||||||
// timeStructure.beforeAfter = Before;
|
|
||||||
// timeStructure.half = true;
|
|
||||||
// timeStructure.hours = calculateHours(tm.tm_hour + 1);
|
|
||||||
// timeStructure.hourPostfix = false;
|
|
||||||
// }
|
|
||||||
// else if (tm.tm_min < 34)
|
|
||||||
// {
|
|
||||||
// timeStructure.fifths = None_FifthIndication;
|
|
||||||
// timeStructure.beforeAfter = None_BeforeAfter;
|
|
||||||
// timeStructure.half = true;
|
|
||||||
// timeStructure.hours = calculateHours(tm.tm_hour + 1);
|
|
||||||
// timeStructure.hourPostfix = false;
|
|
||||||
// }
|
|
||||||
// else if (tm.tm_min < 39)
|
|
||||||
// {
|
|
||||||
// timeStructure.fifths = Five;
|
|
||||||
// timeStructure.beforeAfter = After;
|
|
||||||
// timeStructure.half = true;
|
|
||||||
// timeStructure.hours = calculateHours(tm.tm_hour + 1);
|
|
||||||
// timeStructure.hourPostfix = false;
|
|
||||||
// }
|
|
||||||
// else if (tm.tm_min < 44)
|
|
||||||
// {
|
|
||||||
// timeStructure.fifths = Ten;
|
|
||||||
// timeStructure.beforeAfter = After;
|
|
||||||
// timeStructure.half = true;
|
|
||||||
// timeStructure.hours = calculateHours(tm.tm_hour + 1);
|
|
||||||
// timeStructure.hourPostfix = false;
|
|
||||||
// }
|
|
||||||
// else if (tm.tm_min < 49)
|
|
||||||
// {
|
|
||||||
// timeStructure.fifths = Quarter;
|
|
||||||
// timeStructure.beforeAfter = Before;
|
|
||||||
// timeStructure.half = false;
|
|
||||||
// timeStructure.hours = calculateHours(tm.tm_hour + 1);
|
|
||||||
// timeStructure.hourPostfix = false;
|
|
||||||
// }
|
|
||||||
// else if (tm.tm_min < 54)
|
|
||||||
// {
|
|
||||||
// timeStructure.fifths = Ten;
|
|
||||||
// timeStructure.beforeAfter = Before;
|
|
||||||
// timeStructure.half = false;
|
|
||||||
// timeStructure.hours = calculateHours(tm.tm_hour + 1);
|
|
||||||
// timeStructure.hourPostfix = false;
|
|
||||||
// }
|
|
||||||
// else if (tm.tm_min < 59)
|
|
||||||
// {
|
|
||||||
// timeStructure.fifths = Five;
|
|
||||||
// timeStructure.beforeAfter = Before;
|
|
||||||
// timeStructure.half = false;
|
|
||||||
// timeStructure.hours = calculateHours(tm.tm_hour + 1);
|
|
||||||
// timeStructure.hourPostfix = false;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// toString(&timeStructure);
|
|
||||||
//
|
|
||||||
// return timeStructure;
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
int Clock::calculateHours(struct tm time)
|
||||||
int Clock::calculateHours(int hour)
|
|
||||||
{
|
{
|
||||||
int hours;
|
int hours = time.tm_hour;
|
||||||
|
// Add one hour in case the clock is heading towards half
|
||||||
|
if (time.tm_min > 19)
|
||||||
|
{
|
||||||
|
hours = hours + 1;
|
||||||
|
}
|
||||||
|
|
||||||
// Calculate hours to 12hour system
|
// Calculate hours to 12hour system
|
||||||
if (hour > 12)
|
if (time.tm_hour > 12)
|
||||||
{
|
{
|
||||||
hours = hour - 12;
|
hours = hours - 12;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
hours = hour;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return hours;
|
return hours;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user