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
+2
View File
@@ -100,6 +100,8 @@ class Clock
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:
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
+11 -4
View File
@@ -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<std::string>* wordlist)
struct tm tm;
time(&currentTime);
// currentTime += 100;
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->push_back("it");
wordlist->push_back("is");
@@ -179,6 +183,9 @@ void Clock::generateWordlist(std::list<std::string>* wordlist)
default:
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_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();
}
}
@@ -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)