New logging and more (#446)

- `TT_LOG_*` macros are replaced by `Logger` via `#include<Tactility/Logger.h>`
- Changed default timezone to Europe/Amsterdam
- Fix for logic bug in unPhone hardware
- Fix for init/deinit in DRV2605 driver
- Other fixes
- Removed optimization that broke unPhone (disabled the moving of heap-related functions to flash)
This commit is contained in:
Ken Van Hoeylandt
2026-01-06 22:35:39 +01:00
committed by GitHub
parent 719f7bcece
commit f620255c41
188 changed files with 1973 additions and 1755 deletions
+9 -9
View File
@@ -1,28 +1,28 @@
#include <Tactility/Tactility.h>
#include <Tactility/file/File.h>
#include <Tactility/Logger.h>
#include <Tactility/network/Http.h>
#ifdef ESP_PLATFORM
#include <Tactility/network/EspHttpClient.h>
#include <esp_sntp.h>
#include <esp_http_client.h>
#endif
namespace tt::network::http {
constexpr auto* TAG = "HTTP";
static const auto LOGGER = Logger("HTTP");
void download(
const std::string& url,
const std::string& certFilePath,
const std::string &downloadFilePath,
std::function<void()> onSuccess,
std::function<void(const char* errorMessage)> onError
const std::function<void()>& onSuccess,
const std::function<void(const char* errorMessage)>& onError
) {
TT_LOG_I(TAG, "Downloading %s to %s", url.c_str(), downloadFilePath.c_str());
LOGGER.info("Downloading {} to {}", url, downloadFilePath);
#ifdef ESP_PLATFORM
getMainDispatcher().dispatch([url, certFilePath, downloadFilePath, onSuccess, onError] {
TT_LOG_I(TAG, "Loading certificate");
LOGGER.info("Loading certificate");
auto certificate = file::readString(certFilePath);
if (certificate == nullptr) {
onError("Failed to read certificate");
@@ -68,14 +68,14 @@ void download(
auto lock = file::getLock(downloadFilePath)->asScopedLock();
lock.lock();
TT_LOG_I(TAG, "opening %s", downloadFilePath.c_str());
LOGGER.info("opening {}", downloadFilePath);
auto* file = fopen(downloadFilePath.c_str(), "wb");
if (file == nullptr) {
onError("Failed to open file");
return;
}
TT_LOG_I(TAG, "Writing %d bytes to %s", bytes_left, downloadFilePath.c_str());
LOGGER.info("Writing {} bytes to {}", bytes_left, downloadFilePath);
char buffer[512];
while (bytes_left > 0) {
int data_read = client->read(buffer, 512);
@@ -92,7 +92,7 @@ void download(
}
}
fclose(file);
TT_LOG_I(TAG, "Downloaded %s to %s", url.c_str(), downloadFilePath.c_str());
LOGGER.info("Downloaded {} to {}", url, downloadFilePath);
onSuccess();
});
#else
+7 -7
View File
@@ -2,12 +2,12 @@
#include <Tactility/network/HttpServer.h>
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#include <Tactility/service/wifi/Wifi.h>
namespace tt::network {
constexpr auto* TAG = "HttpServer";
static const auto LOGGER = Logger("HttpServer");
bool HttpServer::startInternal() {
httpd_config_t config = HTTPD_DEFAULT_CONFIG();
@@ -16,7 +16,7 @@ bool HttpServer::startInternal() {
config.uri_match_fn = matchUri;
if (httpd_start(&server, &config) != ESP_OK) {
TT_LOG_E(TAG, "Failed to start http server on port %lu", port);
LOGGER.error("Failed to start http server on port {}", port);
return false;
}
@@ -24,15 +24,15 @@ bool HttpServer::startInternal() {
httpd_register_uri_handler(server, &handler);
}
TT_LOG_I(TAG, "Started on port %lu", config.server_port);
LOGGER.info("Started on port {}", config.server_port);
return true;
}
void HttpServer::stopInternal() {
TT_LOG_I(TAG, "Stopping server");
LOGGER.info("Stopping server");
if (server != nullptr && httpd_stop(server) != ESP_OK) {
TT_LOG_W(TAG, "Error while stopping");
LOGGER.warn("Error while stopping");
server = nullptr;
}
}
@@ -49,7 +49,7 @@ void HttpServer::stop() {
lock.lock();
if (!isStarted()) {
TT_LOG_W(TAG, "Not started");
LOGGER.warn("Not started");
}
stopInternal();
+9 -8
View File
@@ -1,5 +1,6 @@
#include <Tactility/network/HttpdReq.h>
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#include <Tactility/LogMessages.h>
#include <Tactility/StringUtils.h>
#include <Tactility/file/File.h>
@@ -11,7 +12,7 @@
namespace tt::network {
constexpr auto* TAG = "HttpdReq";
static const auto LOGGER = Logger("HttpdReq");
bool getHeaderOrSendError(httpd_req_t* request, const std::string& name, std::string& value) {
size_t header_size = httpd_req_get_hdr_value_len(request, name.c_str());
@@ -22,7 +23,7 @@ bool getHeaderOrSendError(httpd_req_t* request, const std::string& name, std::st
auto header_buffer = std::make_unique<char[]>(header_size + 1);
if (header_buffer == nullptr) {
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
LOGGER.error( LOG_MESSAGE_ALLOC_FAILED);
httpd_resp_send_500(request);
return false;
}
@@ -78,7 +79,7 @@ std::unique_ptr<char[]> receiveByteArray(httpd_req_t* request, size_t length, si
// and we don't have exceptions enabled in the compiler settings
auto* buffer = static_cast<char*>(malloc(length));
if (buffer == nullptr) {
TT_LOG_E(TAG, LOG_MESSAGE_ALLOC_FAILED_FMT, length);
LOGGER.error(LOG_MESSAGE_ALLOC_FAILED_FMT, length);
return nullptr;
}
@@ -86,7 +87,7 @@ std::unique_ptr<char[]> receiveByteArray(httpd_req_t* request, size_t length, si
size_t read_size = length - bytesRead;
size_t bytes_received = httpd_req_recv(request, buffer + bytesRead, read_size);
if (bytes_received <= 0) {
TT_LOG_W(TAG, "Received %zu / %zu", bytesRead + bytes_received, length);
LOGGER.warn("Received error {} after reading {}/{} bytes", bytes_received, bytesRead, length);
return nullptr;
}
@@ -172,7 +173,7 @@ size_t receiveFile(httpd_req_t* request, size_t length, const std::string& fileP
auto* file = fopen(filePath.c_str(), "wb");
if (file == nullptr) {
TT_LOG_E(TAG, "Failed to open file for writing: %s", filePath.c_str());
LOGGER.error("Failed to open file for writing: {}", filePath);
return 0;
}
@@ -180,11 +181,11 @@ size_t receiveFile(httpd_req_t* request, size_t length, const std::string& fileP
auto expected_chunk_size = std::min<size_t>(BUFFER_SIZE, length - bytes_received);
size_t receive_chunk_size = httpd_req_recv(request, buffer, expected_chunk_size);
if (receive_chunk_size <= 0) {
TT_LOG_E(TAG, "Receive failed");
LOGGER.error("Receive failed");
break;
}
if (fwrite(buffer, 1, receive_chunk_size, file) != receive_chunk_size) {
TT_LOG_E(TAG, "Failed to write all bytes");
LOGGER.error("Failed to write all bytes");
break;
}
bytes_received += receive_chunk_size;
+8 -4
View File
@@ -1,6 +1,9 @@
#include <Tactility/network/NtpPrivate.h>
#include <Tactility/Logger.h>
#include <Tactility/Preferences.h>
#include <memory>
#ifdef ESP_PLATFORM
#include <Tactility/kernel/SystemEvents.h>
#include <Tactility/TactilityCore.h>
@@ -10,7 +13,8 @@
namespace tt::network::ntp {
constexpr auto* TAG = "NTP";
static const auto LOGGER = Logger("NTP");
static bool processedSyncEvent = false;
#ifdef ESP_PLATFORM
@@ -21,14 +25,14 @@ void storeTimeInNvs() {
auto preferences = std::make_unique<Preferences>("time");
preferences->putInt64("syncTime", now);
TT_LOG_I(TAG, "Stored time %llu", now);
LOGGER.info("Stored time {}", now);
}
void setTimeFromNvs() {
auto preferences = std::make_unique<Preferences>("time");
time_t synced_time;
if (preferences->optInt64("syncTime", synced_time)) {
TT_LOG_I(TAG, "Restoring last known time to %llu", synced_time);
LOGGER.info("Restoring last known time to {}", synced_time);
timeval get_nvs_time;
get_nvs_time.tv_sec = synced_time;
settimeofday(&get_nvs_time, nullptr);
@@ -36,7 +40,7 @@ void setTimeFromNvs() {
}
static void onTimeSynced(timeval* tv) {
TT_LOG_I(TAG, "Time synced (%llu)", tv->tv_sec);
LOGGER.info("Time synced ({})", tv->tv_sec);
processedSyncEvent = true;
esp_netif_sntp_deinit();
storeTimeInNvs();
-2
View File
@@ -1,7 +1,5 @@
#include "Tactility/network/Url.h"
#include <Tactility/Log.h>
namespace tt::network {
std::map<std::string, std::string> parseUrlQuery(std::string query) {