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
+13 -13
View File
@@ -1,44 +1,44 @@
#include "Tactility/file/ObjectFile.h"
#include "Tactility/file/ObjectFilePrivate.h"
#include <Tactility/file/ObjectFile.h>
#include <Tactility/file/ObjectFilePrivate.h>
#include <cstring>
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
namespace tt::file {
constexpr auto* TAG = "ObjectFileReader";
static const auto LOGGER = Logger("ObjectFileReader");
bool ObjectFileReader::open() {
auto opening_file = std::unique_ptr<FILE, FileCloser>(fopen(filePath.c_str(), "r"));
if (opening_file == nullptr) {
TT_LOG_E(TAG, "Failed to open file %s", filePath.c_str());
LOGGER.error("Failed to open file {}", filePath.c_str());
return false;
}
FileHeader file_header;
if (fread(&file_header, sizeof(FileHeader), 1, opening_file.get()) != 1) {
TT_LOG_E(TAG, "Failed to read file header from %s", filePath.c_str());
LOGGER.error("Failed to read file header from {}", filePath);
return false;
}
if (file_header.identifier != OBJECT_FILE_IDENTIFIER) {
TT_LOG_E(TAG, "Invalid file type for %s", filePath.c_str());
LOGGER.error("Invalid file type for {}", filePath);
return false;
}
if (file_header.version != OBJECT_FILE_VERSION) {
TT_LOG_E(TAG, "Unknown version for %s: %lu", filePath.c_str(), file_header.identifier);
LOGGER.error("Unknown version for {}: {}", filePath, file_header.identifier);
return false;
}
ContentHeader content_header;
if (fread(&content_header, sizeof(ContentHeader), 1, opening_file.get()) != 1) {
TT_LOG_E(TAG, "Failed to read content header from %s", filePath.c_str());
LOGGER.error("Failed to read content header from {}", filePath);
return false;
}
if (recordSize != content_header.recordSize) {
TT_LOG_E(TAG, "Record size mismatch for %s: expected %lu, got %lu", filePath.c_str(), recordSize, content_header.recordSize);
LOGGER.error("Record size mismatch for {}: expected {}, got {}", filePath, recordSize, content_header.recordSize);
return false;
}
@@ -47,8 +47,8 @@ bool ObjectFileReader::open() {
file = std::move(opening_file);
TT_LOG_D(TAG, "File version: %lu", file_header.version);
TT_LOG_D(TAG, "Content: version = %lu, size = %lu bytes, count = %lu", content_header.recordVersion, content_header.recordSize, content_header.recordCount);
LOGGER.debug("File version: {}", file_header.version);
LOGGER.debug("Content: version = {}, size = {} bytes, count = {}", content_header.recordVersion, content_header.recordSize, content_header.recordCount);
return true;
}
@@ -63,7 +63,7 @@ void ObjectFileReader::close() {
bool ObjectFileReader::readNext(void* output) {
if (file == nullptr) {
TT_LOG_E(TAG, "File not open");
LOGGER.error("File not open");
return false;
}
+18 -18
View File
@@ -1,24 +1,24 @@
#include "../../Include/Tactility/file/ObjectFile.h"
#include "Tactility/file/ObjectFilePrivate.h"
#include <Tactility/file/ObjectFile.h>
#include <Tactility/file/ObjectFilePrivate.h>
#include <Tactility/Logger.h>
#include <cstring>
#include <Tactility/Log.h>
#include <unistd.h>
namespace tt::file {
constexpr auto* TAG = "ObjectFileWriter";
static const auto LOGGER = Logger("ObjectFileWriter");
bool ObjectFileWriter::open() {
bool edit_existing = append && access(filePath.c_str(), F_OK) == 0;
if (append && !edit_existing) {
TT_LOG_W(TAG, "access() to %s failed: %s", filePath.c_str(), strerror(errno));
LOGGER.warn("access() to {} failed: {}", filePath, strerror(errno));
}
// Edit existing or create a new file
auto opening_file = std::unique_ptr<FILE, FileCloser>(std::fopen(filePath.c_str(), "wb"));
if (opening_file == nullptr) {
TT_LOG_E(TAG, "Failed to open file %s", filePath.c_str());
LOGGER.error("Failed to open file {}", filePath);
return false;
}
@@ -29,17 +29,17 @@ bool ObjectFileWriter::open() {
FileHeader file_header;
if (fread(&file_header, sizeof(FileHeader), 1, opening_file.get()) != 1) {
TT_LOG_E(TAG, "Failed to read file header from %s", filePath.c_str());
LOGGER.error("Failed to read file header from {}", filePath);
return false;
}
if (file_header.identifier != OBJECT_FILE_IDENTIFIER) {
TT_LOG_E(TAG, "Invalid file type for %s", filePath.c_str());
LOGGER.error("Invalid file type for {}", filePath);
return false;
}
if (file_header.version != OBJECT_FILE_VERSION) {
TT_LOG_E(TAG, "Unknown version for %s: %lu", filePath.c_str(), file_header.identifier);
LOGGER.error("Unknown version for {}: {}", filePath, file_header.version);
return false;
}
@@ -47,17 +47,17 @@ bool ObjectFileWriter::open() {
ContentHeader content_header;
if (fread(&content_header, sizeof(ContentHeader), 1, opening_file.get()) != 1) {
TT_LOG_E(TAG, "Failed to read content header from %s", filePath.c_str());
LOGGER.error("Failed to read content header from {}", filePath);
return false;
}
if (recordSize != content_header.recordSize) {
TT_LOG_E(TAG, "Record size mismatch for %s: expected %lu, got %lu", filePath.c_str(), recordSize, content_header.recordSize);
LOGGER.error("Record size mismatch for {}: expected {}, got {}", filePath, recordSize, content_header.recordSize);
return false;
}
if (recordVersion != content_header.recordVersion) {
TT_LOG_E(TAG, "Version mismatch for %s: expected %lu, got %lu", filePath.c_str(), recordVersion, content_header.recordVersion);
LOGGER.error("Version mismatch for {}: expected {}, got {}", filePath, recordVersion, content_header.recordVersion);
return false;
}
@@ -66,7 +66,7 @@ bool ObjectFileWriter::open() {
} else {
FileHeader file_header;
if (fwrite(&file_header, sizeof(FileHeader), 1, opening_file.get()) != 1) {
TT_LOG_E(TAG, "Failed to write file header for %s", filePath.c_str());
LOGGER.error("Failed to write file header for {}", filePath);
return false;
}
@@ -81,12 +81,12 @@ bool ObjectFileWriter::open() {
void ObjectFileWriter::close() {
if (file == nullptr) {
TT_LOG_E(TAG, "File not opened: %s", filePath.c_str());
LOGGER.error("File not opened: {}", filePath);
return;
}
if (fseek(file.get(), sizeof(FileHeader), SEEK_SET) != 0) {
TT_LOG_E(TAG, "File seek failed: %s", filePath.c_str());
LOGGER.error("File seek failed: {}", filePath);
return;
}
@@ -97,7 +97,7 @@ void ObjectFileWriter::close() {
};
if (fwrite(&content_header, sizeof(ContentHeader), 1, file.get()) != 1) {
TT_LOG_E(TAG, "Failed to write content header to %s", filePath.c_str());
LOGGER.error("Failed to write content header to {}", filePath);
}
file = nullptr;
@@ -105,12 +105,12 @@ void ObjectFileWriter::close() {
bool ObjectFileWriter::write(void* data) {
if (file == nullptr) {
TT_LOG_E(TAG, "File not opened: %s", filePath.c_str());
LOGGER.error("File not opened: {}", filePath);
return false;
}
if (fwrite(data, recordSize, 1, file.get()) != 1) {
TT_LOG_E(TAG, "Failed to write record to %s", filePath.c_str());
LOGGER.error("Failed to write record to {}", filePath);
return false;
}
+6 -5
View File
@@ -3,10 +3,11 @@
#include <Tactility/StringUtils.h>
#include <Tactility/file/File.h>
#include <Tactility/file/FileLock.h>
#include <Tactility/Logger.h>
namespace tt::file {
static auto TAG = "PropertiesFile";
static const auto LOGGER = Logger("PropertiesFile");
bool getKeyValuePair(const std::string& input, std::string& key, std::string& value) {
auto index = input.find('=');
@@ -21,7 +22,7 @@ bool getKeyValuePair(const std::string& input, std::string& key, std::string& va
bool loadPropertiesFile(const std::string& filePath, std::function<void(const std::string& key, const std::string& value)> callback) {
// Reading properties is a common operation; make this debug-level to avoid
// flooding the serial console under frequent polling.
TT_LOG_D(TAG, "Reading properties file %s", filePath.c_str());
LOGGER.debug("Reading properties file {}", filePath);
uint16_t line_count = 0;
std::string key_prefix = "";
// Malformed lines are skipped, valid lines are loaded and callback is called
@@ -39,7 +40,7 @@ bool loadPropertiesFile(const std::string& filePath, std::function<void(const st
std::string trimmed_value = string::trim(value, " \t");
callback(trimmed_key, trimmed_value);
} else {
TT_LOG_E(TAG, "Failed to parse line %d of %s (skipped)", line_count, filePath.c_str());
LOGGER.error("Failed to parse line {} of {} (skipped)", line_count, filePath);
// Continue loading other lines
}
}
@@ -56,11 +57,11 @@ bool loadPropertiesFile(const std::string& filePath, std::map<std::string, std::
bool savePropertiesFile(const std::string& filePath, const std::map<std::string, std::string>& properties) {
bool result = false;
getLock(filePath)->withLock([&result, filePath, &properties] {
TT_LOG_I(TAG, "Saving properties file %s", filePath.c_str());
LOGGER.info("Saving properties file {}", filePath);
FILE* file = fopen(filePath.c_str(), "w");
if (file == nullptr) {
TT_LOG_E(TAG, "Failed to open %s", filePath.c_str());
LOGGER.error("Failed to open {}", filePath);
return;
}