diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index 6b4e5b0..96e0312 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -5,4 +5,5 @@ cmake_minimum_required(VERSION 3.5) include($ENV{IDF_PATH}/tools/cmake/project.cmake) get_filename_component(ProjectId ${CMAKE_CURRENT_LIST_DIR} NAME) string(REPLACE " " "_" ProjectId ${ProjectId}) + project(${ProjectId}) diff --git a/code/main/CMakeLists.txt b/code/main/CMakeLists.txt index 4e217f8..3baa9ae 100644 --- a/code/main/CMakeLists.txt +++ b/code/main/CMakeLists.txt @@ -13,12 +13,12 @@ idf_component_register( "platform/src/logger.cpp" "platform/src/prgm_ledstrip.cpp" "platform/src/wifi.cpp" -# "old/src/led_strip_encoder.c" -# "old/src/ledmatrix.cpp" -# "old/src/clock.cpp" -# "old/src/wordmap.cpp" -# "old/src/clockwordmap.cpp" -# "old/src/daywordmap.cpp" + "platform/src/ledmatrix.cpp" + + "application/src/clock.cpp" + "application/src/clockwordmap.cpp" + "application/src/daywordmap.cpp" + "application/src/wordmap.cpp" # "old/src/temperaturewordmap.cpp" # "old/src/temperature.cpp" INCLUDE_DIRS # optional, add here public include directories diff --git a/code/main/old/inc/clock.h b/code/main/application/inc/clock.h similarity index 68% rename from code/main/old/inc/clock.h rename to code/main/application/inc/clock.h index 3383f0a..0dc70d0 100644 --- a/code/main/old/inc/clock.h +++ b/code/main/application/inc/clock.h @@ -13,8 +13,8 @@ // -------------------------------------------------------------------------------------------------------------------- -#ifndef MAIN_INC_CLOCK_H_ -#define MAIN_INC_CLOCK_H_ +#ifndef MAIN_APPLICATION_INC_CLOCK_H_ +#define MAIN_APPLICATION_INC_CLOCK_H_ /** * clock implementation @@ -47,7 +47,6 @@ // -------------------------------------------------------------------------------------------------------------------- - // -------------------------------------------------------------------------------------------------------------------- // Type definitions. // -------------------------------------------------------------------------------------------------------------------- @@ -58,42 +57,52 @@ // Function declarations // -------------------------------------------------------------------------------------------------------------------- -using namespace std; - class Clock { + // ----------------------------------------------------------------------------------------------------------------- + // Public Section + // ----------------------------------------------------------------------------------------------------------------- public: - enum mode + typedef enum { TEN_BEFORE_HALF, TWENTY_OVER - }; + }Mode_t; - Clock(Clock::mode mode); + // Class Constructor + Clock(Mode_t mode); - void generateWordlist(list* wordlist); + void generateWordlist(std::list* wordlist); time_t getTime(void); - private: + // ----------------------------------------------------------------------------------------------------------------- + // Protected Section + // ----------------------------------------------------------------------------------------------------------------- + protected: - Clock::mode clockmode; + + // ----------------------------------------------------------------------------------------------------------------- + // Private Section + // ----------------------------------------------------------------------------------------------------------------- + private: + Mode_t clockmode; time_t currentTime; - string toNumbers[20] {"zero", "one", "two", "three", "four", + std::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(struct tm time); -}; +}; /** @} */ -#endif /* MAIN_INC_CLOCK_H_ */ + +#endif /* MAIN_APPLICATION_INC_CLOCK_H_ */ diff --git a/code/main/old/inc/clockwordmap.h b/code/main/application/inc/clockwordmap.h similarity index 94% rename from code/main/old/inc/clockwordmap.h rename to code/main/application/inc/clockwordmap.h index 5169058..0b8ee72 100644 --- a/code/main/old/inc/clockwordmap.h +++ b/code/main/application/inc/clockwordmap.h @@ -57,13 +57,14 @@ // Function declarations // -------------------------------------------------------------------------------------------------------------------- -class ClockWordmap: public Wordmap +class ClockWordmap: public wordmap { public: - ClockWordmap(LEDMatrix* matrix); + ClockWordmap(ledmatrix* matrix); + ~ClockWordmap(); protected: void createList_NL(void); -// void createList_EN(void); + void createList_EN(void); }; diff --git a/code/main/old/inc/daywordmap.h b/code/main/application/inc/daywordmap.h similarity index 66% rename from code/main/old/inc/daywordmap.h rename to code/main/application/inc/daywordmap.h index e4f175a..edd52c5 100644 --- a/code/main/old/inc/daywordmap.h +++ b/code/main/application/inc/daywordmap.h @@ -13,8 +13,8 @@ // -------------------------------------------------------------------------------------------------------------------- -#ifndef MAIN_INC_DAYWORDMAP_H_ -#define MAIN_INC_DAYWORDMAP_H_ +#ifndef MAIN_APPLICATION_INC_DAYWORDMAP_H_ +#define MAIN_APPLICATION_INC_DAYWORDMAP_H_ /** * daywordmap implementation @@ -46,7 +46,6 @@ // -------------------------------------------------------------------------------------------------------------------- - // -------------------------------------------------------------------------------------------------------------------- // Type definitions. // -------------------------------------------------------------------------------------------------------------------- @@ -57,16 +56,31 @@ // Function declarations // -------------------------------------------------------------------------------------------------------------------- -class DayWordmap: public Wordmap +class DayWordmap : public wordmap { + // ----------------------------------------------------------------------------------------------------------------- + // Public Section + // ----------------------------------------------------------------------------------------------------------------- public: - DayWordmap(LEDMatrix* matrix); + // Class Constructor + DayWordmap(ledmatrix* matrix); + ~DayWordmap(); + + // ----------------------------------------------------------------------------------------------------------------- + // Protected Section + // ----------------------------------------------------------------------------------------------------------------- protected: void createList_NL(void); -// void createList_EN(void); -}; + void createList_EN(void); + // ----------------------------------------------------------------------------------------------------------------- + // Private Section + // ----------------------------------------------------------------------------------------------------------------- + private: + +}; /** @} */ -#endif /* MAIN_INC_DAYWORDMAP_H_ */ + +#endif /* MAIN_APPLICATION_INC_DAYWORDMAP_H_ */ diff --git a/code/main/old/inc/wordmap.h b/code/main/application/inc/wordmap.h similarity index 62% rename from code/main/old/inc/wordmap.h rename to code/main/application/inc/wordmap.h index 31f69a6..8c022e1 100644 --- a/code/main/old/inc/wordmap.h +++ b/code/main/application/inc/wordmap.h @@ -13,8 +13,8 @@ // -------------------------------------------------------------------------------------------------------------------- -#ifndef MAIN_INC_WORDMAP_H_ -#define MAIN_INC_WORDMAP_H_ +#ifndef MAIN_APPLICATION_INC_WORDMAP_H_ +#define MAIN_APPLICATION_INC_WORDMAP_H_ /** * wordmap implementation @@ -47,7 +47,6 @@ // -------------------------------------------------------------------------------------------------------------------- - // -------------------------------------------------------------------------------------------------------------------- // Type definitions. // -------------------------------------------------------------------------------------------------------------------- @@ -58,50 +57,56 @@ // Function declarations // -------------------------------------------------------------------------------------------------------------------- -using namespace std; - -class Wordmap +class wordmap { + // ----------------------------------------------------------------------------------------------------------------- + // Public Section + // ----------------------------------------------------------------------------------------------------------------- public: - - typedef enum language + // Class Constructor + typedef enum { NL = 0, EN, NumberOfLanguages } Language_t; - Wordmap(LEDMatrix* matrix); + wordmap(ledmatrix* matrix); + virtual ~wordmap() {} bool setColour(uint8_t red, uint8_t green, uint8_t blue); - bool setWord(Language_t lang, string identifier, bool value); + bool setWord(Language_t lang, std::string& identifier, bool value); + // ----------------------------------------------------------------------------------------------------------------- + // Protected Section + // ----------------------------------------------------------------------------------------------------------------- protected: - struct word { - string identifier; - list pixels; -// LEDMatrix::coordinate position; -// int length; + std::string identifier; + std::list pixels; }; - LEDMatrix* matrix; - language language; + ledmatrix* matrix; + Language_t language; - list wordlist[NumberOfLanguages]; + std::list wordlist[NumberOfLanguages]; - void createList_NL(void); - void createList_EN(void); + virtual void createList_NL(void) = 0; + virtual void createList_EN(void) = 0; uint8_t red; uint8_t green; uint8_t blue; + // ----------------------------------------------------------------------------------------------------------------- + // Private Section + // ----------------------------------------------------------------------------------------------------------------- + private: }; - /** @} */ -#endif /* MAIN_INC_WORDMAP_H_ */ + +#endif /* MAIN_APPLICATION_INC_WORDMAP_H_ */ diff --git a/code/main/old/src/clock.cpp b/code/main/application/src/clock.cpp similarity index 85% rename from code/main/old/src/clock.cpp rename to code/main/application/src/clock.cpp index 98be908..a49d5d0 100644 --- a/code/main/old/src/clock.cpp +++ b/code/main/application/src/clock.cpp @@ -17,18 +17,16 @@ // Include files // -------------------------------------------------------------------------------------------------------------------- -#include "clock.h" +#include #include "esp_sntp.h" #include "esp_wifi.h" -#include "logger.h" // -------------------------------------------------------------------------------------------------------------------- // Constant and macro definitions // -------------------------------------------------------------------------------------------------------------------- - // -------------------------------------------------------------------------------------------------------------------- // Type definitions // -------------------------------------------------------------------------------------------------------------------- @@ -51,12 +49,11 @@ // -------------------------------------------------------------------------------------------------------------------- - -Clock::Clock(Clock::mode mode) +Clock::Clock(Mode_t mode) { - Clock::currentTime = 40000; + currentTime = 40000; - Clock::clockmode = mode; + clockmode = mode; // Start NTP setenv("TZ", "CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00", 1); @@ -66,7 +63,7 @@ Clock::Clock(Clock::mode mode) esp_sntp_init(); } -void Clock::generateWordlist(list* wordlist) +void Clock::generateWordlist(std::list* wordlist) { struct tm tm; @@ -187,7 +184,6 @@ void Clock::generateWordlist(list* wordlist) time_t Clock::getTime(void) { -// time(¤tTime); return currentTime; } @@ -196,7 +192,7 @@ 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) + if (time.tm_min >= 19) { hours = hours + 1; } @@ -214,18 +210,3 @@ int Clock::calculateHours(struct tm time) 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" : "" -// ); -//} - diff --git a/code/main/old/src/clockwordmap.cpp b/code/main/application/src/clockwordmap.cpp similarity index 96% rename from code/main/old/src/clockwordmap.cpp rename to code/main/application/src/clockwordmap.cpp index 7cf7096..64b33e0 100644 --- a/code/main/old/src/clockwordmap.cpp +++ b/code/main/application/src/clockwordmap.cpp @@ -49,12 +49,17 @@ // -------------------------------------------------------------------------------------------------------------------- -ClockWordmap::ClockWordmap(LEDMatrix* matrix) : Wordmap(matrix) +ClockWordmap::ClockWordmap(ledmatrix* matrix) : wordmap(matrix) { createList_NL(); createList_EN(); } +ClockWordmap::~ClockWordmap() +{ + +} + void ClockWordmap::createList_NL(void) { // First, clear the list @@ -93,3 +98,7 @@ void ClockWordmap::createList_NL(void) } +void ClockWordmap::createList_EN(void) +{ + +} diff --git a/code/main/old/src/daywordmap.cpp b/code/main/application/src/daywordmap.cpp similarity index 95% rename from code/main/old/src/daywordmap.cpp rename to code/main/application/src/daywordmap.cpp index 27bb1b2..67d9ab5 100644 --- a/code/main/old/src/daywordmap.cpp +++ b/code/main/application/src/daywordmap.cpp @@ -17,16 +17,13 @@ // Include files // -------------------------------------------------------------------------------------------------------------------- -#include "daywordmap.h" - -#include "logger.h" +#include // -------------------------------------------------------------------------------------------------------------------- // Constant and macro definitions // -------------------------------------------------------------------------------------------------------------------- - // -------------------------------------------------------------------------------------------------------------------- // Type definitions // -------------------------------------------------------------------------------------------------------------------- @@ -49,12 +46,17 @@ // -------------------------------------------------------------------------------------------------------------------- -DayWordmap::DayWordmap(LEDMatrix* matrix) : Wordmap(matrix) +DayWordmap::DayWordmap(ledmatrix* matrix) : wordmap(matrix) { createList_NL(); createList_EN(); } +DayWordmap::~DayWordmap() +{ + +} + void DayWordmap::createList_NL(void) { // First, clear the list @@ -68,9 +70,9 @@ void DayWordmap::createList_NL(void) wordlist[NL].push_back((struct word){"friday", {{12,11},{13,11},{14,11},{15,11},{16,11},{17,11},{18,11}}}); wordlist[NL].push_back((struct word){"saturday", {{0,10},{1,10},{2,10},{3,10},{4,10},{5,10},{6,10},{7,10}}}); wordlist[NL].push_back((struct word){"sunday", {{7,12},{8,12},{9,12},{10,12},{11,12},{12,12}}}); - } +void DayWordmap::createList_EN(void) +{ - - +} diff --git a/code/main/old/src/wordmap.cpp b/code/main/application/src/wordmap.cpp similarity index 80% rename from code/main/old/src/wordmap.cpp rename to code/main/application/src/wordmap.cpp index e783214..5359d94 100644 --- a/code/main/old/src/wordmap.cpp +++ b/code/main/application/src/wordmap.cpp @@ -17,9 +17,7 @@ // Include files // -------------------------------------------------------------------------------------------------------------------- -#include "wordmap.h" - -#include "logger.h" +#include #include // -------------------------------------------------------------------------------------------------------------------- @@ -27,7 +25,6 @@ // -------------------------------------------------------------------------------------------------------------------- - // -------------------------------------------------------------------------------------------------------------------- // Type definitions // -------------------------------------------------------------------------------------------------------------------- @@ -50,16 +47,16 @@ // -------------------------------------------------------------------------------------------------------------------- -Wordmap::Wordmap(LEDMatrix* matrix) +wordmap::wordmap(ledmatrix* matrix) { - Wordmap::matrix = matrix; - Wordmap::language = NL; - Wordmap::red = 0xFF; - Wordmap::green = 0xFF; - Wordmap::blue = 0xFF; + wordmap::matrix = matrix; + wordmap::language = NL; + wordmap::red = 0xFF; + wordmap::green = 0xFF; + wordmap::blue = 0xFF; } -bool Wordmap::setWord(Language_t lang, string identifier, bool value) +bool wordmap::setWord(Language_t lang, std::string& identifier, bool value) { bool returnValue; @@ -92,11 +89,17 @@ bool Wordmap::setWord(Language_t lang, string identifier, bool value) if (returnValue) { - std::list::iterator pixel; + std::list::iterator pixel; for (pixel = it->pixels.begin(); pixel != it->pixels.end(); pixel++) { - matrix->setPixelValue(pixel->x, pixel->y, value); - matrix->setPixelColour(pixel->x, pixel->y, Wordmap::red, Wordmap::green, Wordmap::blue); + if (value) + { + matrix->setPixel(pixel->y, pixel->x, wordmap::red, wordmap::green, wordmap::blue); + } + else + { + matrix->setPixel(pixel->y, pixel->x, 0, 0, 0); + } } } @@ -104,28 +107,26 @@ bool Wordmap::setWord(Language_t lang, string identifier, bool value) } -bool Wordmap::setColour(uint8_t red, uint8_t green, uint8_t blue) +bool wordmap::setColour(uint8_t red, uint8_t green, uint8_t blue) { bool returnValue = true; - Wordmap::red = red; - Wordmap::green = green; - Wordmap::blue = blue; + wordmap::red = red; + wordmap::green = green; + wordmap::blue = blue; return returnValue; } -void Wordmap::createList_NL(void) +void wordmap::createList_NL(void) { // First, clear the list wordlist[NL].clear(); } -void Wordmap::createList_EN(void) +void wordmap::createList_EN(void) { // First, clear the list wordlist[EN].clear(); } - - diff --git a/code/main/main.cpp b/code/main/main.cpp index 80ba3bf..35550c3 100644 --- a/code/main/main.cpp +++ b/code/main/main.cpp @@ -35,12 +35,36 @@ // Platform includes #include "isl29125.h" #include "logger.h" -#include "prgm_ledstrip.h" +#include "ledmatrix.h" #include "Wifi.h" + +// Application includes +#include "clock.h" +#include "clockwordmap.h" +#include "daywordmap.h" // -------------------------------------------------------------------------------------------------------------------- // Constant and macro definitions // -------------------------------------------------------------------------------------------------------------------- +#define ESP32C3_01M_KIT +//#define ESP32C3_DEVKIT_M1 + +#if defined(ESP32C3_DEVKIT_M1) +#define GPIO_I2C_SCK ((uint32_t)3) +#define GPIO_I2C_SDA ((uint32_t)2) +#define GPIO_LED_ONBOARD ((uint32_t)8) +#define GPIO_LED_STRIP ((uint32_t)9) +#elif defined(ESP32C3_01M_KIT) +#define GPIO_I2C_SCK ((uint32_t)8) +#define GPIO_I2C_SDA ((uint32_t)9) +#define GPIO_LED_STRIP ((uint32_t)0) +#else +#error "No supported target platform defined" +#endif + + +#define MATRIX_NMBR_ROWS ((uint32_t)13) +#define MATRIX_NMBR_COLUMS ((uint32_t)20) // -------------------------------------------------------------------------------------------------------------------- // Type definitions @@ -103,7 +127,7 @@ extern "C" void app_main(void) logger debugLogger = logger(16, uartDebug); // Call the logger executable within a dedicated task and forget about it afterwards - xTaskCreate(loggerTask, (const char*)"loggerTask", 3072, &debugLogger, 3, &loggerTaskHandle); + xTaskCreate(loggerTask, (const char*)"loggerTask", 4000, &debugLogger, 3, &loggerTaskHandle); LOGGER_PRINT("\n\r-----------------------------------------------------------------------\n\r"); LOGGER_PRINT("System Start\n\r"); @@ -112,41 +136,39 @@ extern "C" void app_main(void) LOGGER_PRINT("Release: %d.%d \n\r", MAJORRELEASE, MINORRELEASE); LOGGER_PRINT("Compiled on %s at %s\n\r\n\r\n\r", __DATE__, __TIME__); - // ----------------------------------------------------------------------------------------------------------------- - // I2C Masterbus for sensoring peripherals - // - i2c_port_t i2c_master_port = I2C_NUM_0; - - i2c_config_t i2cConfig = { - .mode = I2C_MODE_MASTER, - .sda_io_num = (int)2, - .scl_io_num = (int)3, - .sda_pullup_en = GPIO_PULLUP_ENABLE, - .scl_pullup_en = GPIO_PULLUP_ENABLE, - .master = 400000, - .clk_flags = 0 - }; - - ESP_ERROR_CHECK(i2c_param_config(i2c_master_port, &i2cConfig)); - ESP_ERROR_CHECK(i2c_driver_install(i2c_master_port, i2cConfig.mode, 0, 0, 0)); - - i2c i2cSensor = i2c(&i2c_master_port); - i2cSensor.open(); - - // ----------------------------------------------------------------------------------------------------------------- - // I2C RGB Sensor on I2C MasterBus for sensors - // - isl29125 rgbSensor = isl29125(0x44, i2cSensor); - rgbSensor.initialize(); - vTaskDelay(100); - rgbSensor.setMode(isl29125::RGB); - rgbSensor.setRange(isl29125::HIGH); - rgbSensor.setResolution(isl29125::RES_16BIT); - vTaskDelay(100); - struct isl29125::rgb_t rgbValue; - rgbSensor.getRGB(&rgbValue); - -// gpio debugIO = gpio(19, gpio::Direction_t::GPIO_DIRECTION_OUTPUT, gpio::Value_t::GPIO_VALUE_LOW); +// // ----------------------------------------------------------------------------------------------------------------- +// // I2C Masterbus for sensoring peripherals +// // +// i2c_port_t i2c_master_port = I2C_NUM_0; +// +// i2c_config_t i2cConfig = { +// .mode = I2C_MODE_MASTER, +// .sda_io_num = (int)2, +// .scl_io_num = (int)3, +// .sda_pullup_en = GPIO_PULLUP_ENABLE, +// .scl_pullup_en = GPIO_PULLUP_ENABLE, +// .master = 400000, +// .clk_flags = 0 +// }; +// +// ESP_ERROR_CHECK(i2c_param_config(i2c_master_port, &i2cConfig)); +// ESP_ERROR_CHECK(i2c_driver_install(i2c_master_port, i2cConfig.mode, 0, 0, 0)); +// +// i2c i2cSensor = i2c(&i2c_master_port); +// i2cSensor.open(); +// +// // ----------------------------------------------------------------------------------------------------------------- +// // I2C RGB Sensor on I2C MasterBus for sensors +// // +// isl29125 rgbSensor = isl29125(0x44, i2cSensor); +// rgbSensor.initialize(); +// vTaskDelay(100); +// rgbSensor.setMode(isl29125::RGB); +// rgbSensor.setRange(isl29125::HIGH); +// rgbSensor.setResolution(isl29125::RES_16BIT); +// vTaskDelay(100); +// struct isl29125::rgb_t rgbValue; +// rgbSensor.getRGB(&rgbValue); // ----------------------------------------------------------------------------------------------------------------- // Wifi create and connect @@ -157,12 +179,36 @@ extern "C" void app_main(void) // ----------------------------------------------------------------------------------------------------------------- // Programmable LEDs in a strip // - prgm_ledstrip ledstrip = prgm_ledstrip(1, 8); + + ledmatrix matrix = ledmatrix(MATRIX_NMBR_ROWS, MATRIX_NMBR_COLUMS, GPIO_LED_STRIP); + // Set the matrix orientation to ROW-based, from left to right, beginning on the upside + matrix.setOrientation(ledmatrix::ORIENTATION_ROW_LEFT_UP); + + ClockWordmap clockwords = ClockWordmap(&matrix); + clockwords.setColour(0x80, 0x40, 0xFF); + + DayWordmap daywords = DayWordmap(&matrix); + daywords.setColour(0xFF, 0x00, 0x80); + + Clock clk = Clock(Clock::Mode_t::TEN_BEFORE_HALF); + + std::list clockWordlist; - while(1) + while(1) { - vTaskDelay(1000); + matrix.clearAll(); + clk.generateWordlist(&clockWordlist); + + std::list::iterator it; + for(it = clockWordlist.begin(); it != clockWordlist.end(); it++) + { + clockwords.setWord(wordmap::Language_t::NL, *it, true); + daywords.setWord(wordmap::Language_t::NL, *it, true); + } + + matrix.update(); + vTaskDelay(1000); } } diff --git a/code/main/old/inc/ledmatrix.h b/code/main/old/inc/ledmatrix.h deleted file mode 100644 index 41bc3ce..0000000 --- a/code/main/old/inc/ledmatrix.h +++ /dev/null @@ -1,156 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -/// \file ledmatrix.h -/// \brief File description -// -------------------------------------------------------------------------------------------------------------------- -// -// vbchaos software design -// -// -------------------------------------------------------------------------------------------------------------------- -/// $Revision: $ -/// $Author: $ -/// $Date: $ -// (c) 2023 vbchaos -// -------------------------------------------------------------------------------------------------------------------- - - -#ifndef MAIN_INC_LEDMATRIX_H_ -#define MAIN_INC_LEDMATRIX_H_ - -/** - * ledmatrix implementation - * \defgroup ledmatrix - * \brief {group_description} - * \addtogroup {Layer} - * - * Detailed description - * @{ - */ - - - -// -------------------------------------------------------------------------------------------------------------------- -// Include files -// -------------------------------------------------------------------------------------------------------------------- - -// CompilerIncludes -// All include files that are provided by the compiler directly -#include - - -// ProjectIncludes -// All include files that are provided by the project -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#include "freertos/semphr.h" - -#include "driver/rmt_tx.h" - -// -------------------------------------------------------------------------------------------------------------------- -// Constant and macro definitions -// -------------------------------------------------------------------------------------------------------------------- - -#define LEDMATRIX_RED_INDEX ((uint32_t)1) -#define LEDMATRIX_GREEN_INDEX ((uint32_t)0) -#define LEDMATRIX_BLUE_INDEX ((uint32_t)2) - -// -------------------------------------------------------------------------------------------------------------------- -// Type definitions. -// -------------------------------------------------------------------------------------------------------------------- - -typedef enum -{ - LEDMATRIX_ORIENTATION_ROW_LEFT_RIGHT, - LEDMATRIX_ORIENTATION_ROW_RIGHT_LEFT -} LEDMatrix_Orientation_Row_t; - -typedef enum -{ - LEDMATRIX_ORIENTATION_COLUM_UP_DOWN, - LEDMATRIX_ORIENTATION_COLUM_DOWN_UP -} LEDMatrix_Orientation_Colum_t; - -typedef enum -{ - LEDMATRIX_ORIENTATION_ROW, - LEDMATRIX_ORIENTATION_COLUM -}LEDMatrix_Orientation_t; - -typedef struct -{ - LEDMatrix_Orientation_Row_t rowOrientation; - LEDMatrix_Orientation_Colum_t columOrientation; - LEDMatrix_Orientation_t matrixOrientation; - unsigned int width; - unsigned int height; - // RMT objects for transmission - rmt_channel_handle_t* rmtChannel; - rmt_encoder_handle_t* rmtEncoder; - rmt_transmit_config_t* rmtConfig; -} LEDMatrix_Parameters_t; - -typedef struct -{ - bool on; - uint8_t red; - uint8_t green; - uint8_t blue; -} LEDMatrix_Pixel_t; - -// -------------------------------------------------------------------------------------------------------------------- -// Function declarations -// -------------------------------------------------------------------------------------------------------------------- - -class LEDMatrix -{ - public: - - struct coordinate - { - int x; - int y; - }; - - LEDMatrix(LEDMatrix_Parameters_t* parameters); - - bool setPixelValue(unsigned int colum, unsigned int row, bool value); - void setGlobalColour(uint8_t red, uint8_t green, uint8_t blue); - void setPixelColour(unsigned int colum, unsigned int row, uint8_t red, uint8_t green, uint8_t blue); - - void clear(void); - - BaseType_t tick(void); - - protected: - unsigned int findPixelIndexFromCoordinates(unsigned int colum, unsigned int row); - - private: - - LEDMatrix_Parameters_t parameters; - LEDMatrix_Pixel_t* matrix; - uint8_t* tx_matrix; - unsigned int numberOfPixels; - - static bool initialized; - static TaskHandle_t matrixTaskHandle; - static SemaphoreHandle_t taskSemaphore; - static void matrixTask(void* parameters); - - -}; - - -inline BaseType_t LEDMatrix::tick(void) -{ - BaseType_t xHigherPriorityTaskWoken = pdFALSE; - if (LEDMatrix::initialized) - { - xSemaphoreGiveFromISR(LEDMatrix::taskSemaphore, &xHigherPriorityTaskWoken); - } - - return xHigherPriorityTaskWoken; -} - - -/** @} */ - -#endif /* MAIN_INC_LEDMATRIX_H_ */ diff --git a/code/main/old/src/ledmatrix.cpp b/code/main/old/src/ledmatrix.cpp deleted file mode 100644 index d63ce0c..0000000 --- a/code/main/old/src/ledmatrix.cpp +++ /dev/null @@ -1,259 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -/// \file ledmatrix.cpp -/// \brief Description -// -------------------------------------------------------------------------------------------------------------------- -// -// vbchaos software design -// -// -------------------------------------------------------------------------------------------------------------------- -/// $Revision: $ -/// $Author: $ -/// $Date: $ -// (c) 2023 vbchaos -// -------------------------------------------------------------------------------------------------------------------- - - -// -------------------------------------------------------------------------------------------------------------------- -// Include files -// -------------------------------------------------------------------------------------------------------------------- - -#include "ledmatrix.h" -#include "logger.h" -#include "string.h" - -// -------------------------------------------------------------------------------------------------------------------- -// Constant and macro definitions -// -------------------------------------------------------------------------------------------------------------------- - - - -// -------------------------------------------------------------------------------------------------------------------- -// Type definitions -// -------------------------------------------------------------------------------------------------------------------- - - -// -------------------------------------------------------------------------------------------------------------------- -// File-scope variables -// -------------------------------------------------------------------------------------------------------------------- - - - -// -------------------------------------------------------------------------------------------------------------------- -// Function declarations -// -------------------------------------------------------------------------------------------------------------------- - - - -// -------------------------------------------------------------------------------------------------------------------- -// Function definitions -// -------------------------------------------------------------------------------------------------------------------- - -SemaphoreHandle_t LEDMatrix::taskSemaphore = 0; -TaskHandle_t LEDMatrix::matrixTaskHandle = NULL; -bool LEDMatrix::initialized = false; - -LEDMatrix::LEDMatrix(LEDMatrix_Parameters_t* parameters) -{ - // Take the parameters - LEDMatrix::parameters = *parameters; - // Calculate the total number of pixels - LEDMatrix::numberOfPixels = parameters->width * parameters->height; - // Create the matrix storage - matrix = new LEDMatrix_Pixel_t[parameters->width * parameters->height]; - // Create the second matrix, that is actually transmitted to the periphery - - // Create the task Semaphore - vSemaphoreCreateBinary(LEDMatrix::taskSemaphore); - // Take the semaphore immediately so the task cannot run - xSemaphoreTake(LEDMatrix::taskSemaphore, 0); - // Create the matrix task - xTaskCreate(matrixTask, (const char*)"matrixTask", 4096, this, 3, &LEDMatrix::matrixTaskHandle); - - // Clear the matrix initially - LEDMatrix::clear(); - - initialized = true; -} - -bool LEDMatrix::setPixelValue(unsigned int colum, unsigned int row, bool value) -{ - bool returnValue = true; - -// unsigned int rowC = 0; -// unsigned int colC = 0; - unsigned int pixelAddress = 0; - - if ((row < parameters.height) && (colum < parameters.width)) - { - returnValue = true; - } - else - { - returnValue = false; - } - - if (returnValue) - { - -// // Determine the actual row coordinate based on the matrix orientation -// if (parameters.columOrientation == LEDMATRIX_ORIENTATION_COLUM_UP_DOWN) -// { -// rowC = row; -// } -// else if (parameters.columOrientation == LEDMATRIX_ORIENTATION_COLUM_DOWN_UP) -// { -// rowC = (parameters.height - 1) - row; -// } -// -// // Determine the actual row coordinate based on the matrix orientation -// if (parameters.rowOrientation == LEDMATRIX_ORIENTATION_ROW_LEFT_RIGHT) -// { -// colC = colum; -// } -// else if (parameters.rowOrientation == LEDMATRIX_ORIENTATION_ROW_RIGHT_LEFT) -// { -// colC = (parameters.width - 1) - colum; -// } -// -// // Calculate the pixel address in the pixel array based on the previous information -// if (parameters.matrixOrientation == LEDMATRIX_ORIENTATION_COLUM) -// { -// pixelAddress = rowC + (colC * parameters.height); -// } -// else if (parameters.matrixOrientation == LEDMATRIX_ORIENTATION_ROW) -// { -// pixelAddress = (rowC * parameters.width) + colC; -// } - - pixelAddress = LEDMatrix::findPixelIndexFromCoordinates(colum, row); - - // Update the pixel value - matrix[pixelAddress].on = value; - - } - return returnValue; -} - - - - - -void LEDMatrix::setGlobalColour(uint8_t red, uint8_t green, uint8_t blue) -{ - for (int i = 0; i < numberOfPixels; i++) - { - matrix[i].red = red; - matrix[i].green = green; - matrix[i].blue = blue; - } -} - -void LEDMatrix::setPixelColour(unsigned int colum, unsigned int row, uint8_t red, uint8_t green, uint8_t blue) -{ - unsigned int index; - - index = LEDMatrix::findPixelIndexFromCoordinates(colum, row); - - matrix[index].red = red; - matrix[index].green = green; - matrix[index].blue = blue; -} - - -void LEDMatrix::clear(void) -{ - for (int i = 0; i < numberOfPixels; i++) - { - matrix[i].on = false; - } - -} - - -unsigned int LEDMatrix::findPixelIndexFromCoordinates(unsigned int colum, unsigned int row) -{ - bool returnValue = true; - - unsigned int index = 0; - - unsigned int rowC = 0; - unsigned int colC = 0; - - if ((row < parameters.height) && (colum < parameters.width)) - { - returnValue = true; - } - else - { - returnValue = false; - } - - if (returnValue) - { - // Determine the actual row coordinate based on the matrix orientation - if (parameters.columOrientation == LEDMATRIX_ORIENTATION_COLUM_UP_DOWN) - { - rowC = row; - } - else if (parameters.columOrientation == LEDMATRIX_ORIENTATION_COLUM_DOWN_UP) - { - rowC = (parameters.height - 1) - row; - } - - // Determine the actual row coordinate based on the matrix orientation - if (parameters.rowOrientation == LEDMATRIX_ORIENTATION_ROW_LEFT_RIGHT) - { - colC = colum; - } - else if (parameters.rowOrientation == LEDMATRIX_ORIENTATION_ROW_RIGHT_LEFT) - { - colC = (parameters.width - 1) - colum; - } - - // Calculate the pixel address in the pixel array based on the previous information - if (parameters.matrixOrientation == LEDMATRIX_ORIENTATION_COLUM) - { - index = rowC + (colC * parameters.height); - } - else if (parameters.matrixOrientation == LEDMATRIX_ORIENTATION_ROW) - { - index = (rowC * parameters.width) + colC; - } - } - return index; -} - - -void LEDMatrix::matrixTask(void* parameters) -{ - LEDMatrix* ledmatrix = (LEDMatrix*)parameters; - - uint8_t matrix[ledmatrix->numberOfPixels * 3]; - memset(&matrix, 0, sizeof(matrix)); - - while(1) - { - 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; - matrix[i * 3 + LEDMATRIX_GREEN_INDEX] = ledmatrix->matrix[i].green; - matrix[i * 3 + LEDMATRIX_BLUE_INDEX] = ledmatrix->matrix[i].blue; - } - else - { - matrix[i * 3 + 0] = 0; - matrix[i * 3 + 1] = 0; - matrix[i * 3 + 2] = 0; - } - - } - rmt_transmit(*ledmatrix->parameters.rmtChannel, *ledmatrix->parameters.rmtEncoder, matrix, sizeof(matrix), ledmatrix->parameters.rmtConfig); - - - } -} - - diff --git a/code/main/platform/inc/ledmatrix.h b/code/main/platform/inc/ledmatrix.h new file mode 100644 index 0000000..234d612 --- /dev/null +++ b/code/main/platform/inc/ledmatrix.h @@ -0,0 +1,113 @@ +// -------------------------------------------------------------------------------------------------------------------- +/// \file ledmatrix.h +/// \brief File description +// -------------------------------------------------------------------------------------------------------------------- +// +// vbchaos software design +// +// -------------------------------------------------------------------------------------------------------------------- +/// $Revision: $ +/// $Author: $ +/// $Date: $ +// (c) 2023 vbchaos +// -------------------------------------------------------------------------------------------------------------------- + + +#ifndef MAIN_PLATFORM_INC_LEDMATRIX_H_ +#define MAIN_PLATFORM_INC_LEDMATRIX_H_ + +/** + * ledmatrix implementation + * \defgroup ledmatrix + * \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 "prgm_ledstrip.h" + +// -------------------------------------------------------------------------------------------------------------------- +// Constant and macro definitions +// -------------------------------------------------------------------------------------------------------------------- + + +// -------------------------------------------------------------------------------------------------------------------- +// Type definitions. +// -------------------------------------------------------------------------------------------------------------------- + + + +// -------------------------------------------------------------------------------------------------------------------- +// Function declarations +// -------------------------------------------------------------------------------------------------------------------- + +class ledmatrix : public prgm_ledstrip +{ + // ----------------------------------------------------------------------------------------------------------------- + // Public Section + // ----------------------------------------------------------------------------------------------------------------- + public: + typedef enum + { + ORIENTATION_ROW_LEFT_UP = 0, + ORIENTATION_ROW_LEFT_DOWN = 1, + ORIENTATION_ROW_RIGHT_UP = 2, + ORIENTATION_ROW_RIGHT_DOWN = 3, + ORIENTATION_COL_LEFT_UP = 4, + ORIENTATION_COL_LEFT_DOWN = 5, + ORIENTATION_COL_RIGHT_UP = 6, + ORIENTATION_COL_RIGHT_DOWN = 7, + ORIENTATION_END = 8 + } Orientation_t; + + struct coordinate + { + uint32_t x; + uint32_t y; + }; + + // Class Constructor + ledmatrix(uint32_t rows, uint32_t columns, uint32_t gpio); + + FunctionStatus setOrientation(Orientation_t orientation); + + FunctionStatus setPixel(uint32_t row, uint32_t column, uint8_t red, uint8_t green, uint8_t blue); + + + // ----------------------------------------------------------------------------------------------------------------- + // Protected Section + // ----------------------------------------------------------------------------------------------------------------- + protected: + + + // ----------------------------------------------------------------------------------------------------------------- + // Private Section + // ----------------------------------------------------------------------------------------------------------------- + private: + uint32_t width; + uint32_t highth; + Orientation_t orientation; + + FunctionStatus calculateIndexFromCoordinates(uint32_t row, uint32_t column, uint32_t* index); + +}; + +/** @} */ + + +#endif /* MAIN_PLATFORM_INC_LEDMATRIX_H_ */ diff --git a/code/main/platform/inc/prgm_ledstrip.h b/code/main/platform/inc/prgm_ledstrip.h index b03c4d4..d6ccd0f 100644 --- a/code/main/platform/inc/prgm_ledstrip.h +++ b/code/main/platform/inc/prgm_ledstrip.h @@ -76,7 +76,15 @@ class prgm_ledstrip // Class Constructor prgm_ledstrip(uint32_t numberOfLEDs, uint32_t gpio); + // Set and clear functions only update the pixel value(s) locally but do not push the values to the strip FunctionStatus setPixel(struct pixel& pixel); + FunctionStatus clearAll(void); + + // Clears all pixels locally and automatically pushes the values to the strip + FunctionStatus clearAndUpdate(void); + + // Push the latest pixel values to the strip + FunctionStatus update(void); // ----------------------------------------------------------------------------------------------------------------- // Protected Section diff --git a/code/main/platform/src/ledmatrix.cpp b/code/main/platform/src/ledmatrix.cpp new file mode 100644 index 0000000..0a08567 --- /dev/null +++ b/code/main/platform/src/ledmatrix.cpp @@ -0,0 +1,124 @@ +// -------------------------------------------------------------------------------------------------------------------- +/// \file ledmatrix.cpp +/// \brief Description +// -------------------------------------------------------------------------------------------------------------------- +// +// vbchaos software design +// +// -------------------------------------------------------------------------------------------------------------------- +/// $Revision: $ +/// $Author: $ +/// $Date: $ +// (c) 2023 vbchaos +// -------------------------------------------------------------------------------------------------------------------- + + +// -------------------------------------------------------------------------------------------------------------------- +// Include files +// -------------------------------------------------------------------------------------------------------------------- + +#include + +// -------------------------------------------------------------------------------------------------------------------- +// Constant and macro definitions +// -------------------------------------------------------------------------------------------------------------------- + + +// -------------------------------------------------------------------------------------------------------------------- +// Type definitions +// -------------------------------------------------------------------------------------------------------------------- + + +// -------------------------------------------------------------------------------------------------------------------- +// File-scope variables +// -------------------------------------------------------------------------------------------------------------------- + + + +// -------------------------------------------------------------------------------------------------------------------- +// Function declarations +// -------------------------------------------------------------------------------------------------------------------- + + + +// -------------------------------------------------------------------------------------------------------------------- +// Function definitions +// -------------------------------------------------------------------------------------------------------------------- + + +ledmatrix::ledmatrix(uint32_t rows, uint32_t columns, uint32_t gpio) : prgm_ledstrip(rows * columns, gpio) +{ + this->width = columns; + this->highth = rows; + this->orientation = ORIENTATION_ROW_LEFT_UP; +} + + +FunctionStatus ledmatrix::setOrientation(Orientation_t orientation) +{ + FunctionStatus returnValue = FUNCTION_STATUS_OK; + + if (orientation < ORIENTATION_END) + { + this->orientation = orientation; + } + else + { + returnValue = FUNCTION_STATUS_ERROR; + } + return returnValue; +} + + +FunctionStatus ledmatrix::setPixel(uint32_t row, uint32_t column, uint8_t red, uint8_t green, uint8_t blue) +{ + FunctionStatus returnValue = FUNCTION_STATUS_OK; + + uint32_t index = 0; + returnValue = calculateIndexFromCoordinates(row, column, &index); + + if (returnValue == FUNCTION_STATUS_OK) + { + struct pixel p; + p.index = index; + p.red = red; + p.green = green; + p.blue = blue; + returnValue = prgm_ledstrip::setPixel(p); + } + + return returnValue; +} + + +FunctionStatus ledmatrix::calculateIndexFromCoordinates(uint32_t row, uint32_t column, uint32_t* index) +{ + FunctionStatus returnValue = FUNCTION_STATUS_OK; + + switch(orientation) + { + case ORIENTATION_ROW_LEFT_UP: + *index = row * width + column; + break; + case ORIENTATION_ROW_LEFT_DOWN: + break; + case ORIENTATION_ROW_RIGHT_UP: + break; + case ORIENTATION_ROW_RIGHT_DOWN: + break; + case ORIENTATION_COL_LEFT_UP: + break; + case ORIENTATION_COL_LEFT_DOWN: + break; + case ORIENTATION_COL_RIGHT_UP: + break; + case ORIENTATION_COL_RIGHT_DOWN: + break; + default: + *index = 0; + returnValue = FUNCTION_STATUS_ERROR; + + } + + return returnValue; +} diff --git a/code/main/platform/src/prgm_ledstrip.cpp b/code/main/platform/src/prgm_ledstrip.cpp index 0d12683..221e594 100644 --- a/code/main/platform/src/prgm_ledstrip.cpp +++ b/code/main/platform/src/prgm_ledstrip.cpp @@ -53,8 +53,8 @@ prgm_ledstrip::prgm_ledstrip(uint32_t numberOfLEDs, uint32_t gpio) : numberOfLED /* LED strip initialization with the GPIO and pixels number*/ memset(&strip_config, 0, sizeof(strip_config)); - strip_config.strip_gpio_num = 8; // The GPIO that connected to the LED strip's data line - strip_config.max_leds = 2; // The number of LEDs in the strip, + strip_config.strip_gpio_num = gpio; // The GPIO that connected to the LED strip's data line + strip_config.max_leds = numberOfLEDs; // The number of LEDs in the strip, strip_config.led_pixel_format = LED_PIXEL_FORMAT_GRB; // Pixel format of your LED strip strip_config.led_model = LED_MODEL_WS2812; // LED strip model strip_config.flags.invert_out = false; // whether to invert the output signal (useful when your hardware has a level inverter) @@ -69,15 +69,43 @@ prgm_ledstrip::prgm_ledstrip(uint32_t numberOfLEDs, uint32_t gpio) : numberOfLED rmt_config.flags.with_dma = false; // whether to enable the DMA feature #endif ESP_ERROR_CHECK(led_strip_new_rmt_device(&strip_config, &rmt_config, &led_strip)); - } FunctionStatus prgm_ledstrip::setPixel(struct pixel& pixel) { FunctionStatus returnValue = FUNCTION_STATUS_OK; - ESP_ERROR_CHECK(led_strip_set_pixel(led_strip, pixel.index, pixel.red, pixel.green, pixel.blue)); - ESP_ERROR_CHECK(led_strip_refresh(led_strip)); - + if (pixel.index < numberOfLEDs) + { + ESP_ERROR_CHECK(led_strip_set_pixel(led_strip, pixel.index, pixel.red, pixel.green, pixel.blue)); + } + else + { + returnValue = FUNCTION_STATUS_ERROR; + } return returnValue; } + + +FunctionStatus prgm_ledstrip::clearAll(void) +{ + for (int i = 0; i < numberOfLEDs; i++) + { + ESP_ERROR_CHECK(led_strip_set_pixel(led_strip, i, 0, 0, 0)); + } + return FUNCTION_STATUS_OK; +} + + +FunctionStatus prgm_ledstrip::clearAndUpdate(void) +{ + ESP_ERROR_CHECK(led_strip_clear(led_strip)); + return FUNCTION_STATUS_OK; +} + + +FunctionStatus prgm_ledstrip::update(void) +{ + ESP_ERROR_CHECK(led_strip_refresh(led_strip)); + return FUNCTION_STATUS_OK; +}