diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index 96e0312..99b9948 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -6,4 +6,5 @@ include($ENV{IDF_PATH}/tools/cmake/project.cmake) get_filename_component(ProjectId ${CMAKE_CURRENT_LIST_DIR} NAME) string(REPLACE " " "_" ProjectId ${ProjectId}) +set(PROJECT_VER "0.1") project(${ProjectId}) diff --git a/code/main/CMakeLists.txt b/code/main/CMakeLists.txt index 8112b33..92e819d 100644 --- a/code/main/CMakeLists.txt +++ b/code/main/CMakeLists.txt @@ -19,10 +19,11 @@ idf_component_register( "application/src/clock.cpp" "application/src/clockwordmap.cpp" "application/src/daywordmap.cpp" - "application/src/wordmap.cpp" + "application/src/messagewordmap.cpp" "application/src/ota.cpp" "application/src/temperaturewordmap.cpp" "application/src/temperature.cpp" + "application/src/wordmap.cpp" INCLUDE_DIRS # optional, add here public include directories "./" "hal/inc" diff --git a/code/main/application/inc/clock.h b/code/main/application/inc/clock.h index 0dc70d0..6c48194 100644 --- a/code/main/application/inc/clock.h +++ b/code/main/application/inc/clock.h @@ -100,6 +100,8 @@ class Clock int calculateHours(struct tm time); + std::list specialList; + }; /** @} */ diff --git a/code/main/application/inc/messagewordmap.h b/code/main/application/inc/messagewordmap.h new file mode 100644 index 0000000..a34cbce --- /dev/null +++ b/code/main/application/inc/messagewordmap.h @@ -0,0 +1,86 @@ +// -------------------------------------------------------------------------------------------------------------------- +/// \file messagewordmap.h +/// \brief File description +// -------------------------------------------------------------------------------------------------------------------- +// +// vbchaos software design +// +// -------------------------------------------------------------------------------------------------------------------- +/// $Revision: $ +/// $Author: $ +/// $Date: $ +// (c) 2023 vbchaos +// -------------------------------------------------------------------------------------------------------------------- + + +#ifndef MAIN_APPLICATION_INC_MESSAGEWORDMAP_H_ +#define MAIN_APPLICATION_INC_MESSAGEWORDMAP_H_ + +/** + * messagewordmap implementation + * \defgroup messagewordmap + * \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 messagewordmap: public wordmap +{ + // ----------------------------------------------------------------------------------------------------------------- + // Public Section + // ----------------------------------------------------------------------------------------------------------------- + public: + // Class Constructor + messagewordmap(ledmatrix* matrix); + ~messagewordmap(); + + // ----------------------------------------------------------------------------------------------------------------- + // Protected Section + // ----------------------------------------------------------------------------------------------------------------- + protected: + void createList_NL(void); + void createList_EN(void); + + // ----------------------------------------------------------------------------------------------------------------- + // Private Section + // ----------------------------------------------------------------------------------------------------------------- + private: + +}; + +/** @} */ + + +#endif /* MAIN_APPLICATION_INC_MESSAGEWORDMAP_H_ */ diff --git a/code/main/application/inc/ota.h b/code/main/application/inc/ota.h index 93b919c..3398d09 100644 --- a/code/main/application/inc/ota.h +++ b/code/main/application/inc/ota.h @@ -64,9 +64,27 @@ class ota // ----------------------------------------------------------------------------------------------------------------- public: - static const uint32_t checkInterval_ms = 10000; + typedef enum + { + OTA_STATUS_IDLE = 0, + OTA_STATUS_DOWNLOAD, + OTA_STATUS_VERIFY, + OTA_STATUS_WRITE, + OTA_STATUS_UPDATE, + OTA_STATUS_SUCCESS, + OTA_STATUS_FAIL, + OTA_STATUS_RESTART + }UpdateStatus_t; - typedef void (*updateStatusCallback)(int); + struct statusCallbackData + { + UpdateStatus_t status; + int percentage; + }; + + static const uint32_t checkInterval_ms = 60000; + + typedef void (*updateStatusCallback)(struct statusCallbackData* status); static updateStatusCallback usCallback; // Class Constructor diff --git a/code/main/application/src/clock.cpp b/code/main/application/src/clock.cpp index a49d5d0..31f164c 100644 --- a/code/main/application/src/clock.cpp +++ b/code/main/application/src/clock.cpp @@ -51,6 +51,14 @@ Clock::Clock(Mode_t mode) { + specialList.clear(); + + // Add Angelas birthday as special day + struct tm abirthday; + abirthday.tm_mon = 12; + abirthday.tm_mday = 7; + specialList.push_back(abirthday); + currentTime = 40000; clockmode = mode; @@ -68,12 +76,8 @@ void Clock::generateWordlist(std::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"); @@ -179,6 +183,9 @@ void Clock::generateWordlist(std::list* wordlist) default: wordlist->push_back("sunday"); } + + // For special days, add the "i love you" + } diff --git a/code/main/application/src/messagewordmap.cpp b/code/main/application/src/messagewordmap.cpp new file mode 100644 index 0000000..8a1d3d2 --- /dev/null +++ b/code/main/application/src/messagewordmap.cpp @@ -0,0 +1,86 @@ +// -------------------------------------------------------------------------------------------------------------------- +/// \file messagewordmap.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 +// -------------------------------------------------------------------------------------------------------------------- + + +messagewordmap::messagewordmap(ledmatrix* matrix) : wordmap(matrix) +{ + createList_NL(); + createList_EN(); +} + +messagewordmap::~messagewordmap() +{ + +} + +void messagewordmap::createList_NL() +{ + wordlist[NL].clear(); + + // The numbers 0 to 10 in digits + wordlist[NL].push_back((struct word){"0", {{3,0}}}); + wordlist[NL].push_back((struct word){"1", {{6,0}}}); + wordlist[NL].push_back((struct word){"2", {{0,1}}}); + wordlist[NL].push_back((struct word){"3", {{5,1}}}); + wordlist[NL].push_back((struct word){"4", {{0,3}}}); + wordlist[NL].push_back((struct word){"5", {{5,3}}}); + wordlist[NL].push_back((struct word){"6", {{10,3}}}); + wordlist[NL].push_back((struct word){"7", {{0,5}}}); + wordlist[NL].push_back((struct word){"8", {{10,5}}}); + wordlist[NL].push_back((struct word){"9", {{5,7}}}); + wordlist[NL].push_back((struct word){"10", {{0,11}, {1,11}}}); + + // The message "I love you" + wordlist[NL].push_back((struct word){"iloveyou", {{5,4}, {6,4},{6,9},{7,9},{8,9},{11,9},{12,9},{13,9},{8,10},{9,10},{10,10}}}); + // The heart sign + wordlist[NL].push_back((struct word){"heart", {{11,11}}}); +} + +void messagewordmap::createList_EN() +{ + +} diff --git a/code/main/application/src/ota.cpp b/code/main/application/src/ota.cpp index 38e4d84..03f3624 100644 --- a/code/main/application/src/ota.cpp +++ b/code/main/application/src/ota.cpp @@ -22,6 +22,7 @@ #include "esp_crt_bundle.h" #include "esp_https_ota.h" #include "esp_http_client.h" +#include "esp_app_desc.h" #include "logger.h" @@ -57,6 +58,13 @@ bool ota::updateActive = false; ota::ota() { ESP_ERROR_CHECK(esp_event_handler_register(ESP_HTTPS_OTA_EVENT, ESP_EVENT_ANY_ID, &eventHandler, NULL)); + + struct statusCallbackData cbData; + cbData.status = OTA_STATUS_IDLE; + if (usCallback != NULL) + { + usCallback(&cbData); + } } @@ -64,52 +72,52 @@ void ota::eventHandler(void* arg, esp_event_base_t event_base, int32_t event_id, { if(event_base == ESP_HTTPS_OTA_EVENT) { + struct statusCallbackData cbData; + cbData.percentage = 0; switch(event_id) { case ESP_HTTPS_OTA_START: - LOGGER_INFO("OTA started"); + cbData.status = OTA_STATUS_DOWNLOAD; break; case ESP_HTTPS_OTA_CONNECTED: - LOGGER_INFO("Connected to server"); + cbData.status = OTA_STATUS_DOWNLOAD; break; case ESP_HTTPS_OTA_GET_IMG_DESC: - LOGGER_INFO("Reading image description"); + cbData.status = OTA_STATUS_DOWNLOAD; break; case ESP_HTTPS_OTA_VERIFY_CHIP_ID: - LOGGER_INFO("Verifying chip id of new image: %d", *(esp_chip_id_t *)event_data); + cbData.status = OTA_STATUS_VERIFY; break; case ESP_HTTPS_OTA_DECRYPT_CB: - LOGGER_INFO("Callback to decrypt function"); + cbData.status = OTA_STATUS_VERIFY; break; case ESP_HTTPS_OTA_WRITE_FLASH: { - int written = *(int *)event_data; - - LOGGER_INFO("Writing to flash: %d written", written); -// ledRing->ledOn(((ledRing->nrOfLeds - 1) * written) / imageSize); + cbData.percentage = (*(int *)event_data * 100) / imageSize; + cbData.status = OTA_STATUS_WRITE; break; } case ESP_HTTPS_OTA_UPDATE_BOOT_PARTITION: - LOGGER_INFO("Boot partition updated. Next Partition: %d", *(esp_partition_subtype_t*)event_data); + cbData.status = OTA_STATUS_UPDATE; break; case ESP_HTTPS_OTA_FINISH: - LOGGER_INFO("OTA finished"); + cbData.status = OTA_STATUS_SUCCESS; break; case ESP_HTTPS_OTA_ABORT: - LOGGER_INFO("OTA aborted"); + cbData.status = OTA_STATUS_FAIL; break; } if (usCallback != NULL) { - usCallback(5); + usCallback(&cbData); } } } @@ -125,27 +133,24 @@ void ota::task(void) config.timeout_ms = 60000; config.keep_alive_enable = true; config.crt_bundle_attach = esp_crt_bundle_attach; -// config.event_handler = eventHandler; esp_https_ota_config_t ota_config = { .http_config = &config, .http_client_init_cb = NULL, .bulk_flash_erase = true, .partial_http_download = false, - .max_http_request_size = 0, - }; + .max_http_request_size = 0, }; LOGGER_INFO("OTA task executing"); - // First try to download specific firmware config.url = "https://esp.vbchaos.nl/code.bin"; LOGGER_INFO("Trying URL %s", config.url); err = esp_https_ota_begin(&ota_config, &https_ota_handle); - if(err != ESP_OK) + if (err != ESP_OK) - updateActive = false; + updateActive = false; { LOGGER_ERROR("OTA connection failed"); esp_https_ota_abort(https_ota_handle); @@ -156,7 +161,7 @@ void ota::task(void) err = esp_https_ota_begin(&ota_config, &https_ota_handle); - if(err != ESP_OK) + if (err != ESP_OK) { LOGGER_ERROR("OTA connection failed"); esp_https_ota_abort(https_ota_handle); @@ -164,84 +169,92 @@ void ota::task(void) } } - if(err == ESP_OK) - { - err = esp_https_ota_get_img_desc(https_ota_handle, &app_desc); + if (err == ESP_OK) + { + err = esp_https_ota_get_img_desc(https_ota_handle, &app_desc); - if(err != ESP_OK) - { - LOGGER_ERROR("Failed to read image header"); - esp_https_ota_abort(https_ota_handle); - } - } + if (err != ESP_OK) + { + LOGGER_ERROR("Failed to read image header"); + esp_https_ota_abort(https_ota_handle); + } + } if (err == ESP_OK) { - LOGGER_INFO("App description: Magicword: %i", app_desc.magic_word); - LOGGER_INFO("App description: SecureVer: %i", app_desc.secure_version); - LOGGER_INFO("App description: version: %s", app_desc.version); - LOGGER_INFO("App description: PrjctName: %s", app_desc.project_name); - LOGGER_INFO("App description: Time: %s", app_desc.time); - LOGGER_INFO("App description: Date: %s", app_desc.date); - LOGGER_INFO("App description: IDF Ver: %s", app_desc.idf_ver); - LOGGER_INFO("App description: SHA256 %s", app_desc.app_elf_sha256); + const esp_app_desc_t* description = esp_app_get_description(); + LOGGER_INFO("App description: version: %s (current: %s)", app_desc.version, description->version); + LOGGER_INFO("App description: PrjctName: %s (current: %s)", app_desc.project_name, description->project_name); + LOGGER_INFO("App description: Time: %s (current: %s)", app_desc.time, description->time); + LOGGER_INFO("App description: Date: %s (current: %s)", app_desc.date, description->date); + LOGGER_INFO("App description: IDF Ver: %s (current: %s)", app_desc.idf_ver, description->idf_ver); + + if(memcmp(description->version, app_desc.version, sizeof(description->version)) == 0) + { + LOGGER_INFO("OTA version and local version are equal - no OTA update to execute"); + err = ESP_FAIL; + struct statusCallbackData cbData; + cbData.status = OTA_STATUS_IDLE; + if (usCallback != NULL) + { + usCallback(&cbData); + } + } } + if (err == ESP_OK) + { + imageSize = esp_https_ota_get_image_size(https_ota_handle); + LOGGER_INFO("Image is %d bytes large", imageSize); - if(err == ESP_OK) - { - imageSize = esp_https_ota_get_image_size(https_ota_handle); + if (imageSize == -1) + { + err = ESP_FAIL; + esp_https_ota_abort(https_ota_handle); + } + } - LOGGER_INFO("Image is %d bytes large", imageSize); + if (err == ESP_OK) + { + esp_err_t otaStatus; - if(imageSize == -1) - { - err = ESP_FAIL; - esp_https_ota_abort(https_ota_handle); - } - } + do + { + // esp_https_ota_perform returns after every read operation which gives user the ability to + // monitor the status of OTA upgrade by calling esp_https_ota_get_image_len_read, which gives length of image + // data read so far. + //Logger_log("Image bytes read: %d", esp_https_ota_get_image_len_read(https_ota_handle)); + otaStatus = esp_https_ota_perform(https_ota_handle); + } while (otaStatus == ESP_ERR_HTTPS_OTA_IN_PROGRESS); - if(err == ESP_OK) - { - esp_err_t otaStatus; + if (!esp_https_ota_is_complete_data_received(https_ota_handle)) + { + // the OTA image was not completely received and user can customise the response to this situation. + LOGGER_ERROR("Complete data was not received."); + err = ESP_FAIL; + esp_https_ota_abort(https_ota_handle); - do - { - // esp_https_ota_perform returns after every read operation which gives user the ability to - // monitor the status of OTA upgrade by calling esp_https_ota_get_image_len_read, which gives length of image - // data read so far. - //Logger_log("Image bytes read: %d", esp_https_ota_get_image_len_read(https_ota_handle)); - otaStatus = esp_https_ota_perform(https_ota_handle); - } while(otaStatus == ESP_ERR_HTTPS_OTA_IN_PROGRESS); + } + } - if(!esp_https_ota_is_complete_data_received(https_ota_handle)) - { - // the OTA image was not completely received and user can customise the response to this situation. - LOGGER_ERROR("Complete data was not received."); - err = ESP_FAIL; - esp_https_ota_abort(https_ota_handle); + if (err == ESP_OK) + { + err = esp_https_ota_finish(https_ota_handle); - } - } + if (err != ESP_OK) + { + LOGGER_ERROR("Image validation failed, image is corrupted"); + } + } - if(err == ESP_OK) - { - err = esp_https_ota_finish(https_ota_handle); + if (err == ESP_OK) + { + LOGGER_SUCCESS("OTA upgrade successful"); - if(err != ESP_OK) - { - LOGGER_ERROR("Image validation failed, image is corrupted"); - } - } - - if(err == ESP_OK) - { - LOGGER_SUCCESS("OTA upgrade successful"); - - LOGGER_INFO("Rebooting"); - vTaskDelay(100); - esp_restart(); - } + LOGGER_INFO("Rebooting"); + vTaskDelay(100); + esp_restart(); + } } diff --git a/code/main/application/src/temperaturewordmap.cpp b/code/main/application/src/temperaturewordmap.cpp index 61946f6..e096689 100644 --- a/code/main/application/src/temperaturewordmap.cpp +++ b/code/main/application/src/temperaturewordmap.cpp @@ -90,6 +90,9 @@ void temperaturewordmap::createList_NL(void) wordlist[NL].push_back((struct word){"29", {{15,6},{16,6},{17,6},{18,6},{19,6},{12,7},{13,7},{11,8},{12,8},{13,8},{14,8},{15,8},{16,8},{17,8}}}); wordlist[NL].push_back((struct word){"degrees", {{14,9},{15,9},{16,9},{17,9},{18,9},{19,9}}}); + + // Nice weather + wordlist[NL].push_back((struct word){"niceweather",{{16,0},{18,0},{19,0},{16,1},{17,1},{18,1},{19,1},{8,2},{9,2},{10,2},{11,2}}}); } void temperaturewordmap::createList_EN(void) diff --git a/code/main/main.cpp b/code/main/main.cpp index 3a6acec..8db48f8 100644 --- a/code/main/main.cpp +++ b/code/main/main.cpp @@ -44,6 +44,7 @@ #include "clock.h" #include "clockwordmap.h" #include "daywordmap.h" +#include "messagewordmap.h" #include "ota.h" #include "temperature.h" #include "temperaturewordmap.h" @@ -83,6 +84,7 @@ static TaskHandle_t loggerTaskHandle; static TaskHandle_t otaTaskHandle; +static bool otaActive = false; // -------------------------------------------------------------------------------------------------------------------- // Function declarations @@ -91,7 +93,7 @@ static TaskHandle_t otaTaskHandle; void loggerTask(void* parameters); void otaTask(void* parameters); -static void otaCallback(int value); +static void otaCallback(struct ota::statusCallbackData* status); // -------------------------------------------------------------------------------------------------------------------- // Function definitions @@ -224,16 +226,38 @@ extern "C" void app_main(void) temperature temp = temperature(); // ----------------------------------------------------------------------------------------------------------------- - // Wordmaps for clock(time), clock(day) and temperature + // Wordmaps for clock(time), clock(day), temperature and one for other messages // ClockWordmap clockwords = ClockWordmap(&matrix); - clockwords.setColour(0x80, 0x40, 0xFF); + clockwords.setColour(0xFF, 0xFF, 0x20); DayWordmap daywords = DayWordmap(&matrix); - daywords.setColour(0xFF, 0x00, 0x80); + daywords.setColour(0x00, 0xFF, 0xFF); temperaturewordmap tempwords = temperaturewordmap(&matrix); + messagewordmap messagewords = messagewordmap(&matrix); + messagewords.setColour(0xC0, 0x00, 0xC0); + + + for (int cnt = 0; cnt < 10; cnt++) + { + for (uint32_t i = 0; i < MATRIX_NMBR_ROWS; i++) + { + matrix.clearAll(); + matrix.setRow(i, i * 20, i * 30, i * 40); + matrix.update(); + vTaskDelay(2); + } + + for (uint32_t i = 0; i < MATRIX_NMBR_COLUMS; i++) + { + matrix.clearAll(); + matrix.setColumn(i, i * 20, i * 30, i * 40); + matrix.update(); + vTaskDelay(2); + } + } // ----------------------------------------------------------------------------------------------------------------- // OTA handler @@ -246,34 +270,52 @@ extern "C" void app_main(void) std::list clockWordlist; std::list tempWordList; - + uint32_t runninglightIndex = 0; while(1) { - matrix.clearAll(); - clk.generateWordlist(&clockWordlist); - - std::list::iterator it; - for(it = clockWordlist.begin(); it != clockWordlist.end(); it++) + if (!otaActive) { - clockwords.setWord(wordmap::Language_t::NL, *it, true); - daywords.setWord(wordmap::Language_t::NL, *it, true); + 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); + } + + // Get the temperature from sensor + int currentTemperature = tempSensor.getTemperature() / 100; + + LOGGER_INFO("The current temperature is: %i (%s)", currentTemperature, std::to_string(21)); + // Generate temperature wordlist + temp.generateWordlist(currentTemperature, &tempWordList); + for(it = tempWordList.begin(); it != tempWordList.end(); it++) + { + tempwords.setWord(wordmap::Language_t::NL, *it, true); + } + uint8_t tRed, tGreen, tBlue; + temp.calculateRGB(currentTemperature, &tRed, &tGreen, &tBlue); + tempwords.setColour(tRed, tGreen, tBlue); + + matrix.update(); } - - // Get the temperature from sensor - int currentTemperature = tempSensor.getTemperature() / 100; - - LOGGER_INFO("The current temperature is: %i (%s)", currentTemperature, std::to_string(21)); - // Generate temperature wordlist - temp.generateWordlist(currentTemperature, &tempWordList); - for(it = tempWordList.begin(); it != tempWordList.end(); it++) + else { - tempwords.setWord(wordmap::Language_t::NL, *it, true); - } - uint8_t tRed, tGreen, tBlue; - temp.calculateRGB(currentTemperature, &tRed, &tGreen, &tBlue); - tempwords.setColour(tRed, tGreen, tBlue); + matrix.clearAll(); - matrix.update(); + while (otaActive) + { + // Create a running light on the lowest row + matrix.setPixel(MATRIX_NMBR_ROWS - 1, runninglightIndex, 0xFF - runninglightIndex * 10, runninglightIndex * 5, runninglightIndex * 10); + matrix.update(); + vTaskDelay(10); + matrix.setPixel(MATRIX_NMBR_ROWS - 1, runninglightIndex, 0, 0, 0); + matrix.update(); + runninglightIndex < (MATRIX_NMBR_COLUMS - 1) ? runninglightIndex++ : runninglightIndex = 0; + } + } vTaskDelay(1000); } } @@ -286,7 +328,7 @@ void loggerTask(void* parameters) while (1) { debugLogger->task(); - vTaskDelay(10); + vTaskDelay(2); } } @@ -296,12 +338,45 @@ void otaTask(void* parameters) ota* otaHandler = (ota*) parameters; while (1) { -// otaHandler->task(); + otaHandler->task(); vTaskDelay(otaHandler->checkInterval_ms); } } -void otaCallback(int value) +void otaCallback(struct ota::statusCallbackData* status) { - LOGGER_WARNING("Current OTA value is %i", value); + switch (status->status) + { + case ota::UpdateStatus_t::OTA_STATUS_IDLE: + otaActive = false; + break; + case ota::UpdateStatus_t::OTA_STATUS_DOWNLOAD: + LOGGER_INFO("Downloading OTA file from server"); + otaActive = false; + break; + case ota::UpdateStatus_t::OTA_STATUS_VERIFY: + LOGGER_INFO("Verifying OTA firmware file"); + otaActive = false; + break; + case ota::UpdateStatus_t::OTA_STATUS_WRITE: +// LOGGER_INFO("Writing OTA firmware file to FLASH - Current progress: %i \%", status->percentage); + otaActive = true; + break; + case ota::UpdateStatus_t::OTA_STATUS_UPDATE: + LOGGER_INFO("Updating the OTA partition"); + otaActive = true; + break; + case ota::UpdateStatus_t::OTA_STATUS_SUCCESS: + LOGGER_SUCCESS("The OTA firmware update was finished successfully"); + otaActive = true; + break; + case ota::UpdateStatus_t::OTA_STATUS_FAIL: + LOGGER_ERROR("The OTA firmware update failed"); + otaActive = false; + break; + case ota::UpdateStatus_t::OTA_STATUS_RESTART: + LOGGER_INFO("Restarting the device after OTA finished"); + otaActive = false; + break; + } } diff --git a/code/main/platform/inc/ledmatrix.h b/code/main/platform/inc/ledmatrix.h index 234d612..13c6f69 100644 --- a/code/main/platform/inc/ledmatrix.h +++ b/code/main/platform/inc/ledmatrix.h @@ -88,6 +88,9 @@ class ledmatrix : public prgm_ledstrip FunctionStatus setPixel(uint32_t row, uint32_t column, uint8_t red, uint8_t green, uint8_t blue); + FunctionStatus setRow(uint32_t row, uint8_t red, uint8_t green, uint8_t blue); + FunctionStatus setColumn(uint32_t row, uint8_t red, uint8_t green, uint8_t blue); + // ----------------------------------------------------------------------------------------------------------------- // Protected Section diff --git a/code/main/platform/src/ledmatrix.cpp b/code/main/platform/src/ledmatrix.cpp index d1ff111..edf3e2a 100644 --- a/code/main/platform/src/ledmatrix.cpp +++ b/code/main/platform/src/ledmatrix.cpp @@ -73,9 +73,18 @@ FunctionStatus ledmatrix::setOrientation(Orientation_t orientation) 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 ((row > highth) || (column > width)) + { + returnValue = FUNCTION_STATUS_ERROR; + } + + if (returnValue == FUNCTION_STATUS_OK) + { + returnValue = calculateIndexFromCoordinates(row, column, &index); + } if (returnValue == FUNCTION_STATUS_OK) { @@ -90,6 +99,41 @@ FunctionStatus ledmatrix::setPixel(uint32_t row, uint32_t column, uint8_t red, u return returnValue; } +FunctionStatus ledmatrix::setRow(uint32_t row, uint8_t red, uint8_t green, uint8_t blue) +{ + FunctionStatus returnValue = FUNCTION_STATUS_OK; + + for (uint32_t column = 0; column < width; column++) + { + returnValue = setPixel(row, column, red, green, blue); + if (returnValue != FUNCTION_STATUS_OK) + { + break; + } + } + + + return returnValue; +} + + +FunctionStatus ledmatrix::setColumn(uint32_t column, uint8_t red, uint8_t green, uint8_t blue) +{ + FunctionStatus returnValue = FUNCTION_STATUS_OK; + + for (uint32_t row = 0; row < highth; row++) + { + returnValue = setPixel(row, column, red, green, blue); + if (returnValue != FUNCTION_STATUS_OK) + { + break; + } + } + + + return returnValue; +} + FunctionStatus ledmatrix::calculateIndexFromCoordinates(uint32_t row, uint32_t column, uint32_t* index) {