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
+105 -30
View File
@@ -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<std::string> clockWordlist;
std::list<std::string> tempWordList;
uint32_t runninglightIndex = 0;
while(1)
{
matrix.clearAll();
clk.generateWordlist(&clockWordlist);
std::list<std::string>::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<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();
}
// 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;
}
}