diff --git a/code/main/inc/clock.h b/code/main/inc/clock.h index 0d77506..0a9a3c3 100644 --- a/code/main/inc/clock.h +++ b/code/main/inc/clock.h @@ -34,7 +34,8 @@ // CompilerIncludes // All include files that are provided by the compiler directly - +#include +#include // ProjectIncludes @@ -57,45 +58,30 @@ // Function declarations // -------------------------------------------------------------------------------------------------------------------- +using namespace std; class Clock { public: - enum FifthsIndication - { - None_FifthIndication = 0, - Five, - Ten, - Quarter - }; - - enum BeforeAfterIndication - { - None_BeforeAfter = 0, - Before, - After - }; - - struct TimeStructure - { - bool prefix; - bool almost; - FifthsIndication fifths; - BeforeAfterIndication beforeAfter; - bool half; - int hours; - bool hourPostfix; - }; Clock(); - TimeStructure updateTime(void); + void generateWordlist(list* wordlist); + + time_t getTime(void); private: time_t currentTime; - void toString(TimeStructure* timestructure); + string toNumbers[20] {"zero", "one", "two", "three", "four", + "five", "six", "seven", "eight", + "nine", "ten", "eleven", "twelve", + "thirteen", "fourteen", "fifteen", + "sixteen", "seventeen", "eighteen", + "nineteen"}; + +// void toString(TimeStructure* timestructure); int calculateHours(int hour); }; diff --git a/code/main/inc/wordmap.h b/code/main/inc/wordmap.h new file mode 100644 index 0000000..3bf9b66 --- /dev/null +++ b/code/main/inc/wordmap.h @@ -0,0 +1,101 @@ +// -------------------------------------------------------------------------------------------------------------------- +/// \file wordmap.h +/// \brief File description +// -------------------------------------------------------------------------------------------------------------------- +// +// vbchaos software design +// +// -------------------------------------------------------------------------------------------------------------------- +/// $Revision: $ +/// $Author: $ +/// $Date: $ +// (c) 2023 vbchaos +// -------------------------------------------------------------------------------------------------------------------- + + +#ifndef MAIN_INC_WORDMAP_H_ +#define MAIN_INC_WORDMAP_H_ + +/** + * wordmap implementation + * \defgroup wordmap + * \brief {group_description} + * \addtogroup {Layer} + * + * Detailed description + * @{ + */ + + + +// -------------------------------------------------------------------------------------------------------------------- +// Include files +// -------------------------------------------------------------------------------------------------------------------- + +// CompilerIncludes +// All include files that are provided by the compiler directly +#include +#include + + +// ProjectIncludes +// All include files that are provided by the project +#include "ledmatrix.h" + +// -------------------------------------------------------------------------------------------------------------------- +// Constant and macro definitions +// -------------------------------------------------------------------------------------------------------------------- + + + +// -------------------------------------------------------------------------------------------------------------------- +// Type definitions. +// -------------------------------------------------------------------------------------------------------------------- + + + +// -------------------------------------------------------------------------------------------------------------------- +// Function declarations +// -------------------------------------------------------------------------------------------------------------------- + +using namespace std; + +class Wordmap +{ + public: + + typedef enum language + { + NL = 0, + EN, + NumberOfLanguages + } Language_t; + + Wordmap(LEDMatrix* matrix); + + bool setWord(Language_t lang, string identifier, bool value); + + private: + + struct word + { + string identifier; + LEDMatrix::coordinate position; + int length; + }; + + LEDMatrix* matrix; + language language; + + list wordlist[NumberOfLanguages]; + + void createList_NL(void); + void createList_EN(void); + + +}; + + +/** @} */ + +#endif /* MAIN_INC_WORDMAP_H_ */ diff --git a/code/main/main.cpp b/code/main/main.cpp index 31e4427..0009b06 100644 --- a/code/main/main.cpp +++ b/code/main/main.cpp @@ -97,7 +97,7 @@ static gptimer_handle_t matrixRefreshTimer = NULL; // -------------------------------------------------------------------------------------------------------------------- // Simple countdown on display -static void countdown(void); +static void countdown(int delay); // Timer Callback for the LEDMatrix refresh static bool timerCallback(gptimer_handle_t timer, const gptimer_alarm_event_data_t *edata, void *user_data); @@ -211,14 +211,24 @@ extern "C" void app_main(void) wifi.start_client(); Clock clock; - Clock::TimeStructure time; - countdown(); + countdown(200); + list wordlist; while (true) { - time = clock.updateTime(); + clock.generateWordlist(&wordlist); + + LEDMatrix.clear(); + std::list::iterator it; + for(it = wordlist.begin(); it != wordlist.end(); it++) + { + map.setWord(Wordmap::Language_t::NL, *it, true); + } + + // Add a seconds indicator + LEDMatrix.setPixelValue(10, 9, clock.getTime() % 2); // Update the clock every second (1000 ms) vTaskDelay(1000); @@ -240,37 +250,37 @@ static void devTask(void* parameters) } -static void countdown(void) +static void countdown(int delay) { map.setWord(Wordmap::Language_t::NL, "ten", true); - vTaskDelay(1000); + vTaskDelay(delay); map.setWord(Wordmap::Language_t::NL, "ten", false); map.setWord(Wordmap::Language_t::NL, "nine", true); - vTaskDelay(1000); + vTaskDelay(delay); map.setWord(Wordmap::Language_t::NL, "nine", false); map.setWord(Wordmap::Language_t::NL, "eight", true); - vTaskDelay(1000); + vTaskDelay(delay); map.setWord(Wordmap::Language_t::NL, "eight", false); map.setWord(Wordmap::Language_t::NL, "seven", true); - vTaskDelay(1000); + vTaskDelay(delay); map.setWord(Wordmap::Language_t::NL, "seven", false); map.setWord(Wordmap::Language_t::NL, "six", true); - vTaskDelay(1000); + vTaskDelay(delay); map.setWord(Wordmap::Language_t::NL, "six", false); map.setWord(Wordmap::Language_t::NL, "five", true); - vTaskDelay(1000); + vTaskDelay(delay); map.setWord(Wordmap::Language_t::NL, "five", false); map.setWord(Wordmap::Language_t::NL, "four", true); - vTaskDelay(1000); + vTaskDelay(delay); map.setWord(Wordmap::Language_t::NL, "four", false); map.setWord(Wordmap::Language_t::NL, "three", true); - vTaskDelay(1000); + vTaskDelay(delay); map.setWord(Wordmap::Language_t::NL, "three", false); map.setWord(Wordmap::Language_t::NL, "two", true); - vTaskDelay(1000); + vTaskDelay(delay); map.setWord(Wordmap::Language_t::NL, "two", false); map.setWord(Wordmap::Language_t::NL, "one", true); - vTaskDelay(1000); + vTaskDelay(delay); map.setWord(Wordmap::Language_t::NL, "one", false); } diff --git a/code/main/src/clock.cpp b/code/main/src/clock.cpp index 36a556e..35a4a53 100644 --- a/code/main/src/clock.cpp +++ b/code/main/src/clock.cpp @@ -64,124 +64,219 @@ Clock::Clock() sntp_init(); } -Clock::TimeStructure Clock::updateTime(void) +void Clock::generateWordlist(list* wordlist) { + 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; + wordlist->clear(); + wordlist->push_back("it"); + wordlist->push_back("is"); + wordlist->push_back(toNumbers[calculateHours(tm.tm_hour)]); 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; + wordlist->push_back("hours"); } else if (tm.tm_min < 9) { - timeStructure.fifths = Five; - timeStructure.beforeAfter = After; - timeStructure.half = false; - timeStructure.hours = calculateHours(tm.tm_hour); - timeStructure.hourPostfix = false; + wordlist->push_back("ind_five"); + wordlist->push_back("after"); } else if (tm.tm_min < 14) { - timeStructure.fifths = Ten; - timeStructure.beforeAfter = After; - timeStructure.half = false; - timeStructure.hours = calculateHours(tm.tm_hour); - timeStructure.hourPostfix = false; + wordlist->push_back("ind_ten"); + wordlist->push_back("after"); } else if (tm.tm_min < 19) { - timeStructure.fifths = Quarter; - timeStructure.beforeAfter = After; - timeStructure.half = false; - timeStructure.hours = calculateHours(tm.tm_hour); - timeStructure.hourPostfix = false; + wordlist->push_back("ind_quart"); + wordlist->push_back("after"); } 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; + wordlist->push_back("ind_ten"); + wordlist->push_back("before"); + wordlist->push_back("half"); } - else if (tm.tm_min < 29) + else if (tm.tm_min < 28) { - timeStructure.fifths = Five; - timeStructure.beforeAfter = Before; - timeStructure.half = true; - timeStructure.hours = calculateHours(tm.tm_hour + 1); - timeStructure.hourPostfix = false; + 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) { - timeStructure.fifths = None_FifthIndication; - timeStructure.beforeAfter = None_BeforeAfter; - timeStructure.half = true; - timeStructure.hours = calculateHours(tm.tm_hour + 1); - timeStructure.hourPostfix = false; + wordlist->push_back("half"); } 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; + wordlist->push_back("ind_five"); + wordlist->push_back("after"); + wordlist->push_back("half"); } 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; + wordlist->push_back("ind_ten"); + wordlist->push_back("after"); + wordlist->push_back("half"); } 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; + wordlist->push_back("ind_quart"); + wordlist->push_back("before"); } 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; + wordlist->push_back("ind_ten"); + wordlist->push_back("before"); } - else if (tm.tm_min < 59) + else if (tm.tm_min < 58) { - timeStructure.fifths = Five; - timeStructure.beforeAfter = Before; - timeStructure.half = false; - timeStructure.hours = calculateHours(tm.tm_hour + 1); - timeStructure.hourPostfix = false; + wordlist->push_back("ind_five"); + wordlist->push_back("before"); + } + else + { + wordlist->push_back("almost"); } - - toString(&timeStructure); - - return timeStructure; } +time_t Clock::getTime(void) +{ + time(¤tTime); + 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 hours; @@ -197,17 +292,17 @@ int Clock::calculateHours(int hour) 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" : "" - ); -} +//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" : "" +// ); +//} diff --git a/code/main/src/wordmap.cpp b/code/main/src/wordmap.cpp new file mode 100644 index 0000000..374c420 --- /dev/null +++ b/code/main/src/wordmap.cpp @@ -0,0 +1,143 @@ +// -------------------------------------------------------------------------------------------------------------------- +/// \file wordmap.cpp +/// \brief Description +// -------------------------------------------------------------------------------------------------------------------- +// +// vbchaos software design +// +// -------------------------------------------------------------------------------------------------------------------- +/// $Revision: $ +/// $Author: $ +/// $Date: $ +// (c) 2023 vbchaos +// -------------------------------------------------------------------------------------------------------------------- + + +// -------------------------------------------------------------------------------------------------------------------- +// Include files +// -------------------------------------------------------------------------------------------------------------------- + +#include "wordmap.h" + +#include "logger.h" +// -------------------------------------------------------------------------------------------------------------------- +// Constant and macro definitions +// -------------------------------------------------------------------------------------------------------------------- + + + +// -------------------------------------------------------------------------------------------------------------------- +// Type definitions +// -------------------------------------------------------------------------------------------------------------------- + + +// -------------------------------------------------------------------------------------------------------------------- +// File-scope variables +// -------------------------------------------------------------------------------------------------------------------- + + + +// -------------------------------------------------------------------------------------------------------------------- +// Function declarations +// -------------------------------------------------------------------------------------------------------------------- + + + +// -------------------------------------------------------------------------------------------------------------------- +// Function definitions +// -------------------------------------------------------------------------------------------------------------------- + + +Wordmap::Wordmap(LEDMatrix* matrix) +{ + Wordmap::matrix = matrix; + Wordmap::language = NL; + + createList_NL(); +} + +bool Wordmap::setWord(Language_t lang, string identifier, bool value) +{ + bool returnValue; + + auto _compare = [&](struct word currentword) + { + if (identifier.compare(currentword.identifier) == 0) + { + return true; + } + else + { + return false; + } + }; + + // Create a list Iterator + std::list::iterator it; + // Fetch the iterator of element with value 'the' + it = find_if(wordlist[lang].begin(), wordlist[lang].end(), _compare); + // Check if iterator points to end or not + + if(it != wordlist[lang].end()) + { + returnValue = true; + } + else + { + returnValue = false; + } + + if (returnValue) + { + if (it->length > 0) + { + for (int i = 0; i < it->length; i++) + { + matrix->setPixelValue(it->position.x + i, it->position.y, value); + } + } + } + + return returnValue; +} + +void Wordmap::createList_NL(void) +{ + // First, clear the list + wordlist[NL].clear(); + + // Now lets add all relevant words + wordlist[NL].push_back((struct word){"it", {0,0}, 3}); + wordlist[NL].push_back((struct word){"is", {4,0}, 2}); + + wordlist[NL].push_back((struct word){"ind_five", {7,0}, 4}); + wordlist[NL].push_back((struct word){"ind_ten", {1,1}, 4}); + wordlist[NL].push_back((struct word){"ind_quart", {6,1}, 5}); + wordlist[NL].push_back((struct word){"ind_twenty", {0,2}, 7}); + + wordlist[NL].push_back((struct word){"before", {6,3}, 4}); + wordlist[NL].push_back((struct word){"after", {1,3}, 4}); + + wordlist[NL].push_back((struct word){"almost", {1,4}, 5}), + + wordlist[NL].push_back((struct word){"half", {7,4}, 4}); + + wordlist[NL].push_back((struct word){"one", {3,5}, 3}); + wordlist[NL].push_back((struct word){"two", {1,5}, 4}); + wordlist[NL].push_back((struct word){"three", {6,5}, 4}); + wordlist[NL].push_back((struct word){"four", {7,6}, 4}); + wordlist[NL].push_back((struct word){"five", {0,6}, 4}); + wordlist[NL].push_back((struct word){"six", {4,6}, 3}); + wordlist[NL].push_back((struct word){"seven", {0,7}, 5}); + wordlist[NL].push_back((struct word){"eight", {0,8}, 4}); + wordlist[NL].push_back((struct word){"nine", {6,7}, 5}); + wordlist[NL].push_back((struct word){"ten", {4,8}, 4}); + wordlist[NL].push_back((struct word){"eleven", {8,8}, 3}); + wordlist[NL].push_back((struct word){"twelve", {0,9}, 6}); + + wordlist[NL].push_back((struct word){"hours", {7,9}, 3}); +} + + + +