// -------------------------------------------------------------------------------------------------------------------- /// \file clock.cpp /// \brief Description // -------------------------------------------------------------------------------------------------------------------- // // vbchaos software design // // -------------------------------------------------------------------------------------------------------------------- /// $Revision: $ /// $Author: $ /// $Date: $ // (c) 2023 vbchaos // -------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------- // Include files // -------------------------------------------------------------------------------------------------------------------- #include "clock.h" #include "esp_sntp.h" #include "esp_wifi.h" #include "logger.h" // -------------------------------------------------------------------------------------------------------------------- // Constant and macro definitions // -------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------- // Type definitions // -------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------- // File-scope variables // -------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------- // Function declarations // -------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------- // Function definitions // -------------------------------------------------------------------------------------------------------------------- Clock::Clock(Clock::mode mode) { Clock::currentTime = 40000; Clock::clockmode = mode; // Start NTP setenv("TZ", "CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00", 1); tzset(); esp_sntp_setoperatingmode(ESP_SNTP_OPMODE_POLL); esp_sntp_setservername(0, "pool.ntp.org"); esp_sntp_init(); } void Clock::generateWordlist(list* wordlist) { struct tm tm; time(¤tTime); // currentTime += 100; 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); wordlist->clear(); wordlist->push_back("it"); wordlist->push_back("is"); wordlist->push_back(toNumbers[calculateHours(tm)]); if (tm.tm_min < 4) { wordlist->push_back("hours"); } else if (tm.tm_min < 9) { wordlist->push_back("ind_five"); wordlist->push_back("after"); } else if (tm.tm_min < 14) { wordlist->push_back("ind_ten"); wordlist->push_back("after"); } else if (tm.tm_min < 19) { wordlist->push_back("ind_quart"); wordlist->push_back("after"); } else if (tm.tm_min < 24) { wordlist->push_back("ind_ten"); wordlist->push_back("before"); wordlist->push_back("half"); } else if (tm.tm_min < 28) { wordlist->push_back("ind_five"); wordlist->push_back("before"); wordlist->push_back("half"); } else if (tm.tm_min < 30) { wordlist->push_back("almost"); wordlist->push_back("half"); } else if (tm.tm_min < 34) { wordlist->push_back("half"); } else if (tm.tm_min < 39) { wordlist->push_back("ind_five"); wordlist->push_back("after"); wordlist->push_back("half"); } else if (tm.tm_min < 44) { wordlist->push_back("ind_ten"); wordlist->push_back("after"); wordlist->push_back("half"); } else if (tm.tm_min < 49) { wordlist->push_back("ind_quart"); wordlist->push_back("before"); } else if (tm.tm_min < 54) { wordlist->push_back("ind_ten"); wordlist->push_back("before"); } else if (tm.tm_min < 58) { wordlist->push_back("ind_five"); wordlist->push_back("before"); } else { wordlist->push_back("almost"); wordlist->push_back("hours"); } // Attach the day as a word, too switch (tm.tm_wday) { case 0: wordlist->push_back("sunday"); break; case 1: wordlist->push_back("monday"); break; case 2: wordlist->push_back("tuesday"); break; case 3: wordlist->push_back("wednesday"); break; case 4: wordlist->push_back("thursday"); break; case 5: wordlist->push_back("friday"); break; case 6: wordlist->push_back("saturday"); break; default: wordlist->push_back("sunday"); } } time_t Clock::getTime(void) { // time(¤tTime); return currentTime; } int Clock::calculateHours(struct tm time) { 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 (hours > 12) { hours = hours - 12; } // Start at 1, not 0 if (hours == 0) { hours++; } return hours; } //void Clock::toString(TimeStructure* timestructure) //{ // LOGGER_SUCCESS("%s%s%s%s%d%s", timestructure->prefix ? "Het is " : "", // timestructure->fifths == Five ? "Vijf " : // timestructure->fifths == Ten ? "Tien " : // timestructure->fifths == Quarter ? "kwart ": "", // timestructure->beforeAfter == Before ? "voor " : // timestructure->beforeAfter == After ? "over " : "", // timestructure->half ? "half " : "", // timestructure->hours, // timestructure->hourPostfix ? " uur" : "" // ); //}