From 35c940ca5b6cd330d19b362c4fc378edfc6c2247 Mon Sep 17 00:00:00 2001 From: Matthias Mitscherlich Date: Tue, 7 Feb 2023 13:38:23 +0100 Subject: [PATCH] added clock wordmap and made wordmap a baseclass --- code/main/CMakeLists.txt | 1 + code/main/inc/clockwordmap.h | 72 ++++++++++++++++++++++++++ code/main/inc/wordmap.h | 8 +-- code/main/main.cpp | 52 +++++++++---------- code/main/src/clockwordmap.cpp | 95 ++++++++++++++++++++++++++++++++++ code/main/src/ledmatrix.cpp | 1 - code/main/src/wordmap.cpp | 47 +++-------------- 7 files changed, 206 insertions(+), 70 deletions(-) create mode 100644 code/main/inc/clockwordmap.h create mode 100644 code/main/src/clockwordmap.cpp diff --git a/code/main/CMakeLists.txt b/code/main/CMakeLists.txt index e64c792..89e49cc 100644 --- a/code/main/CMakeLists.txt +++ b/code/main/CMakeLists.txt @@ -13,6 +13,7 @@ idf_component_register( "src/ledmatrix.cpp" "src/clock.cpp" "src/wordmap.cpp" + "src/clockwordmap.cpp" INCLUDE_DIRS # optional, add here public include directories "inc" PRIV_INCLUDE_DIRS # optional, add here private include directories diff --git a/code/main/inc/clockwordmap.h b/code/main/inc/clockwordmap.h new file mode 100644 index 0000000..5169058 --- /dev/null +++ b/code/main/inc/clockwordmap.h @@ -0,0 +1,72 @@ +// -------------------------------------------------------------------------------------------------------------------- +/// \file clockwordmap.h +/// \brief File description +// -------------------------------------------------------------------------------------------------------------------- +// +// vbchaos software design +// +// -------------------------------------------------------------------------------------------------------------------- +/// $Revision: $ +/// $Author: $ +/// $Date: $ +// (c) 2023 vbchaos +// -------------------------------------------------------------------------------------------------------------------- + + +#ifndef MAIN_INC_CLOCKWORDMAP_H_ +#define MAIN_INC_CLOCKWORDMAP_H_ + +/** + * clockwordmap implementation + * \defgroup clockwordmap + * \brief {group_description} + * \addtogroup {Layer} + * + * Detailed description + * @{ + */ + + + +// -------------------------------------------------------------------------------------------------------------------- +// Include files +// -------------------------------------------------------------------------------------------------------------------- + +// CompilerIncludes +// All include files that are provided by the compiler directly + + + +// ProjectIncludes +// All include files that are provided by the project +#include "wordmap.h" + +// -------------------------------------------------------------------------------------------------------------------- +// Constant and macro definitions +// -------------------------------------------------------------------------------------------------------------------- + + + +// -------------------------------------------------------------------------------------------------------------------- +// Type definitions. +// -------------------------------------------------------------------------------------------------------------------- + + + +// -------------------------------------------------------------------------------------------------------------------- +// Function declarations +// -------------------------------------------------------------------------------------------------------------------- + +class ClockWordmap: public Wordmap +{ + public: + ClockWordmap(LEDMatrix* matrix); + protected: + void createList_NL(void); +// void createList_EN(void); +}; + + +/** @} */ + +#endif /* MAIN_INC_CLOCKWORDMAP_H_ */ diff --git a/code/main/inc/wordmap.h b/code/main/inc/wordmap.h index b74bb36..6ce9f98 100644 --- a/code/main/inc/wordmap.h +++ b/code/main/inc/wordmap.h @@ -75,14 +75,14 @@ class Wordmap bool setWord(Language_t lang, string identifier, bool value); - private: + protected: struct word { string identifier; -// list pixels; - LEDMatrix::coordinate position; - int length; + list pixels; +// LEDMatrix::coordinate position; +// int length; }; LEDMatrix* matrix; diff --git a/code/main/main.cpp b/code/main/main.cpp index ce48e28..50eaa94 100644 --- a/code/main/main.cpp +++ b/code/main/main.cpp @@ -42,7 +42,7 @@ #include "inc/wifi.h" #include "clock.h" -#include "wordmap.h" +#include "clockwordmap.h" // -------------------------------------------------------------------------------------------------------------------- @@ -80,9 +80,9 @@ static rmt_encoder_handle_t led_encoder = NULL; static LEDMatrix_Parameters_t ledmatrix_parameters = { - LEDMATRIX_ORIENTATION_ROW_LEFT_RIGHT, - LEDMATRIX_ORIENTATION_COLUM_DOWN_UP, - LEDMATRIX_ORIENTATION_ROW, + LEDMATRIX_ORIENTATION_ROW_RIGHT_LEFT, + LEDMATRIX_ORIENTATION_COLUM_UP_DOWN, + LEDMATRIX_ORIENTATION_COLUM, 11, 10, &led_chan, @@ -92,7 +92,7 @@ static LEDMatrix_Parameters_t ledmatrix_parameters = static LEDMatrix matrix(&ledmatrix_parameters); -static Wordmap map(&matrix); +static ClockWordmap clockWordmap(&matrix); static gptimer_handle_t matrixRefreshTimer = NULL; @@ -279,7 +279,7 @@ extern "C" void app_main(void) std::list::iterator it; for(it = wordlist.begin(); it != wordlist.end(); it++) { - map.setWord(Wordmap::Language_t::NL, *it, true); + clockWordmap.setWord(Wordmap::Language_t::NL, *it, true); } // Add a seconds indicator @@ -341,36 +341,36 @@ static void colourMapTask(void* parameters) static void countdown(int delay) { - map.setWord(Wordmap::Language_t::NL, "ten", true); + clockWordmap.setWord(Wordmap::Language_t::NL, "ten", true); vTaskDelay(delay); - map.setWord(Wordmap::Language_t::NL, "ten", false); - map.setWord(Wordmap::Language_t::NL, "nine", true); + clockWordmap.setWord(Wordmap::Language_t::NL, "ten", false); + clockWordmap.setWord(Wordmap::Language_t::NL, "nine", true); vTaskDelay(delay); - map.setWord(Wordmap::Language_t::NL, "nine", false); - map.setWord(Wordmap::Language_t::NL, "eight", true); + clockWordmap.setWord(Wordmap::Language_t::NL, "nine", false); + clockWordmap.setWord(Wordmap::Language_t::NL, "eight", true); vTaskDelay(delay); - map.setWord(Wordmap::Language_t::NL, "eight", false); - map.setWord(Wordmap::Language_t::NL, "seven", true); + clockWordmap.setWord(Wordmap::Language_t::NL, "eight", false); + clockWordmap.setWord(Wordmap::Language_t::NL, "seven", true); vTaskDelay(delay); - map.setWord(Wordmap::Language_t::NL, "seven", false); - map.setWord(Wordmap::Language_t::NL, "six", true); + clockWordmap.setWord(Wordmap::Language_t::NL, "seven", false); + clockWordmap.setWord(Wordmap::Language_t::NL, "six", true); vTaskDelay(delay); - map.setWord(Wordmap::Language_t::NL, "six", false); - map.setWord(Wordmap::Language_t::NL, "five", true); + clockWordmap.setWord(Wordmap::Language_t::NL, "six", false); + clockWordmap.setWord(Wordmap::Language_t::NL, "five", true); vTaskDelay(delay); - map.setWord(Wordmap::Language_t::NL, "five", false); - map.setWord(Wordmap::Language_t::NL, "four", true); + clockWordmap.setWord(Wordmap::Language_t::NL, "five", false); + clockWordmap.setWord(Wordmap::Language_t::NL, "four", true); vTaskDelay(delay); - map.setWord(Wordmap::Language_t::NL, "four", false); - map.setWord(Wordmap::Language_t::NL, "three", true); + clockWordmap.setWord(Wordmap::Language_t::NL, "four", false); + clockWordmap.setWord(Wordmap::Language_t::NL, "three", true); vTaskDelay(delay); - map.setWord(Wordmap::Language_t::NL, "three", false); - map.setWord(Wordmap::Language_t::NL, "two", true); + clockWordmap.setWord(Wordmap::Language_t::NL, "three", false); + clockWordmap.setWord(Wordmap::Language_t::NL, "two", true); vTaskDelay(delay); - map.setWord(Wordmap::Language_t::NL, "two", false); - map.setWord(Wordmap::Language_t::NL, "one", true); + clockWordmap.setWord(Wordmap::Language_t::NL, "two", false); + clockWordmap.setWord(Wordmap::Language_t::NL, "one", true); vTaskDelay(delay); - map.setWord(Wordmap::Language_t::NL, "one", false); + clockWordmap.setWord(Wordmap::Language_t::NL, "one", false); } static bool IRAM_ATTR timerCallback(gptimer_handle_t timer, const gptimer_alarm_event_data_t *edata, void *user_data) diff --git a/code/main/src/clockwordmap.cpp b/code/main/src/clockwordmap.cpp new file mode 100644 index 0000000..5a78569 --- /dev/null +++ b/code/main/src/clockwordmap.cpp @@ -0,0 +1,95 @@ +// -------------------------------------------------------------------------------------------------------------------- +/// \file clockwordmap.cpp +/// \brief Description +// -------------------------------------------------------------------------------------------------------------------- +// +// vbchaos software design +// +// -------------------------------------------------------------------------------------------------------------------- +/// $Revision: $ +/// $Author: $ +/// $Date: $ +// (c) 2023 vbchaos +// -------------------------------------------------------------------------------------------------------------------- + + +// -------------------------------------------------------------------------------------------------------------------- +// Include files +// -------------------------------------------------------------------------------------------------------------------- + +#include "clockwordmap.h" + + +#include "logger.h" +// -------------------------------------------------------------------------------------------------------------------- +// Constant and macro definitions +// -------------------------------------------------------------------------------------------------------------------- + + + +// -------------------------------------------------------------------------------------------------------------------- +// Type definitions +// -------------------------------------------------------------------------------------------------------------------- + + +// -------------------------------------------------------------------------------------------------------------------- +// File-scope variables +// -------------------------------------------------------------------------------------------------------------------- + + + +// -------------------------------------------------------------------------------------------------------------------- +// Function declarations +// -------------------------------------------------------------------------------------------------------------------- + + + +// -------------------------------------------------------------------------------------------------------------------- +// Function definitions +// -------------------------------------------------------------------------------------------------------------------- + + +ClockWordmap::ClockWordmap(LEDMatrix* matrix) : Wordmap(matrix) +{ + createList_NL(); + createList_EN(); +} + +void ClockWordmap::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},{1,0},{2,0}}}); + wordlist[NL].push_back((struct word){"is", {{4,0},{5,0}}}); + + wordlist[NL].push_back((struct word){"ind_five", {{7,0},{8,0},{9,0},{10,0}}}); + wordlist[NL].push_back((struct word){"ind_ten", {{1,1},{2,1},{3,1},{4,1}}}); + wordlist[NL].push_back((struct word){"ind_quart", {{6,1},{7,1},{8,1},{9,1},{10,1}}}); + wordlist[NL].push_back((struct word){"ind_twenty", {{0,2},{1,2},{2,2},{3,2},{4,2},{5,2},{6,2}}}); + + wordlist[NL].push_back((struct word){"before", {{6,3},{7,3},{8,3},{9,3}}}); + wordlist[NL].push_back((struct word){"after", {{1,3},{2,3},{3,3},{4,3}}}); + + wordlist[NL].push_back((struct word){"almost", {{0,4},{1,4},{2,4},{3,4},{4,4}}}); + + wordlist[NL].push_back((struct word){"half", {{7,4},{8,4},{9,4},{10,4}}}); + + wordlist[NL].push_back((struct word){"one", {{3,5},{4,5},{5,5}}}); + wordlist[NL].push_back((struct word){"two", {{1,5},{2,5},{3,5},{4,5}}}); + wordlist[NL].push_back((struct word){"three", {{6,5},{7,5},{8,5},{9,5}}}); + wordlist[NL].push_back((struct word){"four", {{7,6},{8,6},{9,6},{10,5}}}); + wordlist[NL].push_back((struct word){"five", {{0,6},{1,6},{2,6},{3,6}}}); + wordlist[NL].push_back((struct word){"six", {{4,6},{5,6},{6,6}}}); + wordlist[NL].push_back((struct word){"seven", {{0,7},{1,7},{2,7},{3,7},{4,7}}}); + wordlist[NL].push_back((struct word){"eight", {{0,8},{1,8},{2,8},{3,8}}}); + wordlist[NL].push_back((struct word){"nine", {{6,7},{7,7},{8,7},{9,7},{10,7}}}); + wordlist[NL].push_back((struct word){"ten", {{4,8},{5,8},{6,8},{7,8}}}); + wordlist[NL].push_back((struct word){"eleven", {{8,8},{9,8},{10,8}}}); + wordlist[NL].push_back((struct word){"twelve", {{0,9},{1,9},{2,9},{3,9},{4,9},{5,9}}}); + + wordlist[NL].push_back((struct word){"hours", {{7,9},{8,9},{9,9}}}); +} + + diff --git a/code/main/src/ledmatrix.cpp b/code/main/src/ledmatrix.cpp index 6798bd8..ac313b8 100644 --- a/code/main/src/ledmatrix.cpp +++ b/code/main/src/ledmatrix.cpp @@ -162,7 +162,6 @@ void LEDMatrix::matrixTask(void* parameters) xSemaphoreTake(ledmatrix->taskSemaphore, portMAX_DELAY); for (int i = 0; i < ledmatrix->numberOfPixels; i++) { - if (ledmatrix->matrix[i].on) { matrix[i * 3 + LEDMATRIX_RED_INDEX] = ledmatrix->matrix[i].red; diff --git a/code/main/src/wordmap.cpp b/code/main/src/wordmap.cpp index 374c420..3f7c385 100644 --- a/code/main/src/wordmap.cpp +++ b/code/main/src/wordmap.cpp @@ -52,8 +52,6 @@ Wordmap::Wordmap(LEDMatrix* matrix) { Wordmap::matrix = matrix; Wordmap::language = NL; - - createList_NL(); } bool Wordmap::setWord(Language_t lang, string identifier, bool value) @@ -89,12 +87,10 @@ bool Wordmap::setWord(Language_t lang, string identifier, bool value) if (returnValue) { - if (it->length > 0) + std::list::iterator pixel; + for (pixel = it->pixels.begin(); pixel != it->pixels.end(); pixel++) { - for (int i = 0; i < it->length; i++) - { - matrix->setPixelValue(it->position.x + i, it->position.y, value); - } + matrix->setPixelValue(pixel->x, pixel->y, value); } } @@ -105,39 +101,12 @@ 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}); +void Wordmap::createList_EN(void) +{ + // First, clear the list + wordlist[EN].clear(); } - -