Updated hours bug
This commit is contained in:
+10
-2
@@ -64,16 +64,24 @@ class Clock
|
||||
{
|
||||
public:
|
||||
|
||||
enum mode
|
||||
{
|
||||
TEN_BEFORE_HALF,
|
||||
TWENTY_OVER
|
||||
};
|
||||
|
||||
Clock();
|
||||
Clock(Clock::mode mode);
|
||||
|
||||
void generateWordlist(list<string>* wordlist);
|
||||
|
||||
time_t getTime(void);
|
||||
|
||||
private:
|
||||
|
||||
Clock::mode clockmode;
|
||||
time_t currentTime;
|
||||
|
||||
|
||||
string toNumbers[20] {"zero", "one", "two", "three", "four",
|
||||
"five", "six", "seven", "eight",
|
||||
"nine", "ten", "eleven", "twelve",
|
||||
@@ -82,7 +90,7 @@ class Clock
|
||||
"nineteen"};
|
||||
|
||||
// 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.start_client();
|
||||
|
||||
Clock clock;
|
||||
Clock clock(Clock::mode::TEN_BEFORE_HALF);
|
||||
|
||||
countdown(200);
|
||||
|
||||
|
||||
+16
-127
@@ -52,10 +52,12 @@
|
||||
|
||||
|
||||
|
||||
Clock::Clock()
|
||||
Clock::Clock(Clock::mode mode)
|
||||
{
|
||||
Clock::currentTime = 0;
|
||||
|
||||
Clock::clockmode = mode;
|
||||
|
||||
// Start NTP
|
||||
setenv("TZ", "CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00", 1);
|
||||
tzset();
|
||||
@@ -77,7 +79,7 @@ void Clock::generateWordlist(list<string>* wordlist)
|
||||
wordlist->clear();
|
||||
wordlist->push_back("it");
|
||||
wordlist->push_back("is");
|
||||
wordlist->push_back(toNumbers[calculateHours(tm.tm_hour)]);
|
||||
wordlist->push_back(toNumbers[calculateHours(tm)]);
|
||||
|
||||
if (tm.tm_min < 4)
|
||||
{
|
||||
@@ -159,136 +161,23 @@ time_t Clock::getTime(void)
|
||||
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(int hour)
|
||||
int Clock::calculateHours(struct tm time)
|
||||
{
|
||||
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
|
||||
if (hour > 12)
|
||||
if (time.tm_hour > 12)
|
||||
{
|
||||
hours = hour - 12;
|
||||
}
|
||||
else
|
||||
{
|
||||
hours = hour;
|
||||
hours = hours - 12;
|
||||
}
|
||||
|
||||
|
||||
return hours;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user