Added the message wordmap and worked on the OTA. Basically functional, but only checks the difference in version, not the actual version number.

LED matrix got row and column write actions
This commit is contained in:
Matthias Mitscherlich
2024-03-28 17:24:12 +01:00
parent 39dcb7cf80
commit 22cdad69fc
12 changed files with 461 additions and 122 deletions
+1
View File
@@ -6,4 +6,5 @@ include($ENV{IDF_PATH}/tools/cmake/project.cmake)
get_filename_component(ProjectId ${CMAKE_CURRENT_LIST_DIR} NAME) get_filename_component(ProjectId ${CMAKE_CURRENT_LIST_DIR} NAME)
string(REPLACE " " "_" ProjectId ${ProjectId}) string(REPLACE " " "_" ProjectId ${ProjectId})
set(PROJECT_VER "0.1")
project(${ProjectId}) project(${ProjectId})
+2 -1
View File
@@ -19,10 +19,11 @@ idf_component_register(
"application/src/clock.cpp" "application/src/clock.cpp"
"application/src/clockwordmap.cpp" "application/src/clockwordmap.cpp"
"application/src/daywordmap.cpp" "application/src/daywordmap.cpp"
"application/src/wordmap.cpp" "application/src/messagewordmap.cpp"
"application/src/ota.cpp" "application/src/ota.cpp"
"application/src/temperaturewordmap.cpp" "application/src/temperaturewordmap.cpp"
"application/src/temperature.cpp" "application/src/temperature.cpp"
"application/src/wordmap.cpp"
INCLUDE_DIRS # optional, add here public include directories INCLUDE_DIRS # optional, add here public include directories
"./" "./"
"hal/inc" "hal/inc"
+2
View File
@@ -100,6 +100,8 @@ class Clock
int calculateHours(struct tm time); int calculateHours(struct tm time);
std::list<struct tm> specialList;
}; };
/** @} */ /** @} */
@@ -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_ */
+20 -2
View File
@@ -64,9 +64,27 @@ class ota
// ----------------------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------------------
public: 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; static updateStatusCallback usCallback;
// Class Constructor // Class Constructor
+11 -4
View File
@@ -51,6 +51,14 @@
Clock::Clock(Mode_t mode) 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; currentTime = 40000;
clockmode = mode; clockmode = mode;
@@ -68,12 +76,8 @@ void Clock::generateWordlist(std::list<std::string>* wordlist)
struct tm tm; struct tm tm;
time(&currentTime); time(&currentTime);
// currentTime += 100;
localtime_r(&currentTime, &tm); localtime_r(&currentTime, &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->clear();
wordlist->push_back("it"); wordlist->push_back("it");
wordlist->push_back("is"); wordlist->push_back("is");
@@ -179,6 +183,9 @@ void Clock::generateWordlist(std::list<std::string>* wordlist)
default: default:
wordlist->push_back("sunday"); wordlist->push_back("sunday");
} }
// For special days, add the "i love you"
} }
@@ -0,0 +1,86 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file messagewordmap.cpp
/// \brief Description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
#include <messagewordmap.h>
// --------------------------------------------------------------------------------------------------------------------
// 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()
{
}
+96 -83
View File
@@ -22,6 +22,7 @@
#include "esp_crt_bundle.h" #include "esp_crt_bundle.h"
#include "esp_https_ota.h" #include "esp_https_ota.h"
#include "esp_http_client.h" #include "esp_http_client.h"
#include "esp_app_desc.h"
#include "logger.h" #include "logger.h"
@@ -57,6 +58,13 @@ bool ota::updateActive = false;
ota::ota() ota::ota()
{ {
ESP_ERROR_CHECK(esp_event_handler_register(ESP_HTTPS_OTA_EVENT, ESP_EVENT_ANY_ID, &eventHandler, NULL)); 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) if(event_base == ESP_HTTPS_OTA_EVENT)
{ {
struct statusCallbackData cbData;
cbData.percentage = 0;
switch(event_id) switch(event_id)
{ {
case ESP_HTTPS_OTA_START: case ESP_HTTPS_OTA_START:
LOGGER_INFO("OTA started"); cbData.status = OTA_STATUS_DOWNLOAD;
break; break;
case ESP_HTTPS_OTA_CONNECTED: case ESP_HTTPS_OTA_CONNECTED:
LOGGER_INFO("Connected to server"); cbData.status = OTA_STATUS_DOWNLOAD;
break; break;
case ESP_HTTPS_OTA_GET_IMG_DESC: case ESP_HTTPS_OTA_GET_IMG_DESC:
LOGGER_INFO("Reading image description"); cbData.status = OTA_STATUS_DOWNLOAD;
break; break;
case ESP_HTTPS_OTA_VERIFY_CHIP_ID: 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; break;
case ESP_HTTPS_OTA_DECRYPT_CB: case ESP_HTTPS_OTA_DECRYPT_CB:
LOGGER_INFO("Callback to decrypt function"); cbData.status = OTA_STATUS_VERIFY;
break; break;
case ESP_HTTPS_OTA_WRITE_FLASH: case ESP_HTTPS_OTA_WRITE_FLASH:
{ {
int written = *(int *)event_data; cbData.percentage = (*(int *)event_data * 100) / imageSize;
cbData.status = OTA_STATUS_WRITE;
LOGGER_INFO("Writing to flash: %d written", written);
// ledRing->ledOn(((ledRing->nrOfLeds - 1) * written) / imageSize);
break; break;
} }
case ESP_HTTPS_OTA_UPDATE_BOOT_PARTITION: 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; break;
case ESP_HTTPS_OTA_FINISH: case ESP_HTTPS_OTA_FINISH:
LOGGER_INFO("OTA finished"); cbData.status = OTA_STATUS_SUCCESS;
break; break;
case ESP_HTTPS_OTA_ABORT: case ESP_HTTPS_OTA_ABORT:
LOGGER_INFO("OTA aborted"); cbData.status = OTA_STATUS_FAIL;
break; break;
} }
if (usCallback != NULL) if (usCallback != NULL)
{ {
usCallback(5); usCallback(&cbData);
} }
} }
} }
@@ -125,27 +133,24 @@ void ota::task(void)
config.timeout_ms = 60000; config.timeout_ms = 60000;
config.keep_alive_enable = true; config.keep_alive_enable = true;
config.crt_bundle_attach = esp_crt_bundle_attach; config.crt_bundle_attach = esp_crt_bundle_attach;
// config.event_handler = eventHandler;
esp_https_ota_config_t ota_config = esp_https_ota_config_t ota_config =
{ {
.http_config = &config, .http_config = &config,
.http_client_init_cb = NULL, .http_client_init_cb = NULL,
.bulk_flash_erase = true, .bulk_flash_erase = true,
.partial_http_download = false, .partial_http_download = false,
.max_http_request_size = 0, .max_http_request_size = 0, };
};
LOGGER_INFO("OTA task executing"); LOGGER_INFO("OTA task executing");
// First try to download specific firmware // First try to download specific firmware
config.url = "https://esp.vbchaos.nl/code.bin"; config.url = "https://esp.vbchaos.nl/code.bin";
LOGGER_INFO("Trying URL %s", config.url); LOGGER_INFO("Trying URL %s", config.url);
err = esp_https_ota_begin(&ota_config, &https_ota_handle); 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"); LOGGER_ERROR("OTA connection failed");
esp_https_ota_abort(https_ota_handle); 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); err = esp_https_ota_begin(&ota_config, &https_ota_handle);
if(err != ESP_OK) if (err != ESP_OK)
{ {
LOGGER_ERROR("OTA connection failed"); LOGGER_ERROR("OTA connection failed");
esp_https_ota_abort(https_ota_handle); esp_https_ota_abort(https_ota_handle);
@@ -164,84 +169,92 @@ void ota::task(void)
} }
} }
if(err == ESP_OK) if (err == ESP_OK)
{ {
err = esp_https_ota_get_img_desc(https_ota_handle, &app_desc); err = esp_https_ota_get_img_desc(https_ota_handle, &app_desc);
if(err != ESP_OK) if (err != ESP_OK)
{ {
LOGGER_ERROR("Failed to read image header"); LOGGER_ERROR("Failed to read image header");
esp_https_ota_abort(https_ota_handle); esp_https_ota_abort(https_ota_handle);
} }
} }
if (err == ESP_OK) if (err == ESP_OK)
{ {
LOGGER_INFO("App description: Magicword: %i", app_desc.magic_word); const esp_app_desc_t* description = esp_app_get_description();
LOGGER_INFO("App description: SecureVer: %i", app_desc.secure_version); LOGGER_INFO("App description: version: %s (current: %s)", app_desc.version, description->version);
LOGGER_INFO("App description: version: %s", app_desc.version); LOGGER_INFO("App description: PrjctName: %s (current: %s)", app_desc.project_name, description->project_name);
LOGGER_INFO("App description: PrjctName: %s", app_desc.project_name); LOGGER_INFO("App description: Time: %s (current: %s)", app_desc.time, description->time);
LOGGER_INFO("App description: Time: %s", app_desc.time); LOGGER_INFO("App description: Date: %s (current: %s)", app_desc.date, description->date);
LOGGER_INFO("App description: Date: %s", app_desc.date); LOGGER_INFO("App description: IDF Ver: %s (current: %s)", app_desc.idf_ver, description->idf_ver);
LOGGER_INFO("App description: IDF Ver: %s", app_desc.idf_ver);
LOGGER_INFO("App description: SHA256 %s", app_desc.app_elf_sha256); 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) if (imageSize == -1)
{ {
imageSize = esp_https_ota_get_image_size(https_ota_handle); 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) do
{ {
err = ESP_FAIL; // esp_https_ota_perform returns after every read operation which gives user the ability to
esp_https_ota_abort(https_ota_handle); // 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) if (!esp_https_ota_is_complete_data_received(https_ota_handle))
{ {
esp_err_t otaStatus; // 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)) if (err == ESP_OK)
{ {
// the OTA image was not completely received and user can customise the response to this situation. err = esp_https_ota_finish(https_ota_handle);
LOGGER_ERROR("Complete data was not received.");
err = ESP_FAIL;
esp_https_ota_abort(https_ota_handle);
} if (err != ESP_OK)
} {
LOGGER_ERROR("Image validation failed, image is corrupted");
}
}
if(err == ESP_OK) if (err == ESP_OK)
{ {
err = esp_https_ota_finish(https_ota_handle); LOGGER_SUCCESS("OTA upgrade successful");
if(err != ESP_OK) LOGGER_INFO("Rebooting");
{ vTaskDelay(100);
LOGGER_ERROR("Image validation failed, image is corrupted"); esp_restart();
} }
}
if(err == ESP_OK)
{
LOGGER_SUCCESS("OTA upgrade successful");
LOGGER_INFO("Rebooting");
vTaskDelay(100);
esp_restart();
}
} }
@@ -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){"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}}}); 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) void temperaturewordmap::createList_EN(void)
+105 -30
View File
@@ -44,6 +44,7 @@
#include "clock.h" #include "clock.h"
#include "clockwordmap.h" #include "clockwordmap.h"
#include "daywordmap.h" #include "daywordmap.h"
#include "messagewordmap.h"
#include "ota.h" #include "ota.h"
#include "temperature.h" #include "temperature.h"
#include "temperaturewordmap.h" #include "temperaturewordmap.h"
@@ -83,6 +84,7 @@
static TaskHandle_t loggerTaskHandle; static TaskHandle_t loggerTaskHandle;
static TaskHandle_t otaTaskHandle; static TaskHandle_t otaTaskHandle;
static bool otaActive = false;
// -------------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------------
// Function declarations // Function declarations
@@ -91,7 +93,7 @@ static TaskHandle_t otaTaskHandle;
void loggerTask(void* parameters); void loggerTask(void* parameters);
void otaTask(void* parameters); void otaTask(void* parameters);
static void otaCallback(int value); static void otaCallback(struct ota::statusCallbackData* status);
// -------------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------------
// Function definitions // Function definitions
@@ -224,16 +226,38 @@ extern "C" void app_main(void)
temperature temp = temperature(); 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); ClockWordmap clockwords = ClockWordmap(&matrix);
clockwords.setColour(0x80, 0x40, 0xFF); clockwords.setColour(0xFF, 0xFF, 0x20);
DayWordmap daywords = DayWordmap(&matrix); DayWordmap daywords = DayWordmap(&matrix);
daywords.setColour(0xFF, 0x00, 0x80); daywords.setColour(0x00, 0xFF, 0xFF);
temperaturewordmap tempwords = temperaturewordmap(&matrix); 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 // OTA handler
@@ -246,34 +270,52 @@ extern "C" void app_main(void)
std::list<std::string> clockWordlist; std::list<std::string> clockWordlist;
std::list<std::string> tempWordList; std::list<std::string> tempWordList;
uint32_t runninglightIndex = 0;
while(1) while(1)
{ {
matrix.clearAll(); if (!otaActive)
clk.generateWordlist(&clockWordlist);
std::list<std::string>::iterator it;
for(it = clockWordlist.begin(); it != clockWordlist.end(); it++)
{ {
clockwords.setWord(wordmap::Language_t::NL, *it, true); matrix.clearAll();
daywords.setWord(wordmap::Language_t::NL, *it, true); clk.generateWordlist(&clockWordlist);
std::list<std::string>::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();
} }
else
// 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); matrix.clearAll();
}
uint8_t tRed, tGreen, tBlue;
temp.calculateRGB(currentTemperature, &tRed, &tGreen, &tBlue);
tempwords.setColour(tRed, tGreen, tBlue);
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); vTaskDelay(1000);
} }
} }
@@ -286,7 +328,7 @@ void loggerTask(void* parameters)
while (1) while (1)
{ {
debugLogger->task(); debugLogger->task();
vTaskDelay(10); vTaskDelay(2);
} }
} }
@@ -296,12 +338,45 @@ void otaTask(void* parameters)
ota* otaHandler = (ota*) parameters; ota* otaHandler = (ota*) parameters;
while (1) while (1)
{ {
// otaHandler->task(); otaHandler->task();
vTaskDelay(otaHandler->checkInterval_ms); 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;
}
} }
+3
View File
@@ -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 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 // Protected Section
+46 -2
View File
@@ -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 ledmatrix::setPixel(uint32_t row, uint32_t column, uint8_t red, uint8_t green, uint8_t blue)
{ {
FunctionStatus returnValue = FUNCTION_STATUS_OK; FunctionStatus returnValue = FUNCTION_STATUS_OK;
uint32_t index = 0; 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) if (returnValue == FUNCTION_STATUS_OK)
{ {
@@ -90,6 +99,41 @@ FunctionStatus ledmatrix::setPixel(uint32_t row, uint32_t column, uint8_t red, u
return returnValue; 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) FunctionStatus ledmatrix::calculateIndexFromCoordinates(uint32_t row, uint32_t column, uint32_t* index)
{ {