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
@@ -3,12 +3,13 @@
#ifdef ESP_PLATFORM
#include <esp_http_client.h>
#include <Tactility/Logger.h>
namespace tt::network {
class EspHttpClient {
static constexpr auto* TAG = "EspHttpClient";
const Logger logger = Logger("EspHttpClient");
std::unique_ptr<esp_http_client_config_t> config = nullptr;
esp_http_client_handle_t client = nullptr;
@@ -27,7 +28,7 @@ public:
}
bool init(std::unique_ptr<esp_http_client_config_t> inConfig) {
TT_LOG_I(TAG, "init(%s)", inConfig->url);
logger.info("init({})", inConfig->url);
assert(this->config == nullptr);
config = std::move(inConfig);
client = esp_http_client_init(config.get());
@@ -36,11 +37,11 @@ public:
bool open() {
assert(client != nullptr);
TT_LOG_I(TAG, "open()");
logger.info("open()");
auto result = esp_http_client_open(client, 0);
if (result != ESP_OK) {
TT_LOG_E(TAG, "open() failed: %s", esp_err_to_name(result));
logger.error("open() failed: {}", esp_err_to_name(result));
return false;
}
@@ -50,7 +51,7 @@ public:
bool fetchHeaders() const {
assert(client != nullptr);
TT_LOG_I(TAG, "fetchHeaders()");
logger.info("fetchHeaders()");
return esp_http_client_fetch_headers(client) >= 0;
}
@@ -63,7 +64,7 @@ public:
int getStatusCode() const {
assert(client != nullptr);
const auto status_code = esp_http_client_get_status_code(client);
TT_LOG_I(TAG, "Status code %d", status_code);
logger.info("Status code {}", status_code);
return status_code;
}
@@ -74,19 +75,19 @@ public:
int read(char* bytes, int size) const {
assert(client != nullptr);
TT_LOG_I(TAG, "read(%d)", size);
logger.info("read({})", size);
return esp_http_client_read(client, bytes, size);
}
int readResponse(char* bytes, int size) const {
assert(client != nullptr);
TT_LOG_I(TAG, "readResponse(%d)", size);
logger.info("readResponse({})", size);
return esp_http_client_read_response(client, bytes, size);
}
bool close() {
assert(client != nullptr);
TT_LOG_I(TAG, "close()");
logger.info("close()");
if (esp_http_client_close(client) == ESP_OK) {
isOpen = false;
}
@@ -96,7 +97,7 @@ public:
bool cleanup() {
assert(client != nullptr);
assert(!isOpen);
TT_LOG_I(TAG, "cleanup()");
logger.info("cleanup()");
const auto result = esp_http_client_cleanup(client);
client = nullptr;
return result == ESP_OK;
+2 -2
View File
@@ -17,8 +17,8 @@ namespace tt::network::http {
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
);
}
@@ -6,7 +6,7 @@
#include <Tactility/Bundle.h>
#include <Tactility/Check.h>
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#include <Tactility/Mutex.h>
#include <memory>
@@ -48,7 +48,7 @@ class AppInstance : public AppContext {
return manifest->createApp();
} else if (manifest->appLocation.isExternal()) {
if (manifest->createApp != nullptr) {
TT_LOG_W("", "Manifest specifies createApp, but this is not used with external apps");
Logger("AppInstance").warn("Manifest specifies createApp, but this is not used with external apps");
}
#ifdef ESP_PLATFORM
return createElfApp(manifest);
+9 -7
View File
@@ -4,12 +4,14 @@
#include <string>
#include <vector>
#include <Tactility/Logger.h>
namespace tt::json {
class Reader {
const cJSON* root;
static constexpr const char* TAG = "json::Reader";
Logger logger = Logger("json::Reader");
public:
@@ -18,7 +20,7 @@ public:
bool readString(const char* key, std::string& output) const {
const auto* child = cJSON_GetObjectItemCaseSensitive(root, key);
if (!cJSON_IsString(child)) {
TT_LOG_E(TAG, "%s is not a string", key);
logger.error("{} is not a string", key);
return false;
}
output = cJSON_GetStringValue(child);
@@ -30,7 +32,7 @@ public:
if (!readNumber(key, buffer)) {
return false;
}
output = buffer;
output = static_cast<int32_t>(buffer);
return true;
}
@@ -46,7 +48,7 @@ public:
bool readNumber(const char* key, double& output) const {
const auto* child = cJSON_GetObjectItemCaseSensitive(root, key);
if (!cJSON_IsNumber(child)) {
TT_LOG_E(TAG, "%s is not a number", key);
logger.error("{} is not a number", key);
return false;
}
output = cJSON_GetNumberValue(child);
@@ -56,16 +58,16 @@ public:
bool readStringArray(const char* key, std::vector<std::string>& output) const {
const auto* child = cJSON_GetObjectItemCaseSensitive(root, key);
if (!cJSON_IsArray(child)) {
TT_LOG_E(TAG, "%s is not an array", key);
logger.error("{} is not an array", key);
return false;
}
const auto size = cJSON_GetArraySize(child);
TT_LOG_I(TAG, "Processing %d array children", size);
logger.info("Processing {} array children", size);
output.resize(size);
for (int i = 0; i < size; ++i) {
const auto string_json = cJSON_GetArrayItem(child, i);
if (!cJSON_IsString(string_json)) {
TT_LOG_E(TAG, "array child of %s is not a string", key);
logger.error("Array child of {} is not a string", key);
return false;
}
output[i] = cJSON_GetStringValue(string_json);
+8 -9
View File
@@ -1,15 +1,14 @@
#ifdef ESP_PLATFORM
#include "Tactility/PartitionsEsp.h"
#include <Tactility/Log.h>
#include <Tactility/PartitionsEsp.h>
#include <Tactility/Logger.h>
#include <esp_vfs_fat.h>
#include <nvs_flash.h>
namespace tt {
constexpr auto* TAG = "Partitions";
static const auto LOGGER = Logger("Partitions");
static esp_err_t initNvsFlashSafely() {
esp_err_t result = nvs_flash_init();
@@ -41,7 +40,7 @@ size_t getSectorSize() {
}
esp_err_t initPartitionsEsp() {
TT_LOG_I(TAG, "Init partitions");
LOGGER.info("Init partitions");
ESP_ERROR_CHECK(initNvsFlashSafely());
const esp_vfs_fat_mount_config_t mount_config = {
@@ -54,16 +53,16 @@ esp_err_t initPartitionsEsp() {
auto system_result = esp_vfs_fat_spiflash_mount_ro("/system", "system", &mount_config);
if (system_result != ESP_OK) {
TT_LOG_E(TAG, "Failed to mount /system (%s)", esp_err_to_name(system_result));
LOGGER.error("Failed to mount /system ({})", esp_err_to_name(system_result));
} else {
TT_LOG_I(TAG, "Mounted /system");
LOGGER.info("Mounted /system");
}
auto data_result = esp_vfs_fat_spiflash_mount_rw_wl("/data", "data", &mount_config, &data_wl_handle);
if (data_result != ESP_OK) {
TT_LOG_E(TAG, "Failed to mount /data (%s)", esp_err_to_name(data_result));
LOGGER.error("Failed to mount /data ({})", esp_err_to_name(data_result));
} else {
TT_LOG_I(TAG, "Mounted /data");
LOGGER.info("Mounted /data");
}
return system_result == ESP_OK && data_result == ESP_OK;
+18 -17
View File
@@ -1,5 +1,6 @@
#ifdef ESP_PLATFORM
#include <Tactility/Logger.h>
#include <Tactility/Preferences.h>
#include <Tactility/TactilityCore.h>
@@ -7,12 +8,12 @@
namespace tt {
constexpr auto* TAG = "Preferences";
static const auto LOGGER = Logger("Preferences");
bool Preferences::optBool(const std::string& key, bool& out) const {
nvs_handle_t handle;
if (nvs_open(namespace_, NVS_READWRITE, &handle) != ESP_OK) {
TT_LOG_E(TAG, "Failed to open namespace %s", namespace_);
LOGGER.error("Failed to open namespace {}", namespace_);
return false;
} else {
uint8_t out_number;
@@ -28,7 +29,7 @@ bool Preferences::optBool(const std::string& key, bool& out) const {
bool Preferences::optInt32(const std::string& key, int32_t& out) const {
nvs_handle_t handle;
if (nvs_open(namespace_, NVS_READWRITE, &handle) != ESP_OK) {
TT_LOG_E(TAG, "Failed to open namespace %s", namespace_);
LOGGER.error("Failed to open namespace {}", namespace_);
return false;
} else {
bool success = nvs_get_i32(handle, key.c_str(), &out) == ESP_OK;
@@ -40,7 +41,7 @@ bool Preferences::optInt32(const std::string& key, int32_t& out) const {
bool Preferences::optInt64(const std::string& key, int64_t& out) const {
nvs_handle_t handle;
if (nvs_open(namespace_, NVS_READWRITE, &handle) != ESP_OK) {
TT_LOG_E(TAG, "Failed to open namespace %s", namespace_);
LOGGER.error("Failed to open namespace {}", namespace_);
return false;
} else {
bool success = nvs_get_i64(handle, key.c_str(), &out) == ESP_OK;
@@ -52,7 +53,7 @@ bool Preferences::optInt64(const std::string& key, int64_t& out) const {
bool Preferences::optString(const std::string& key, std::string& out) const {
nvs_handle_t handle;
if (nvs_open(namespace_, NVS_READWRITE, &handle) != ESP_OK) {
TT_LOG_E(TAG, "Failed to open namespace %s", namespace_);
LOGGER.error("Failed to open namespace {}", namespace_);
return false;
} else {
size_t out_size = 256;
@@ -89,13 +90,13 @@ void Preferences::putBool(const std::string& key, bool value) {
nvs_handle_t handle;
if (nvs_open(namespace_, NVS_READWRITE, &handle) == ESP_OK) {
if (nvs_set_u8(handle, key.c_str(), value) != ESP_OK) {
TT_LOG_E(TAG, "Failed to set %s:%s", namespace_, key.c_str());
LOGGER.error("Failed to set {}:{}", namespace_, key);
} else if (nvs_commit(handle) != ESP_OK) {
TT_LOG_E(TAG, "Failed to commit %s:%s", namespace_, key.c_str());
LOGGER.error("Failed to commit {}:{}", namespace_, key);
}
nvs_close(handle);
} else {
TT_LOG_E(TAG, "Failed to open namespace %s", namespace_);
LOGGER.error("Failed to open namespace {}", namespace_);
}
}
@@ -103,13 +104,13 @@ void Preferences::putInt32(const std::string& key, int32_t value) {
nvs_handle_t handle;
if (nvs_open(namespace_, NVS_READWRITE, &handle) == ESP_OK) {
if (nvs_set_i32(handle, key.c_str(), value) != ESP_OK) {
TT_LOG_E(TAG, "Failed to set %s:%s", namespace_, key.c_str());
LOGGER.error("Failed to set {}:{}", namespace_, key);
} else if (nvs_commit(handle) != ESP_OK) {
TT_LOG_E(TAG, "Failed to commit %s:%s", namespace_, key.c_str());
LOGGER.error("Failed to commit {}:{}", namespace_, key);
}
nvs_close(handle);
} else {
TT_LOG_E(TAG, "Failed to open namespace %s", namespace_);
LOGGER.error("Failed to open namespace {}", namespace_);
}
}
@@ -117,13 +118,13 @@ void Preferences::putInt64(const std::string& key, int64_t value) {
nvs_handle_t handle;
if (nvs_open(namespace_, NVS_READWRITE, &handle) == ESP_OK) {
if (nvs_set_i64(handle, key.c_str(), value) != ESP_OK) {
TT_LOG_E(TAG, "Failed to set %s:%s", namespace_, key.c_str());
LOGGER.error("Failed to set {}:{}", namespace_, key);
} else if (nvs_commit(handle) != ESP_OK) {
TT_LOG_E(TAG, "Failed to commit %s:%s", namespace_, key.c_str());
LOGGER.error("Failed to commit {}:{}", namespace_, key);
}
nvs_close(handle);
} else {
TT_LOG_E(TAG, "Failed to open namespace %s", namespace_);
LOGGER.error("Failed to open namespace {}", namespace_);
}
}
@@ -131,13 +132,13 @@ void Preferences::putString(const std::string& key, const std::string& text) {
nvs_handle_t handle;
if (nvs_open(namespace_, NVS_READWRITE, &handle) == ESP_OK) {
if (nvs_set_str(handle, key.c_str(), text.c_str()) != ESP_OK) {
TT_LOG_E(TAG, "Failed to set %s:%s", namespace_, key.c_str());
LOGGER.error("Failed to set {}:{}", namespace_, key.c_str());
} else if (nvs_commit(handle) != ESP_OK) {
TT_LOG_E(TAG, "Failed to commit %s:%s", namespace_, key.c_str());
LOGGER.error("Failed to commit {}:{}", namespace_, key);
}
nvs_close(handle);
} else {
TT_LOG_E(TAG, "Failed to open namespace %s", namespace_);
LOGGER.error("Failed to open namespace {}", namespace_);
}
}
+1 -2
View File
@@ -1,7 +1,6 @@
#ifndef ESP_PLATFOM
#include "Tactility/Preferences.h"
#include <Tactility/Preferences.h>
#include <Tactility/Bundle.h>
namespace tt {
+22 -20
View File
@@ -5,15 +5,17 @@
#include <Tactility/Tactility.h>
#include <Tactility/TactilityConfig.h>
#include <Tactility/DispatcherThread.h>
#include <Tactility/MountPoints.h>
#include <Tactility/app/AppManifestParsing.h>
#include <Tactility/app/AppRegistration.h>
#include <Tactility/DispatcherThread.h>
#include <Tactility/file/File.h>
#include <Tactility/file/FileLock.h>
#include <Tactility/file/PropertiesFile.h>
#include <Tactility/hal/HalPrivate.h>
#include <Tactility/Logger.h>
#include <Tactility/LogMessages.h>
#include <Tactility/lvgl/LvglPrivate.h>
#include <Tactility/MountPoints.h>
#include <Tactility/network/NtpPrivate.h>
#include <Tactility/service/ServiceManifest.h>
#include <Tactility/service/ServiceRegistration.h>
@@ -29,7 +31,7 @@
namespace tt {
constexpr auto* TAG = "Tactility";
static auto LOGGER = Logger("Tactility");
static const Configuration* config_instance = nullptr;
static Dispatcher mainDispatcher;
@@ -117,7 +119,7 @@ namespace app {
// List of all apps excluding Boot app (as Boot app calls this function indirectly)
static void registerInternalApps() {
TT_LOG_I(TAG, "Registering internal apps");
LOGGER.info("Registering internal apps");
addAppManifest(app::alertdialog::manifest);
addAppManifest(app::appdetails::manifest);
@@ -178,22 +180,22 @@ static void registerInternalApps() {
}
static void registerInstalledApp(std::string path) {
TT_LOG_I(TAG, "Registering app at %s", path.c_str());
LOGGER.info("Registering app at {}", path);
std::string manifest_path = path + "/manifest.properties";
if (!file::isFile(manifest_path)) {
TT_LOG_E(TAG, "Manifest not found at %s", manifest_path.c_str());
LOGGER.error("Manifest not found at {}", manifest_path);
return;
}
std::map<std::string, std::string> properties;
if (!file::loadPropertiesFile(manifest_path, properties)) {
TT_LOG_E(TAG, "Failed to load manifest at %s", manifest_path.c_str());
LOGGER.error("Failed to load manifest at {}", manifest_path);
return;
}
app::AppManifest manifest;
if (!app::parseManifest(properties, manifest)) {
TT_LOG_E(TAG, "Failed to parse manifest at %s", manifest_path.c_str());
LOGGER.error("Failed to parse manifest at {}", manifest_path);
return;
}
@@ -204,7 +206,7 @@ static void registerInstalledApp(std::string path) {
}
static void registerInstalledApps(const std::string& path) {
TT_LOG_I(TAG, "Registering apps from %s", path.c_str());
LOGGER.info("Registering apps from {}", path);
file::listDirectory(path, [&path](const auto& entry) {
auto absolute_path = std::format("{}/{}", path, entry.d_name);
@@ -226,14 +228,14 @@ static void registerInstalledAppsFromSdCards() {
auto sdcard_devices = hal::findDevices<hal::sdcard::SdCardDevice>(hal::Device::Type::SdCard);
for (const auto& sdcard : sdcard_devices) {
if (sdcard->isMounted()) {
TT_LOG_I(TAG, "Registering apps from %s", sdcard->getMountPath().c_str());
LOGGER.info("Registering apps from {}", sdcard->getMountPath());
registerInstalledAppsFromSdCard(sdcard);
}
}
}
static void registerAndStartSecondaryServices() {
TT_LOG_I(TAG, "Registering and starting system services");
LOGGER.info("Registering and starting secondary system services");
addService(service::loader::manifest);
addService(service::gui::manifest);
addService(service::statusbar::manifest);
@@ -248,7 +250,7 @@ static void registerAndStartSecondaryServices() {
}
static void registerAndStartPrimaryServices() {
TT_LOG_I(TAG, "Registering and starting system services");
LOGGER.info("Registering and starting primary system services");
addService(service::gps::manifest);
if (hal::hasDevice(hal::Device::Type::SdCard)) {
addService(service::sdcard::manifest);
@@ -269,15 +271,15 @@ void createTempDirectory(const std::string& rootPath) {
auto lock = file::getLock(rootPath)->asScopedLock();
if (lock.lock(1000 / portTICK_PERIOD_MS)) {
if (mkdir(temp_path.c_str(), 0777) == 0) {
TT_LOG_I(TAG, "Created %s", temp_path.c_str());
LOGGER.info("Created {}", temp_path);
} else {
TT_LOG_E(TAG, "Failed to create %s", temp_path.c_str());
LOGGER.error("Failed to create {}", temp_path);
}
} else {
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, rootPath.c_str());
LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, rootPath);
}
} else {
TT_LOG_I(TAG, "Found existing %s", temp_path.c_str());
LOGGER.info("Found existing {}", temp_path);
}
}
@@ -305,7 +307,7 @@ void registerApps() {
}
void run(const Configuration& config) {
TT_LOG_I(TAG, "Tactility v%s on %s (%s)", TT_VERSION, CONFIG_TT_DEVICE_NAME, CONFIG_TT_DEVICE_ID);
LOGGER.info("Tactility v{} on {} ({})", TT_VERSION, CONFIG_TT_DEVICE_NAME, CONFIG_TT_DEVICE_ID);
assert(config.hardware);
const hal::Configuration& hardware = *config.hardware;
@@ -325,14 +327,14 @@ void run(const Configuration& config) {
lvgl::init(hardware);
registerAndStartSecondaryServices();
TT_LOG_I(TAG, "Core systems ready");
LOGGER.info("Core systems ready");
TT_LOG_I(TAG, "Starting boot app");
LOGGER.info("Starting boot app");
// The boot app takes care of registering system apps, user services and user apps
addAppManifest(app::boot::manifest);
app::start(app::boot::manifest.appId);
TT_LOG_I(TAG, "Main dispatcher ready");
LOGGER.info("Main dispatcher ready");
while (true) {
mainDispatcher.consume();
}
@@ -1,7 +1,8 @@
#ifdef ESP_PLATFORM
#include "Tactility/PartitionsEsp.h"
#include "Tactility/TactilityCore.h"
#include <Tactility/Logger.h>
#include <Tactility/PartitionsEsp.h>
#include <Tactility/TactilityCore.h>
#include "esp_event.h"
#include "esp_netif.h"
@@ -9,14 +10,14 @@
namespace tt {
constexpr auto* TAG = "Tactility";
static auto LOGGER = Logger("Tactility");
// Initialize NVS
static void initNvs() {
TT_LOG_I(TAG, "Init NVS");
LOGGER.info("Init NVS");
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
TT_LOG_I(TAG, "NVS erasing");
LOGGER.info("NVS erasing");
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
@@ -24,7 +25,7 @@ static void initNvs() {
}
static void initNetwork() {
TT_LOG_I(TAG, "Init network");
LOGGER.info("Init network");
ESP_ERROR_CHECK(esp_netif_init());
ESP_ERROR_CHECK(esp_event_loop_create_default());
}
+28 -31
View File
@@ -6,35 +6,32 @@
#include <Tactility/file/FileLock.h>
#include <Tactility/file/PropertiesFile.h>
#include <Tactility/hal/Device.h>
#include <Tactility/hal/sdcard/SdCardDevice.h>
#include <Tactility/Logger.h>
#include <Tactility/Paths.h>
#include <cerrno>
#include <cstdio>
#include <cstring>
#include <fcntl.h>
#include <format>
#include <libgen.h>
#include <map>
#include <sys/types.h>
#include <unistd.h>
#include <minitar.h>
constexpr auto* TAG = "App";
namespace tt::app {
static const auto LOGGER = Logger("App");
static bool untarFile(minitar* mp, const minitar_entry* entry, const std::string& destinationPath) {
const auto absolute_path = destinationPath + "/" + entry->metadata.path;
if (!file::findOrCreateDirectory(destinationPath, 0777)) {
TT_LOG_E(TAG, "Can't find or create directory %s", destinationPath.c_str());
LOGGER.error("Can't find or create directory {}", destinationPath.c_str());
return false;
}
// minitar_read_contents(&mp, &entry, file_buffer, entry.metadata.size);
if (!minitar_read_contents_to_file(mp, entry, absolute_path.c_str())) {
TT_LOG_E(TAG, "Failed to write data to %s", absolute_path.c_str());
LOGGER.error("Failed to write data to {}", absolute_path.c_str());
return false;
}
@@ -63,32 +60,32 @@ static bool untar(const std::string& tarPath, const std::string& destinationPath
do {
if (minitar_read_entry(&mp, &entry) == 0) {
TT_LOG_I(TAG, "Extracting %s", entry.metadata.path);
LOGGER.info("Extracting {}", entry.metadata.path);
if (entry.metadata.type == MTAR_DIRECTORY) {
if (!strcmp(entry.metadata.name, ".") || !strcmp(entry.metadata.name, "..") || !strcmp(entry.metadata.name, "/")) continue;
if (!untarDirectory(&entry, destinationPath)) {
TT_LOG_E(TAG, "Failed to create directory %s/%s: %s", destinationPath.c_str(), entry.metadata.name, strerror(errno));
LOGGER.error("Failed to create directory {}/{}: {}", destinationPath, entry.metadata.name, strerror(errno));
success = false;
break;
}
} else if (entry.metadata.type == MTAR_REGULAR) {
if (!untarFile(&mp, &entry, destinationPath)) {
TT_LOG_E(TAG, "Failed to extract file %s: %s", entry.metadata.path, strerror(errno));
LOGGER.error("Failed to extract file {}: {}", entry.metadata.path, strerror(errno));
success = false;
break;
}
} else if (entry.metadata.type == MTAR_SYMLINK) {
TT_LOG_E(TAG, "SYMLINK not supported");
LOGGER.error("SYMLINK not supported");
} else if (entry.metadata.type == MTAR_HARDLINK) {
TT_LOG_E(TAG, "HARDLINK not supported");
LOGGER.error("HARDLINK not supported");
} else if (entry.metadata.type == MTAR_FIFO) {
TT_LOG_E(TAG, "FIFO not supported");
LOGGER.error("FIFO not supported");
} else if (entry.metadata.type == MTAR_BLKDEV) {
TT_LOG_E(TAG, "BLKDEV not supported");
LOGGER.error("BLKDEV not supported");
} else if (entry.metadata.type == MTAR_CHRDEV) {
TT_LOG_E(TAG, "CHRDEV not supported");
LOGGER.error("CHRDEV not supported");
} else {
TT_LOG_E(TAG, "Unknown entry type: %d", entry.metadata.type);
LOGGER.error("Unknown entry type: {}", static_cast<int>(entry.metadata.type));
success = false;
break;
}
@@ -100,7 +97,7 @@ static bool untar(const std::string& tarPath, const std::string& destinationPath
void cleanupInstallDirectory(const std::string& path) {
if (!file::deleteRecursively(path)) {
TT_LOG_W(TAG, "Failed to delete existing installation at %s", path.c_str());
LOGGER.warn("Failed to delete existing installation at {}", path);
}
}
@@ -109,16 +106,16 @@ bool install(const std::string& path) {
// the lock with the display. We don't want to lock the display for very long.
auto app_parent_path = getAppInstallPath();
TT_LOG_I(TAG, "Installing app %s to %s", path.c_str(), app_parent_path.c_str());
LOGGER.info("Installing app {} to {}", path, app_parent_path);
auto filename = file::getLastPathSegment(path);
const std::string app_target_path = std::format("{}/{}", app_parent_path, filename);
if (file::isDirectory(app_target_path) && !file::deleteRecursively(app_target_path)) {
TT_LOG_W(TAG, "Failed to delete %s", app_target_path.c_str());
LOGGER.warn("Failed to delete {}", app_target_path);
}
if (!file::findOrCreateDirectory(app_target_path, 0777)) {
TT_LOG_I(TAG, "Failed to create directory %s", app_target_path.c_str());
LOGGER.info("Failed to create directory {}", app_target_path);
return false;
}
@@ -126,9 +123,9 @@ bool install(const std::string& path) {
auto source_path_lock = file::getLock(path)->asScopedLock();
target_path_lock.lock();
source_path_lock.lock();
TT_LOG_I(TAG, "Extracting app from %s to %s", path.c_str(), app_target_path.c_str());
LOGGER.info("Extracting app from {} to {}", path, app_target_path);
if (!untar(path, app_target_path)) {
TT_LOG_E(TAG, "Failed to extract");
LOGGER.error("Failed to extract");
return false;
}
source_path_lock.unlock();
@@ -136,21 +133,21 @@ bool install(const std::string& path) {
auto manifest_path = app_target_path + "/manifest.properties";
if (!file::isFile(manifest_path)) {
TT_LOG_E(TAG, "Manifest not found at %s", manifest_path.c_str());
LOGGER.error("Manifest not found at {}", manifest_path);
cleanupInstallDirectory(app_target_path);
return false;
}
std::map<std::string, std::string> properties;
if (!file::loadPropertiesFile(manifest_path, properties)) {
TT_LOG_E(TAG, "Failed to load manifest at %s", manifest_path.c_str());
LOGGER.error("Failed to load manifest at {}", manifest_path);
cleanupInstallDirectory(app_target_path);
return false;
}
AppManifest manifest;
if (!parseManifest(properties, manifest)) {
TT_LOG_W(TAG, "Invalid manifest");
LOGGER.warn("Invalid manifest");
cleanupInstallDirectory(app_target_path);
return false;
}
@@ -163,7 +160,7 @@ bool install(const std::string& path) {
const std::string renamed_target_path = std::format("{}/{}", app_parent_path, manifest.appId);
if (file::isDirectory(renamed_target_path)) {
if (!file::deleteRecursively(renamed_target_path)) {
TT_LOG_W(TAG, "Failed to delete existing installation at %s", renamed_target_path.c_str());
LOGGER.warn("Failed to delete existing installation at {}", renamed_target_path);
cleanupInstallDirectory(app_target_path);
return false;
}
@@ -174,7 +171,7 @@ bool install(const std::string& path) {
target_path_lock.unlock();
if (!rename_success) {
TT_LOG_E(TAG, "Failed to rename \"%s\" to \"%s\"", app_target_path.c_str(), manifest.appId.c_str());
LOGGER.error(R"(Failed to rename "{}" to "{}")", app_target_path, manifest.appId);
cleanupInstallDirectory(app_target_path);
return false;
}
@@ -187,7 +184,7 @@ bool install(const std::string& path) {
}
bool uninstall(const std::string& appId) {
TT_LOG_I(TAG, "Uninstalling app %s", appId.c_str());
LOGGER.info("Uninstalling app {}", appId);
// If the app was running, then stop it
if (isRunning(appId)) {
@@ -196,7 +193,7 @@ bool uninstall(const std::string& appId) {
auto app_path = getAppInstallPath(appId);
if (!file::isDirectory(app_path)) {
TT_LOG_E(TAG, "App %s not found at %s", appId.c_str(), app_path.c_str());
LOGGER.error("App {} not found at {}", appId, app_path);
return false;
}
@@ -205,7 +202,7 @@ bool uninstall(const std::string& appId) {
}
if (!removeAppManifest(appId)) {
TT_LOG_W(TAG, "Failed to remove app %s from registry", appId.c_str());
LOGGER.warn("Failed to remove app {} from registry", appId);
}
return true;
-2
View File
@@ -3,8 +3,6 @@
namespace tt::app {
#define TAG "app"
void AppInstance::setState(State newState) {
mutex.lock();
state = newState;
+15 -19
View File
@@ -1,25 +1,21 @@
#include <Tactility/app/AppManifestParsing.h>
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#include <algorithm>
#include <regex>
namespace tt::app {
constexpr auto* TAG = "App";
static const auto LOGGER = Logger("AppManifest");
static bool validateString(const std::string& value, const std::function<bool(const char)>& isValidChar) {
for (const auto& c : value) {
if (!isValidChar(c)) {
return false;
}
}
return true;
constexpr bool validateString(const std::string& value, const std::function<bool(char)>& isValidChar) {
return std::ranges::all_of(value, isValidChar);
}
static bool getValueFromManifest(const std::map<std::string, std::string>& map, const std::string& key, std::string& output) {
const auto iterator = map.find(key);
if (iterator == map.end()) {
TT_LOG_E(TAG, "Failed to find %s in manifest", key.c_str());
LOGGER.error("Failed to find {} in manifest", key);
return false;
}
output = iterator->second;
@@ -33,19 +29,19 @@ bool isValidId(const std::string& id) {
}
static bool isValidManifestVersion(const std::string& version) {
return version.size() > 0 && validateString(version, [](const char c) {
return !version.empty() && validateString(version, [](const char c) {
return std::isalnum(c) != 0 || c == '.';
});
}
static bool isValidAppVersionName(const std::string& version) {
return version.size() > 0 && validateString(version, [](const char c) {
return !version.empty() && validateString(version, [](const char c) {
return std::isalnum(c) != 0 || c == '.' || c == '-' || c == '_';
});
}
static bool isValidAppVersionCode(const std::string& version) {
return version.size() > 0 && validateString(version, [](const char c) {
return !version.empty() && validateString(version, [](const char c) {
return std::isdigit(c) != 0;
});
}
@@ -57,7 +53,7 @@ static bool isValidName(const std::string& name) {
}
bool parseManifest(const std::map<std::string, std::string>& map, AppManifest& manifest) {
TT_LOG_I(TAG, "Parsing manifest");
LOGGER.info("Parsing manifest");
// [manifest]
@@ -67,7 +63,7 @@ bool parseManifest(const std::map<std::string, std::string>& map, AppManifest& m
}
if (!isValidManifestVersion(manifest_version)) {
TT_LOG_E(TAG, "Invalid version");
LOGGER.error("Invalid version");
return false;
}
@@ -78,7 +74,7 @@ bool parseManifest(const std::map<std::string, std::string>& map, AppManifest& m
}
if (!isValidId(manifest.appId)) {
TT_LOG_E(TAG, "Invalid app id");
LOGGER.error("Invalid app id");
return false;
}
@@ -87,7 +83,7 @@ bool parseManifest(const std::map<std::string, std::string>& map, AppManifest& m
}
if (!isValidName(manifest.appName)) {
TT_LOG_I(TAG, "Invalid app name");
LOGGER.error("Invalid app name");
return false;
}
@@ -96,7 +92,7 @@ bool parseManifest(const std::map<std::string, std::string>& map, AppManifest& m
}
if (!isValidAppVersionName(manifest.appVersionName)) {
TT_LOG_E(TAG, "Invalid app version name");
LOGGER.error("Invalid app version name");
return false;
}
@@ -106,7 +102,7 @@ bool parseManifest(const std::map<std::string, std::string>& map, AppManifest& m
}
if (!isValidAppVersionCode(version_code_string)) {
TT_LOG_E(TAG, "Invalid app version code");
LOGGER.error("Invalid app version code");
return false;
}
+8 -7
View File
@@ -1,27 +1,28 @@
#include "Tactility/app/AppRegistration.h"
#include "Tactility/app/AppManifest.h"
#include <Tactility/app/AppRegistration.h>
#include <Tactility/app/AppManifest.h>
#include <Tactility/Logger.h>
#include <Tactility/Mutex.h>
#include <unordered_map>
#include <Tactility/file/File.h>
#define TAG "app"
namespace tt::app {
static const auto LOGGER = Logger("AppRegistration");
typedef std::unordered_map<std::string, std::shared_ptr<AppManifest>> AppManifestMap;
static AppManifestMap app_manifest_map;
static Mutex hash_mutex;
void addAppManifest(const AppManifest& manifest) {
TT_LOG_I(TAG, "Registering manifest %s", manifest.appId.c_str());
LOGGER.info("Registering manifest {}", manifest.appId);
hash_mutex.lock();
if (app_manifest_map.contains(manifest.appId)) {
TT_LOG_W(TAG, "Overwriting existing manifest for %s", manifest.appId.c_str());
LOGGER.warn("Overwriting existing manifest for {}", manifest.appId);
}
app_manifest_map[manifest.appId] = std::make_shared<AppManifest>(manifest);
@@ -30,7 +31,7 @@ void addAppManifest(const AppManifest& manifest) {
}
bool removeAppManifest(const std::string& id) {
TT_LOG_I(TAG, "Removing manifest for %s", id.c_str());
LOGGER.info("Removing manifest for {}", id);
auto lock = hash_mutex.asScopedLock();
lock.lock();
+9 -10
View File
@@ -4,18 +4,17 @@
#include <Tactility/app/ElfApp.h>
#include <Tactility/file/File.h>
#include <Tactility/file/FileLock.h>
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#include <Tactility/service/loader/Loader.h>
#include <Tactility/StringUtils.h>
#include <esp_elf.h>
#include <string>
#include <utility>
namespace tt::app {
constexpr auto* TAG = "ElfApp";
static auto LOGGER = Logger("ElfApp");
static std::string getErrorCodeString(int error_code) {
switch (error_code) {
@@ -72,7 +71,7 @@ private:
bool startElf() {
const std::string elf_path = std::format("{}/elf/{}.elf", appPath, CONFIG_IDF_TARGET);
TT_LOG_I(TAG, "Starting ELF %s", elf_path.c_str());
LOGGER.info("Starting ELF {}", elf_path);
assert(elfFileData == nullptr);
size_t size = 0;
@@ -86,7 +85,7 @@ private:
if (esp_elf_init(&elf) != ESP_OK) {
lastError = "Failed to initialize";
TT_LOG_E(TAG, "%s", lastError.c_str());
LOGGER.error("{}", lastError);
elfFileData = nullptr;
return false;
}
@@ -95,7 +94,7 @@ private:
if (relocate_result != 0) {
// Note: the result code maps to values from cstdlib's errno.h
lastError = getErrorCodeString(-relocate_result);
TT_LOG_E(TAG, "Application failed to load: %s", lastError.c_str());
LOGGER.error("Application failed to load: {}", lastError);
elfFileData = nullptr;
return false;
}
@@ -105,7 +104,7 @@ private:
if (esp_elf_request(&elf, 0, argc, argv) != ESP_OK) {
lastError = "Executable returned error code";
TT_LOG_E(TAG, "%s", lastError.c_str());
LOGGER.error("{}", lastError);
esp_elf_deinit(&elf);
elfFileData = nullptr;
return false;
@@ -116,7 +115,7 @@ private:
}
void stopElf() {
TT_LOG_I(TAG, "Cleaning up ELF");
LOGGER.info("Cleaning up ELF");
if (shouldCleanupElf) {
esp_elf_deinit(&elf);
@@ -164,7 +163,7 @@ public:
}
void onDestroy(AppContext& appContext) override {
TT_LOG_I(TAG, "Cleaning up app");
LOGGER.info("Cleaning up app");
if (manifest != nullptr) {
if (manifest->onDestroy != nullptr) {
manifest->onDestroy(&appContext, data);
@@ -223,7 +222,7 @@ void setElfAppParameters(
}
std::shared_ptr<App> createElfApp(const std::shared_ptr<AppManifest>& manifest) {
TT_LOG_I(TAG, "createElfApp");
LOGGER.info("createElfApp");
assert(manifest != nullptr);
assert(manifest->appLocation.isExternal());
return std::make_shared<ElfApp>(manifest->appLocation.getPath());
+11 -12
View File
@@ -1,23 +1,22 @@
#include "Tactility/StringUtils.h"
#include "Tactility/app/AppManifest.h"
#include "Tactility/app/alertdialog/AlertDialog.h"
#include "Tactility/hal/gps/GpsDevice.h"
#include "Tactility/hal/uart/Uart.h"
#include "Tactility/lvgl/Style.h"
#include "Tactility/lvgl/Toolbar.h"
#include "Tactility/service/gps/GpsService.h"
#include <Tactility/Logger.h>
#include <Tactility/StringUtils.h>
#include <Tactility/app/AppManifest.h>
#include <Tactility/app/alertdialog/AlertDialog.h>
#include <Tactility/hal/gps/GpsDevice.h>
#include <Tactility/hal/uart/Uart.h>
#include <Tactility/lvgl/Style.h>
#include <Tactility/lvgl/Toolbar.h>
#include <Tactility/service/gps/GpsService.h>
#include <cstring>
#include <lvgl.h>
namespace tt::app::addgps {
constexpr const char* TAG = "AddGps";
static const auto LOGGER = Logger("AddGps");
class AddGpsApp final : public App {
private:
lv_obj_t* uartDropdown = nullptr;
lv_obj_t* modelDropdown = nullptr;
lv_obj_t* baudDropdown = nullptr;
@@ -48,7 +47,7 @@ private:
return;
}
TT_LOG_I(TAG, "Saving: uart=%s, model=%lu, baud=%lu", new_configuration.uartName, (uint32_t)new_configuration.model, new_configuration.baudRate);
LOGGER.info("Saving: uart={}, model={}, baud={}", new_configuration.uartName, (uint32_t)new_configuration.model, new_configuration.baudRate);
auto service = service::gps::findGpsService();
std::vector<tt::hal::gps::GpsConfiguration> configurations;
@@ -3,8 +3,8 @@
#include "Tactility/lvgl/Toolbar.h"
#include "Tactility/service/loader/Loader.h"
#include <Tactility/Logger.h>
#include <Tactility/StringUtils.h>
#include <Tactility/TactilityCore.h>
#include <lvgl.h>
@@ -16,9 +16,9 @@ namespace tt::app::alertdialog {
#define RESULT_BUNDLE_KEY_INDEX "index"
#define PARAMETER_ITEM_CONCATENATION_TOKEN ";;"
#define DEFAULT_TITLE "Select..."
#define DEFAULT_TITLE ""
#define TAG "selection_dialog"
static const auto LOGGER = Logger("AlertDialog");
extern const AppManifest manifest;
@@ -74,7 +74,7 @@ class AlertDialogApp : public App {
void onButtonClicked(lv_event_t* e) {
auto index = reinterpret_cast<std::size_t>(lv_event_get_user_data(e));
TT_LOG_I(TAG, "Selected item at index %d", index);
LOGGER.info("Selected item at index {}", index);
auto bundle = std::make_unique<Bundle>();
bundle->putInt32(RESULT_BUNDLE_KEY_INDEX, (int32_t)index);
+5 -4
View File
@@ -5,6 +5,7 @@
#include <Tactility/lvgl/LvglSync.h>
#include <Tactility/lvgl/Spinner.h>
#include <Tactility/lvgl/Toolbar.h>
#include <Tactility/Logger.h>
#include <Tactility/network/Http.h>
#include <Tactility/Paths.h>
#include <Tactility/service/loader/Loader.h>
@@ -16,7 +17,7 @@
namespace tt::app::apphub {
constexpr auto* TAG = "AppHub";
static const auto LOGGER = Logger("AppHub");
extern const AppManifest manifest;
@@ -55,7 +56,7 @@ class AppHubApp final : public App {
}
void onRefreshSuccess() {
TT_LOG_I(TAG, "Request success");
LOGGER.info("Request success");
auto lock = lvgl::getSyncLock()->asScopedLock();
lock.lock();
@@ -63,7 +64,7 @@ class AppHubApp final : public App {
}
void onRefreshError(const char* error) {
TT_LOG_E(TAG, "Request failed: %s", error);
LOGGER.error("Request failed: {}", error);
auto lock = lvgl::getSyncLock()->asScopedLock();
lock.lock();
@@ -106,7 +107,7 @@ class AppHubApp final : public App {
lv_obj_set_size(list, LV_PCT(100), LV_SIZE_CONTENT);
for (int i = 0; i < entries.size(); i++) {
auto& entry = entries[i];
TT_LOG_I(TAG, "Adding %s", entry.appName.c_str());
LOGGER.info("Adding {}", entry.appName.c_str());
const char* icon = findAppManifestById(entry.appId) != nullptr ? LV_SYMBOL_OK : nullptr;
auto* entry_button = lv_list_add_button(list, icon, entry.appName.c_str());
auto int_as_voidptr = reinterpret_cast<void*>(i);
+6 -5
View File
@@ -1,10 +1,11 @@
#include <Tactility/app/apphub/AppHubEntry.h>
#include <Tactility/file/File.h>
#include <Tactility/json/Reader.h>
#include <Tactility/Logger.h>
namespace tt::app::apphub {
constexpr auto* TAG = "AppHubJson";
static const auto LOGGER = Logger("AppHubJson");
static bool parseEntry(const cJSON* object, AppHubEntry& entry) {
const json::Reader reader(object);
@@ -24,21 +25,21 @@ bool parseJson(const std::string& filePath, std::vector<AppHubEntry>& entries) {
auto data = file::readString(filePath);
if (data == nullptr) {
TT_LOG_E(TAG, "Failed to read %s", filePath.c_str());
LOGGER.error("Failed to read {}", filePath);
return false;
}
auto data_ptr = reinterpret_cast<const char*>(data.get());
auto* json = cJSON_Parse(data_ptr);
if (json == nullptr) {
TT_LOG_E(TAG, "Failed to parse %s", filePath.c_str());
LOGGER.error("Failed to parse {}", filePath);
return false;
}
const cJSON* apps_json = cJSON_GetObjectItemCaseSensitive(json, "apps");
if (!cJSON_IsArray(apps_json)) {
cJSON_Delete(json);
TT_LOG_E(TAG, "apps is not an array");
LOGGER.error("apps is not an array");
return false;
}
@@ -48,7 +49,7 @@ bool parseJson(const std::string& filePath, std::vector<AppHubEntry>& entries) {
auto& entry = entries.at(i);
auto* entry_json = cJSON_GetArrayItem(apps_json, i);
if (!parseEntry(entry_json, entry)) {
TT_LOG_E(TAG, "Failed to read entry");
LOGGER.error("Failed to read entry");
cJSON_Delete(json);
return false;
}
@@ -5,6 +5,7 @@
#include <Tactility/file/File.h>
#include <Tactility/lvgl/LvglSync.h>
#include <Tactility/lvgl/Toolbar.h>
#include <Tactility/Logger.h>
#include <Tactility/network/Http.h>
#include <Tactility/Paths.h>
#include <Tactility/service/loader/Loader.h>
@@ -15,8 +16,9 @@
namespace tt::app::apphubdetails {
static const auto LOGGER = Logger("AppHubDetails");
extern const AppManifest manifest;
constexpr auto* TAG = "AppHubDetails";
static std::shared_ptr<Bundle> toBundle(const apphub::AppHubEntry& entry) {
auto bundle = std::make_shared<Bundle>();
@@ -83,7 +85,7 @@ class AppHubDetailsApp final : public App {
}
void uninstallApp() {
TT_LOG_I(TAG, "Uninstall");
LOGGER.info("Uninstall");
lvgl::getSyncLock()->lock();
lv_obj_remove_flag(spinner, LV_OBJ_FLAG_HIDDEN);
@@ -107,10 +109,10 @@ class AppHubDetailsApp final : public App {
[this, temp_file_path] {
install(temp_file_path);
if (!file::deleteFile(temp_file_path.c_str())) {
TT_LOG_W(TAG, "Failed to remove %s", temp_file_path.c_str());
if (!file::deleteFile(temp_file_path)) {
LOGGER.warn("Failed to remove {}", temp_file_path);
} else {
TT_LOG_I(TAG, "Deleted temporary file %s", temp_file_path.c_str());
LOGGER.info("Deleted temporary file {}", temp_file_path);
}
lvgl::getSyncLock()->lock();
@@ -118,18 +120,18 @@ class AppHubDetailsApp final : public App {
lvgl::getSyncLock()->unlock();
},
[temp_file_path](const char* errorMessage) {
TT_LOG_E(TAG, "Download failed: %s", errorMessage);
LOGGER.error("Download failed: {}", errorMessage);
alertdialog::start("Error", "Failed to install app");
if (file::isFile(temp_file_path) && !file::deleteFile(temp_file_path.c_str())) {
TT_LOG_W(TAG, "Failed to remove %s", temp_file_path.c_str());
LOGGER.warn("Failed to remove {}", temp_file_path);
}
}
);
}
void installApp() {
TT_LOG_I(TAG, "Install");
LOGGER.info("Install");
lvgl::getSyncLock()->lock();
lv_obj_remove_flag(spinner, LV_OBJ_FLAG_HIDDEN);
@@ -139,15 +141,15 @@ class AppHubDetailsApp final : public App {
}
void updateApp() {
TT_LOG_I(TAG, "Update");
LOGGER.info("Update");
lvgl::getSyncLock()->lock();
lv_obj_remove_flag(spinner, LV_OBJ_FLAG_HIDDEN);
lvgl::getSyncLock()->unlock();
TT_LOG_I(TAG, "Removing previous version");
LOGGER.info("Removing previous version");
uninstall(entry.appId);
TT_LOG_I(TAG, "Installing new version");
LOGGER.info("Installing new version");
doInstall();
}
@@ -173,13 +175,13 @@ public:
void onCreate(AppContext& appContext) override {
auto parameters = appContext.getParameters();
if (parameters == nullptr) {
TT_LOG_E(TAG, "No parameters");
LOGGER.error("No parameters");
stop();
return;
}
if (!fromBundle(*parameters.get(), entry)) {
TT_LOG_E(TAG, "Invalid parameters");
LOGGER.error("Invalid parameters");
stop();
}
}
+15 -14
View File
@@ -8,6 +8,7 @@
#include <Tactility/hal/display/DisplayDevice.h>
#include <Tactility/hal/usb/Usb.h>
#include <Tactility/kernel/SystemEvents.h>
#include <Tactility/Logger.h>
#include <Tactility/lvgl/Style.h>
#include <Tactility/service/loader/Loader.h>
#include <Tactility/settings/BootSettings.h>
@@ -25,7 +26,8 @@
namespace tt::app::boot {
constexpr auto* TAG = "Boot";
static const auto LOGGER = Logger("Boot");
extern const AppManifest manifest;
static std::shared_ptr<hal::display::DisplayDevice> getHalDisplay() {
@@ -51,17 +53,17 @@ class BootApp : public App {
if (settings::display::load(settings)) {
if (hal_display->getGammaCurveCount() > 0) {
hal_display->setGammaCurve(settings.gammaCurve);
TT_LOG_I(TAG, "Gamma curve %du", settings.gammaCurve);
LOGGER.info("Gamma curve {}", settings.gammaCurve);
}
} else {
settings = settings::display::getDefault();
}
if (hal_display->supportsBacklightDuty()) {
TT_LOG_I(TAG, "Backlight %du", settings.backlightDuty);
LOGGER.info("Backlight {}", settings.backlightDuty);
hal_display->setBacklightDuty(settings.backlightDuty);
} else {
TT_LOG_I(TAG, "no backlight");
LOGGER.info("No backlight");
}
}
@@ -70,17 +72,17 @@ class BootApp : public App {
return false;
}
TT_LOG_I(TAG, "Rebooting into mass storage device mode");
LOGGER.info("Rebooting into mass storage device mode");
auto mode = hal::usb::getUsbBootMode(); // Get mode before reset
hal::usb::resetUsbBootMode();
if (mode == hal::usb::BootMode::Flash) {
if (!hal::usb::startMassStorageWithFlash()) {
TT_LOG_E(TAG, "Unable to start flash mass storage");
LOGGER.error("Unable to start flash mass storage");
return false;
}
} else if (mode == hal::usb::BootMode::Sdmmc) {
if (!hal::usb::startMassStorageWithSdmmc()) {
TT_LOG_E(TAG, "Unable to start SD mass storage");
LOGGER.error("Unable to start SD mass storage");
return false;
}
}
@@ -98,23 +100,22 @@ class BootApp : public App {
}
static int32_t bootThreadCallback() {
TT_LOG_I(TAG, "Starting boot thread");
LOGGER.info("Starting boot thread");
const auto start_time = kernel::getTicks();
// Give the UI some time to redraw
// If we don't do this, various init calls will read files and block SPI IO for the display
// This would result in a blank/black screen being shown during this phase of the boot process
// This works with 5 ms on a T-Lora Pager, so we give it 10 ms to be safe
TT_LOG_I(TAG, "Delay");
kernel::delayMillis(10);
// TODO: Support for multiple displays
TT_LOG_I(TAG, "Setup display");
LOGGER.info("Setup display");
setupDisplay(); // Set backlight
prepareFileSystems();
if (!setupUsbBootMode()) {
TT_LOG_I(TAG, "initFromBootApp");
LOGGER.info("initFromBootApp");
registerApps();
waitForMinimalSplashDuration(start_time);
stop(manifest.appId);
@@ -123,7 +124,7 @@ class BootApp : public App {
// This event will likely block as other systems are initialized
// e.g. Wi-Fi reads AP configs from SD card
TT_LOG_I(TAG, "Publish event");
LOGGER.info("Publish event");
kernel::publishSystemEvent(kernel::SystemEvent::BootSplash);
return 0;
@@ -140,7 +141,7 @@ class BootApp : public App {
settings::BootSettings boot_properties;
std::string launcher_app_id;
if (settings::loadBootSettings(boot_properties) && boot_properties.launcherAppId.empty()) {
TT_LOG_E(TAG, "Failed to load launcher configuration, or launcher not configured");
LOGGER.error("Failed to load launcher configuration, or launcher not configured");
launcher_app_id = boot_properties.launcherAppId;
} else {
launcher_app_id = "Launcher";
@@ -187,7 +188,7 @@ public:
logo = hal::usb::isUsbBootMode() ? "logo_usb.png" : "logo.png";
}
const auto logo_path = lvgl::PATH_PREFIX + paths->getAssetsPath(logo);
TT_LOG_I(TAG, "%s", logo_path.c_str());
LOGGER.info("{}", logo_path);
lv_image_set_src(image, logo_path.c_str());
}
};
+3 -2
View File
@@ -7,6 +7,7 @@
#include <Tactility/app/AppManifest.h>
#include <Tactility/lvgl/Toolbar.h>
#include <Tactility/Assets.h>
#include <Tactility/Logger.h>
#include <Tactility/service/espnow/EspNow.h>
#include "Tactility/lvgl/LvglSync.h"
@@ -18,7 +19,7 @@
namespace tt::app::chat {
constexpr const char* TAG = "ChatApp";
static const auto LOGGER = Logger("ChatApp");
constexpr uint8_t BROADCAST_ADDRESS[ESP_NOW_ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
class ChatApp : public App {
@@ -46,7 +47,7 @@ class ChatApp : public App {
self->addMessage(msg);
if (!service::espnow::send(BROADCAST_ADDRESS, reinterpret_cast<const uint8_t*>(msg), msg_len)) {
TT_LOG_E(TAG, "Failed to send message");
LOGGER.error("Failed to send message");
}
lv_textarea_set_text(self->input_field, "");
@@ -1,20 +1,20 @@
#ifdef ESP_PLATFORM
#include "Tactility/hal/Device.h"
#include <Tactility/app/crashdiagnostics/QrHelpers.h>
#include <Tactility/app/crashdiagnostics/QrUrl.h>
#include <Tactility/app/launcher/Launcher.h>
#include <Tactility/hal/Device.h>
#include <Tactility/Logger.h>
#include <Tactility/lvgl/Statusbar.h>
#include <Tactility/service/loader/Loader.h>
#include <lvgl.h>
#include <qrcode.h>
#define TAG "CrashDiagnostics"
namespace tt::app::crashdiagnostics {
static const auto LOGGER = Logger("CrashDiagnostics");
extern const AppManifest manifest;
void onContinuePressed(TT_UNUSED lv_event_t* event) {
@@ -44,38 +44,38 @@ public:
lv_obj_align(bottom_label, LV_ALIGN_BOTTOM_MID, 0, -2);
std::string url = getUrlFromCrashData();
TT_LOG_I(TAG, "%s", url.c_str());
LOGGER.info("{}", url);
size_t url_length = url.length();
int qr_version;
if (!getQrVersionForBinaryDataLength(url_length, qr_version)) {
TT_LOG_E(TAG, "QR is too large");
LOGGER.error("QR is too large");
stop(manifest.appId);
return;
}
TT_LOG_I(TAG, "QR version %d (length: %d)", qr_version, url_length);
LOGGER.info("QR version {} (length: {})", qr_version, url_length);
auto qrcodeData = std::make_shared<uint8_t[]>(qrcode_getBufferSize(qr_version));
if (qrcodeData == nullptr) {
TT_LOG_E(TAG, "Failed to allocate QR buffer");
stop();
LOGGER.error("Failed to allocate QR buffer");
stop(manifest.appId);
return;
}
QRCode qrcode;
TT_LOG_I(TAG, "QR init text");
LOGGER.info("QR init text");
if (qrcode_initText(&qrcode, qrcodeData.get(), qr_version, ECC_LOW, url.c_str()) != 0) {
TT_LOG_E(TAG, "QR init text failed");
LOGGER.error("QR init text failed");
stop(manifest.appId);
return;
}
TT_LOG_I(TAG, "QR size: %d", qrcode.size);
LOGGER.info("QR size: {}", qrcode.size);
// Calculate QR dot size
int32_t top_label_height = lv_obj_get_height(top_label) + 2;
int32_t bottom_label_height = lv_obj_get_height(bottom_label) + 2;
TT_LOG_I(TAG, "Create canvas");
LOGGER.info("Create canvas");
int32_t available_height = parent_height - top_label_height - bottom_label_height;
int32_t available_width = lv_display_get_horizontal_resolution(display);
int32_t smallest_size = std::min(available_height, available_width);
@@ -85,7 +85,7 @@ public:
} else if (qrcode.size <= smallest_size) {
pixel_size = 1;
} else {
TT_LOG_E(TAG, "QR code won't fit screen");
LOGGER.error("QR code won't fit screen");
stop(manifest.appId);
return;
}
@@ -97,10 +97,10 @@ public:
lv_obj_set_content_height(canvas, qrcode.size * pixel_size);
lv_obj_set_content_width(canvas, qrcode.size * pixel_size);
TT_LOG_I(TAG, "Create draw buffer");
LOGGER.info("Create draw buffer");
auto* draw_buf = lv_draw_buf_create(pixel_size * qrcode.size, pixel_size * qrcode.size, LV_COLOR_FORMAT_RGB565, LV_STRIDE_AUTO);
if (draw_buf == nullptr) {
TT_LOG_E(TAG, "Draw buffer alloc");
LOGGER.error("Failed to allocate draw buffer");
stop(manifest.appId);
return;
}
@@ -7,6 +7,7 @@
#include <Tactility/lvgl/LvglSync.h>
#include <Tactility/lvgl/Style.h>
#include <Tactility/lvgl/Toolbar.h>
#include <Tactility/Logger.h>
#include <Tactility/service/development/DevelopmentService.h>
#include <Tactility/service/development/DevelopmentSettings.h>
#include <Tactility/service/loader/Loader.h>
@@ -17,7 +18,7 @@
namespace tt::app::development {
constexpr const char* TAG = "Development";
static const auto LOGGER = Logger("Development");
extern const AppManifest manifest;
class DevelopmentApp final : public App {
@@ -84,7 +85,7 @@ public:
void onCreate(AppContext& appContext) override {
service = service::development::findService();
if (service == nullptr) {
TT_LOG_E(TAG, "Service not found");
LOGGER.error("Service not found");
stop(manifest.appId);
}
}
+3 -2
View File
@@ -3,13 +3,14 @@
#include <Tactility/settings/DisplaySettings.h>
#include <Tactility/Assets.h>
#include <Tactility/hal/display/DisplayDevice.h>
#include <Tactility/Logger.h>
#include <Tactility/lvgl/Toolbar.h>
#include <lvgl.h>
namespace tt::app::display {
constexpr auto* TAG = "Display";
static const auto LOGGER = Logger("Display");
static std::shared_ptr<hal::display::DisplayDevice> getHalDisplay() {
return hal::findFirstDevice<hal::display::DisplayDevice>(hal::Device::Type::Display);
@@ -54,7 +55,7 @@ class DisplayApp final : public App {
auto* app = static_cast<DisplayApp*>(lv_event_get_user_data(event));
auto* dropdown = static_cast<lv_obj_t*>(lv_event_get_target(event));
uint32_t selected_index = lv_dropdown_get_selected(dropdown);
TT_LOG_I(TAG, "Selected %ld", selected_index);
LOGGER.info("Selected {}", selected_index);
auto selected_orientation = static_cast<settings::display::Orientation>(selected_index);
if (selected_orientation != app->displaySettings.orientation) {
app->displaySettings.orientation = selected_orientation;
+12 -10
View File
@@ -3,18 +3,19 @@
#include <Tactility/file/File.h>
#include <Tactility/file/FileLock.h>
#include <Tactility/hal/sdcard/SdCardDevice.h>
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#include <Tactility/LogMessages.h>
#include <Tactility/MountPoints.h>
#include <Tactility/kernel/Platform.h>
#include <cstring>
#include <dirent.h>
#include <unistd.h>
#include <vector>
#include <dirent.h>
namespace tt::app::files {
constexpr auto* TAG = "Files";
static const auto LOGGER = Logger("Files");
State::State() {
if (kernel::getPlatform() == kernel::PlatformSimulator) {
@@ -22,7 +23,7 @@ State::State() {
if (getcwd(cwd, sizeof(cwd)) != nullptr) {
setEntriesForPath(cwd);
} else {
TT_LOG_E(TAG, "Failed to get current work directory files");
LOGGER.error("Failed to get current work directory files");
setEntriesForPath("/");
}
} else {
@@ -37,11 +38,11 @@ std::string State::getSelectedChildPath() const {
bool State::setEntriesForPath(const std::string& path) {
auto lock = mutex.asScopedLock();
if (!lock.lock(100)) {
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "setEntriesForPath");
LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "setEntriesForPath");
return false;
}
TT_LOG_I(TAG, "Changing path: %s -> %s", current_path.c_str(), path.c_str());
LOGGER.info("Changing path: {} -> {}", current_path, path);
/**
* On PC, the root entry point ("/") is a folder.
@@ -49,7 +50,7 @@ bool State::setEntriesForPath(const std::string& path) {
*/
bool get_mount_points = (kernel::getPlatform() == kernel::PlatformEsp) && (path == "/");
if (get_mount_points) {
TT_LOG_I(TAG, "Setting custom root");
LOGGER.info("Setting custom root");
dir_entries = file::getMountPoints();
current_path = path;
selected_child_entry = "";
@@ -59,13 +60,13 @@ bool State::setEntriesForPath(const std::string& path) {
dir_entries.clear();
int count = file::scandir(path, dir_entries, &file::direntFilterDotEntries, file::direntSortAlphaAndType);
if (count >= 0) {
TT_LOG_I(TAG, "%s has %u entries", path.c_str(), count);
LOGGER.info("{} has {} entries", path, count);
current_path = path;
selected_child_entry = "";
action = ActionNone;
return true;
} else {
TT_LOG_E(TAG, "Failed to fetch entries for %s", path.c_str());
LOGGER.error("Failed to fetch entries for {}", path);
return false;
}
}
@@ -73,7 +74,7 @@ bool State::setEntriesForPath(const std::string& path) {
bool State::setEntriesForChildPath(const std::string& childPath) {
auto path = file::getChildPath(current_path, childPath);
TT_LOG_I(TAG, "Navigating from %s to %s", current_path.c_str(), path.c_str());
LOGGER.info("Navigating from {} to {}", current_path, path);
return setEntriesForPath(path);
}
@@ -90,4 +91,5 @@ bool State::getDirent(uint32_t index, dirent& dirent) {
return false;
}
}
}
+30 -30
View File
@@ -2,21 +2,21 @@
#include <Tactility/app/files/SupportedFiles.h>
#include <Tactility/file/File.h>
#include <Tactility/file/FileLock.h>
#include <Tactility/app/alertdialog/AlertDialog.h>
#include <Tactility/app/imageviewer/ImageViewer.h>
#include <Tactility/app/inputdialog/InputDialog.h>
#include <Tactility/app/notes/Notes.h>
#include <Tactility/app/ElfApp.h>
#include <Tactility/kernel/Platform.h>
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#include <Tactility/LogMessages.h>
#include <Tactility/lvgl/Toolbar.h>
#include <Tactility/lvgl/LvglSync.h>
#include <Tactility/StringUtils.h>
#include <Tactility/Tactility.h>
#include <cstring>
#include <cstdio>
#include <cstring>
#include <unistd.h>
#ifdef ESP_PLATFORM
@@ -25,7 +25,7 @@
namespace tt::app::files {
constexpr auto* TAG = "Files";
static const auto LOGGER = Logger("Files");
// region Callbacks
@@ -84,11 +84,11 @@ void View::viewFile(const std::string& path, const std::string& filename) {
if (kernel::getPlatform() == kernel::PlatformSimulator) {
char cwd[PATH_MAX];
if (getcwd(cwd, sizeof(cwd)) == nullptr) {
TT_LOG_E(TAG, "Failed to get current working directory");
LOGGER.error("Failed to get current working directory");
return;
}
if (!file_path.starts_with(cwd)) {
TT_LOG_E(TAG, "Can only work with files in working directory %s", cwd);
LOGGER.error("Can only work with files in working directory {}", cwd);
return;
}
processed_filepath = file_path.substr(strlen(cwd));
@@ -96,7 +96,7 @@ void View::viewFile(const std::string& path, const std::string& filename) {
processed_filepath = file_path;
}
TT_LOG_I(TAG, "Clicked %s", file_path.c_str());
LOGGER.info("Clicked {}", file_path);
if (isSupportedAppFile(filename)) {
#ifdef ESP_PLATFORM
@@ -116,7 +116,7 @@ void View::viewFile(const std::string& path, const std::string& filename) {
notes::start(processed_filepath.substr(1));
}
} else {
TT_LOG_W(TAG, "opening files of this type is not supported");
LOGGER.warn("Opening files of this type is not supported");
}
onNavigate();
@@ -125,7 +125,7 @@ void View::viewFile(const std::string& path, const std::string& filename) {
void View::onDirEntryPressed(uint32_t index) {
dirent dir_entry;
if (state->getDirent(index, dir_entry)) {
TT_LOG_I(TAG, "Pressed %s %d", dir_entry.d_name, dir_entry.d_type);
LOGGER.info("Pressed {} {}", dir_entry.d_name, dir_entry.d_type);
state->setSelectedChildEntry(dir_entry.d_name);
using namespace tt::file;
switch (dir_entry.d_type) {
@@ -136,7 +136,7 @@ void View::onDirEntryPressed(uint32_t index) {
update();
break;
case TT_DT_LNK:
TT_LOG_W(TAG, "opening links is not supported");
LOGGER.warn("opening links is not supported");
break;
case TT_DT_REG:
viewFile(state->getCurrentPath(), dir_entry.d_name);
@@ -155,7 +155,7 @@ void View::onDirEntryPressed(uint32_t index) {
void View::onDirEntryLongPressed(int32_t index) {
dirent dir_entry;
if (state->getDirent(index, dir_entry)) {
TT_LOG_I(TAG, "Pressed %s %d", dir_entry.d_name, dir_entry.d_type);
LOGGER.info("Pressed {} {}", dir_entry.d_name, dir_entry.d_type);
state->setSelectedChildEntry(dir_entry.d_name);
using namespace file;
switch (dir_entry.d_type) {
@@ -164,7 +164,7 @@ void View::onDirEntryLongPressed(int32_t index) {
showActionsForDirectory();
break;
case TT_DT_LNK:
TT_LOG_W(TAG, "opening links is not supported");
LOGGER.warn("Opening links is not supported");
break;
case TT_DT_REG:
showActionsForFile();
@@ -228,7 +228,7 @@ void View::createDirEntryWidget(lv_obj_t* list, dirent& dir_entry) {
void View::onNavigateUpPressed() {
if (state->getCurrentPath() != "/") {
TT_LOG_I(TAG, "Navigating upwards");
LOGGER.info("Navigating upwards");
std::string new_absolute_path;
if (string::getPathParent(state->getCurrentPath(), new_absolute_path)) {
state->setEntriesForPath(new_absolute_path);
@@ -240,14 +240,14 @@ void View::onNavigateUpPressed() {
void View::onRenamePressed() {
std::string entry_name = state->getSelectedChildEntry();
TT_LOG_I(TAG, "Pending rename %s", entry_name.c_str());
LOGGER.info("Pending rename {}", entry_name);
state->setPendingAction(State::ActionRename);
inputdialog::start("Rename", "", entry_name);
}
void View::onDeletePressed() {
std::string file_path = state->getSelectedChildPath();
TT_LOG_I(TAG, "Pending delete %s", file_path.c_str());
LOGGER.info("Pending delete {}", file_path);
state->setPendingAction(State::ActionDelete);
std::string message = "Do you want to delete this?\n" + file_path;
const std::vector<std::string> choices = { "Yes", "No" };
@@ -255,13 +255,13 @@ void View::onDeletePressed() {
}
void View::onNewFilePressed() {
TT_LOG_I(TAG, "Creating new file");
LOGGER.info("Creating new file");
state->setPendingAction(State::ActionCreateFile);
inputdialog::start("New File", "Enter filename:", "");
}
void View::onNewFolderPressed() {
TT_LOG_I(TAG, "Creating new folder");
LOGGER.info("Creating new folder");
state->setPendingAction(State::ActionCreateFolder);
inputdialog::start("New Folder", "Enter folder name:", "");
}
@@ -295,7 +295,7 @@ void View::update() {
state->withEntries([this](const std::vector<dirent>& entries) {
for (auto entry : entries) {
TT_LOG_D(TAG, "Entry: %s %d", entry.d_name, entry.d_type);
LOGGER.debug("Entry: {} {}", entry.d_name, entry.d_type);
createDirEntryWidget(dir_entry_list, entry);
}
});
@@ -306,7 +306,7 @@ void View::update() {
lv_obj_remove_flag(navigate_up_button, LV_OBJ_FLAG_HIDDEN);
}
} else {
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "lvgl");
LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "lvgl");
}
}
@@ -369,20 +369,20 @@ void View::onResult(LaunchId launchId, Result result, std::unique_ptr<Bundle> bu
}
std::string filepath = state->getSelectedChildPath();
TT_LOG_I(TAG, "Result for %s", filepath.c_str());
LOGGER.info("Result for {}", filepath);
switch (state->getPendingAction()) {
case State::ActionDelete: {
if (alertdialog::getResultIndex(*bundle) == 0) {
if (file::isDirectory(filepath)) {
if (!file::deleteRecursively(filepath)) {
TT_LOG_W(TAG, "Failed to delete %s", filepath.c_str());
LOGGER.warn("Failed to delete {}", filepath);
}
} else if (file::isFile(filepath)) {
auto lock = file::getLock(filepath);
lock->lock();
if (remove(filepath.c_str()) <= 0) {
TT_LOG_W(TAG, "Failed to delete %s", filepath.c_str());
LOGGER.warn("Failed to delete {}", filepath);
}
lock->unlock();
}
@@ -399,9 +399,9 @@ void View::onResult(LaunchId launchId, Result result, std::unique_ptr<Bundle> bu
lock->lock();
std::string rename_to = file::getChildPath(state->getCurrentPath(), new_name);
if (rename(filepath.c_str(), rename_to.c_str())) {
TT_LOG_I(TAG, "Renamed \"%s\" to \"%s\"", filepath.c_str(), rename_to.c_str());
LOGGER.info("Renamed \"{}\" to \"{}\"", filepath, rename_to);
} else {
TT_LOG_E(TAG, "Failed to rename \"%s\" to \"%s\"", filepath.c_str(), rename_to.c_str());
LOGGER.error("Failed to rename \"{}\" to \"{}\"", filepath, rename_to);
}
lock->unlock();
@@ -420,7 +420,7 @@ void View::onResult(LaunchId launchId, Result result, std::unique_ptr<Bundle> bu
struct stat st;
if (stat(new_file_path.c_str(), &st) == 0) {
TT_LOG_W(TAG, "File already exists: \"%s\"", new_file_path.c_str());
LOGGER.warn("File already exists: \"{}\"", new_file_path);
lock->unlock();
break;
}
@@ -428,9 +428,9 @@ void View::onResult(LaunchId launchId, Result result, std::unique_ptr<Bundle> bu
FILE* new_file = fopen(new_file_path.c_str(), "w");
if (new_file) {
fclose(new_file);
TT_LOG_I(TAG, "Created file \"%s\"", new_file_path.c_str());
LOGGER.info("Created file \"{}\"", new_file_path);
} else {
TT_LOG_E(TAG, "Failed to create file \"%s\"", new_file_path.c_str());
LOGGER.error("Failed to create file \"{}\"", new_file_path);
}
lock->unlock();
@@ -449,15 +449,15 @@ void View::onResult(LaunchId launchId, Result result, std::unique_ptr<Bundle> bu
struct stat st;
if (stat(new_folder_path.c_str(), &st) == 0) {
TT_LOG_W(TAG, "Folder already exists: \"%s\"", new_folder_path.c_str());
LOGGER.warn("Folder already exists: \"{}\"", new_folder_path);
lock->unlock();
break;
}
if (mkdir(new_folder_path.c_str(), 0755) == 0) {
TT_LOG_I(TAG, "Created folder \"%s\"", new_folder_path.c_str());
LOGGER.info("Created folder \"{}\"", new_folder_path);
} else {
TT_LOG_E(TAG, "Failed to create folder \"%s\"", new_folder_path.c_str());
LOGGER.error("Failed to create folder \"{}\"", new_folder_path);
}
lock->unlock();
+8 -8
View File
@@ -2,7 +2,7 @@
#include <Tactility/file/File.h>
#include "Tactility/hal/sdcard/SdCardDevice.h"
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#include <Tactility/MountPoints.h>
#include <Tactility/kernel/Platform.h>
@@ -13,7 +13,7 @@
namespace tt::app::fileselection {
constexpr auto* TAG = "FileSelection";
static const auto LOGGER = Logger("FileSelection");
State::State() {
if (kernel::getPlatform() == kernel::PlatformSimulator) {
@@ -21,7 +21,7 @@ State::State() {
if (getcwd(cwd, sizeof(cwd)) != nullptr) {
setEntriesForPath(cwd);
} else {
TT_LOG_E(TAG, "Failed to get current work directory files");
LOGGER.error("Failed to get current work directory files");
setEntriesForPath("/");
}
} else {
@@ -34,7 +34,7 @@ std::string State::getSelectedChildPath() const {
}
bool State::setEntriesForPath(const std::string& path) {
TT_LOG_I(TAG, "Changing path: %s -> %s", current_path.c_str(), path.c_str());
LOGGER.info("Changing path: {} -> {}", current_path, path);
/**
* ESP32 does not have a root directory, so we have to create it manually.
@@ -42,7 +42,7 @@ bool State::setEntriesForPath(const std::string& path) {
*/
bool show_custom_root = (kernel::getPlatform() == kernel::PlatformEsp) && (path == "/");
if (show_custom_root) {
TT_LOG_I(TAG, "Setting custom root");
LOGGER.info("Setting custom root");
dir_entries = file::getMountPoints();
current_path = path;
selected_child_entry = "";
@@ -51,12 +51,12 @@ bool State::setEntriesForPath(const std::string& path) {
dir_entries.clear();
int count = file::scandir(path, dir_entries, &file::direntFilterDotEntries, file::direntSortAlphaAndType);
if (count >= 0) {
TT_LOG_I(TAG, "%s has %u entries", path.c_str(), count);
LOGGER.info("{} has {} entries", path, count);
current_path = path;
selected_child_entry = "";
return true;
} else {
TT_LOG_E(TAG, "Failed to fetch entries for %s", path.c_str());
LOGGER.error("Failed to fetch entries for {}", path);
return false;
}
}
@@ -64,7 +64,7 @@ bool State::setEntriesForPath(const std::string& path) {
bool State::setEntriesForChildPath(const std::string& childPath) {
auto path = file::getChildPath(current_path, childPath);
TT_LOG_I(TAG, "Navigating from %s to %s", current_path.c_str(), path.c_str());
LOGGER.info("Navigating from {} to {}", current_path, path);
return setEntriesForPath(path);
}
+16 -15
View File
@@ -1,14 +1,15 @@
#include <Tactility/app/fileselection/View.h>
#include <Tactility/app/alertdialog/AlertDialog.h>
#include <Tactility/file/File.h>
#include <Tactility/Logger.h>
#include <Tactility/LogMessages.h>
#include <Tactility/lvgl/Toolbar.h>
#include <Tactility/lvgl/LvglSync.h>
#include <Tactility/Tactility.h>
#include <Tactility/file/File.h>
#include <Tactility/StringUtils.h>
#include <Tactility/kernel/Platform.h>
#include <Tactility/StringUtils.h>
#include <Tactility/Tactility.h>
#include <cstring>
#include <unistd.h>
@@ -18,7 +19,7 @@
namespace tt::app::fileselection {
constexpr auto* TAG = "FileSelection";
const static Logger LOGGER = Logger("FileSelection");
// region Callbacks
@@ -45,11 +46,11 @@ void View::onTapFile(const std::string& path, const std::string& filename) {
if (kernel::getPlatform() == kernel::PlatformSimulator) {
char cwd[PATH_MAX];
if (getcwd(cwd, sizeof(cwd)) == nullptr) {
TT_LOG_E(TAG, "Failed to get current working directory");
LOGGER.error("Failed to get current working directory");
return;
}
if (!file_path.starts_with(cwd)) {
TT_LOG_E(TAG, "Can only work with files in working directory %s", cwd);
LOGGER.error("Can only work with files in working directory {}", cwd);
return;
}
processed_filepath = file_path.substr(strlen(cwd));
@@ -57,7 +58,7 @@ void View::onTapFile(const std::string& path, const std::string& filename) {
processed_filepath = file_path;
}
TT_LOG_I(TAG, "Clicked %s", processed_filepath.c_str());
LOGGER.info("Clicked {}", processed_filepath);
lv_textarea_set_text(path_textarea, processed_filepath.c_str());
}
@@ -65,7 +66,7 @@ void View::onTapFile(const std::string& path, const std::string& filename) {
void View::onDirEntryPressed(uint32_t index) {
dirent dir_entry;
if (state->getDirent(index, dir_entry)) {
TT_LOG_I(TAG, "Pressed %s %d", dir_entry.d_name, dir_entry.d_type);
LOGGER.info("Pressed {} {}", dir_entry.d_name, dir_entry.d_type);
state->setSelectedChildEntry(dir_entry.d_name);
using namespace tt::file;
switch (dir_entry.d_type) {
@@ -76,7 +77,7 @@ void View::onDirEntryPressed(uint32_t index) {
update();
break;
case TT_DT_LNK:
TT_LOG_W(TAG, "opening links is not supported");
LOGGER.warn("Opening links is not supported");
break;
case TT_DT_REG:
onTapFile(state->getCurrentPath(), dir_entry.d_name);
@@ -94,7 +95,7 @@ void View::onSelectButtonPressed(lv_event_t* event) {
auto* view = static_cast<View*>(lv_event_get_user_data(event));
const char* path = lv_textarea_get_text(view->path_textarea);
if (path == nullptr || strlen(path) == 0) {
TT_LOG_W(TAG, "Select pressed, but not path found in textarea");
LOGGER.warn("Select pressed, but not path found in textarea");
return;
}
@@ -138,7 +139,7 @@ void View::createDirEntryWidget(lv_obj_t* list, dirent& dir_entry) {
void View::onNavigateUpPressed() {
if (state->getCurrentPath() != "/") {
TT_LOG_I(TAG, "Navigating upwards");
LOGGER.info("Navigating upwards");
std::string new_absolute_path;
if (string::getPathParent(state->getCurrentPath(), new_absolute_path)) {
state->setEntriesForPath(new_absolute_path);
@@ -159,7 +160,7 @@ void View::update() {
state->withEntries([this](const std::vector<dirent>& entries) {
for (auto entry : entries) {
TT_LOG_D(TAG, "Entry: %s %d", entry.d_name, entry.d_type);
LOGGER.debug("Entry: {} {}", entry.d_name, entry.d_type);
createDirEntryWidget(dir_entry_list, entry);
}
});
@@ -170,7 +171,7 @@ void View::update() {
lv_obj_remove_flag(navigate_up_button, LV_OBJ_FLAG_HIDDEN);
}
} else {
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "lvgl");
LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "lvgl");
}
}
@@ -5,6 +5,7 @@
#include <Tactility/app/alertdialog/AlertDialog.h>
#include <Tactility/lvgl/LvglSync.h>
#include <Tactility/lvgl/Toolbar.h>
#include <Tactility/Logger.h>
#include <Tactility/service/gps/GpsService.h>
#include <Tactility/service/gps/GpsState.h>
#include <Tactility/service/loader/Loader.h>
@@ -23,7 +24,7 @@ extern const AppManifest manifest;
class GpsSettingsApp final : public App {
static constexpr auto* TAG = "GpsSettings";
const Logger logger = Logger("GpsSettings");
std::unique_ptr<Timer> timer;
std::shared_ptr<GpsSettingsApp*> appReference = std::make_shared<GpsSettingsApp*>(this);
@@ -92,8 +93,8 @@ class GpsSettingsApp final : public App {
std::vector<tt::hal::gps::GpsConfiguration> configurations;
auto gps_service = service::gps::findGpsService();
if (gps_service && gps_service->getGpsConfigurations(configurations)) {
TT_LOG_I(TAG, "Found service and configs %d %d", index, configurations.size());
if (index <= configurations.size()) {
Logger("GpsSettings").info("Found service and configs {} {}", index, configurations.size());
if (index < configurations.size()) {
if (gps_service->removeGpsConfiguration(configurations[index])) {
app->updateViews();
} else {
@@ -154,7 +155,7 @@ class GpsSettingsApp final : public App {
// Update toolbar
switch (state) {
case service::gps::State::OnPending:
TT_LOG_D(TAG, "OnPending");
logger.debug("OnPending");
lv_obj_remove_flag(spinnerWidget, LV_OBJ_FLAG_HIDDEN);
lv_obj_add_state(switchWidget, LV_STATE_CHECKED);
lv_obj_add_state(switchWidget, LV_STATE_DISABLED);
@@ -163,7 +164,7 @@ class GpsSettingsApp final : public App {
lv_obj_add_flag(addGpsWrapper, LV_OBJ_FLAG_HIDDEN);
break;
case service::gps::State::On:
TT_LOG_D(TAG, "On");
logger.debug("On");
lv_obj_add_flag(spinnerWidget, LV_OBJ_FLAG_HIDDEN);
lv_obj_add_state(switchWidget, LV_STATE_CHECKED);
lv_obj_remove_state(switchWidget, LV_STATE_DISABLED);
@@ -172,7 +173,7 @@ class GpsSettingsApp final : public App {
lv_obj_add_flag(addGpsWrapper, LV_OBJ_FLAG_HIDDEN);
break;
case service::gps::State::OffPending:
TT_LOG_D(TAG, "OffPending");
logger.debug("OffPending");
lv_obj_remove_flag(spinnerWidget, LV_OBJ_FLAG_HIDDEN);
lv_obj_remove_state(switchWidget, LV_STATE_CHECKED);
lv_obj_add_state(switchWidget, LV_STATE_DISABLED);
@@ -181,7 +182,7 @@ class GpsSettingsApp final : public App {
lv_obj_remove_flag(addGpsWrapper, LV_OBJ_FLAG_HIDDEN);
break;
case service::gps::State::Off:
TT_LOG_D(TAG, "Off");
logger.debug("Off");
lv_obj_add_flag(spinnerWidget, LV_OBJ_FLAG_HIDDEN);
lv_obj_remove_state(switchWidget, LV_STATE_CHECKED);
lv_obj_remove_state(switchWidget, LV_STATE_DISABLED);
@@ -254,11 +255,11 @@ class GpsSettingsApp final : public App {
if (wants_on != is_on) {
// start/stop are potentially blocking calls, so we use a dispatcher to not block the UI
if (wants_on) {
getMainDispatcher().dispatch([this]() {
getMainDispatcher().dispatch([this] {
service->startReceiving();
});
} else {
getMainDispatcher().dispatch([this]() {
getMainDispatcher().dispatch([this] {
service->stopReceiving();
});
}
+24 -21
View File
@@ -1,17 +1,18 @@
#include <Tactility/app/i2cscanner/I2cScannerPrivate.h>
#include <Tactility/app/i2cscanner/I2cHelpers.h>
#include <Tactility/Preferences.h>
#include <Tactility/Assets.h>
#include <Tactility/app/AppContext.h>
#include <Tactility/hal/i2c/I2cDevice.h>
#include <Tactility/Logger.h>
#include <Tactility/LogMessages.h>
#include <Tactility/lvgl/LvglSync.h>
#include <Tactility/lvgl/Toolbar.h>
#include <Tactility/service/loader/Loader.h>
#include <Tactility/Timer.h>
#include <Tactility/Assets.h>
#include <Tactility/Preferences.h>
#include <Tactility/RecursiveMutex.h>
#include <Tactility/service/loader/Loader.h>
#include <Tactility/Tactility.h>
#include <Tactility/Timer.h>
#include <format>
@@ -21,6 +22,8 @@ extern const AppManifest manifest;
class I2cScannerApp final : public App {
const Logger logger = Logger("I2cScanner");
static constexpr auto* START_SCAN_TEXT = "Scan";
static constexpr auto* STOP_SCAN_TEXT = "Stop scan";
@@ -189,7 +192,7 @@ bool I2cScannerApp::getPort(i2c_port_t* outPort) {
mutex.unlock();
return true;
} else {
TT_LOG_W(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "getPort");
logger.warn(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "getPort");
return false;
}
}
@@ -200,7 +203,7 @@ bool I2cScannerApp::addAddressToList(uint8_t address) {
mutex.unlock();
return true;
} else {
TT_LOG_W(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "addAddressToList");
logger.warn(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "addAddressToList");
return false;
}
}
@@ -216,24 +219,24 @@ bool I2cScannerApp::shouldStopScanTimer() {
}
void I2cScannerApp::onScanTimer() {
TT_LOG_I(TAG, "Scan thread started");
logger.info("Scan thread started");
i2c_port_t safe_port;
if (!getPort(&safe_port)) {
TT_LOG_E(TAG, "Failed to get I2C port");
logger.error("Failed to get I2C port");
onScanTimerFinished();
return;
}
if (!hal::i2c::isStarted(safe_port)) {
TT_LOG_E(TAG, "I2C port not started");
logger.error("I2C port not started");
onScanTimerFinished();
return;
}
for (uint8_t address = 0; address < 128; ++address) {
if (hal::i2c::masterHasDeviceAtAddress(port, address, 10 / portTICK_PERIOD_MS)) {
TT_LOG_I(TAG, "Found device at address 0x%02X", address);
if (hal::i2c::masterHasDeviceAtAddress(safe_port, address, 10 / portTICK_PERIOD_MS)) {
logger.info("Found device at address 0x{:02X}", address);
if (!shouldStopScanTimer()) {
addAddressToList(address);
} else {
@@ -246,11 +249,11 @@ void I2cScannerApp::onScanTimer() {
}
}
TT_LOG_I(TAG, "Scan thread finalizing");
logger.info("Scan thread finalizing");
onScanTimerFinished();
TT_LOG_I(TAG, "Scan timer done");
logger.info("Scan timer done");
}
bool I2cScannerApp::hasScanThread() {
@@ -261,7 +264,7 @@ bool I2cScannerApp::hasScanThread() {
return has_thread;
} else {
// Unsafe way
TT_LOG_W(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "hasScanTimer");
logger.warn(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "hasScanTimer");
return scanTimer != nullptr;
}
}
@@ -284,7 +287,7 @@ void I2cScannerApp::startScanning() {
scanTimer->start();
mutex.unlock();
} else {
TT_LOG_W(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "startScanning");
logger.warn(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "startScanning");
}
}
void I2cScannerApp::stopScanning() {
@@ -293,7 +296,7 @@ void I2cScannerApp::stopScanning() {
scanState = ScanStateStopped;
mutex.unlock();
} else {
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
logger.error(LOG_MESSAGE_MUTEX_LOCK_FAILED);
}
}
@@ -314,7 +317,7 @@ void I2cScannerApp::selectBus(int32_t selected) {
mutex.unlock();
}
TT_LOG_I(TAG, "Selected %ld", selected);
logger.info("Selected {}", selected);
setLastBusIndex(selected);
startScanning();
@@ -377,7 +380,7 @@ void I2cScannerApp::updateViews() {
mutex.unlock();
} else {
TT_LOG_W(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "updateViews");
logger.warn(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "updateViews");
}
}
@@ -386,7 +389,7 @@ void I2cScannerApp::updateViewsSafely() {
updateViews();
lvgl::unlock();
} else {
TT_LOG_W(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "updateViewsSafely");
logger.warn(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "updateViewsSafely");
}
}
@@ -399,7 +402,7 @@ void I2cScannerApp::onScanTimerFinished() {
updateViewsSafely();
} else {
TT_LOG_W(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "onScanTimerFinished");
logger.warn(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "onScanTimerFinished");
}
}
@@ -2,7 +2,7 @@
#include <Tactility/lvgl/Style.h>
#include <Tactility/lvgl/Toolbar.h>
#include <Tactility/service/loader/Loader.h>
#include <Tactility/TactilityCore.h>
#include <Tactility/Logger.h>
#include <Tactility/StringUtils.h>
#include <lvgl.h>
@@ -11,7 +11,7 @@ namespace tt::app::imageviewer {
extern const AppManifest manifest;
constexpr auto* TAG = "ImageViewer";
static const auto LOGGER = Logger("ImageViewer");
constexpr auto* IMAGE_VIEWER_FILE_ARGUMENT = "file";
class ImageViewerApp final : public App {
@@ -49,7 +49,7 @@ class ImageViewerApp final : public App {
std::string file_argument;
if (bundle->optString(IMAGE_VIEWER_FILE_ARGUMENT, file_argument)) {
std::string prefixed_path = lvgl::PATH_PREFIX + file_argument;
TT_LOG_I(TAG, "Opening %s", prefixed_path.c_str());
LOGGER.info("Opening {}", prefixed_path);
lv_img_set_src(image, prefixed_path.c_str());
auto path = string::getLastPathSegment(file_argument);
lv_label_set_text(file_label, path.c_str());
@@ -15,7 +15,7 @@ constexpr auto* RESULT_BUNDLE_KEY_RESULT = "result";
constexpr auto* DEFAULT_TITLE = "Input";
constexpr auto* TAG = "InputDialog";
static const auto LOGGER = Logger("InputDialog");
extern const AppManifest manifest;
class InputDialogApp;
@@ -62,7 +62,7 @@ class InputDialogApp final : public App {
void onButtonClicked(lv_event_t* e) {
auto user_data = lv_event_get_user_data(e);
int index = (user_data != 0) ? 0 : 1;
TT_LOG_I(TAG, "Selected item at index %d", index);
LOGGER.info("Selected item at index {}", index);
if (index == 0) {
auto bundle = std::make_unique<Bundle>();
const char* text = lv_textarea_get_text((lv_obj_t*)user_data);
+2 -2
View File
@@ -12,7 +12,7 @@
namespace tt::app::launcher {
constexpr auto* TAG = "Launcher";
static const auto LOGGER = Logger("Launcher");
static int getButtonSize(hal::UiScale scale) {
if (scale == hal::UiScale::Smallest) {
@@ -93,7 +93,7 @@ public:
void onCreate(TT_UNUSED AppContext& app) override {
settings::BootSettings boot_properties;
if (settings::loadBootSettings(boot_properties) && !boot_properties.autoStartAppId.empty()) {
TT_LOG_I(TAG, "Starting %s", boot_properties.autoStartAppId.c_str());
LOGGER.info("Starting {}", boot_properties.autoStartAppId);
start(boot_properties.autoStartAppId);
}
}
+7 -7
View File
@@ -12,7 +12,7 @@
namespace tt::app::notes {
constexpr auto* TAG = "Notes";
static const auto LOGGER = Logger("Notes");
constexpr auto* NOTES_FILE_ARGUMENT = "file";
class NotesApp final : public App {
@@ -52,11 +52,11 @@ class NotesApp final : public App {
saveBuffer = lv_textarea_get_text(uiNoteText);
lvgl::getSyncLock()->unlock();
saveFileLaunchId = fileselection::startForExistingOrNewFile();
TT_LOG_I(TAG, "launched with id %d", loadFileLaunchId);
LOGGER.info("launched with id {}", saveFileLaunchId);
break;
case 3: // Load
loadFileLaunchId = fileselection::startForExistingFile();
TT_LOG_I(TAG, "launched with id %d", loadFileLaunchId);
LOGGER.info("launched with id {}", loadFileLaunchId);
break;
}
} else {
@@ -64,7 +64,7 @@ class NotesApp final : public App {
if (obj == cont) return;
if (lv_obj_get_child(cont, 1)) {
saveFileLaunchId = fileselection::startForExistingOrNewFile();
TT_LOG_I(TAG, "launched with id %d", loadFileLaunchId);
LOGGER.info("launched with id {}", saveFileLaunchId);
} else { //Reset
resetFileContent();
}
@@ -91,7 +91,7 @@ class NotesApp final : public App {
lv_textarea_set_text(uiNoteText, reinterpret_cast<const char*>(data.get()));
lv_label_set_text(uiCurrentFileName, path.c_str());
filePath = path;
TT_LOG_I(TAG, "Loaded from %s", path.c_str());
LOGGER.info("Loaded from {}", path);
}
});
}
@@ -101,7 +101,7 @@ class NotesApp final : public App {
bool result = false;
file::getLock(path)->withLock([&result, this, path] {
if (file::writeString(path, saveBuffer.c_str())) {
TT_LOG_I(TAG, "Saved to %s", path.c_str());
LOGGER.info("Saved to {}", path);
filePath = path;
result = true;
}
@@ -186,7 +186,7 @@ class NotesApp final : public App {
}
void onResult(AppContext& appContext, LaunchId launchId, Result result, std::unique_ptr<Bundle> resultData) override {
TT_LOG_I(TAG, "Result for launch id %d", launchId);
LOGGER.info("Result for launch id {}", launchId);
if (launchId == loadFileLaunchId) {
loadFileLaunchId = 0;
if (result == Result::Ok && resultData != nullptr) {
+11 -10
View File
@@ -9,15 +9,16 @@
#include <Tactility/app/App.h>
#include <Tactility/app/AppManifest.h>
#include <Tactility/kernel/Platform.h>
#include <Tactility/Logger.h>
#include <Tactility/lvgl/Lvgl.h>
#include <Tactility/lvgl/LvglSync.h>
#include <Tactility/lvgl/Toolbar.h>
#include <Tactility/service/screenshot/Screenshot.h>
constexpr auto* TAG = "Screenshot";
namespace tt::app::screenshot {
static const auto LOGGER = Logger("Screenshot");
extern const AppManifest manifest;
class ScreenshotApp final : public App {
@@ -97,27 +98,27 @@ void ScreenshotApp::onModeSet() {
void ScreenshotApp::onStartPressed() {
auto service = service::screenshot::optScreenshotService();
if (service == nullptr) {
TT_LOG_E(TAG, "Service not found/running");
LOGGER.error("Service not found/running");
return;
}
if (service->isTaskStarted()) {
TT_LOG_I(TAG, "Stop screenshot");
LOGGER.info("Stop screenshot");
service->stop();
} else {
uint32_t selected = lv_dropdown_get_selected(modeDropdown);
const char* path = lv_textarea_get_text(pathTextArea);
if (selected == 0) {
TT_LOG_I(TAG, "Start timed screenshots");
LOGGER.info("Start timed screenshots");
const char* delay_text = lv_textarea_get_text(delayTextArea);
int delay = atoi(delay_text);
if (delay > 0) {
service->startTimed(path, delay, 1);
} else {
TT_LOG_W(TAG, "Ignored screenshot start because delay was 0");
LOGGER.warn("Ignored screenshot start because delay was 0");
}
} else {
TT_LOG_I(TAG, "Start app screenshots");
LOGGER.info("Start app screenshots");
service->startApps(path);
}
}
@@ -128,7 +129,7 @@ void ScreenshotApp::onStartPressed() {
void ScreenshotApp::updateScreenshotMode() {
auto service = service::screenshot::optScreenshotService();
if (service == nullptr) {
TT_LOG_E(TAG, "Service not found/running");
LOGGER.error("Service not found/running");
return;
}
@@ -151,7 +152,7 @@ void ScreenshotApp::updateScreenshotMode() {
void ScreenshotApp::createModeSettingWidgets(lv_obj_t* parent) {
auto service = service::screenshot::optScreenshotService();
if (service == nullptr) {
TT_LOG_E(TAG, "Service not found/running");
LOGGER.error("Service not found/running");
return;
}
@@ -203,7 +204,7 @@ void ScreenshotApp::createFilePathWidgets(lv_obj_t* parent) {
if (kernel::getPlatform() == kernel::PlatformEsp) {
auto sdcard_devices = tt::hal::findDevices<tt::hal::sdcard::SdCardDevice>(tt::hal::Device::Type::SdCard);
if (sdcard_devices.size() > 1) {
TT_LOG_W(TAG, "Found multiple SD card devices - picking first");
LOGGER.warn("Found multiple SD card devices - picking first");
}
if (!sdcard_devices.empty() && sdcard_devices.front()->isMounted()) {
std::string lvgl_mount_path = lvgl::PATH_PREFIX + sdcard_devices.front()->getMountPath();
@@ -1,9 +1,9 @@
#include <Tactility/app/selectiondialog/SelectionDialog.h>
#include <Tactility/Logger.h>
#include <Tactility/lvgl/Toolbar.h>
#include <Tactility/service/loader/Loader.h>
#include <Tactility/StringUtils.h>
#include <Tactility/TactilityCore.h>
#include <lvgl.h>
@@ -16,7 +16,7 @@ constexpr auto* RESULT_BUNDLE_KEY_INDEX = "index";
constexpr auto* PARAMETER_ITEM_CONCATENATION_TOKEN = ";;";
constexpr auto* DEFAULT_TITLE = "Select...";
constexpr auto* TAG = "SelectionDialog";
static const auto LOGGER = Logger("SelectionDialog");
extern const AppManifest manifest;
@@ -53,7 +53,7 @@ class SelectionDialogApp final : public App {
void onListItemSelected(lv_event_t* e) {
auto index = reinterpret_cast<std::size_t>(lv_event_get_user_data(e));
TT_LOG_I(TAG, "Selected item at index %d", index);
LOGGER.info("Selected item at index {}", index);
auto bundle = std::make_unique<Bundle>();
bundle->putInt32(RESULT_BUNDLE_KEY_INDEX, (int32_t)index);
setResult(Result::Ok, std::move(bundle));
@@ -85,7 +85,7 @@ public:
if (parameters->optString(PARAMETER_BUNDLE_KEY_ITEMS, items_concatenated)) {
std::vector<std::string> items = string::split(items_concatenated, PARAMETER_ITEM_CONCATENATION_TOKEN);
if (items.empty() || items.front().empty()) {
TT_LOG_E(TAG, "No items provided");
LOGGER.error("No items provided");
setResult(Result::Error);
stop(manifest.appId);
} else if (items.size() == 1) {
@@ -93,7 +93,7 @@ public:
result_bundle->putInt32(RESULT_BUNDLE_KEY_INDEX, 0);
setResult(Result::Ok, std::move(result_bundle));
stop(manifest.appId);
TT_LOG_W(TAG, "Auto-selecting single item");
LOGGER.warn("Auto-selecting single item");
} else {
size_t index = 0;
for (const auto& item: items) {
@@ -101,7 +101,7 @@ public:
}
}
} else {
TT_LOG_E(TAG, "No items provided");
LOGGER.error("No items provided");
setResult(Result::Error);
stop(manifest.appId);
}
@@ -1,9 +1,10 @@
#include <Tactility/Assets.h>
#include <Tactility/app/AppManifest.h>
#include <Tactility/app/timezone/TimeZone.h>
#include <Tactility/Logger.h>
#include <Tactility/lvgl/Toolbar.h>
#include <Tactility/RecursiveMutex.h>
#include <Tactility/lvgl/LvglSync.h>
#include <Tactility/RecursiveMutex.h>
#include <Tactility/service/loader/Loader.h>
#include <Tactility/settings/Time.h>
#include <Tactility/settings/SystemSettings.h>
@@ -12,7 +13,7 @@
namespace tt::app::timedatesettings {
constexpr auto* TAG = "TimeDate";
static const auto LOGGER = Logger("TimeDate");
extern const AppManifest manifest;
@@ -137,7 +138,7 @@ public:
if (result == Result::Ok && bundle != nullptr) {
const auto name = timezone::getResultName(*bundle);
const auto code = timezone::getResultCode(*bundle);
TT_LOG_I(TAG, "Result name=%s code=%s", name.c_str(), code.c_str());
LOGGER.info("Result name={} code={}", name, code);
settings::setTimeZone(name, code);
if (!name.empty()) {
+12 -10
View File
@@ -2,21 +2,23 @@
#include <Tactility/app/AppManifest.h>
#include <Tactility/app/AppPaths.h>
#include <Tactility/app/timezone/TimeZone.h>
#include <Tactility/Logger.h>
#include <Tactility/LogMessages.h>
#include <Tactility/lvgl/Lvgl.h>
#include <Tactility/lvgl/Toolbar.h>
#include <Tactility/lvgl/LvglSync.h>
#include <Tactility/service/loader/Loader.h>
#include <Tactility/Timer.h>
#include <Tactility/MountPoints.h>
#include <Tactility/service/loader/Loader.h>
#include <Tactility/StringUtils.h>
#include <Tactility/Timer.h>
#include <lvgl.h>
#include <memory>
namespace tt::app::timezone {
constexpr auto* TAG = "TimeZone";
static const auto LOGGER = Logger("TimeZone");
constexpr auto* RESULT_BUNDLE_CODE_INDEX = "code";
constexpr auto* RESULT_BUNDLE_NAME_INDEX = "name";
@@ -96,7 +98,7 @@ class TimeZoneApp final : public App {
}
void onListItemSelected(std::size_t index) {
TT_LOG_I(TAG, "Selected item at index %zu", index);
LOGGER.info("Selected item at index {}", index);
auto& entry = entries[index];
@@ -117,7 +119,7 @@ class TimeZoneApp final : public App {
auto path = std::string(file::MOUNT_POINT_SYSTEM) + "/timezones.csv";
auto* file = fopen(path.c_str(), "rb");
if (file == nullptr) {
TT_LOG_E(TAG, "Failed to open %s", path.c_str());
LOGGER.error("Failed to open {}", path);
return;
}
char line[96];
@@ -138,7 +140,7 @@ class TimeZoneApp final : public App {
}
}
} else {
TT_LOG_E(TAG, "Parse error at line %lu", count);
LOGGER.error("Parse error at line {}", count);
}
}
@@ -148,10 +150,10 @@ class TimeZoneApp final : public App {
entries = std::move(new_entries);
mutex.unlock();
} else {
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED);
}
TT_LOG_I(TAG, "Processed %lu entries", count);
LOGGER.info("Processed {} entries", count);
}
void updateList() {
@@ -160,7 +162,7 @@ class TimeZoneApp final : public App {
readTimeZones(filter);
lvgl::unlock();
} else {
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "LVGL");
LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "LVGL");
return;
}
@@ -6,15 +6,16 @@
#include <Tactility/app/AppContext.h>
#include <Tactility/app/AppManifest.h>
#include <Tactility/app/alertdialog/AlertDialog.h>
#include <Tactility/Logger.h>
#include <Tactility/LogMessages.h>
#include <Tactility/lvgl/Style.h>
#include <Tactility/lvgl/Toolbar.h>
#include <Tactility/TactilityCore.h>
#include <lvgl.h>
namespace tt::app::wifiapsettings {
constexpr auto* TAG = "WifiApSettings";
static const auto LOGGER = Logger("WifiApSettings");
extern const AppManifest manifest;
@@ -50,10 +51,10 @@ class WifiApSettings : public App {
if (service::wifi::settings::load(self->ssid.c_str(), settings)) {
settings.autoConnect = is_on;
if (!service::wifi::settings::save(settings)) {
TT_LOG_E(TAG, "Failed to save settings");
LOGGER.error("Failed to save settings");
}
} else {
TT_LOG_E(TAG, "Failed to load settings");
LOGGER.error("Failed to load settings");
}
}
@@ -89,7 +90,7 @@ class WifiApSettings : public App {
updateViews();
lvgl::unlock();
} else {
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "LVGL");
LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "LVGL");
}
}
}
@@ -192,7 +193,7 @@ public:
lv_obj_remove_state(auto_connect_switch, LV_STATE_CHECKED);
}
} else {
TT_LOG_W(TAG, "No settings found");
LOGGER.warn("No settings found");
lv_obj_add_flag(forget_button, LV_OBJ_FLAG_HIDDEN);
lv_obj_add_flag(auto_connect_wrapper, LV_OBJ_FLAG_HIDDEN);
}
@@ -223,11 +224,11 @@ public:
std::string ssid = parameters->getString("ssid");
if (!service::wifi::settings::remove(ssid.c_str())) {
TT_LOG_E(TAG, "Failed to remove SSID");
LOGGER.error("Failed to remove SSID");
return;
}
TT_LOG_I(TAG, "Removed SSID");
LOGGER.info("Removed SSID");
if (
service::wifi::getRadioState() == service::wifi::RadioState::ConnectionActive &&
service::wifi::getConnectionTarget() == ssid
+5 -4
View File
@@ -2,6 +2,7 @@
#include <Tactility/app/wificonnect/View.h>
#include <Tactility/app/wificonnect/WifiConnect.h>
#include <Tactility/Logger.h>
#include <Tactility/lvgl/Toolbar.h>
#include <Tactility/lvgl/Spinner.h>
#include <Tactility/service/wifi/WifiApSettings.h>
@@ -12,7 +13,7 @@
namespace tt::app::wificonnect {
constexpr auto* TAG = "WifiConnect";
static const auto LOGGER = Logger("WifiConnect");
void View::resetErrors() {
lv_obj_add_flag(password_error, LV_OBJ_FLAG_HIDDEN);
@@ -30,7 +31,7 @@ static void onConnect(TT_UNUSED lv_event_t* event) {
const char* ssid = lv_textarea_get_text(view.ssid_textarea);
size_t ssid_len = strlen(ssid);
if (ssid_len > TT_WIFI_SSID_LIMIT) {
TT_LOG_E(TAG, "SSID too long");
LOGGER.error("SSID too long");
lv_label_set_text(view.ssid_error, "SSID too long");
lv_obj_remove_flag(view.ssid_error, LV_OBJ_FLAG_HIDDEN);
return;
@@ -39,7 +40,7 @@ static void onConnect(TT_UNUSED lv_event_t* event) {
const char* password = lv_textarea_get_text(view.password_textarea);
size_t password_len = strlen(password);
if (password_len > TT_WIFI_CREDENTIALS_PASSWORD_LIMIT) {
TT_LOG_E(TAG, "Password too long");
LOGGER.error("Password too long");
lv_label_set_text(view.password_error, "Password too long");
lv_obj_remove_flag(view.password_error, LV_OBJ_FLAG_HIDDEN);
return;
@@ -199,7 +200,7 @@ void View::init(AppContext& app, lv_obj_t* parent) {
}
std::string password;
if (optPasswordParameter(bundle, ssid)) {
if (optPasswordParameter(bundle, password)) {
lv_textarea_set_text(password_textarea, password.c_str());
}
}
@@ -1,13 +1,15 @@
#include <Tactility/app/wificonnect/WifiConnect.h>
#include <Tactility/Logger.h>
#include <Tactility/LogMessages.h>
#include <Tactility/app/AppContext.h>
#include <Tactility/lvgl/LvglSync.h>
#include <Tactility/service/loader/Loader.h>
#include <Tactility/service/wifi/Wifi.h>
#include <Tactility/lvgl/LvglSync.h>
namespace tt::app::wificonnect {
constexpr auto* TAG = "WifiConnect";
static const auto LOGGER = Logger("WifiConnect");
constexpr auto* WIFI_CONNECT_PARAM_SSID = "ssid"; // String
constexpr auto* WIFI_CONNECT_PARAM_PASSWORD = "password"; // String
@@ -72,7 +74,7 @@ void WifiConnect::requestViewUpdate() {
view.update();
lvgl::unlock();
} else {
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "LVGL");
LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "LVGL");
}
}
unlock();
+10 -14
View File
@@ -1,24 +1,20 @@
#include <Tactility/network/HttpdReq.h>
#include <Tactility/app/wifimanage/View.h>
#include <Tactility/Tactility.h>
#include <Tactility/app/wifimanage/WifiManagePrivate.h>
#include <Tactility/Logger.h>
#include <Tactility/lvgl/Style.h>
#include <Tactility/lvgl/Toolbar.h>
#include <Tactility/Log.h>
#include <Tactility/service/wifi/Wifi.h>
#include <Tactility/service/wifi/WifiSettings.h>
#include <format>
#include <string>
#include <set>
#include <Tactility/service/wifi/WifiSettings.h>
namespace tt::app::wifimanage {
constexpr auto* TAG = "WifiManageView";
static const auto LOGGER = Logger("WifiManageView");
std::shared_ptr<WifiManage> _Nullable optWifiManage();
@@ -70,16 +66,16 @@ static void onConnectToHiddenClicked(lv_event_t* event) {
// region Secondary updates
void View::connect(lv_event_t* event) {
TT_LOG_D(TAG, "connect()");
LOGGER.debug("connect()");
auto* widget = lv_event_get_current_target_obj(event);
auto index = reinterpret_cast<size_t>(lv_obj_get_user_data(widget));
auto* self = static_cast<View*>(lv_event_get_user_data(event));
auto ap_records = self->state->getApRecords();
if (index < ap_records.size()) {
TT_LOG_I(TAG, "Clicked %d/%d", index, ap_records.size() - 1);
LOGGER.info("Clicked {}/{}", index, ap_records.size() - 1);
auto& ssid = ap_records[index].ssid;
TT_LOG_I(TAG, "Clicked AP: %s", ssid.c_str());
LOGGER.info("Clicked AP: {}", ssid);
std::string connection_target = service::wifi::getConnectionTarget();
if (connection_target == ssid) {
self->bindings->onDisconnect();
@@ -87,12 +83,12 @@ void View::connect(lv_event_t* event) {
self->bindings->onConnectSsid(ssid);
}
} else {
TT_LOG_W(TAG, "Clicked AP: record %d/%d does not exist", index, ap_records.size() - 1);
LOGGER.warn("Clicked AP: record {}/{} does not exist", index, ap_records.size() - 1);
}
}
void View::showDetails(lv_event_t* event) {
TT_LOG_D(TAG, "showDetails()");
LOGGER.debug("showDetails()");
auto* widget = lv_event_get_current_target_obj(event);
auto index = reinterpret_cast<size_t>(lv_obj_get_user_data(widget));
auto* self = static_cast<View*>(lv_event_get_user_data(event));
@@ -100,10 +96,10 @@ void View::showDetails(lv_event_t* event) {
if (index < ap_records.size()) {
auto& ssid = ap_records[index].ssid;
TT_LOG_I(TAG, "Clicked AP: %s", ssid.c_str());
LOGGER.info("Clicked AP: {}", ssid);
self->bindings->onShowApSettings(ssid);
} else {
TT_LOG_W(TAG, "Clicked AP: record %d/%d does not exist", index, ap_records.size() - 1);
LOGGER.warn("Clicked AP: record {}/{} does not exist", index, ap_records.size() - 1);
}
}
@@ -4,22 +4,24 @@
#include <Tactility/app/AppContext.h>
#include <Tactility/app/wifiapsettings/WifiApSettings.h>
#include <Tactility/app/wificonnect/WifiConnect.h>
#include <Tactility/Logger.h>
#include <Tactility/LogMessages.h>
#include <Tactility/lvgl/LvglSync.h>
#include <Tactility/service/loader/Loader.h>
namespace tt::app::wifimanage {
constexpr auto TAG = "WifiManage";
static const auto LOGGER = Logger("WifiManage");
extern const AppManifest manifest;
static void onConnect(const std::string& ssid) {
service::wifi::settings::WifiApSettings settings;
if (service::wifi::settings::load(ssid, settings)) {
TT_LOG_I(TAG, "Connecting with known credentials");
LOGGER.info("Connecting with known credentials");
service::wifi::connect(settings, false);
} else {
TT_LOG_I(TAG, "Starting connection dialog");
LOGGER.info("Starting connection dialog");
wificonnect::start(ssid);
}
}
@@ -65,7 +67,7 @@ void WifiManage::requestViewUpdate() {
view.update();
lvgl::unlock();
} else {
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "LVGL");
LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "LVGL");
}
}
unlock();
@@ -73,7 +75,7 @@ void WifiManage::requestViewUpdate() {
void WifiManage::onWifiEvent(service::wifi::WifiEvent event) {
auto radio_state = service::wifi::getRadioState();
TT_LOG_I(TAG, "Update with state %s", service::wifi::radioStateToString(radio_state));
LOGGER.info("Update with state {}", service::wifi::radioStateToString(radio_state));
getState().setRadioState(radio_state);
switch (event) {
using enum service::wifi::WifiEvent;
@@ -118,7 +120,7 @@ void WifiManage::onShow(AppContext& app, lv_obj_t* parent) {
bool can_scan = radio_state == service::wifi::RadioState::On ||
radio_state == service::wifi::RadioState::ConnectionPending ||
radio_state == service::wifi::RadioState::ConnectionActive;
TT_LOG_I(TAG, "%s %d", service::wifi::radioStateToString(radio_state), (int)service::wifi::isScanning());
LOGGER.info("{} {}", service::wifi::radioStateToString(radio_state), service::wifi::isScanning());
if (can_scan && !service::wifi::isScanning()) {
service::wifi::scan();
}
+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;
}
+6 -6
View File
@@ -1,6 +1,6 @@
#include <Tactility/hal/Device.h>
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#include <Tactility/RecursiveMutex.h>
#include <algorithm>
@@ -10,7 +10,7 @@ std::vector<std::shared_ptr<Device>> devices;
RecursiveMutex mutex;
static Device::Id nextId = 0;
constexpr auto TAG = "devices";
static const auto LOGGER = Logger("Devices");
Device::Device() : id(nextId++) {}
@@ -26,9 +26,9 @@ void registerDevice(const std::shared_ptr<Device>& device) {
if (findDevice(device->getId()) == nullptr) {
devices.push_back(device);
TT_LOG_I(TAG, "Registered %s with id %lu", device->getName().c_str(), device->getId());
LOGGER.info("Registered {} with id {}", device->getName(), device->getId());
} else {
TT_LOG_W(TAG, "Device %s with id %lu was already registered", device->getName().c_str(), device->getId());
LOGGER.warn("Device {} with id {} was already registered", device->getName(), device->getId());
}
}
@@ -41,10 +41,10 @@ void deregisterDevice(const std::shared_ptr<Device>& device) {
return device->getId() == id_to_remove;
});
if (remove_iterator != devices.end()) {
TT_LOG_I(TAG, "Deregistering %s with id %lu", device->getName().c_str(), device->getId());
LOGGER.info("Deregistering {} with id {}", device->getName(), device->getId());
devices.erase(remove_iterator);
} else {
TT_LOG_W(TAG, "Deregistering %s with id %lu failed: not found", device->getName().c_str(), device->getId());
LOGGER.warn("Deregistering {} with id {} failed: not found", device->getName(), device->getId());
}
}
+20 -19
View File
@@ -1,11 +1,12 @@
#include "Tactility/Tactility.h"
#include "Tactility/hal/Configuration.h"
#include "Tactility/hal/Device.h"
#include "Tactility/hal/gps/GpsInit.h"
#include "Tactility/hal/i2c/I2cInit.h"
#include "Tactility/hal/power/PowerDevice.h"
#include "Tactility/hal/spi/SpiInit.h"
#include "Tactility/hal/uart/UartInit.h"
#include <Tactility/Tactility.h>
#include <Tactility/hal/Configuration.h>
#include <Tactility/hal/Device.h>
#include <Tactility/hal/gps/GpsInit.h>
#include <Tactility/hal/i2c/I2cInit.h>
#include <Tactility/hal/power/PowerDevice.h>
#include <Tactility/hal/spi/SpiInit.h>
#include <Tactility/hal/uart/UartInit.h>
#include <Tactility/Logger.h>
#include <Tactility/hal/display/DisplayDevice.h>
#include <Tactility/hal/sdcard/SdCardMounting.h>
@@ -14,10 +15,10 @@
namespace tt::hal {
constexpr auto* TAG = "Hal";
static const auto LOGGER = Logger("Hal");
void registerDevices(const Configuration& configuration) {
TT_LOG_I(TAG, "Registering devices");
LOGGER.info("Registering devices");
auto devices = configuration.createDevices();
for (auto& device : devices) {
@@ -36,27 +37,27 @@ void registerDevices(const Configuration& configuration) {
}
static void startDisplays() {
TT_LOG_I(TAG, "Starting displays & touch");
LOGGER.info("Starting displays & touch");
auto displays = hal::findDevices<display::DisplayDevice>(Device::Type::Display);
for (auto& display : displays) {
TT_LOG_I(TAG, "%s starting", display->getName().c_str());
LOGGER.info("{} starting", display->getName());
if (!display->start()) {
TT_LOG_E(TAG, "%s start failed", display->getName().c_str());
LOGGER.error("{} start failed", display->getName());
} else {
TT_LOG_I(TAG, "%s started", display->getName().c_str());
LOGGER.info("{} started", display->getName());
if (display->supportsBacklightDuty()) {
TT_LOG_I(TAG, "Setting backlight");
LOGGER.info("Setting backlight");
display->setBacklightDuty(0);
}
auto touch = display->getTouchDevice();
if (touch != nullptr) {
TT_LOG_I(TAG, "%s starting", touch->getName().c_str());
LOGGER.info("{} starting", touch->getName());
if (!touch->start()) {
TT_LOG_E(TAG, "%s start failed", touch->getName().c_str());
LOGGER.error("{} start failed", touch->getName());
} else {
TT_LOG_I(TAG, "%s started", touch->getName().c_str());
LOGGER.info("{} started", touch->getName());
}
}
}
@@ -79,7 +80,7 @@ void init(const Configuration& configuration) {
kernel::publishSystemEvent(kernel::SystemEvent::BootInitUartEnd);
if (configuration.initBoot != nullptr) {
TT_LOG_I(TAG, "Init power");
LOGGER.info("Init power");
tt_check(configuration.initBoot(), "Init power failed");
}
+22 -17
View File
@@ -2,7 +2,7 @@
#include <Tactility/hal/gps/GpsInit.h>
#include <Tactility/hal/gps/Probe.h>
#include <Tactility/hal/uart/Uart.h>
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#include <cstring>
#include <minmea.h>
@@ -10,24 +10,25 @@
namespace tt::hal::gps {
constexpr uint32_t GPS_UART_BUFFER_SIZE = 256;
constexpr const char* TAG = "GpsDevice";
static const auto LOGGER = Logger("GpsDevice");
int32_t GpsDevice::threadMain() {
uint8_t buffer[GPS_UART_BUFFER_SIZE];
auto uart = uart::open(configuration.uartName);
if (uart == nullptr) {
TT_LOG_E(TAG, "Failed to open UART %s", configuration.uartName);
LOGGER.error("Failed to open UART {}", configuration.uartName);
return -1;
}
if (!uart->start()) {
TT_LOG_E(TAG, "Failed to start UART %s", configuration.uartName);
LOGGER.error("Failed to start UART {}", configuration.uartName);
return -1;
}
if (!uart->setBaudRate((int)configuration.baudRate)) {
TT_LOG_E(TAG, "Failed to set baud rate to %lu for UART %s", configuration.baudRate, configuration.uartName);
if (!uart->setBaudRate(static_cast<int>(configuration.baudRate))) {
LOGGER.error("Failed to set baud rate to {} for UART {}", configuration.baudRate, configuration.uartName);
return -1;
}
@@ -35,7 +36,7 @@ int32_t GpsDevice::threadMain() {
if (model == GpsModel::Unknown) {
model = probe(*uart);
if (model == GpsModel::Unknown) {
TT_LOG_E(TAG, "Probe failed");
LOGGER.error("Probe failed");
setState(State::Error);
return -1;
}
@@ -45,7 +46,7 @@ int32_t GpsDevice::threadMain() {
mutex.unlock();
if (!init(*uart, model)) {
TT_LOG_E(TAG, "Init failed");
LOGGER.error("Init failed");
setState(State::Error);
return -1;
}
@@ -63,7 +64,7 @@ int32_t GpsDevice::threadMain() {
if (bytes_read > 0U) {
TT_LOG_I(TAG, "[%ul] %s", bytes_read, buffer);
LOGGER.info("[{}] {}", bytes_read, reinterpret_cast<const char*>(buffer));
switch (minmea_sentence_id((char*)buffer, false)) {
case MINMEA_SENTENCE_RMC:
@@ -74,9 +75,11 @@ int32_t GpsDevice::threadMain() {
(*subscription.onData)(getId(), rmc_frame);
}
mutex.unlock();
TT_LOG_D(TAG, "RMC %f lat, %f lon, %f m/s", minmea_tocoord(&rmc_frame.latitude), minmea_tocoord(&rmc_frame.longitude), minmea_tofloat(&rmc_frame.speed));
if (LOGGER.isLoggingDebug()) {
LOGGER.debug("RMC {} lat, {} lon, {} m/s", minmea_tocoord(&rmc_frame.latitude), minmea_tocoord(&rmc_frame.longitude), minmea_tofloat(&rmc_frame.speed));
}
} else {
TT_LOG_W(TAG, "RMC parse error: %s", buffer);
LOGGER.error("RMC parse error: {}", reinterpret_cast<const char*>(buffer));
}
break;
case MINMEA_SENTENCE_GGA:
@@ -87,9 +90,11 @@ int32_t GpsDevice::threadMain() {
(*subscription.onData)(getId(), gga_frame);
}
mutex.unlock();
TT_LOG_D(TAG, "GGA %f lat, %f lon", minmea_tocoord(&gga_frame.latitude), minmea_tocoord(&gga_frame.longitude));
if (LOGGER.isLoggingDebug()) {
LOGGER.debug("GGA {} lat, {} lon", minmea_tocoord(&gga_frame.latitude), minmea_tocoord(&gga_frame.longitude));
}
} else {
TT_LOG_W(TAG, "GGA parse error: %s", buffer);
LOGGER.error("GGA parse error: {}", reinterpret_cast<const char*>(buffer));
}
break;
default:
@@ -99,7 +104,7 @@ int32_t GpsDevice::threadMain() {
}
if (uart->isStarted() && !uart->stop()) {
TT_LOG_W(TAG, "Failed to stop UART %s", configuration.uartName);
LOGGER.warn("Failed to stop UART {}", configuration.uartName);
}
return 0;
@@ -110,13 +115,13 @@ bool GpsDevice::start() {
lock.lock();
if (thread != nullptr && thread->getState() != Thread::State::Stopped) {
TT_LOG_W(TAG, "Already started");
LOGGER.warn("Already started");
return true;
}
threadInterrupted = false;
TT_LOG_I(TAG, "Starting thread");
LOGGER.info("Starting thread");
setState(State::PendingOn);
thread = std::make_unique<Thread>(
@@ -129,7 +134,7 @@ bool GpsDevice::start() {
thread->setPriority(tt::Thread::Priority::High);
thread->start();
TT_LOG_I(TAG, "Starting finished");
LOGGER.info("Starting finished");
return true;
}
+8 -8
View File
@@ -3,13 +3,13 @@
#include <Tactility/hal/gps/GpsDevice.h>
#include <Tactility/hal/gps/Ublox.h>
#include <Tactility/kernel/Kernel.h>
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#include <cstring>
namespace tt::hal::gps {
constexpr auto TAG = "gps";
static const auto LOGGER = Logger("Gps");
bool initMtk(uart::Uart& uart);
bool initMtkL76b(uart::Uart& uart);
@@ -112,7 +112,7 @@ GpsResponse getACKCas(uart::Uart& uart, uint8_t class_id, uint8_t msg_id, uint32
// Check for an ACK-ACK for the specified class and message id
if ((msg_cls == 0x05) && (msg_msg_id == 0x01) && payload_cls == class_id && payload_msg == msg_id) {
#ifdef GPS_DEBUG
LOG_INFO("Got ACK for class %02X message %02X in %dms", class_id, msg_id, millis() - startTime);
LOGGER.info("Got ACK for class {:02X} message {:02X} in {} ms", class_id, msg_id, kernel::getMillis() - startTime);
#endif
return GpsResponse::Ok;
}
@@ -120,7 +120,7 @@ GpsResponse getACKCas(uart::Uart& uart, uint8_t class_id, uint8_t msg_id, uint32
// Check for an ACK-NACK for the specified class and message id
if ((msg_cls == 0x05) && (msg_msg_id == 0x00) && payload_cls == class_id && payload_msg == msg_id) {
#ifdef GPS_DEBUG
LOG_WARN("Got NACK for class %02X message %02X in %dms", class_id, msg_id, millis() - startTime);
LOGGER.warn("Got NACK for class {:02X} message {:02X} in {} ms", class_id, msg_id, millis() - startTime);
#endif
return GpsResponse::NotAck;
}
@@ -163,7 +163,7 @@ bool init(uart::Uart& uart, GpsModel type) {
return initUc6580(uart);
}
TT_LOG_I(TAG, "Init not implemented %d", static_cast<int>(type));
LOGGER.info("Init not implemented {}", static_cast<int>(type));
return false;
}
@@ -213,14 +213,14 @@ bool initAtgm336h(uart::Uart& uart) {
int msglen = makeCASPacket(buffer, 0x06, 0x07, sizeof(_message_CAS_CFG_NAVX_CONF), _message_CAS_CFG_NAVX_CONF);
uart.writeBytes(buffer, msglen);
if (getACKCas(uart, 0x06, 0x07, 250) != GpsResponse::Ok) {
TT_LOG_W(TAG, "ATGM336H: Could not set Config");
LOGGER.warn("ATGM336H: Could not set Config");
}
// Set the update frequence to 1Hz
msglen = makeCASPacket(buffer, 0x06, 0x04, sizeof(_message_CAS_CFG_RATE_1HZ), _message_CAS_CFG_RATE_1HZ);
uart.writeBytes(buffer, msglen);
if (getACKCas(uart, 0x06, 0x04, 250) != GpsResponse::Ok) {
TT_LOG_W(TAG, "ATGM336H: Could not set Update Frequency");
LOGGER.warn("ATGM336H: Could not set Update Frequency");
}
// Set the NEMA output messages
@@ -232,7 +232,7 @@ bool initAtgm336h(uart::Uart& uart) {
msglen = makeCASPacket(buffer, 0x06, 0x01, sizeof(cas_cfg_msg_packet), cas_cfg_msg_packet);
uart.writeBytes(buffer, msglen);
if (getACKCas(uart, 0x06, 0x01, 250) != GpsResponse::Ok) {
TT_LOG_W(TAG, "ATGM336H: Could not enable NMEA MSG: %d", fields[i]);
LOGGER.warn("ATGM336H: Could not enable NMEA MSG: {}", fields[i]);
}
}
return true;
+16 -14
View File
@@ -1,11 +1,13 @@
#include "Tactility/hal/gps/GpsDevice.h"
#include "Tactility/hal/gps/Ublox.h"
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#include <Tactility/hal/uart/Uart.h>
#include <Tactility/kernel/Kernel.h>
#include <cstring>
#define TAG "gps"
static const auto LOGGER = tt::Logger("Gps");
#define GPS_UART_BUFFER_SIZE 256
using namespace tt;
@@ -59,13 +61,13 @@ GpsResponse getAck(uart::Uart& uart, const char* message, uint32_t waitMillis) {
if ((bytesRead == 767) || (b == '\r')) {
if (strnstr((char*)buffer, message, bytesRead) != nullptr) {
#ifdef GPS_DEBUG
LOG_DEBUG("Found: %s", message); // Log the found message
LOGGER.debug("Found: {}", message); // Log the found message
#endif
return GpsResponse::Ok;
} else {
bytesRead = 0;
#ifdef GPS_DEBUG
LOG_DEBUG(debugmsg.c_str());
LOGGER.debug("{}", debugmsg);
#endif
}
}
@@ -77,15 +79,15 @@ GpsResponse getAck(uart::Uart& uart, const char* message, uint32_t waitMillis) {
/**
* From: https://github.com/meshtastic/firmware/blob/f81d3b045dd1b7e3ca7870af3da915ff4399ea98/src/gps/GPS.cpp
*/
#define PROBE_SIMPLE(UART, CHIP, TOWRITE, RESPONSE, DRIVER, TIMEOUT, ...) \
do { \
TT_LOG_I(TAG, "Probing for %s (%s)", CHIP, TOWRITE); \
UART.flushInput(); \
UART.writeString(TOWRITE "\r\n", TIMEOUT); \
if (getAck(UART, RESPONSE, TIMEOUT) == GpsResponse::Ok) { \
TT_LOG_I(TAG, "Probe detected %s %s", CHIP, #DRIVER); \
return DRIVER; \
} \
#define PROBE_SIMPLE(UART, CHIP, TOWRITE, RESPONSE, DRIVER, TIMEOUT, ...) \
do { \
LOGGER.info("Probing for {} ({})", CHIP, TOWRITE); \
UART.flushInput(); \
UART.writeString(TOWRITE "\r\n", TIMEOUT); \
if (getAck(UART, RESPONSE, TIMEOUT) == GpsResponse::Ok) { \
LOGGER.info("Probe detected {} {}", CHIP, #DRIVER); \
return DRIVER; \
} \
} while (0)
/**
@@ -132,7 +134,7 @@ GpsModel probe(uart::Uart& uart) {
if (ublox_result != GpsModel::Unknown) {
return ublox_result;
} else {
TT_LOG_W(TAG, "No GNSS Module (baudrate %lu)", uart.getBaudRate());
LOGGER.warn("No GNSS Module (baud rate {})", uart.getBaudRate());
return GpsModel::Unknown;
}
}
+17 -9
View File
@@ -1,12 +1,10 @@
#include <Tactility/hal/gps/Satellites.h>
#include <Tactility/kernel/Kernel.h>
#include <Tactility/Log.h>
#include <algorithm>
#include <Tactility/Logger.h>
namespace tt::hal::gps {
constexpr auto TAG = "Satellites";
static const auto LOGGER = Logger("Satellites");
constexpr bool hasTimeElapsed(TickType_t now, TickType_t timeInThePast, TickType_t expireTimeInTicks) {
return (TickType_t)(now - timeInThePast) >= expireTimeInTicks;
@@ -35,7 +33,9 @@ SatelliteStorage::SatelliteRecord* SatelliteStorage::findUnusedRecord() {
if (!result.empty()) {
auto* record = &result.front();
record->inUse = true;
TT_LOG_D(TAG, "Found unused record");
if (LOGGER.isLoggingDebug()) {
LOGGER.debug("Found unused record");
}
return record;
} else {
return nullptr;
@@ -53,7 +53,9 @@ SatelliteStorage::SatelliteRecord* SatelliteStorage::findRecordToRecycle() {
for (int i = 0; i < records.size(); ++i) {
// First try to find a record that is "old enough"
if (hasTimeElapsed(now, records[i].lastUpdated, expire_duration)) {
TT_LOG_D(TAG, "! [%d] %lu < %lu", i, records[i].lastUpdated, expire_duration);
if (LOGGER.isLoggingDebug()) {
LOGGER.debug("! [{}] {} < {}", i, records[i].lastUpdated, expire_duration);
}
candidate_index = i;
break;
}
@@ -62,13 +64,17 @@ SatelliteStorage::SatelliteRecord* SatelliteStorage::findRecordToRecycle() {
if (records[i].inUse && records[i].lastUpdated < candidate_age) {
candidate_index = i;
candidate_age = records[i].lastUpdated;
TT_LOG_D(TAG, "? [%d] %lu < %lu", i, records[i].lastUpdated, candidate_age);
if (LOGGER.isLoggingDebug()) {
LOGGER.debug("? [{}] {} < {}", i, records[i].lastUpdated, candidate_age);
}
}
}
assert(candidate_index != -1);
TT_LOG_D(TAG, "Recycled record %d", candidate_index);
if (LOGGER.isLoggingDebug()) {
LOGGER.debug("Recycled record {}", candidate_index);
}
return &records[candidate_index];
}
@@ -95,7 +101,9 @@ void SatelliteStorage::notify(const minmea_sat_info& data) {
record->inUse = true;
record->lastUpdated = kernel::getTicks();
record->data = data;
TT_LOG_D(TAG, "Updated satellite %d: elevation %d, azimuth %d, snr %d", record->data.nr, record->data.elevation, record->data.elevation, record->data.snr);
if (LOGGER.isLoggingDebug()) {
LOGGER.debug("Updated satellite {}: elevation {}, azimuth {}, snr {}", record->data.nr, record->data.elevation, record->data.elevation, record->data.snr);
}
}
}
+38 -39
View File
@@ -2,13 +2,13 @@
#include <Tactility/hal/gps/UbloxMessages.h>
#include <Tactility/hal/uart/Uart.h>
#include <Tactility/kernel/Kernel.h>
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#include <cstring>
namespace tt::hal::gps::ublox {
constexpr auto TAG = "ublox";
static const auto LOGGER = Logger("Ublox");
bool initUblox6(uart::Uart& uart);
bool initUblox789(uart::Uart& uart, GpsModel model);
@@ -19,7 +19,7 @@ bool initUblox10(uart::Uart& uart);
auto msglen = makePacket(TYPE, ID, DATA, sizeof(DATA), BUFFER); \
UART.writeBytes(BUFFER, sizeof(BUFFER)); \
if (getAck(UART, TYPE, ID, TIMEOUT) != GpsResponse::Ok) { \
TT_LOG_I(TAG, "Sending packet failed: %s", #ERRMSG); \
LOGGER.info("Sending packet failed: {}", #ERRMSG); \
} \
} while (0)
@@ -82,7 +82,7 @@ GpsResponse getAck(uart::Uart& uart, uint8_t class_id, uint8_t msg_id, uint32_t
while (kernel::getTicks() - startTime < waitMillis) {
if (ack > 9) {
#ifdef GPS_DEBUG
TT_LOG_I(TAG, "Got ACK for class %02X message %02X in %lums", class_id, msg_id, kernel::getMillis() - startTime);
LOGGER.info("Got ACK for class {:02X} message {:02X} in {}ms", class_id, msg_id, kernel::getMillis() - startTime);
#endif
return GpsResponse::Ok; // ACK received
}
@@ -93,7 +93,7 @@ GpsResponse getAck(uart::Uart& uart, uint8_t class_id, uint8_t msg_id, uint32_t
if (sCounter == 26) {
#ifdef GPS_DEBUG
TT_LOG_I(TAG, "%s", debugmsg.c_str());
LOGGER.info("%s", debugmsg.c_str());
#endif
return GpsResponse::FrameErrors;
}
@@ -108,9 +108,9 @@ GpsResponse getAck(uart::Uart& uart, uint8_t class_id, uint8_t msg_id, uint32_t
} else {
if (ack == 3 && b == 0x00) { // UBX-ACK-NAK message
#ifdef GPS_DEBUG
TT_LOG_I(TAG, "%s", debugmsg.c_str());
LOGGER.info("%s", debugmsg.c_str());
#endif
TT_LOG_W(TAG, "Got NAK for class %02X message %02X", class_id, msg_id);
LOGGER.warn("Got NAK for class {:02X} message {:02X}", class_id, msg_id);
return GpsResponse::NotAck; // NAK received
}
ack = 0; // Reset the acknowledgement counter
@@ -118,8 +118,8 @@ GpsResponse getAck(uart::Uart& uart, uint8_t class_id, uint8_t msg_id, uint32_t
}
}
#ifdef GPS_DEBUG
TT_LOG_I(TAG, "%s", debugmsg.c_str());
TT_LOG_W(TAG, "No response for class %02X message %02X", class_id, msg_id);
LOGGER.info("%s", debugmsg.c_str());
LOGGER.warn("No response for class %02X message %02X", class_id, msg_id);
#endif
return GpsResponse::None; // No response received within timeout
}
@@ -180,7 +180,7 @@ static int getAck(uart::Uart& uart, uint8_t* buffer, uint16_t size, uint8_t requ
} else {
// return payload length
#ifdef GPS_DEBUG
TT_LOG_I(TAG, "Got ACK for class %02X message %02X in %lums", requestedClass, requestedId, kernel::getMillis() - startTime);
LOGGER.info("Got ACK for class {:02X} message {:02X} in {}ms", requestedClass, requestedId, kernel::getMillis() - startTime);
#endif
return needRead;
}
@@ -195,8 +195,6 @@ static int getAck(uart::Uart& uart, uint8_t* buffer, uint16_t size, uint8_t requ
return 0;
}
#define DETECTED_MESSAGE "%s detected, using %s Module"
static struct uBloxGnssModelInfo {
char swVersion[30];
char hwVersion[10];
@@ -206,7 +204,8 @@ static struct uBloxGnssModelInfo {
} ublox_info;
GpsModel probe(uart::Uart& uart) {
TT_LOG_I(TAG, "Probing for U-blox");
LOGGER.info("Probing for U-blox");
constexpr auto DETECTED_MESSAGE = "{} detected, using {} Module";
uint8_t cfg_rate[] = {0xB5, 0x62, 0x06, 0x08, 0x00, 0x00, 0x00, 0x00};
checksum(cfg_rate, sizeof(cfg_rate));
@@ -215,10 +214,10 @@ GpsModel probe(uart::Uart& uart) {
// Check that the returned response class and message ID are correct
GpsResponse response = getAck(uart, 0x06, 0x08, 750);
if (response == GpsResponse::None) {
TT_LOG_W(TAG, "No GNSS Module (baudrate %lu)", uart.getBaudRate());
LOGGER.warn("No GNSS Module (baudrate {})", uart.getBaudRate());
return GpsModel::Unknown;
} else if (response == GpsResponse::FrameErrors) {
TT_LOG_W(TAG, "UBlox Frame Errors (baudrate %lu)", uart.getBaudRate());
LOGGER.warn("UBlox Frame Errors (baudrate {})", uart.getBaudRate());
}
uint8_t buffer[256];
@@ -256,12 +255,12 @@ GpsModel probe(uart::Uart& uart) {
break;
}
TT_LOG_I(TAG, "Module Info : ");
TT_LOG_I(TAG, "Soft version: %s", ublox_info.swVersion);
TT_LOG_I(TAG, "Hard version: %s", ublox_info.hwVersion);
TT_LOG_I(TAG, "Extensions:%d", ublox_info.extensionNo);
LOGGER.info("Module Info:");
LOGGER.info("Soft version: {}", ublox_info.swVersion);
LOGGER.info("Hard version: {}", ublox_info.hwVersion);
LOGGER.info("Extensions: {}", ublox_info.extensionNo);
for (int i = 0; i < ublox_info.extensionNo; i++) {
TT_LOG_I(TAG, " %s", ublox_info.extension[i]);
LOGGER.info(" %s", ublox_info.extension[i]);
}
memset(buffer, 0, sizeof(buffer));
@@ -274,29 +273,29 @@ GpsModel probe(uart::Uart& uart) {
char* ptr = nullptr;
memset(buffer, 0, sizeof(buffer));
strncpy((char*)buffer, &(ublox_info.extension[i][8]), sizeof(buffer));
TT_LOG_I(TAG, "Protocol Version:%s", (char*)buffer);
LOGGER.info("Protocol Version: {}", (char*)buffer);
if (strlen((char*)buffer)) {
ublox_info.protocol_version = strtoul((char*)buffer, &ptr, 10);
TT_LOG_I(TAG, "ProtVer=%d", ublox_info.protocol_version);
LOGGER.info("ProtVer={}", ublox_info.protocol_version);
} else {
ublox_info.protocol_version = 0;
}
}
}
if (strncmp(ublox_info.hwVersion, "00040007", 8) == 0) {
TT_LOG_I(TAG, DETECTED_MESSAGE, "U-blox 6", "6");
LOGGER.info(DETECTED_MESSAGE, "U-blox 6", "6");
return GpsModel::UBLOX6;
} else if (strncmp(ublox_info.hwVersion, "00070000", 8) == 0) {
TT_LOG_I(TAG, DETECTED_MESSAGE, "U-blox 7", "7");
LOGGER.info(DETECTED_MESSAGE, "U-blox 7", "7");
return GpsModel::UBLOX7;
} else if (strncmp(ublox_info.hwVersion, "00080000", 8) == 0) {
TT_LOG_I(TAG, DETECTED_MESSAGE, "U-blox 8", "8");
LOGGER.info(DETECTED_MESSAGE, "U-blox 8", "8");
return GpsModel::UBLOX8;
} else if (strncmp(ublox_info.hwVersion, "00190000", 8) == 0) {
TT_LOG_I(TAG, DETECTED_MESSAGE, "U-blox 9", "9");
LOGGER.info(DETECTED_MESSAGE, "U-blox 9", "9");
return GpsModel::UBLOX9;
} else if (strncmp(ublox_info.hwVersion, "000A0000", 8) == 0) {
TT_LOG_I(TAG, DETECTED_MESSAGE, "U-blox 10", "10");
LOGGER.info(DETECTED_MESSAGE, "U-blox 10", "10");
return GpsModel::UBLOX10;
}
}
@@ -305,7 +304,7 @@ GpsModel probe(uart::Uart& uart) {
}
bool init(uart::Uart& uart, GpsModel model) {
TT_LOG_I(TAG, "U-blox init");
LOGGER.info("U-blox init");
switch (model) {
case GpsModel::UBLOX6:
return initUblox6(uart);
@@ -316,7 +315,7 @@ bool init(uart::Uart& uart, GpsModel model) {
case GpsModel::UBLOX10:
return initUblox10(uart);
default:
TT_LOG_E(TAG, "Unknown or unsupported U-blox model");
LOGGER.error("Unknown or unsupported U-blox model");
return false;
}
}
@@ -365,9 +364,9 @@ bool initUblox10(uart::Uart& uart) {
auto packet_size = makePacket(0x06, 0x09, _message_SAVE_10, sizeof(_message_SAVE_10), buffer);
uart.writeBytes(buffer, packet_size);
if (getAck(uart, 0x06, 0x09, 2000) != GpsResponse::Ok) {
TT_LOG_W(TAG, "Unable to save GNSS module config");
LOGGER.warn("Unable to save GNSS module config");
} else {
TT_LOG_I(TAG, "GNSS module configuration saved!");
LOGGER.info("GNSS module configuration saved!");
}
return true;
}
@@ -375,7 +374,7 @@ bool initUblox10(uart::Uart& uart) {
bool initUblox789(uart::Uart& uart, GpsModel model) {
uint8_t buffer[256];
if (model == GpsModel::UBLOX7) {
TT_LOG_D(TAG, "Set GPS+SBAS");
LOGGER.debug("Set GPS+SBAS");
auto msglen = makePacket(0x06, 0x3e, _message_GNSS_7, sizeof(_message_GNSS_7), buffer);
uart.writeBytes(buffer, msglen);
} else { // 8,9
@@ -385,12 +384,12 @@ bool initUblox789(uart::Uart& uart, GpsModel model) {
if (getAck(uart, 0x06, 0x3e, 800) == GpsResponse::NotAck) {
// It's not critical if the module doesn't acknowledge this configuration.
TT_LOG_D(TAG, "reconfigure GNSS - defaults maintained. Is this module GPS-only?");
LOGGER.debug("reconfigure GNSS - defaults maintained. Is this module GPS-only?");
} else {
if (model == GpsModel::UBLOX7) {
TT_LOG_I(TAG, "GPS+SBAS configured");
LOGGER.info("GPS+SBAS configured");
} else { // 8,9
TT_LOG_I(TAG, "GPS+SBAS+GLONASS+Galileo configured");
LOGGER.info("GPS+SBAS+GLONASS+Galileo configured");
}
// Documentation say, we need wait at least 0.5s after reconfiguration of GNSS module, before sending next
// commands for the M8 it tends to be more. 1 sec should be enough
@@ -439,9 +438,9 @@ bool initUblox789(uart::Uart& uart, GpsModel model) {
auto packet_size = makePacket(0x06, 0x09, _message_SAVE, sizeof(_message_SAVE), buffer);
uart.writeBytes(buffer, packet_size);
if (getAck(uart, 0x06, 0x09, 2000) != GpsResponse::Ok) {
TT_LOG_W(TAG, "Unable to save GNSS module config");
LOGGER.warn("Unable to save GNSS module config");
} else {
TT_LOG_I(TAG, "GNSS module configuration saved!");
LOGGER.info("GNSS module configuration saved!");
}
return true;
}
@@ -473,9 +472,9 @@ bool initUblox6(uart::Uart& uart) {
auto packet_size = makePacket(0x06, 0x09, _message_SAVE, sizeof(_message_SAVE), buffer);
uart.writeBytes(buffer, packet_size);
if (getAck(uart, 0x06, 0x09, 2000) != GpsResponse::Ok) {
TT_LOG_W(TAG, "Unable to save GNSS module config");
LOGGER.warn("Unable to save GNSS module config");
} else {
TT_LOG_I(TAG, "GNSS module config saved!");
LOGGER.info("GNSS module config saved!");
}
return true;
}
+24 -24
View File
@@ -1,12 +1,12 @@
#include "Tactility/hal/i2c/I2c.h"
#include <Tactility/hal/i2c/I2c.h>
#include <Tactility/Log.h>
#include <Tactility/Mutex.h>
#include <Tactility/Check.h>
#include <Tactility/Logger.h>
#include <Tactility/Mutex.h>
namespace tt::hal::i2c {
constexpr auto TAG = "i2c";
static const auto LOGGER = Logger("I2C");
struct Data {
Mutex mutex;
@@ -18,12 +18,12 @@ struct Data {
static const uint8_t ACK_CHECK_EN = 1;
static Data dataArray[I2C_NUM_MAX];
bool init(const std::vector<i2c::Configuration>& configurations) {
TT_LOG_I(TAG, "Init");
bool init(const std::vector<Configuration>& configurations) {
LOGGER.info("Init");
for (const auto& configuration: configurations) {
#ifdef ESP_PLATFORM
if (configuration.config.mode != I2C_MODE_MASTER) {
TT_LOG_E(TAG, "Currently only master mode is supported");
LOGGER.error("Currently only master mode is supported");
return false;
}
#endif // ESP_PLATFORM
@@ -51,10 +51,10 @@ bool configure(i2c_port_t port, const i2c_config_t& configuration) {
Data& data = dataArray[port];
if (data.isStarted) {
TT_LOG_E(TAG, "(%d) Cannot reconfigure while interface is started", port);
LOGGER.error("({}) Cannot reconfigure while interface is started", static_cast<int>(port));
return false;
} else if (!data.configuration.isMutable) {
TT_LOG_E(TAG, "(%d) Mutation not allowed because configuration is immutable", port);
LOGGER.error("({}) Mutation not allowed because configuration is immutable", static_cast<int>(port));
return false;
} else {
data.configuration.config = configuration;
@@ -70,32 +70,32 @@ bool start(i2c_port_t port) {
Configuration& config = data.configuration;
if (data.isStarted) {
TT_LOG_E(TAG, "(%d) Starting: Already started", port);
LOGGER.error("({}) Starting: Already started", static_cast<int>(port));
return false;
}
if (!data.isConfigured) {
TT_LOG_E(TAG, "(%d) Starting: Not configured", port);
LOGGER.error("({}) Starting: Not configured", static_cast<int>(port));
return false;
}
#ifdef ESP_PLATFORM
esp_err_t result = i2c_param_config(port, &config.config);
if (result != ESP_OK) {
TT_LOG_E(TAG, "(%d) Starting: Failed to configure: %s", port, esp_err_to_name(result));
LOGGER.error("({}) Starting: Failed to configure: {}", static_cast<int>(port), esp_err_to_name(result));
return false;
}
result = i2c_driver_install(port, config.config.mode, 0, 0, 0);
if (result != ESP_OK) {
TT_LOG_E(TAG, "(%d) Starting: Failed to install driver: %s", port, esp_err_to_name(result));
LOGGER.error("({}) Starting: Failed to install driver: {}", static_cast<int>(port), esp_err_to_name(result));
return false;
}
#endif // ESP_PLATFORM
data.isStarted = true;
TT_LOG_I(TAG, "(%d) Started", port);
LOGGER.info("({}) Started", static_cast<int>(port));
return true;
}
@@ -107,26 +107,26 @@ bool stop(i2c_port_t port) {
Configuration& config = data.configuration;
if (!config.isMutable) {
TT_LOG_E(TAG, "(%d) Stopping: Not allowed for immutable configuration", port);
LOGGER.error("({}) Stopping: Not allowed for immutable configuration", static_cast<int>(port));
return false;
}
if (!data.isStarted) {
TT_LOG_E(TAG, "(%d) Stopping: Not started", port);
LOGGER.error("({}) Stopping: Not started", static_cast<int>(port));
return false;
}
#ifdef ESP_PLATFORM
esp_err_t result = i2c_driver_delete(port);
if (result != ESP_OK) {
TT_LOG_E(TAG, "(%d) Stopping: Failed to delete driver: %s", port, esp_err_to_name(result));
LOGGER.error("({}) Stopping: Failed to delete driver: {}", static_cast<int>(port), esp_err_to_name(result));
return false;
}
#endif // ESP_PLATFORM
data.isStarted = false;
TT_LOG_I(TAG, "(%d) Stopped", port);
LOGGER.info("({}) Stopped", static_cast<int>(port));
return true;
}
@@ -139,7 +139,7 @@ bool isStarted(i2c_port_t port) {
bool masterRead(i2c_port_t port, uint8_t address, uint8_t* data, size_t dataSize, TickType_t timeout) {
auto lock = getLock(port).asScopedLock();
if (!lock.lock(timeout)) {
TT_LOG_E(TAG, "(%d) Mutex timeout", port);
LOGGER.error("({}) Mutex timeout", static_cast<int>(port));
return false;
}
@@ -155,7 +155,7 @@ bool masterRead(i2c_port_t port, uint8_t address, uint8_t* data, size_t dataSize
bool masterReadRegister(i2c_port_t port, uint8_t address, uint8_t reg, uint8_t* data, size_t dataSize, TickType_t timeout) {
auto lock = getLock(port).asScopedLock();
if (!lock.lock(timeout)) {
TT_LOG_E(TAG, "(%d) Mutex timeout", port);
LOGGER.error("({}) Mutex timeout", static_cast<int>(port));
return false;
}
@@ -188,7 +188,7 @@ bool masterReadRegister(i2c_port_t port, uint8_t address, uint8_t reg, uint8_t*
bool masterWrite(i2c_port_t port, uint8_t address, const uint8_t* data, uint16_t dataSize, TickType_t timeout) {
auto lock = getLock(port).asScopedLock();
if (!lock.lock(timeout)) {
TT_LOG_E(TAG, "(%d) Mutex timeout", port);
LOGGER.error("({}) Mutex timeout", static_cast<int>(port));
return false;
}
@@ -206,7 +206,7 @@ bool masterWriteRegister(i2c_port_t port, uint8_t address, uint8_t reg, const ui
auto lock = getLock(port).asScopedLock();
if (!lock.lock(timeout)) {
TT_LOG_E(TAG, "(%d) Mutex timeout", port);
LOGGER.error("({}) Mutex timeout", static_cast<int>(port));
return false;
}
@@ -248,7 +248,7 @@ bool masterWriteRegisterArray(i2c_port_t port, uint8_t address, const uint8_t* d
bool masterWriteRead(i2c_port_t port, uint8_t address, const uint8_t* writeData, size_t writeDataSize, uint8_t* readData, size_t readDataSize, TickType_t timeout) {
auto lock = getLock(port).asScopedLock();
if (!lock.lock(timeout)) {
TT_LOG_E(TAG, "(%d) Mutex timeout", port);
LOGGER.error("({}) Mutex timeout", static_cast<int>(port));
return false;
}
@@ -264,7 +264,7 @@ bool masterWriteRead(i2c_port_t port, uint8_t address, const uint8_t* writeData,
bool masterHasDeviceAtAddress(i2c_port_t port, uint8_t address, TickType_t timeout) {
auto lock = getLock(port).asScopedLock();
if (!lock.lock(timeout)) {
TT_LOG_E(TAG, "(%d) Mutex timeout", port);
LOGGER.error("({}) Mutex timeout", static_cast<int>(port));
return false;
}
@@ -1,17 +1,19 @@
#include <Tactility/hal/sdcard/SdCardMounting.h>
#include <Tactility/hal/sdcard/SdCardDevice.h>
#include <Tactility/Logger.h>
#include <format>
namespace tt::hal::sdcard {
constexpr auto* TAG = "SdCardMounting";
static const auto LOGGER = Logger("SdCardMounting");
constexpr auto* TT_SDCARD_MOUNT_POINT = "/sdcard";
static void mount(const std::shared_ptr<SdCardDevice>& sdcard, const std::string& path) {
TT_LOG_I(TAG, "Mounting sdcard at %s", path.c_str());
LOGGER.info("Mounting sdcard at {}", path);
if (!sdcard->mount(path)) {
TT_LOG_W(TAG, "SD card mount failed for %s (init can continue)", path.c_str());
LOGGER.warn("SD card mount failed for {} (init can continue)", path);
}
}
+10 -10
View File
@@ -5,7 +5,7 @@
#if defined(ESP_PLATFORM) && defined(SOC_SDMMC_HOST_SUPPORTED)
#include <Tactility/hal/sdcard/SdmmcDevice.h>
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#include <esp_vfs_fat.h>
#include <sdmmc_cmd.h>
@@ -13,10 +13,10 @@
namespace tt::hal::sdcard {
constexpr auto* TAG = "SdmmcDevice";
static const auto LOGGER = Logger("SdmmcDevice");
bool SdmmcDevice::mountInternal(const std::string& newMountPath) {
TT_LOG_I(TAG, "Mounting %s", newMountPath.c_str());
LOGGER.info("Mounting {}", newMountPath);
esp_vfs_fat_sdmmc_mount_config_t mount_config = {
.format_if_mount_failed = config->formatOnMountFailed,
@@ -49,9 +49,9 @@ bool SdmmcDevice::mountInternal(const std::string& newMountPath) {
if (result != ESP_OK || card == nullptr) {
if (result == ESP_FAIL) {
TT_LOG_E(TAG, "Mounting failed. Ensure the card is formatted with FAT.");
LOGGER.error("Mounting failed. Ensure the card is formatted with FAT.");
} else {
TT_LOG_E(TAG, "Mounting failed (%s)", esp_err_to_name(result));
LOGGER.error("Mounting failed ({})", esp_err_to_name(result));
}
return false;
}
@@ -66,11 +66,11 @@ bool SdmmcDevice::mount(const std::string& newMountPath) {
lock.lock();
if (mountInternal(newMountPath)) {
TT_LOG_I(TAG, "Mounted at %s", newMountPath.c_str());
LOGGER.info("Mounted at {}", newMountPath);
sdmmc_card_print_info(stdout, card);
return true;
} else {
TT_LOG_E(TAG, "Mount failed for %s", newMountPath.c_str());
LOGGER.error("Mount failed for {}", newMountPath);
return false;
}
}
@@ -80,16 +80,16 @@ bool SdmmcDevice::unmount() {
lock.lock();
if (card == nullptr) {
TT_LOG_E(TAG, "Can't unmount: not mounted");
LOGGER.error("Can't unmount: not mounted");
return false;
}
if (esp_vfs_fat_sdcard_unmount(mountPath.c_str(), card) != ESP_OK) {
TT_LOG_E(TAG, "Unmount failed for %s", mountPath.c_str());
LOGGER.error("Unmount failed for {}", mountPath);
return false;
}
TT_LOG_I(TAG, "Unmounted %s", mountPath.c_str());
LOGGER.info("Unmounted {}", mountPath);
mountPath = "";
card = nullptr;
return true;
+14 -14
View File
@@ -2,14 +2,14 @@
#include <Tactility/hal/gpio/Gpio.h>
#include <Tactility/hal/sdcard/SpiSdCardDevice.h>
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#include <esp_vfs_fat.h>
#include <sdmmc_cmd.h>
namespace tt::hal::sdcard {
constexpr auto* TAG = "SpiSdCardDevice";
static const auto LOGGER = Logger("SpiSdCardDevice");
/**
* Before we can initialize the sdcard's SPI communications, we have to set all
@@ -19,7 +19,7 @@ constexpr auto* TAG = "SpiSdCardDevice";
* @return success result
*/
bool SpiSdCardDevice::applyGpioWorkAround() {
TT_LOG_D(TAG, "init");
LOGGER.info("applyGpioWorkAround");
uint64_t pin_bit_mask = BIT64(config->spiPinCs);
for (auto const& pin: config->csPinWorkAround) {
@@ -27,13 +27,13 @@ bool SpiSdCardDevice::applyGpioWorkAround() {
}
if (!gpio::configureWithPinBitmask(pin_bit_mask, gpio::Mode::Output, false, false)) {
TT_LOG_E(TAG, "GPIO init failed");
LOGGER.error("GPIO work-around failed");
return false;
}
for (auto const& pin: config->csPinWorkAround) {
if (!gpio::setLevel(pin, true)) {
TT_LOG_E(TAG, "Failed to set board CS pin high");
LOGGER.error("Failed to set board CS pin high");
return false;
}
}
@@ -42,7 +42,7 @@ bool SpiSdCardDevice::applyGpioWorkAround() {
}
bool SpiSdCardDevice::mountInternal(const std::string& newMountPath) {
TT_LOG_I(TAG, "Mounting %s", newMountPath.c_str());
LOGGER.info("Mounting {}", newMountPath);
esp_vfs_fat_sdmmc_mount_config_t mount_config = {
.format_if_mount_failed = config->formatOnMountFailed,
@@ -71,9 +71,9 @@ bool SpiSdCardDevice::mountInternal(const std::string& newMountPath) {
if (result != ESP_OK || card == nullptr) {
if (result == ESP_FAIL) {
TT_LOG_E(TAG, "Mounting failed. Ensure the card is formatted with FAT.");
LOGGER.error("Mounting failed. Ensure the card is formatted with FAT.");
} else {
TT_LOG_E(TAG, "Mounting failed (%s)", esp_err_to_name(result));
LOGGER.error("Mounting failed ({})", esp_err_to_name(result));
}
return false;
}
@@ -88,16 +88,16 @@ bool SpiSdCardDevice::mount(const std::string& newMountPath) {
lock.lock();
if (!applyGpioWorkAround()) {
TT_LOG_E(TAG, "Failed to apply GPIO work-around");
LOGGER.error("Failed to apply GPIO work-around");
return false;
}
if (mountInternal(newMountPath)) {
TT_LOG_I(TAG, "Mounted at %s", newMountPath.c_str());
LOGGER.info("Mounted at {}", newMountPath);
sdmmc_card_print_info(stdout, card);
return true;
} else {
TT_LOG_E(TAG, "Mount failed for %s", newMountPath.c_str());
LOGGER.error("Mount failed for {}", newMountPath);
return false;
}
}
@@ -107,16 +107,16 @@ bool SpiSdCardDevice::unmount() {
lock.lock();
if (card == nullptr) {
TT_LOG_E(TAG, "Can't unmount: not mounted");
LOGGER.error("Can't unmount: not mounted");
return false;
}
if (esp_vfs_fat_sdcard_unmount(mountPath.c_str(), card) != ESP_OK) {
TT_LOG_E(TAG, "Unmount failed for %s", mountPath.c_str());
LOGGER.error("Unmount failed for {}", mountPath);
return false;
}
TT_LOG_I(TAG, "Unmounted %s", mountPath.c_str());
LOGGER.info("Unmounted {}", mountPath);
mountPath = "";
card = nullptr;
return true;
+13 -13
View File
@@ -1,11 +1,11 @@
#include <Tactility/hal/spi/Spi.h>
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#include <Tactility/RecursiveMutex.h>
namespace tt::hal::spi {
constexpr auto* TAG = "SPI";
static const auto LOGGER = Logger("SPI");
struct Data {
std::shared_ptr<Lock> lock;
@@ -17,7 +17,7 @@ struct Data {
static Data dataArray[SPI_HOST_MAX];
bool init(const std::vector<Configuration>& configurations) {
TT_LOG_I(TAG, "Init");
LOGGER.info("Init");
for (const auto& configuration: configurations) {
Data& data = dataArray[configuration.device];
data.configuration = configuration;
@@ -48,10 +48,10 @@ bool configure(spi_host_device_t device, const spi_bus_config_t& configuration)
Data& data = dataArray[device];
if (data.isStarted) {
TT_LOG_E(TAG, "(%d) Cannot reconfigure while interface is started", device);
LOGGER.error("({}) Cannot reconfigure while interface is started", static_cast<int>(device));
return false;
} else if (!data.configuration.isMutable) {
TT_LOG_E(TAG, "(%d) Mutation not allowed by original configuration", device);
LOGGER.error("({}) Mutation not allowed by original configuration", static_cast<int>(device));
return false;
} else {
data.configuration.config = configuration;
@@ -66,12 +66,12 @@ bool start(spi_host_device_t device) {
Data& data = dataArray[device];
if (data.isStarted) {
TT_LOG_E(TAG, "(%d) Starting: Already started", device);
LOGGER.error("({}) Starting: Already started", static_cast<int>(device));
return false;
}
if (!data.isConfigured) {
TT_LOG_E(TAG, "(%d) Starting: Not configured", device);
LOGGER.error("({}) Starting: Not configured", static_cast<int>(device));
return false;
}
@@ -79,7 +79,7 @@ bool start(spi_host_device_t device) {
auto result = spi_bus_initialize(device, &data.configuration.config, data.configuration.dma);
if (result != ESP_OK) {
TT_LOG_E(TAG, "(%d) Starting: Failed to initialize: %s", device, esp_err_to_name(result));
LOGGER.error("({}) Starting: Failed to initialize: {}", static_cast<int>(device), esp_err_to_name(result));
return false;
} else {
data.isStarted = true;
@@ -91,7 +91,7 @@ bool start(spi_host_device_t device) {
#endif
TT_LOG_I(TAG, "(%d) Started", device);
LOGGER.info("({}) Started", static_cast<int>(device));
return true;
}
@@ -103,12 +103,12 @@ bool stop(spi_host_device_t device) {
Configuration& config = data.configuration;
if (!config.isMutable) {
TT_LOG_E(TAG, "(%d) Stopping: Not allowed, immutable", device);
LOGGER.error("({}) Stopping: Not allowed, immutable", static_cast<int>(device));
return false;
}
if (!data.isStarted) {
TT_LOG_E(TAG, "(%d) Stopping: Not started", device);
LOGGER.error("({}) Stopping: Not started", static_cast<int>(device));
return false;
}
@@ -116,7 +116,7 @@ bool stop(spi_host_device_t device) {
auto result = spi_bus_free(device);
if (result != ESP_OK) {
TT_LOG_E(TAG, "(%d) Stopping: Failed to free device: %s", device, esp_err_to_name(result));
LOGGER.error("({}) Stopping: Failed to free device: {}", static_cast<int>(device), esp_err_to_name(result));
return false;
} else {
data.isStarted = false;
@@ -128,7 +128,7 @@ bool stop(spi_host_device_t device) {
#endif
TT_LOG_I(TAG, "(%d) Stopped", device);
LOGGER.info("({}) Stopped", static_cast<int>(device));
return true;
}
+14 -14
View File
@@ -1,6 +1,6 @@
#include "Tactility/hal/uart/Uart.h"
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#include <Tactility/Mutex.h>
#include <ranges>
@@ -15,10 +15,10 @@
#include <dirent.h>
#endif
#define TAG "uart"
namespace tt::hal::uart {
static const auto LOGGER = Logger("UART");
constexpr uint32_t uartIdNotInUse = 0;
struct UartEntry {
@@ -30,7 +30,7 @@ static std::vector<UartEntry> uartEntries = {};
static uint32_t lastUartId = uartIdNotInUse;
bool init(const std::vector<Configuration>& configurations) {
TT_LOG_I(TAG, "Init");
LOGGER.info("Init");
for (const auto& configuration: configurations) {
uartEntries.push_back({
.usageId = uartIdNotInUse,
@@ -78,7 +78,7 @@ size_t Uart::readUntil(std::byte* buffer, size_t bufferSize, uint8_t untilByte,
TickType_t now = kernel::getTicks();
if (now > (start_time + timeout)) {
#ifdef DEBUG_READ_UNTIL
TT_LOG_W(TAG, "readUntil() timeout");
LOGGER.warn("readUntil() timeout");
#endif
break;
} else {
@@ -102,26 +102,26 @@ size_t Uart::readUntil(std::byte* buffer, size_t bufferSize, uint8_t untilByte,
static std::unique_ptr<Uart> open(UartEntry& entry) {
if (entry.usageId != uartIdNotInUse) {
TT_LOG_E(TAG, "UART in use: %s", entry.configuration.name.c_str());
LOGGER.error("UART in use: {}", entry.configuration.name);
return nullptr;
}
auto uart = create(entry.configuration);
assert(uart != nullptr);
entry.usageId = uart->getId();
TT_LOG_I(TAG, "Opened %lu", entry.usageId);
LOGGER.info("Opened {}", entry.usageId);
return uart;
}
std::unique_ptr<Uart> open(uart_port_t port) {
TT_LOG_I(TAG, "Open %d", port);
LOGGER.info("Open {}", static_cast<int>(port));
auto result = std::views::filter(uartEntries, [port](auto& entry) {
return entry.configuration.port == port;
});
if (result.empty()) {
TT_LOG_E(TAG, "UART not found: %d", port);
LOGGER.error("UART not found: {}", static_cast<int>(port));
return nullptr;
}
@@ -129,14 +129,14 @@ std::unique_ptr<Uart> open(uart_port_t port) {
}
std::unique_ptr<Uart> open(std::string name) {
TT_LOG_I(TAG, "Open %s", name.c_str());
LOGGER.info("Open {}", name);
auto result = std::views::filter(uartEntries, [&name](auto& entry) {
return entry.configuration.name == name;
});
if (result.empty()) {
TT_LOG_E(TAG, "UART not found: %s", name.c_str());
LOGGER.error("UART not found: {}", name);
return nullptr;
}
@@ -144,7 +144,7 @@ std::unique_ptr<Uart> open(std::string name) {
}
void close(uint32_t uartId) {
TT_LOG_I(TAG, "Close %lu", uartId);
LOGGER.info("Close {}", uartId);
auto result = std::views::filter(uartEntries, [&uartId](auto& entry) {
return entry.usageId == uartId;
});
@@ -153,7 +153,7 @@ void close(uint32_t uartId) {
auto& entry = *result.begin();
entry.usageId = uartIdNotInUse;
} else {
TT_LOG_W(TAG, "Auto-closing UART, but can't find it");
LOGGER.warn("Auto-closing UART, but can't find it");
}
}
@@ -166,7 +166,7 @@ std::vector<std::string> getNames() {
#else
DIR* dir = opendir("/dev");
if (dir == nullptr) {
TT_LOG_E(TAG, "Failed to read /dev");
LOGGER.error("Failed to read /dev");
return names;
}
struct dirent* current_entry;
+13 -13
View File
@@ -2,7 +2,7 @@
#include <Tactility/hal/uart/UartEsp.h>
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#include <Tactility/kernel/Kernel.h>
#include <Tactility/Mutex.h>
@@ -11,16 +11,16 @@
namespace tt::hal::uart {
constexpr auto TAG = "uart";
static const auto LOGGER = Logger("UART");
bool UartEsp::start() {
TT_LOG_I(TAG, "[%s] Starting", configuration.name.c_str());
LOGGER.info("[{}] Starting", configuration.name);
auto lock = mutex.asScopedLock();
lock.lock();
if (started) {
TT_LOG_E(TAG, "[%s] Starting: Already started", configuration.name.c_str());
LOGGER.error("[{}] Starting: Already started", configuration.name);
return false;
}
@@ -33,53 +33,53 @@ bool UartEsp::start() {
esp_err_t result = uart_param_config(configuration.port, &configuration.config);
if (result != ESP_OK) {
TT_LOG_E(TAG, "[%s] Starting: Failed to configure: %s", configuration.name.c_str(), esp_err_to_name(result));
LOGGER.error("[{}] Starting: Failed to configure: {}", configuration.name, esp_err_to_name(result));
return false;
}
if (uart_is_driver_installed(configuration.port)) {
TT_LOG_W(TAG, "[%s] Driver was still installed. You probably forgot to stop, or another system uses/used the driver.", configuration.name.c_str());
LOGGER.error("[{}] Driver was still installed. You probably forgot to stop, or another system uses/used the driver.", configuration.name);
uart_driver_delete(configuration.port);
}
result = uart_set_pin(configuration.port, configuration.txPin, configuration.rxPin, configuration.rtsPin, configuration.ctsPin);
if (result != ESP_OK) {
TT_LOG_E(TAG, "[%s] Starting: Failed set pins: %s", configuration.name.c_str(), esp_err_to_name(result));
LOGGER.error("[{}] Starting: Failed set pins: {}", configuration.name, esp_err_to_name(result));
return false;
}
result = uart_driver_install(configuration.port, (int)configuration.rxBufferSize, (int)configuration.txBufferSize, 0, nullptr, intr_alloc_flags);
if (result != ESP_OK) {
TT_LOG_E(TAG, "[%s] Starting: Failed to install driver: %s", configuration.name.c_str(), esp_err_to_name(result));
LOGGER.error("[{}] Starting: Failed to install driver: {}", configuration.name, esp_err_to_name(result));
return false;
}
started = true;
TT_LOG_I(TAG, "[%s] Started", configuration.name.c_str());
LOGGER.info("[{}] Started", configuration.name);
return true;
}
bool UartEsp::stop() {
TT_LOG_I(TAG, "[%s] Stopping", configuration.name.c_str());
LOGGER.info("[{}] Stopping", configuration.name);
auto lock = mutex.asScopedLock();
lock.lock();
if (!started) {
TT_LOG_E(TAG, "[%s] Stopping: Not started", configuration.name.c_str());
LOGGER.error("[{}] Stopping: Not started", configuration.name);
return false;
}
esp_err_t result = uart_driver_delete(configuration.port);
if (result != ESP_OK) {
TT_LOG_E(TAG, "[%s] Stopping: Failed to delete driver: %s", configuration.name.c_str(), esp_err_to_name(result));
LOGGER.error("[{}] Stopping: Failed to delete driver: {}", configuration.name, esp_err_to_name(result));
return false;
}
started = false;
TT_LOG_I(TAG, "[%s] Stopped", configuration.name.c_str());
LOGGER.info("[{}] Stopped", configuration.name);
return true;
}
+15 -15
View File
@@ -3,7 +3,7 @@
#include <Tactility/hal/uart/UartPosix.h>
#include <Tactility/hal/uart/Uart.h>
#include <Tactility/kernel/Kernel.h>
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#include <cstring>
#include <sstream>
@@ -12,20 +12,20 @@
namespace tt::hal::uart {
constexpr auto TAG = "uart";
static const auto LOGGER = Logger("UART");
bool UartPosix::start() {
auto lock = mutex.asScopedLock();
lock.lock();
if (device != nullptr) {
TT_LOG_E(TAG, "[%s] Starting: Already started", configuration.name.c_str());
LOGGER.error("[{}] Starting: Already started", configuration.name);
return false;
}
auto file = fopen(configuration.name.c_str(), "w");
if (file == nullptr) {
TT_LOG_E(TAG, "[%s] Open device failed", configuration.name.c_str());
LOGGER.error("[{}] Open device failed", configuration.name);
return false;
}
@@ -33,16 +33,16 @@ bool UartPosix::start() {
struct termios tty;
if (tcgetattr(fileno(file), &tty) < 0) {
printf("[%s] tcgetattr failed: %s\n", configuration.name.c_str(), strerror(errno));
LOGGER.error("[{}] tcgetattr failed: {}", configuration.name, strerror(errno));
return false;
}
if (cfsetospeed(&tty, (speed_t)configuration.baudRate) == -1) {
TT_LOG_E(TAG, "[%s] Setting output speed failed", configuration.name.c_str());
LOGGER.error("[{}] Setting output speed failed", configuration.name);
}
if (cfsetispeed(&tty, (speed_t)configuration.baudRate) == -1) {
TT_LOG_E(TAG, "[%s] Setting input speed failed", configuration.name.c_str());
LOGGER.error("[{}] Setting input speed failed", configuration.name);
}
tty.c_cflag |= (CLOCAL | CREAD); /* ignore modem controls */
@@ -61,13 +61,13 @@ bool UartPosix::start() {
tty.c_cc[VTIME] = 1;
if (tcsetattr(fileno(file), TCSANOW, &tty) != 0) {
printf("[%s] tcsetattr failed: %s\n", configuration.name.c_str(), strerror(errno));
LOGGER.error("[{}] tcsetattr failed: {}", configuration.name, strerror(errno));
return false;
}
device = std::move(new_device);
TT_LOG_I(TAG, "[%s] Started", configuration.name.c_str());
LOGGER.info("[{}] Started", configuration.name);
return true;
}
@@ -76,13 +76,13 @@ bool UartPosix::stop() {
lock.lock();
if (device == nullptr) {
TT_LOG_E(TAG, "[%s] Stopping: Not started", configuration.name.c_str());
LOGGER.error("[{}] Stopping: Not started", configuration.name);
return false;
}
device = nullptr;
TT_LOG_I(TAG, "[%s] Stopped", configuration.name.c_str());
LOGGER.info("[{}] Stopped", configuration.name);
return true;
}
@@ -139,7 +139,7 @@ void UartPosix::flushInput() {
uint32_t UartPosix::getBaudRate() {
struct termios tty;
if (tcgetattr(fileno(device.get()), &tty) < 0) {
printf("[%s] tcgetattr failed: %s\n", configuration.name.c_str(), strerror(errno));
LOGGER.error("[{}] tcgetattr failed: {}", configuration.name, strerror(errno));
return false;
} else {
return (uint32_t)cfgetispeed(&tty);
@@ -154,17 +154,17 @@ bool UartPosix::setBaudRate(uint32_t baudRate, TickType_t timeout) {
struct termios tty;
if (tcgetattr(fileno(device.get()), &tty) < 0) {
printf("[%s] tcgetattr failed: %s\n", configuration.name.c_str(), strerror(errno));
LOGGER.error("[{}] tcgetattr failed: {}", configuration.name, strerror(errno));
return false;
}
if (cfsetospeed(&tty, (speed_t)configuration.baudRate) == -1) {
TT_LOG_E(TAG, "[%s] Failed to set output speed", configuration.name.c_str());
LOGGER.error("[{}] Failed to set output speed", configuration.name);
return false;
}
if (cfsetispeed(&tty, (speed_t)configuration.baudRate) == -1) {
TT_LOG_E(TAG, "[%s] Failed to set input speed", configuration.name.c_str());
LOGGER.error("[{}] Failed to set input speed", configuration.name);
return false;
}
+9 -8
View File
@@ -4,11 +4,12 @@
#include <Tactility/hal/sdcard/SpiSdCardDevice.h>
#include <Tactility/hal/usb/UsbTusb.h>
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
namespace tt::hal::usb {
constexpr auto* TAG = "usb";
static const auto LOGGER = Logger("USB");
constexpr auto BOOT_FLAG_SDMMC = 42; // Existing
constexpr auto BOOT_FLAG_FLASH = 43; // For flash mode
@@ -32,13 +33,13 @@ sdmmc_card_t* _Nullable getCard() {
}
if (usable_sdcard == nullptr) {
TT_LOG_W(TAG, "Couldn't find a mounted SpiSdCard");
LOGGER.warn("Couldn't find a mounted SpiSdCard");
return nullptr;
}
auto* sdmmc_card = usable_sdcard->getCard();
if (sdmmc_card == nullptr) {
TT_LOG_W(TAG, "SD card has no card object available");
LOGGER.warn("SD card has no card object available");
return nullptr;
}
@@ -55,7 +56,7 @@ bool isSupported() {
bool startMassStorageWithSdmmc() {
if (!canStartNewMode()) {
TT_LOG_E(TAG, "Can't start");
LOGGER.error("Can't start");
return false;
}
@@ -63,7 +64,7 @@ bool startMassStorageWithSdmmc() {
currentMode = Mode::MassStorageSdmmc;
return true;
} else {
TT_LOG_E(TAG, "Failed to init mass storage");
LOGGER.error("Failed to init mass storage");
return false;
}
}
@@ -96,7 +97,7 @@ void rebootIntoMassStorageSdmmc() {
// NEW: Flash mass storage functions
bool startMassStorageWithFlash() {
if (!canStartNewMode()) {
TT_LOG_E(TAG, "Can't start flash mass storage");
LOGGER.error("Can't start flash mass storage");
return false;
}
@@ -104,7 +105,7 @@ bool startMassStorageWithFlash() {
currentMode = Mode::MassStorageFlash;
return true;
} else {
TT_LOG_E(TAG, "Failed to init flash mass storage");
LOGGER.error("Failed to init flash mass storage");
return false;
}
}
-2
View File
@@ -2,8 +2,6 @@
#include "Tactility/hal/usb/Usb.h"
#define TAG "usb"
namespace tt::hal::usb {
bool startMassStorageWithSdmmc() { return false; }
+13 -12
View File
@@ -7,16 +7,17 @@
#if CONFIG_TINYUSB_MSC_ENABLED == 1
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#include <tinyusb.h>
#include <tusb_msc_storage.h>
#include <wear_levelling.h>
#define TAG "usb"
#define EPNUM_MSC 1
#define TUSB_DESC_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_MSC_DESC_LEN)
#define SECTOR_SIZE 512
static const auto LOGGER = tt::Logger("USB");
namespace tt::hal::usb {
extern sdmmc_card_t* _Nullable getCard();
}
@@ -93,9 +94,9 @@ static uint8_t const msc_hs_configuration_desc[] = {
static void storage_mount_changed_cb(tinyusb_msc_event_t* event) {
if (event->mount_changed_data.is_mounted) {
TT_LOG_I(TAG, "MSC Mounted");
LOGGER.info("MSC Mounted");
} else {
TT_LOG_I(TAG, "MSC Unmounted");
LOGGER.info("MSC Unmounted");
}
}
@@ -121,7 +122,7 @@ static bool ensureDriverInstalled() {
};
if (tinyusb_driver_install(&tusb_cfg) != ESP_OK) {
TT_LOG_E(TAG, "Failed to install TinyUSB driver");
LOGGER.error("Failed to install TinyUSB driver");
return false;
}
@@ -136,7 +137,7 @@ bool tusbStartMassStorageWithSdmmc() {
auto* card = tt::hal::usb::getCard();
if (card == nullptr) {
TT_LOG_E(TAG, "SD card not mounted");
LOGGER.error("SD card not mounted");
return false;
}
@@ -155,21 +156,21 @@ bool tusbStartMassStorageWithSdmmc() {
auto result = tinyusb_msc_storage_init_sdmmc(&config_sdmmc);
if (result != ESP_OK) {
TT_LOG_E(TAG, "TinyUSB SDMMC init failed: %s", esp_err_to_name(result));
LOGGER.error("TinyUSB SDMMC init failed: {}", esp_err_to_name(result));
} else {
TT_LOG_I(TAG, "TinyUSB SDMMC init success");
LOGGER.info("TinyUSB SDMMC init success");
}
return result == ESP_OK;
}
bool tusbStartMassStorageWithFlash() {
TT_LOG_I(TAG, "Starting flash MSC");
LOGGER.info("Starting flash MSC");
ensureDriverInstalled();
wl_handle_t handle = tt::getDataPartitionWlHandle();
if (handle == WL_INVALID_HANDLE) {
TT_LOG_E(TAG, "WL not mounted for /data");
LOGGER.error("WL not mounted for /data");
return false;
}
@@ -188,9 +189,9 @@ bool tusbStartMassStorageWithFlash() {
esp_err_t result = tinyusb_msc_storage_init_spiflash(&config_flash);
if (result != ESP_OK) {
TT_LOG_E(TAG, "TinyUSB flash init failed: %s", esp_err_to_name(result));
LOGGER.error("TinyUSB flash init failed: {}", esp_err_to_name(result));
} else {
TT_LOG_I(TAG, "TinyUSB flash init success");
LOGGER.info("TinyUSB flash init success");
}
return result == ESP_OK;
}
+9 -9
View File
@@ -1,16 +1,16 @@
#include "Tactility/i18n/TextResources.h"
#include "Tactility/file/FileLock.h"
#include <Tactility/i18n/TextResources.h>
#include <Tactility/file/FileLock.h>
#include <Tactility/file/File.h>
#include <Tactility/Logger.h>
#include <Tactility/settings/Language.h>
#include <cstring>
#include <format>
#include <utility>
#include <Tactility/settings/Language.h>
namespace tt::i18n {
constexpr auto* TAG = "I18n";
static const auto LOGGER = Logger("I18n");
static std::string getFallbackLocale() {
return "en-US";
@@ -39,7 +39,7 @@ static std::string getI18nDataFilePath(const std::string& path) {
if (file::isFile(desired_file_path)) {
return desired_file_path;
} else {
TT_LOG_W(TAG, "Translations not found for %s at %s", locale.c_str(), desired_file_path.c_str());
LOGGER.warn("Translations not found for {} at {}", locale, desired_file_path);
}
auto fallback_locale = getFallbackLocale();
@@ -47,7 +47,7 @@ static std::string getI18nDataFilePath(const std::string& path) {
if (file::isFile(fallback_file_path)) {
return fallback_file_path;
} else {
TT_LOG_W(TAG, "Fallback translations not found for %s at %s", fallback_locale.c_str(), fallback_file_path.c_str());
LOGGER.warn("Fallback translations not found for {} at {}", fallback_locale, fallback_file_path);
return "";
}
}
@@ -60,7 +60,7 @@ bool TextResources::load() {
// Resolve the language file that we need (depends on system language selection)
auto file_path = getI18nDataFilePath(path);
if (file_path.empty()) {
TT_LOG_E(TAG, "Couldn't find i18n data for %s", path.c_str());
LOGGER.error("Couldn't find i18n data for {}", path);
return false;
}
@@ -69,7 +69,7 @@ bool TextResources::load() {
});
if (new_data.empty()) {
TT_LOG_E(TAG, "Couldn't find i18n data for %s", path.c_str());
LOGGER.error("Couldn't find i18n data for {}", path);
return false;
}
+6 -6
View File
@@ -1,14 +1,14 @@
#include <Tactility/kernel/SystemEvents.h>
#include <Tactility/Check.h>
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#include <Tactility/Mutex.h>
#include <list>
namespace tt::kernel {
constexpr auto* TAG = "SystemEvents";
static const auto LOGGER = Logger("SystemEvents");
struct SubscriptionData {
SystemEventSubscription id;
@@ -57,9 +57,9 @@ static const char* getEventName(SystemEvent event) {
}
void publishSystemEvent(SystemEvent event) {
TT_LOG_I(TAG, "%s", getEventName(event));
LOGGER.info("{}", getEventName(event));
if (mutex.lock(kernel::MAX_TICKS)) {
if (mutex.lock(MAX_TICKS)) {
for (auto& subscription : subscriptions) {
if (subscription.event == event) {
subscription.handler(event);
@@ -71,7 +71,7 @@ void publishSystemEvent(SystemEvent event) {
}
SystemEventSubscription subscribeSystemEvent(SystemEvent event, OnSystemEvent handler) {
if (mutex.lock(kernel::MAX_TICKS)) {
if (mutex.lock(MAX_TICKS)) {
auto id = ++subscriptionCounter;
subscriptions.push_back({
@@ -88,7 +88,7 @@ SystemEventSubscription subscribeSystemEvent(SystemEvent event, OnSystemEvent ha
}
void unsubscribeSystemEvent(SystemEventSubscription subscription) {
if (mutex.lock(kernel::MAX_TICKS)) {
if (mutex.lock(MAX_TICKS)) {
std::erase_if(subscriptions, [subscription](auto& item) {
return (item.id == subscription);
});
+8 -7
View File
@@ -2,32 +2,33 @@
#include <Tactility/Thread.h>
#include <Tactility/CpuAffinity.h>
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#include <Tactility/Mutex.h>
#include <Tactility/lvgl/LvglSync.h>
#include <esp_lvgl_port.h>
namespace tt::lvgl {
// LVGL
// The minimum task stack seems to be about 3500, but that crashes the wifi app in some scenarios
// At 8192, it sometimes crashes when wifi-auto enables and is busy connecting and then you open WifiManage
#define TDECK_LVGL_TASK_STACK_DEPTH 9216
auto constexpr TAG = "lvgl";
constexpr auto LVGL_TASK_STACK_DEPTH = 9216;
namespace tt::lvgl {
static const auto LOGGER = Logger("EspLvglPort");
bool initEspLvglPort() {
TT_LOG_D(TAG, "Port init");
LOGGER.debug("Init");
const lvgl_port_cfg_t lvgl_cfg = {
.task_priority = static_cast<UBaseType_t>(Thread::Priority::Critical),
.task_stack = TDECK_LVGL_TASK_STACK_DEPTH,
.task_stack = LVGL_TASK_STACK_DEPTH,
.task_affinity = getCpuAffinityConfiguration().graphics,
.task_max_sleep_ms = 500,
.timer_period_ms = 5
};
if (lvgl_port_init(&lvgl_cfg) != ESP_OK) {
TT_LOG_E(TAG, "Port init failed");
LOGGER.error("Init failed");
return false;
}
+3 -5
View File
@@ -1,11 +1,9 @@
#include "Tactility/lvgl/LabelUtils.h"
#include "Tactility/file/File.h"
#include "Tactility/file/FileLock.h"
#include <Tactility/lvgl/LabelUtils.h>
#include <Tactility/file/File.h>
#include <Tactility/file/FileLock.h>
namespace tt::lvgl {
constexpr auto* TAG = "LabelUtils";
bool label_set_text_file(lv_obj_t* label, const char* filepath) {
std::unique_ptr<uint8_t[]> text;
file::getLock(filepath)->withLock([&text, filepath] {
+32 -31
View File
@@ -3,6 +3,7 @@
#include <Tactility/hal/display/DisplayDevice.h>
#include <Tactility/hal/keyboard/KeyboardDevice.h>
#include <Tactility/hal/touch/TouchDevice.h>
#include <Tactility/Logger.h>
#include <Tactility/lvgl/Keyboard.h>
#include <Tactility/lvgl/Lvgl.h>
#include <Tactility/lvgl/LvglSync.h>
@@ -18,12 +19,12 @@
namespace tt::lvgl {
constexpr auto* TAG = "Lvgl";
static const auto LOGGER = Logger("Lvgl");
static bool started = false;
void init(const hal::Configuration& config) {
TT_LOG_I(TAG, "Init started");
LOGGER.info("Init started");
#ifdef ESP_PLATFORM
if (config.lvglInit == hal::LvglInit::Default && !initEspLvglPort()) {
@@ -33,7 +34,7 @@ void init(const hal::Configuration& config) {
start();
TT_LOG_I(TAG, "Init finished");
LOGGER.info("Init finished");
}
bool isStarted() {
@@ -41,10 +42,10 @@ bool isStarted() {
}
void start() {
TT_LOG_I(TAG, "Start LVGL");
LOGGER.info("Start LVGL");
if (started) {
TT_LOG_W(TAG, "Can't start LVGL twice");
LOGGER.warn("Can't start LVGL twice");
return;
}
@@ -53,12 +54,12 @@ void start() {
// Start displays (their related touch devices start automatically within)
TT_LOG_I(TAG, "Start displays");
LOGGER.info("Start displays");
auto displays = hal::findDevices<hal::display::DisplayDevice>(hal::Device::Type::Display);
for (auto display : displays) {
for (const auto& display : displays) {
if (display->supportsLvgl()) {
if (display->startLvgl()) {
TT_LOG_I(TAG, "Started %s", display->getName().c_str());
LOGGER.info("Started {}", display->getName());
auto lvgl_display = display->getLvglDisplay();
assert(lvgl_display != nullptr);
auto settings = settings::display::loadOrGetDefault();
@@ -67,7 +68,7 @@ void start() {
lv_display_set_rotation(lvgl_display, rotation);
}
} else {
TT_LOG_E(TAG, "Start failed for %s", display->getName().c_str());
LOGGER.error("Start failed for {}", display->getName());
}
}
}
@@ -79,42 +80,42 @@ void start() {
// Start display-related peripherals
if (primary_display != nullptr) {
TT_LOG_I(TAG, "Start touch devices");
LOGGER.info("Start touch devices");
auto touch_devices = hal::findDevices<hal::touch::TouchDevice>(hal::Device::Type::Touch);
for (auto touch_device : touch_devices) {
for (const auto& touch_device : touch_devices) {
// Start any touch devices that haven't been started yet
if (touch_device->supportsLvgl() && touch_device->getLvglIndev() == nullptr) {
if (touch_device->startLvgl(primary_display->getLvglDisplay())) {
TT_LOG_I(TAG, "Started %s", touch_device->getName().c_str());
LOGGER.info("Started {}", touch_device->getName());
} else {
TT_LOG_E(TAG, "Start failed for %s", touch_device->getName().c_str());
LOGGER.error("Start failed for {}", touch_device->getName());
}
}
}
// Start keyboards
TT_LOG_I(TAG, "Start keyboards");
LOGGER.info("Start keyboards");
auto keyboards = hal::findDevices<hal::keyboard::KeyboardDevice>(hal::Device::Type::Keyboard);
for (auto keyboard : keyboards) {
for (const auto& keyboard : keyboards) {
if (keyboard->isAttached()) {
if (keyboard->startLvgl(primary_display->getLvglDisplay())) {
lv_indev_t* keyboard_indev = keyboard->getLvglIndev();
hardware_keyboard_set_indev(keyboard_indev);
TT_LOG_I(TAG, "Started %s", keyboard->getName().c_str());
LOGGER.info("Started {}", keyboard->getName());
} else {
TT_LOG_E(TAG, "Start failed for %s", keyboard->getName().c_str());
LOGGER.error("Start failed for {}", keyboard->getName());
}
}
}
// Start encoders
TT_LOG_I(TAG, "Start encoders");
LOGGER.info("Start encoders");
auto encoders = hal::findDevices<hal::encoder::EncoderDevice>(hal::Device::Type::Encoder);
for (auto encoder : encoders) {
for (const auto& encoder : encoders) {
if (encoder->startLvgl(primary_display->getLvglDisplay())) {
TT_LOG_I(TAG, "Started %s", encoder->getName().c_str());
LOGGER.info("Started {}", encoder->getName());
} else {
TT_LOG_E(TAG, "Start failed for %s", encoder->getName().c_str());
LOGGER.error("Start failed for {}", encoder->getName());
}
}
}
@@ -127,7 +128,7 @@ void start() {
if (service::getState("Gui") == service::State::Stopped) {
service::startService("Gui");
} else {
TT_LOG_E(TAG, "Gui service is not in Stopped state");
LOGGER.error("Gui service is not in Stopped state");
}
}
@@ -137,7 +138,7 @@ void start() {
if (service::getState("Statusbar") == service::State::Stopped) {
service::startService("Statusbar");
} else {
TT_LOG_E(TAG, "Statusbar service is not in Stopped state");
LOGGER.error("Statusbar service is not in Stopped state");
}
}
@@ -149,10 +150,10 @@ void start() {
}
void stop() {
TT_LOG_I(TAG, "Stopping LVGL");
LOGGER.info("Stopping LVGL");
if (!started) {
TT_LOG_W(TAG, "Can't stop LVGL: not started");
LOGGER.warn("Can't stop LVGL: not started");
return;
}
@@ -166,7 +167,7 @@ void stop() {
// Stop keyboards
TT_LOG_I(TAG, "Stopping keyboards");
LOGGER.info("Stopping keyboards");
auto keyboards = hal::findDevices<hal::keyboard::KeyboardDevice>(hal::Device::Type::Keyboard);
for (auto keyboard : keyboards) {
if (keyboard->getLvglIndev() != nullptr) {
@@ -176,7 +177,7 @@ void stop() {
// Stop touch
TT_LOG_I(TAG, "Stopping touch");
LOGGER.info("Stopping touch");
// The display generally stops their own touch devices, but we'll clean up anything that didn't
auto touch_devices = hal::findDevices<hal::touch::TouchDevice>(hal::Device::Type::Touch);
for (auto touch_device : touch_devices) {
@@ -187,7 +188,7 @@ void stop() {
// Stop encoders
TT_LOG_I(TAG, "Stopping encoders");
LOGGER.info("Stopping encoders");
// The display generally stops their own touch devices, but we'll clean up anything that didn't
auto encoder_devices = hal::findDevices<hal::encoder::EncoderDevice>(hal::Device::Type::Encoder);
for (auto encoder_device : encoder_devices) {
@@ -197,11 +198,11 @@ void stop() {
}
// Stop displays (and their touch devices)
TT_LOG_I(TAG, "Stopping displays");
LOGGER.info("Stopping displays");
auto displays = hal::findDevices<hal::display::DisplayDevice>(hal::Device::Type::Display);
for (auto display : displays) {
if (display->supportsLvgl() && display->getLvglDisplay() != nullptr && !display->stopLvgl()) {
TT_LOG_E("HelloWorld", "Failed to detach display from LVGL");
LOGGER.error("Failed to detach display from LVGL");
}
}
@@ -209,7 +210,7 @@ void stop() {
kernel::publishSystemEvent(kernel::SystemEvent::LvglStopped);
TT_LOG_I(TAG, "Stopped LVGL");
LOGGER.info("Stopped LVGL");
}
} // namespace
-1
View File
@@ -2,7 +2,6 @@
#include <Tactility/Assets.h>
#include <Tactility/CoreDefines.h>
#include <Tactility/Log.h>
#include <lvgl.h>
+31 -15
View File
@@ -1,22 +1,23 @@
#define LV_USE_PRIVATE_API 1 // For actual lv_obj_t declaration
#include <Tactility/Tactility.h>
#include <Tactility/TactilityCore.h>
#include <Tactility/PubSub.h>
#include <Tactility/Timer.h>
#include <Tactility/RecursiveMutex.h>
#include <Tactility/kernel/SystemEvents.h>
#include <Tactility/Logger.h>
#include <Tactility/LogMessages.h>
#include <Tactility/lvgl/LvglSync.h>
#include <Tactility/lvgl/Statusbar.h>
#include <Tactility/lvgl/Style.h>
#include <Tactility/PubSub.h>
#include <Tactility/RecursiveMutex.h>
#include <Tactility/settings/Time.h>
#include <Tactility/Tactility.h>
#include <Tactility/TactilityCore.h>
#include <Tactility/Timer.h>
#include <lvgl.h>
namespace tt::lvgl {
constexpr auto TAG = "statusbar";
static const auto LOGGER = Logger("statusbar");
static void onUpdateTime();
@@ -58,7 +59,9 @@ static TickType_t getNextUpdateTime() {
time_t now = ::time(nullptr);
tm* tm_struct = localtime(&now);
uint32_t seconds_to_wait = 60U - tm_struct->tm_sec;
TT_LOG_D(TAG, "Update in %lu s", seconds_to_wait);
if (LOGGER.isLoggingDebug()) {
LOGGER.debug("Update in {} s", seconds_to_wait);
}
return pdMS_TO_TICKS(seconds_to_wait * 1000U);
}
@@ -101,13 +104,15 @@ static const lv_obj_class_t statusbar_class = {
};
static void statusbar_pubsub_event(Statusbar* statusbar) {
TT_LOG_D(TAG, "Update event");
if (LOGGER.isLoggingDebug()) {
LOGGER.debug("Update event");
}
if (lock(defaultLockTime)) {
update_main(statusbar);
lv_obj_invalidate(&statusbar->obj);
unlock();
} else {
TT_LOG_W(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "Statusbar");
LOGGER.warn(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "Statusbar");
}
}
@@ -152,7 +157,6 @@ static void update_icon(lv_obj_t* image, const StatusbarIcon* icon) {
}
lv_obj_t* statusbar_create(lv_obj_t* parent) {
LV_LOG_INFO("begin");
lv_obj_t* obj = lv_obj_class_create_obj(&statusbar_class, parent);
lv_obj_class_init_obj(obj);
@@ -235,7 +239,9 @@ int8_t statusbar_icon_add(const std::string& image, bool visible) {
statusbar_data.icons[i].visible = visible;
statusbar_data.icons[i].image = image;
result = i;
TT_LOG_D(TAG, "id %d: added", i);
if (LOGGER.isLoggingDebug()) {
LOGGER.debug("id {}: added", i);
}
break;
}
}
@@ -249,7 +255,9 @@ int8_t statusbar_icon_add() {
}
void statusbar_icon_remove(int8_t id) {
TT_LOG_D(TAG, "id %d: remove", id);
if (LOGGER.isLoggingDebug()) {
LOGGER.debug("id {}: remove", id);
}
tt_check(id >= 0 && id < STATUSBAR_ICON_LIMIT);
statusbar_data.mutex.lock();
StatusbarIcon* icon = &statusbar_data.icons[id];
@@ -261,7 +269,13 @@ void statusbar_icon_remove(int8_t id) {
}
void statusbar_icon_set_image(int8_t id, const std::string& image) {
TT_LOG_D(TAG, "id %d: set image %s", id, image.empty() ? "(none)" : image.c_str());
if (LOGGER.isLoggingDebug()) {
if (image.empty()) {
LOGGER.debug("id {}: set image (none)", id);
} else {
LOGGER.debug("id {}: set image {}", id, image);
}
}
tt_check(id >= 0 && id < STATUSBAR_ICON_LIMIT);
statusbar_data.mutex.lock();
StatusbarIcon* icon = &statusbar_data.icons[id];
@@ -272,7 +286,9 @@ void statusbar_icon_set_image(int8_t id, const std::string& image) {
}
void statusbar_icon_set_visibility(int8_t id, bool visible) {
TT_LOG_D(TAG, "id %d: set visibility %d", id, visible);
if (LOGGER.isLoggingDebug()) {
LOGGER.debug("id {}: set visibility {}", id, visible);
}
tt_check(id >= 0 && id < STATUSBAR_ICON_LIMIT);
statusbar_data.mutex.lock();
StatusbarIcon* icon = &statusbar_data.icons[id];
-3
View File
@@ -1,11 +1,8 @@
#define LV_USE_PRIVATE_API 1 // For actual lv_obj_t declaration
#include <Tactility/TactilityConfig.h>
#include <Tactility/lvgl/Keyboard.h>
#include <Tactility/lvgl/Toolbar.h>
#include <Tactility/service/loader/Loader.h>
#include <Tactility/lvgl/Style.h>
#include <Tactility/lvgl/Spinner.h>
namespace tt::lvgl {
+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) {
@@ -1,6 +1,6 @@
#include <Tactility/service/ServiceRegistration.h>
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#include <Tactility/Mutex.h>
#include <Tactility/service/ServiceInstance.h>
#include <Tactility/service/ServiceManifest.h>
@@ -9,7 +9,7 @@
namespace tt::service {
constexpr auto* TAG = "ServiceRegistry";
static const auto LOGGER = Logger("ServiceRegistration");
typedef std::unordered_map<std::string, std::shared_ptr<const ServiceManifest>> ManifestMap;
typedef std::unordered_map<std::string, std::shared_ptr<ServiceInstance>> ServiceInstanceMap;
@@ -25,13 +25,13 @@ void addService(std::shared_ptr<const ServiceManifest> manifest, bool autoStart)
// We'll move the manifest pointer, but we'll need to id later
const auto& id = manifest->id;
TT_LOG_I(TAG, "Adding %s", id.c_str());
LOGGER.info("Adding {}", id);
manifest_mutex.lock();
if (service_manifest_map[id] == nullptr) {
service_manifest_map[id] = std::move(manifest);
} else {
TT_LOG_E(TAG, "Service id in use: %s", id.c_str());
LOGGER.error("Service id in use: {}", id);
}
manifest_mutex.unlock();
@@ -62,10 +62,10 @@ static std::shared_ptr<ServiceInstance> _Nullable findServiceInstanceById(const
// TODO: Return proper error/status instead of BOOL?
bool startService(const std::string& id) {
TT_LOG_I(TAG, "Starting %s", id.c_str());
LOGGER.info("Starting {}", id);
auto manifest = findManifestById(id);
if (manifest == nullptr) {
TT_LOG_E(TAG, "manifest not found for service %s", id.c_str());
LOGGER.error("manifest not found for service {}", id);
return false;
}
@@ -80,14 +80,14 @@ bool startService(const std::string& id) {
if (service_instance->getService()->onStart(*service_instance)) {
service_instance->setState(State::Started);
} else {
TT_LOG_E(TAG, "Starting %s failed", id.c_str());
LOGGER.error("Starting {} failed", id);
service_instance->setState(State::Stopped);
instance_mutex.lock();
service_instance_map.erase(manifest->id);
instance_mutex.unlock();
}
TT_LOG_I(TAG, "Started %s", id.c_str());
LOGGER.info("Started {}", id);
return true;
}
@@ -102,10 +102,10 @@ std::shared_ptr<Service> _Nullable findServiceById(const std::string& id) {
}
bool stopService(const std::string& id) {
TT_LOG_I(TAG, "Stopping %s", id.c_str());
LOGGER.info("Stopping {}", id);
auto service_instance = findServiceInstanceById(id);
if (service_instance == nullptr) {
TT_LOG_W(TAG, "Service not running: %s", id.c_str());
LOGGER.warn("Service not running: {}", id);
return false;
}
@@ -118,10 +118,10 @@ bool stopService(const std::string& id) {
instance_mutex.unlock();
if (service_instance.use_count() > 1) {
TT_LOG_W(TAG, "Possible memory leak: service %s still has %ld references", service_instance->getManifest().id.c_str(), service_instance.use_count() - 1);
LOGGER.warn("Possible memory leak: service {} still has {} references", service_instance->getManifest().id, service_instance.use_count() - 1);
}
TT_LOG_I(TAG, "Stopped %s", id.c_str());
LOGGER.info("Stopped {}", id);
return true;
}
@@ -7,6 +7,7 @@
#include <Tactility/file/File.h>
#include <Tactility/network/HttpdReq.h>
#include <Tactility/network/Url.h>
#include <Tactility/Logger.h>
#include <Tactility/Paths.h>
#include <Tactility/service/development/DevelopmentSettings.h>
#include <Tactility/service/ServiceRegistration.h>
@@ -19,7 +20,7 @@ namespace tt::service::development {
extern const ServiceManifest manifest;
constexpr const char* TAG = "DevService";
static const auto LOGGER = Logger("DevService");
bool DevelopmentService::onStart(ServiceContext& service) {
std::stringstream stream;
@@ -65,26 +66,26 @@ bool DevelopmentService::isEnabled() const {
// region endpoints
esp_err_t DevelopmentService::handleGetInfo(httpd_req_t* request) {
TT_LOG_I(TAG, "GET /device");
LOGGER.info("GET /device");
if (httpd_resp_set_type(request, "application/json") != ESP_OK) {
TT_LOG_W(TAG, "Failed to send header");
LOGGER.warn("Failed to send header");
return ESP_FAIL;
}
auto* service = static_cast<DevelopmentService*>(request->user_ctx);
if (httpd_resp_sendstr(request, service->deviceResponse.c_str()) != ESP_OK) {
TT_LOG_W(TAG, "Failed to send response body");
LOGGER.warn("Failed to send response body");
return ESP_FAIL;
}
TT_LOG_I(TAG, "[200] /device");
LOGGER.info("[200] /device");
return ESP_OK;
}
esp_err_t DevelopmentService::handleAppRun(httpd_req_t* request) {
TT_LOG_I(TAG, "POST /app/run");
LOGGER.info("POST /app/run");
std::string query;
if (!network::getQueryOrSendError(request, query)) {
@@ -94,7 +95,7 @@ esp_err_t DevelopmentService::handleAppRun(httpd_req_t* request) {
auto parameters = network::parseUrlQuery(query);
auto id_key_pos = parameters.find("id");
if (id_key_pos == parameters.end()) {
TT_LOG_W(TAG, "[400] /app/run id not specified");
LOGGER.warn("[400] /app/run id not specified");
httpd_resp_send_err(request, HTTPD_400_BAD_REQUEST, "id not specified");
return ESP_FAIL;
}
@@ -106,14 +107,14 @@ esp_err_t DevelopmentService::handleAppRun(httpd_req_t* request) {
app::start(app_id);
TT_LOG_I(TAG, "[200] /app/run %s", id_key_pos->second.c_str());
LOGGER.info("[200] /app/run {}", id_key_pos->second);
httpd_resp_send(request, nullptr, 0);
return ESP_OK;
}
esp_err_t DevelopmentService::handleAppInstall(httpd_req_t* request) {
TT_LOG_I(TAG, "PUT /app/install");
LOGGER.info("PUT /app/install");
std::string boundary;
if (!network::getMultiPartBoundaryOrSendError(request, boundary)) {
@@ -174,7 +175,7 @@ esp_err_t DevelopmentService::handleAppInstall(httpd_req_t* request) {
content_left -= boundary_and_newlines_after_file.length();
if (content_left != 0) {
TT_LOG_W(TAG, "We have more bytes at the end of the request parsing?!");
LOGGER.warn("We have more bytes at the end of the request parsing?!");
}
if (!app::install(file_path)) {
@@ -182,11 +183,11 @@ esp_err_t DevelopmentService::handleAppInstall(httpd_req_t* request) {
return ESP_FAIL;
}
if (!file::deleteFile(file_path.c_str())) {
TT_LOG_W(TAG, "Failed to delete %s", file_path.c_str());
if (!file::deleteFile(file_path)) {
LOGGER.warn("Failed to delete {}", file_path);
}
TT_LOG_I(TAG, "[200] /app/install -> %s", file_path.c_str());
LOGGER.info("[200] /app/install -> {}", file_path);
httpd_resp_send(request, nullptr, 0);
@@ -194,7 +195,7 @@ esp_err_t DevelopmentService::handleAppInstall(httpd_req_t* request) {
}
esp_err_t DevelopmentService::handleAppUninstall(httpd_req_t* request) {
TT_LOG_I(TAG, "PUT /app/uninstall");
LOGGER.info("PUT /app/uninstall");
std::string query;
if (!network::getQueryOrSendError(request, query)) {
@@ -204,23 +205,23 @@ esp_err_t DevelopmentService::handleAppUninstall(httpd_req_t* request) {
auto parameters = network::parseUrlQuery(query);
auto id_key_pos = parameters.find("id");
if (id_key_pos == parameters.end()) {
TT_LOG_W(TAG, "[400] /app/uninstall id not specified");
LOGGER.warn("[400] /app/uninstall id not specified");
httpd_resp_send_err(request, HTTPD_400_BAD_REQUEST, "id not specified");
return ESP_FAIL;
}
if (!app::findAppManifestById(id_key_pos->second)) {
TT_LOG_I(TAG, "[200] /app/uninstall %s (app wasn't installed)", id_key_pos->second.c_str());
LOGGER.info("[200] /app/uninstall {} (app wasn't installed)", id_key_pos->second);
httpd_resp_send(request, nullptr, 0);
return ESP_OK;
}
if (app::uninstall(id_key_pos->second)) {
TT_LOG_I(TAG, "[200] /app/uninstall %s", id_key_pos->second.c_str());
LOGGER.info("[200] /app/uninstall {}", id_key_pos->second);
httpd_resp_send(request, nullptr, 0);
return ESP_OK;
} else {
TT_LOG_W(TAG, "[500] /app/uninstall %s", id_key_pos->second.c_str());
LOGGER.warn("[500] /app/uninstall {}", id_key_pos->second);
httpd_resp_send_err(request, HTTPD_500_INTERNAL_SERVER_ERROR, "Failed to uninstall");
return ESP_FAIL;
}
@@ -1,13 +1,14 @@
#ifdef ESP_PLATFORM
#include <Tactility/file/PropertiesFile.h>
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#include <Tactility/service/development/DevelopmentSettings.h>
#include <map>
#include <string>
namespace tt::service::development {
constexpr auto* TAG = "DevSettings";
static const auto LOGGER = Logger("DevSettings");
constexpr auto* SETTINGS_FILE = "/data/settings/development.properties";
constexpr auto* SETTINGS_KEY_ENABLE_ON_BOOT = "enableOnBoot";
@@ -39,7 +40,7 @@ static bool save(const DevelopmentSettings& settings) {
void setEnableOnBoot(bool enable) {
DevelopmentSettings properties { .enableOnBoot = enable };
if (!save(properties)) {
TT_LOG_E(TAG, "Failed to save %s", SETTINGS_FILE);
LOGGER.error("Failed to save {}", SETTINGS_FILE);
}
}
@@ -1,16 +1,14 @@
#include <Tactility/CoreDefines.h>
#include <Tactility/Timer.h>
#include <Tactility/hal/display/DisplayDevice.h>
#include <Tactility/lvgl/LvglSync.h>
#include <Tactility/service/ServiceContext.h>
#include <Tactility/service/ServiceManifest.h>
#include <Tactility/service/ServiceRegistration.h>
#include <Tactility/settings/DisplaySettings.h>
#include <Tactility/Timer.h>
namespace tt::service::displayidle {
constexpr auto* TAG = "DisplayIdle";
class DisplayIdleService final : public Service {
std::unique_ptr<Timer> timer;
+10 -10
View File
@@ -4,21 +4,21 @@
#ifdef CONFIG_ESP_WIFI_ENABLED
#include "Tactility/service/espnow/EspNow.h"
#include "Tactility/service/espnow/EspNowService.h"
#include <Tactility/service/espnow/EspNow.h>
#include <Tactility/service/espnow/EspNowService.h>
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
namespace tt::service::espnow {
constexpr const char* TAG = "EspNow";
static const auto LOGGER = Logger("EspNow");
void enable(const EspNowConfig& config) {
auto service = findService();
if (service != nullptr) {
service->enable(config);
} else {
TT_LOG_E(TAG, "Service not found");
LOGGER.error("Service not found");
}
}
@@ -27,7 +27,7 @@ void disable() {
if (service != nullptr) {
service->disable();
} else {
TT_LOG_E(TAG, "Service not found");
LOGGER.error("Service not found");
}
}
@@ -45,7 +45,7 @@ bool addPeer(const esp_now_peer_info_t& peer) {
if (service != nullptr) {
return service->addPeer(peer);
} else {
TT_LOG_E(TAG, "Service not found");
LOGGER.error("Service not found");
return false;
}
}
@@ -55,7 +55,7 @@ bool send(const uint8_t* address, const uint8_t* buffer, size_t bufferLength) {
if (service != nullptr) {
return service->send(address, buffer, bufferLength);
} else {
TT_LOG_E(TAG, "Service not found");
LOGGER.error("Service not found");
return false;
}
}
@@ -65,7 +65,7 @@ ReceiverSubscription subscribeReceiver(std::function<void(const esp_now_recv_inf
if (service != nullptr) {
return service->subscribeReceiver(onReceive);
} else {
TT_LOG_E(TAG, "Service not found");
LOGGER.error("Service not found");
return -1;
}
}
@@ -75,7 +75,7 @@ void unsubscribeReceiver(ReceiverSubscription subscription) {
if (service != nullptr) {
service->unsubscribeReceiver(subscription);
} else {
TT_LOG_E(TAG, "Service not found");
LOGGER.error("Service not found");
}
}
@@ -4,6 +4,7 @@
#ifdef CONFIG_ESP_WIFI_ENABLED
#include <Tactility/Logger.h>
#include <Tactility/Tactility.h>
#include <Tactility/service/espnow/EspNowService.h>
#include <Tactility/service/ServiceManifest.h>
@@ -18,10 +19,10 @@ namespace tt::service::espnow {
extern const ServiceManifest manifest;
constexpr const char* TAG = "EspNowService";
constexpr TickType_t MAX_DELAY = 1000U / portTICK_PERIOD_MS;
static const auto LOGGER = Logger("EspNowService");
static uint8_t BROADCAST_MAC[ESP_NOW_ETH_ALEN];
constexpr TickType_t MAX_DELAY = 1000U / portTICK_PERIOD_MS;
constexpr bool isBroadcastAddress(uint8_t address[ESP_NOW_ETH_ALEN]) { return memcmp(address, BROADCAST_MAC, ESP_NOW_ETH_ALEN) == 0; }
bool EspNowService::onStart(ServiceContext& service) {
@@ -45,7 +46,7 @@ void EspNowService::onStop(ServiceContext& service) {
// region Enable
void EspNowService::enable(const EspNowConfig& config) {
getMainDispatcher().dispatch([this, config]() {
getMainDispatcher().dispatch([this, config] {
enableFromDispatcher(config);
});
}
@@ -59,17 +60,17 @@ void EspNowService::enableFromDispatcher(const EspNowConfig& config) {
}
if (!initWifi(config)) {
TT_LOG_E(TAG, "initWifi() failed");
LOGGER.error("initWifi() failed");
return;
}
if (esp_now_init() != ESP_OK) {
TT_LOG_E(TAG, "esp_now_init() failed");
LOGGER.error("esp_now_init() failed");
return;
}
if (esp_now_register_recv_cb(receiveCallback) != ESP_OK) {
TT_LOG_E(TAG, "esp_now_register_recv_cb() failed");
LOGGER.error("esp_now_register_recv_cb() failed");
return;
}
@@ -79,7 +80,7 @@ void EspNowService::enableFromDispatcher(const EspNowConfig& config) {
//#endif
if (esp_now_set_pmk(config.masterKey) != ESP_OK) {
TT_LOG_E(TAG, "esp_now_set_pmk() failed");
LOGGER.error("esp_now_set_pmk() failed");
return;
}
@@ -111,11 +112,11 @@ void EspNowService::disableFromDispatcher() {
}
if (esp_now_deinit() != ESP_OK) {
TT_LOG_E(TAG, "esp_now_deinit() failed");
LOGGER.error("esp_now_deinit() failed");
}
if (!deinitWifi()) {
TT_LOG_E(TAG, "deinitWifi() failed");
LOGGER.error("deinitWifi() failed");
}
enabled = false;
@@ -128,7 +129,7 @@ void EspNowService::disableFromDispatcher() {
void EspNowService::receiveCallback(const esp_now_recv_info_t* receiveInfo, const uint8_t* data, int length) {
auto service = findService();
if (service == nullptr) {
TT_LOG_E(TAG, "Service not running");
LOGGER.error("Service not running");
return;
}
service->onReceive(receiveInfo, data, length);
@@ -138,7 +139,7 @@ void EspNowService::onReceive(const esp_now_recv_info_t* receiveInfo, const uint
auto lock = mutex.asScopedLock();
lock.lock();
TT_LOG_D(TAG, "Received %d bytes", length);
LOGGER.debug("Received {} bytes", length);
for (const auto& item: subscriptions) {
item.onReceive(receiveInfo, data, length);
@@ -155,10 +156,10 @@ bool EspNowService::isEnabled() const {
bool EspNowService::addPeer(const esp_now_peer_info_t& peer) {
if (esp_now_add_peer(&peer) != ESP_OK) {
TT_LOG_E(TAG, "Failed to add peer");
LOGGER.error("Failed to add peer");
return false;
} else {
TT_LOG_I(TAG, "Peer added");
LOGGER.info("Peer added");
return true;
}
}
@@ -188,7 +189,7 @@ ReceiverSubscription EspNowService::subscribeReceiver(std::function<void(const e
return id;
}
void EspNowService::unsubscribeReceiver(tt::service::espnow::ReceiverSubscription subscriptionId) {
void EspNowService::unsubscribeReceiver(ReceiverSubscription subscriptionId) {
auto lock = mutex.asScopedLock();
lock.lock();
std::erase_if(subscriptions, [subscriptionId](auto& subscription) { return subscription.id == subscriptionId; });
@@ -196,7 +197,7 @@ void EspNowService::unsubscribeReceiver(tt::service::espnow::ReceiverSubscriptio
std::shared_ptr<EspNowService> findService() {
return std::static_pointer_cast<EspNowService>(
service::findServiceById(manifest.id)
findServiceById(manifest.id)
);
}
+11 -11
View File
@@ -5,7 +5,7 @@
#ifdef CONFIG_ESP_WIFI_ENABLED
#include <Tactility/kernel/Kernel.h>
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#include <Tactility/service/espnow/EspNow.h>
#include <Tactility/service/wifi/Wifi.h>
@@ -14,7 +14,7 @@
namespace tt::service::espnow {
constexpr const char* TAG = "EspNowService";
static const auto LOGGER = Logger("EspNowService");
static bool disableWifiService() {
auto wifi_state = wifi::getRadioState();
@@ -43,7 +43,7 @@ bool initWifi(const EspNowConfig& config) {
// If WiFi is already connected, keep it running and just add ESP-NOW on top
if (!wifi_was_connected && wifi_state != wifi::RadioState::Off && wifi_state != wifi::RadioState::OffPending) {
if (!disableWifiService()) {
TT_LOG_E(TAG, "Failed to disable wifi");
LOGGER.error("Failed to disable wifi");
return false;
}
}
@@ -60,28 +60,28 @@ bool initWifi(const EspNowConfig& config) {
if (wifi::getRadioState() == wifi::RadioState::Off) {
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
if (esp_wifi_init(&cfg) != ESP_OK) {
TT_LOG_E(TAG, "esp_wifi_init() failed");
LOGGER.error("esp_wifi_init() failed");
return false;
}
if (esp_wifi_set_storage(WIFI_STORAGE_RAM) != ESP_OK) {
TT_LOG_E(TAG, "esp_wifi_set_storage() failed");
LOGGER.error("esp_wifi_set_storage() failed");
return false;
}
if (esp_wifi_set_mode(mode) != ESP_OK) {
TT_LOG_E(TAG, "esp_wifi_set_mode() failed");
LOGGER.error("esp_wifi_set_mode() failed");
return false;
}
if (esp_wifi_start() != ESP_OK) {
TT_LOG_E(TAG, "esp_wifi_start() failed");
LOGGER.error("esp_wifi_start() failed");
return false;
}
}
if (esp_wifi_set_channel(config.channel, WIFI_SECOND_CHAN_NONE) != ESP_OK) {
TT_LOG_E(TAG, "esp_wifi_set_channel() failed");
LOGGER.error("esp_wifi_set_channel() failed");
return false;
}
@@ -94,11 +94,11 @@ bool initWifi(const EspNowConfig& config) {
}
if (esp_wifi_set_protocol(wifi_interface, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N | WIFI_PROTOCOL_LR) != ESP_OK) {
TT_LOG_W(TAG, "esp_wifi_set_protocol() for long range failed");
LOGGER.warn("esp_wifi_set_protocol() for long range failed");
}
}
TT_LOG_I(TAG, "WiFi initialized for ESP-NOW (preserved existing connection: %s)", wifi_was_connected ? "yes" : "no");
LOGGER.info("WiFi initialized for ESP-NOW (preserved existing connection: {})", wifi_was_connected ? "yes" : "no");
return true;
}
@@ -110,7 +110,7 @@ bool deinitWifi() {
// Since we're only using WiFi for ESP-NOW, we can safely keep it in a minimal state
// or shut it down. For now, keep it running to support STA + ESP-NOW coexistence.
TT_LOG_I(TAG, "ESP-NOW WiFi deinitialized (WiFi service continues independently)");
LOGGER.info("ESP-NOW WiFi deinitialized (WiFi service continues independently)");
return true;
}
@@ -1,4 +1,5 @@
#include <Tactility/file/ObjectFile.h>
#include <Tactility/Logger.h>
#include <Tactility/service/gps/GpsService.h>
#include <Tactility/service/ServicePaths.h>
@@ -9,16 +10,16 @@ using tt::hal::gps::GpsDevice;
namespace tt::service::gps {
constexpr const char* TAG = "GpsService";
static const auto LOGGER = Logger("GpsService");
bool GpsService::getConfigurationFilePath(std::string& output) const {
if (paths == nullptr) {
TT_LOG_E(TAG, "Can't add configuration: service not started");
LOGGER.error("Can't add configuration: service not started");
return false;
}
if (!file::findOrCreateDirectory(paths->getUserDataDirectory(), 0777)) {
TT_LOG_E(TAG, "Failed to find or create path %s", paths->getUserDataDirectory().c_str());
LOGGER.error("Failed to find or create path {}", paths->getUserDataDirectory());
return false;
}
@@ -34,21 +35,21 @@ bool GpsService::getGpsConfigurations(std::vector<hal::gps::GpsConfiguration>& c
// If file does not exist, return empty list
if (access(path.c_str(), F_OK) != 0) {
TT_LOG_W(TAG, "No configurations (file not found: %s)", path.c_str());
LOGGER.warn("No configurations (file not found: {})", path);
return true;
}
TT_LOG_I(TAG, "Reading configuration file %s", path.c_str());
LOGGER.info("Reading configuration file {}", path);
auto reader = file::ObjectFileReader(path, sizeof(hal::gps::GpsConfiguration));
if (!reader.open()) {
TT_LOG_E(TAG, "Failed to open configuration file");
LOGGER.error("Failed to open configuration file");
return false;
}
hal::gps::GpsConfiguration configuration;
while (reader.hasNext()) {
if (!reader.readNext(&configuration)) {
TT_LOG_E(TAG, "Failed to read configuration");
LOGGER.error("Failed to read configuration");
reader.close();
return false;
} else {
@@ -67,12 +68,12 @@ bool GpsService::addGpsConfiguration(hal::gps::GpsConfiguration configuration) {
auto appender = file::ObjectFileWriter(path, sizeof(hal::gps::GpsConfiguration), 1, true);
if (!appender.open()) {
TT_LOG_E(TAG, "Failed to open/create configuration file");
LOGGER.error("Failed to open/create configuration file");
return false;
}
if (!appender.write(&configuration)) {
TT_LOG_E(TAG, "Failed to add configuration");
LOGGER.error("Failed to add configuration");
appender.close();
return false;
}
@@ -89,7 +90,7 @@ bool GpsService::removeGpsConfiguration(hal::gps::GpsConfiguration configuration
std::vector<hal::gps::GpsConfiguration> configurations;
if (!getGpsConfigurations(configurations)) {
TT_LOG_E(TAG, "Failed to get gps configurations");
LOGGER.error("Failed to get gps configurations");
return false;
}
@@ -101,7 +102,7 @@ bool GpsService::removeGpsConfiguration(hal::gps::GpsConfiguration configuration
auto writer = file::ObjectFileWriter(path, sizeof(hal::gps::GpsConfiguration), 1, false);
if (!writer.open()) {
TT_LOG_E(TAG, "Failed to open configuration file");
LOGGER.error("Failed to open configuration file");
return false;
}
+13 -13
View File
@@ -1,7 +1,7 @@
#include <Tactility/service/gps/GpsService.h>
#include <Tactility/file/File.h>
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#include <Tactility/service/ServicePaths.h>
#include <Tactility/service/ServiceManifest.h>
#include <Tactility/service/ServiceRegistration.h>
@@ -10,7 +10,7 @@ using tt::hal::gps::GpsDevice;
namespace tt::service::gps {
constexpr const char* TAG = "GpsService";
static const auto LOGGER = Logger("GpsService");
extern const ServiceManifest manifest;
constexpr bool hasTimeElapsed(TickType_t now, TickType_t timeInThePast, TickType_t expireTimeInTicks) {
@@ -73,7 +73,7 @@ void GpsService::onStop(ServiceContext& serviceContext) {
}
bool GpsService::startGpsDevice(GpsDeviceRecord& record) {
TT_LOG_I(TAG, "[device %lu] starting", record.device->getId());
LOGGER.info("[device {}] starting", record.device->getId());
auto lock = mutex.asScopedLock();
lock.lock();
@@ -81,7 +81,7 @@ bool GpsService::startGpsDevice(GpsDeviceRecord& record) {
auto device = record.device;
if (!device->start()) {
TT_LOG_E(TAG, "[device %lu] starting failed", record.device->getId());
LOGGER.error("[device {}] starting failed", record.device->getId());
return false;
}
@@ -105,7 +105,7 @@ bool GpsService::startGpsDevice(GpsDeviceRecord& record) {
}
bool GpsService::stopGpsDevice(GpsDeviceRecord& record) {
TT_LOG_I(TAG, "[device %lu] stopping", record.device->getId());
LOGGER.info("[device {}] stopping", record.device->getId());
auto device = record.device;
@@ -116,7 +116,7 @@ bool GpsService::stopGpsDevice(GpsDeviceRecord& record) {
record.rmcSubscriptionId = -1;
if (!device->stop()) {
TT_LOG_E(TAG, "[device %lu] stopping failed", record.device->getId());
LOGGER.error("[device {}] stopping failed", record.device->getId());
return false;
}
@@ -124,10 +124,10 @@ bool GpsService::stopGpsDevice(GpsDeviceRecord& record) {
}
bool GpsService::startReceiving() {
TT_LOG_I(TAG, "Start receiving");
LOGGER.info("Start receiving");
if (getState() != State::Off) {
TT_LOG_E(TAG, "Already receiving");
LOGGER.error("Already receiving");
return false;
}
@@ -140,13 +140,13 @@ bool GpsService::startReceiving() {
std::vector<hal::gps::GpsConfiguration> configurations;
if (!getGpsConfigurations(configurations)) {
TT_LOG_E(TAG, "Failed to get GPS configurations");
LOGGER.error("Failed to get GPS configurations");
setState(State::Off);
return false;
}
if (configurations.empty()) {
TT_LOG_E(TAG, "No GPS configurations");
LOGGER.error("No GPS configurations");
setState(State::Off);
return false;
}
@@ -174,7 +174,7 @@ bool GpsService::startReceiving() {
}
void GpsService::stopReceiving() {
TT_LOG_I(TAG, "Stop receiving");
LOGGER.info("Stop receiving");
setState(State::OffPending);
@@ -191,11 +191,11 @@ void GpsService::stopReceiving() {
}
void GpsService::onGgaSentence(hal::Device::Id deviceId, const minmea_sentence_gga& gga) {
TT_LOG_D(TAG, "[device %lu] LAT %f LON %f, satellites: %d", deviceId, minmea_tocoord(&gga.latitude), minmea_tocoord(&gga.longitude), gga.satellites_tracked);
LOGGER.debug("[device {}] LAT {} LON {}, satellites: {}", deviceId, minmea_tocoord(&gga.latitude), minmea_tocoord(&gga.longitude), gga.satellites_tracked);
}
void GpsService::onRmcSentence(hal::Device::Id deviceId, const minmea_sentence_rmc& rmc) {
TT_LOG_D(TAG, "[device %lu] LAT %f LON %f, speed: %.2f", deviceId, minmea_tocoord(&rmc.latitude), minmea_tocoord(&rmc.longitude), minmea_tofloat(&rmc.speed));
LOGGER.debug("[device {}] LAT {} LON {}, speed: {}", deviceId, minmea_tocoord(&rmc.latitude), minmea_tocoord(&rmc.longitude), minmea_tofloat(&rmc.speed));
}
State GpsService::getState() const {
+12 -13
View File
@@ -1,6 +1,8 @@
#include <Tactility/service/gui/GuiService.h>
#include <Tactility/app/AppInstance.h>
#include <Tactility/Logger.h>
#include <Tactility/LogMessages.h>
#include <Tactility/lvgl/LvglSync.h>
#include <Tactility/lvgl/Statusbar.h>
#include <Tactility/service/loader/Loader.h>
@@ -10,7 +12,7 @@
namespace tt::service::gui {
extern const ServiceManifest manifest;
constexpr auto* TAG = "GuiService";
static const auto LOGGER = Logger("GuiService");
using namespace loader;
// region AppManifest
@@ -39,10 +41,7 @@ int32_t GuiService::guiMain() {
// Process and dispatch draw call
if (flags & GUI_THREAD_FLAG_DRAW) {
service->threadFlags.clear(GUI_THREAD_FLAG_DRAW);
auto service = findService();
if (service != nullptr) {
service->redraw();
}
service->redraw();
}
if (flags & GUI_THREAD_FLAG_EXIT) {
@@ -103,13 +102,13 @@ void GuiService::redraw() {
lv_obj_t* container = createAppViews(appRootWidget);
appToRender->getApp()->onShow(*appToRender, container);
} else {
TT_LOG_W(TAG, "nothing to draw");
LOGGER.warn("nothing to draw");
}
// Unlock GUI and LVGL
lvgl::unlock();
} else {
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "LVGL");
LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "LVGL");
}
unlock();
@@ -118,7 +117,7 @@ void GuiService::redraw() {
bool GuiService::onStart(TT_UNUSED ServiceContext& service) {
auto* screen_root = lv_screen_active();
if (screen_root == nullptr) {
TT_LOG_E(TAG, "No display found");
LOGGER.error("No display found");
return false;
}
@@ -202,16 +201,16 @@ void GuiService::showApp(std::shared_ptr<app::AppInstance> app) {
lock.lock();
if (!isStarted) {
TT_LOG_E(TAG, "Failed to show app %s: GUI not started", app->getManifest().appId.c_str());
LOGGER.error("Failed to show app {}: GUI not started", app->getManifest().appId);
return;
}
if (appToRender != nullptr && appToRender->getLaunchId() == app->getLaunchId()) {
TT_LOG_W(TAG, "Already showing %s", app->getManifest().appId.c_str());
LOGGER.warn("Already showing {}", app->getManifest().appId);
return;
}
TT_LOG_I(TAG, "Showing %s", app->getManifest().appId.c_str());
LOGGER.info("Showing {}", app->getManifest().appId);
// Ensure previous app triggers onHide() logic
if (appToRender != nullptr) {
hideApp();
@@ -226,12 +225,12 @@ void GuiService::hideApp() {
lock.lock();
if (!isStarted) {
TT_LOG_E(TAG, "Failed to hide app: GUI not started");
LOGGER.error("Failed to hide app: GUI not started");
return;
}
if (appToRender == nullptr) {
TT_LOG_W(TAG, "hideApp() called but no app is currently shown");
LOGGER.warn("hideApp() called but no app is currently shown");
return;
}
@@ -15,8 +15,6 @@ namespace keyboardbacklight {
namespace tt::service::keyboardidle {
constexpr auto* TAG = "KeyboardIdle";
class KeyboardIdleService final : public Service {
std::unique_ptr<Timer> timer;
+22 -21
View File
@@ -4,6 +4,8 @@
#include <Tactility/app/AppRegistration.h>
#include <Tactility/DispatcherThread.h>
#include <Tactility/Logger.h>
#include <Tactility/LogMessages.h>
#include <Tactility/service/ServiceManifest.h>
#include <Tactility/service/ServiceRegistration.h>
@@ -16,7 +18,8 @@
namespace tt::service::loader {
constexpr auto* TAG = "Loader";
static const auto LOGGER = Logger("Boot");
constexpr auto LOADER_TIMEOUT = (100 / portTICK_PERIOD_MS);
// Forward declaration
@@ -41,17 +44,17 @@ static const char* appStateToString(app::State state) {
}
void LoaderService::onStartAppMessage(const std::string& id, app::LaunchId launchId, std::shared_ptr<const Bundle> parameters) {
TT_LOG_I(TAG, "Start by id %s", id.c_str());
LOGGER.info("Start by id {}", id);
auto app_manifest = app::findAppManifestById(id);
if (app_manifest == nullptr) {
TT_LOG_E(TAG, "App not found: %s", id.c_str());
LOGGER.error("App not found: {}", id);
return;
}
auto lock = mutex.asScopedLock();
if (!lock.lock(LOADER_TIMEOUT)) {
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED);
return;
}
@@ -73,14 +76,14 @@ void LoaderService::onStartAppMessage(const std::string& id, app::LaunchId launc
void LoaderService::onStopTopAppMessage(const std::string& id) {
auto lock = mutex.asScopedLock();
if (!lock.lock(LOADER_TIMEOUT)) {
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED);
return;
}
size_t original_stack_size = appStack.size();
if (original_stack_size == 0) {
TT_LOG_E(TAG, "Stop app: no app running");
LOGGER.error("Stop app: no app running");
return;
}
@@ -88,12 +91,12 @@ void LoaderService::onStopTopAppMessage(const std::string& id) {
auto app_to_stop = appStack[appStack.size() - 1];
if (app_to_stop->getManifest().appId != id) {
TT_LOG_E(TAG, "Stop app: id mismatch (wanted %s but found %s on top of stack)", id.c_str(), app_to_stop->getManifest().appId.c_str());
LOGGER.error("Stop app: id mismatch (wanted {} but found {} on top of stack)", id, app_to_stop->getManifest().appId);
return;
}
if (original_stack_size == 1 && app_to_stop->getManifest().appName != "Boot") {
TT_LOG_E(TAG, "Stop app: can't stop root app");
LOGGER.error("Stop app: can't stop root app");
return;
}
@@ -113,16 +116,16 @@ void LoaderService::onStopTopAppMessage(const std::string& id) {
// We only expect the app to be referenced within the current scope
if (app_to_stop.use_count() > 1) {
TT_LOG_W(TAG, "Memory leak: Stopped %s, but use count is %ld", app_to_stop->getManifest().appId.c_str(), app_to_stop.use_count() - 1);
LOGGER.warn("Memory leak: Stopped {}, but use count is {}", app_to_stop->getManifest().appId, app_to_stop.use_count() - 1);
}
// Refcount is expected to be 2: 1 within app_to_stop and 1 within the current scope
if (app_to_stop->getApp().use_count() > 2) {
TT_LOG_W(TAG, "Memory leak: Stopped %s, but use count is %ld", app_to_stop->getManifest().appId.c_str(), app_to_stop->getApp().use_count() - 2);
LOGGER.warn("Memory leak: Stopped {}, but use count is {}", app_to_stop->getManifest().appId, app_to_stop->getApp().use_count() - 2);
}
#ifdef ESP_PLATFORM
TT_LOG_I(TAG, "Free heap: %zu", heap_caps_get_free_size(MALLOC_CAP_INTERNAL));
LOGGER.info("Free heap: {}", heap_caps_get_free_size(MALLOC_CAP_INTERNAL));
#endif
std::shared_ptr<app::AppInstance> instance_to_resume;
@@ -179,18 +182,18 @@ int LoaderService::findAppInStack(const std::string& id) const {
void LoaderService::onStopAllAppMessage(const std::string& id) {
auto lock = mutex.asScopedLock();
if (!lock.lock(LOADER_TIMEOUT)) {
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED);
return;
}
if (!isRunning(id)) {
TT_LOG_E(TAG, "Stop all: %s not running", id.c_str());
LOGGER.error("Stop all: {} not running", id);
return;
}
int app_to_stop_index = findAppInStack(id);
if (app_to_stop_index < 0) {
TT_LOG_E(TAG, "Stop all: %s not found in stack", id.c_str());
LOGGER.error("Stop all: {} not found in stack", id);
return;
}
@@ -217,7 +220,7 @@ void LoaderService::onStopAllAppMessage(const std::string& id) {
}
if (instance_to_resume != nullptr) {
TT_LOG_I(TAG, "Resuming %s", instance_to_resume->getManifest().appId.c_str());
LOGGER.info("Resuming {}", instance_to_resume->getManifest().appId);
transitionAppToState(instance_to_resume, app::State::Showing);
instance_to_resume->getApp()->onResult(
@@ -233,10 +236,8 @@ void LoaderService::transitionAppToState(const std::shared_ptr<app::AppInstance>
const app::AppManifest& app_manifest = app->getManifest();
const app::State old_state = app->getState();
TT_LOG_I(
TAG,
"App \"%s\" state: %s -> %s",
app_manifest.appId.c_str(),
LOGGER.info( "App \"{}\" state: {} -> {}",
app_manifest.appId,
appStateToString(old_state),
appStateToString(state)
);
@@ -283,14 +284,14 @@ void LoaderService::stopTop() {
}
void LoaderService::stopTop(const std::string& id) {
TT_LOG_I(TAG, "dispatching stopTop(%s)", id.c_str());
LOGGER.info("dispatching stopTop({})", id);
dispatcherThread->dispatch([this, id] {
onStopTopAppMessage(id);
});
}
void LoaderService::stopAll(const std::string& id) {
TT_LOG_I(TAG, "dispatching stopAll(%s)", id.c_str());
LOGGER.info("dispatching stopAll({})", id);
dispatcherThread->dispatch([this, id] {
onStopAllAppMessage(id);
});
@@ -1,4 +1,6 @@
#include <Tactility/Tactility.h>
#include <Tactility/Logger.h>
#include <Tactility/lvgl/Statusbar.h>
#include <Tactility/service/ServiceContext.h>
#include <Tactility/service/ServiceManifest.h>
@@ -7,7 +9,7 @@
namespace tt::service::memorychecker {
constexpr const char* TAG = "MemoryChecker";
static const auto LOGGER = Logger("MemoryChecker");
// Total memory (in bytes) that should be free before warnings occur
constexpr auto TOTAL_FREE_THRESHOLD = 10'000;
@@ -36,13 +38,13 @@ static bool isMemoryLow() {
bool memory_low = false;
const auto total_free = getInternalFree();
if (total_free < TOTAL_FREE_THRESHOLD) {
TT_LOG_W(TAG, "Internal memory low: %zu bytes", total_free);
LOGGER.warn("Internal memory low: {} bytes", total_free);
memory_low = true;
}
const auto largest_block = getInternalLargestFreeBlock();
if (largest_block < LARGEST_FREE_BLOCK_THRESHOLD) {
TT_LOG_W(TAG, "Largest free internal memory block is %zu bytes", largest_block);
LOGGER.warn("Largest free internal memory block is {} bytes", largest_block);
memory_low = true;
}
@@ -2,7 +2,7 @@
#if TT_FEATURE_SCREENSHOT_ENABLED
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#include <Tactility/LogMessages.h>
#include <Tactility/service/screenshot/Screenshot.h>
#include <Tactility/service/ServiceRegistration.h>
@@ -12,7 +12,7 @@
namespace tt::service::screenshot {
constexpr auto* TAG = "ScreenshotService";
static const auto LOGGER = Logger("ScreenshotService");
extern const ServiceManifest manifest;
@@ -23,7 +23,7 @@ std::shared_ptr<ScreenshotService> _Nullable optScreenshotService() {
void ScreenshotService::startApps(const std::string& path) {
auto lock = mutex.asScopedLock();
if (!lock.lock(50 / portTICK_PERIOD_MS)) {
TT_LOG_W(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
LOGGER.warn(LOG_MESSAGE_MUTEX_LOCK_FAILED);
return;
}
@@ -32,14 +32,14 @@ void ScreenshotService::startApps(const std::string& path) {
mode = Mode::Apps;
task->startApps(path);
} else {
TT_LOG_W(TAG, "Screenshot task already running");
LOGGER.warn("Screenshot task already running");
}
}
void ScreenshotService::startTimed(const std::string& path, uint8_t delayInSeconds, uint8_t amount) {
auto lock = mutex.asScopedLock();
if (!lock.lock(50 / portTICK_PERIOD_MS)) {
TT_LOG_W(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
LOGGER.warn(LOG_MESSAGE_MUTEX_LOCK_FAILED);
return;
}
@@ -48,13 +48,13 @@ void ScreenshotService::startTimed(const std::string& path, uint8_t delayInSecon
mode = Mode::Timed;
task->startTimed(path, delayInSeconds, amount);
} else {
TT_LOG_W(TAG, "Screenshot task already running");
LOGGER.warn("Screenshot task already running");
}
}
bool ScreenshotService::onStart(ServiceContext& serviceContext) {
if (lv_screen_active() == nullptr) {
TT_LOG_E(TAG, "No display found");
LOGGER.error("No display found");
return false;
}
@@ -64,7 +64,7 @@ bool ScreenshotService::onStart(ServiceContext& serviceContext) {
void ScreenshotService::stop() {
auto lock = mutex.asScopedLock();
if (!lock.lock(50 / portTICK_PERIOD_MS)) {
TT_LOG_W(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
LOGGER.warn(LOG_MESSAGE_MUTEX_LOCK_FAILED);
return;
}
@@ -72,14 +72,14 @@ void ScreenshotService::stop() {
task = nullptr;
mode = Mode::None;
} else {
TT_LOG_W(TAG, "Screenshot task not running");
LOGGER.warn("Screenshot task not running");
}
}
Mode ScreenshotService::getMode() const {
auto lock = mutex.asScopedLock();
if (!lock.lock(50 / portTICK_PERIOD_MS)) {
TT_LOG_W(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
LOGGER.warn(LOG_MESSAGE_MUTEX_LOCK_FAILED);
return Mode::None;
}
@@ -1,21 +1,22 @@
#include "Tactility/TactilityConfig.h"
#include <Tactility/TactilityConfig.h>
#if TT_FEATURE_SCREENSHOT_ENABLED
#include "Tactility/service/screenshot/ScreenshotTask.h"
#include "Tactility/service/loader/Loader.h"
#include "Tactility/lvgl/LvglSync.h"
#include <lv_screenshot.h>
#include <Tactility/CpuAffinity.h>
#include <Tactility/Logger.h>
#include <Tactility/LogMessages.h>
#include <Tactility/lvgl/LvglSync.h>
#include <Tactility/service/screenshot/ScreenshotTask.h>
#include <Tactility/service/loader/Loader.h>
#include <Tactility/TactilityCore.h>
#include <lv_screenshot.h>
#include <format>
#include <Tactility/CpuAffinity.h>
namespace tt::service::screenshot {
#define TAG "screenshot_task"
static const auto LOGGER = Logger("ScreenshotTask");
ScreenshotTask::~ScreenshotTask() {
if (thread) {
@@ -26,7 +27,7 @@ ScreenshotTask::~ScreenshotTask() {
bool ScreenshotTask::isInterrupted() {
auto lock = mutex.asScopedLock();
if (!lock.lock(50 / portTICK_PERIOD_MS)) {
TT_LOG_W(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
LOGGER.warn(LOG_MESSAGE_MUTEX_LOCK_FAILED);
return true;
}
return interrupted;
@@ -35,7 +36,7 @@ bool ScreenshotTask::isInterrupted() {
bool ScreenshotTask::isFinished() {
auto lock = mutex.asScopedLock();
if (!lock.lock(50 / portTICK_PERIOD_MS)) {
TT_LOG_W(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
LOGGER.warn(LOG_MESSAGE_MUTEX_LOCK_FAILED);
return false;
}
return finished;
@@ -50,13 +51,13 @@ void ScreenshotTask::setFinished() {
static void makeScreenshot(const std::string& filename) {
if (lvgl::lock(50 / portTICK_PERIOD_MS)) {
if (lv_screenshot_create(lv_scr_act(), LV_100ASK_SCREENSHOT_SV_PNG, filename.c_str())) {
TT_LOG_I(TAG, "Screenshot saved to %s", filename.c_str());
LOGGER.info("Screenshot saved to {}", filename);
} else {
TT_LOG_E(TAG, "Screenshot not saved to %s", filename.c_str());
LOGGER.error("Screenshot not saved to {}", filename);
}
lvgl::unlock();
} else {
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "LVGL");
LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "LVGL");
}
}
@@ -102,7 +103,7 @@ void ScreenshotTask::taskMain() {
void ScreenshotTask::taskStart() {
auto lock = mutex.asScopedLock();
if (!lock.lock(50 / portTICK_PERIOD_MS)) {
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED);
return;
}
@@ -122,7 +123,7 @@ void ScreenshotTask::taskStart() {
void ScreenshotTask::startApps(const std::string& path) {
auto lock = mutex.asScopedLock();
if (!lock.lock(50 / portTICK_PERIOD_MS)) {
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED);
return;
}
@@ -132,14 +133,14 @@ void ScreenshotTask::startApps(const std::string& path) {
work.path = path;
taskStart();
} else {
TT_LOG_E(TAG, "Task was already running");
LOGGER.error("Task was already running");
}
}
void ScreenshotTask::startTimed(const std::string& path, uint8_t delay_in_seconds, uint8_t amount) {
auto lock = mutex.asScopedLock();
if (!lock.lock(50 / portTICK_PERIOD_MS)) {
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED);
return;
}
@@ -151,7 +152,7 @@ void ScreenshotTask::startTimed(const std::string& path, uint8_t delay_in_second
work.path = path;
taskStart();
} else {
TT_LOG_E(TAG, "Task was already running");
LOGGER.error("Task was already running");
}
}
+9 -8
View File
@@ -1,14 +1,15 @@
#include <Tactility/hal/sdcard/SdCardDevice.h>
#include <Tactility/Logger.h>
#include <Tactility/LogMessages.h>
#include <Tactility/Mutex.h>
#include <Tactility/service/ServiceContext.h>
#include <Tactility/service/ServiceRegistration.h>
#include <Tactility/Timer.h>
#include <Tactility/Mutex.h>
#include <Tactility/Tactility.h>
#include <Tactility/hal/sdcard/SdCardDevice.h>
#include <Tactility/Timer.h>
namespace tt::service::sdcard {
constexpr auto* TAG = "SdcardService";
static const auto LOGGER = Logger("SdcardService");
extern const ServiceManifest manifest;
@@ -37,7 +38,7 @@ class SdCardService final : public Service {
auto new_state = sdcard->getState();
if (new_state == hal::sdcard::SdCardDevice::State::Error) {
TT_LOG_E(TAG, "Sdcard error - unmounting. Did you eject the card in an unsafe manner?");
LOGGER.error("Sdcard error - unmounting. Did you eject the card in an unsafe manner?");
sdcard->unmount();
}
@@ -47,7 +48,7 @@ class SdCardService final : public Service {
unlock();
} else {
TT_LOG_W(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
LOGGER.warn(LOG_MESSAGE_MUTEX_LOCK_FAILED);
}
}
@@ -55,7 +56,7 @@ public:
bool onStart(ServiceContext& serviceContext) override {
if (hal::findFirstDevice<hal::sdcard::SdCardDevice>(hal::Device::Type::SdCard) == nullptr) {
TT_LOG_W(TAG, "No SD card device found - not starting Service");
LOGGER.warn("No SD card device found - not starting Service");
return false;
}
@@ -1,20 +1,21 @@
#include <Tactility/lvgl/Statusbar.h>
#include <Tactility/Timer.h>
#include <Tactility/Mutex.h>
#include <Tactility/hal/power/PowerDevice.h>
#include <Tactility/hal/sdcard/SdCardDevice.h>
#include <Tactility/Logger.h>
#include <Tactility/lvgl/Lvgl.h>
#include <Tactility/lvgl/LvglSync.h>
#include <Tactility/Mutex.h>
#include <Tactility/service/ServiceContext.h>
#include <Tactility/service/ServicePaths.h>
#include <Tactility/service/ServiceRegistration.h>
#include <Tactility/service/gps/GpsService.h>
#include <Tactility/service/wifi/Wifi.h>
#include <Tactility/Timer.h>
namespace tt::service::statusbar {
constexpr auto* TAG = "StatusbarService";
static const auto LOGGER = Logger("StatusbarService");
// SD card status
constexpr auto* STATUSBAR_ICON_SDCARD = "sdcard.png";
@@ -252,7 +253,7 @@ public:
bool onStart(ServiceContext& serviceContext) override {
if (lv_screen_active() == nullptr) {
TT_LOG_E(TAG, "No display found");
LOGGER.error("No display found");
return false;
}
@@ -4,6 +4,7 @@
#include <Tactility/crypt/Crypt.h>
#include <Tactility/file/File.h>
#include <Tactility/Logger.h>
#include <Tactility/service/ServicePaths.h>
#include <format>
@@ -14,7 +15,7 @@
namespace tt::service::wifi::settings {
constexpr auto* TAG = "WifiApSettings";
static const auto LOGGER = Logger("WifiApSettings");
constexpr auto* AP_SETTINGS_FORMAT = "{}/{}.ap.properties";
@@ -33,7 +34,7 @@ std::string toHexString(const uint8_t *data, int length) {
bool readHex(const std::string& input, uint8_t* buffer, int length) {
if (input.size() / 2 != length) {
TT_LOG_E(TAG, "readHex() length mismatch");
LOGGER.error("readHex() length mismatch");
return false;
}
@@ -63,7 +64,7 @@ static bool encrypt(const std::string& ssidInput, std::string& ssidOutput) {
crypt::getIv(ssidInput.c_str(), ssidInput.size(), iv);
if (crypt::encrypt(iv, reinterpret_cast<const uint8_t*>(ssidInput.c_str()), buffer, encrypted_length) != 0) {
TT_LOG_E(TAG, "Failed to encrypt");
LOGGER.error("Failed to encrypt");
free(buffer);
return false;
}
@@ -79,7 +80,7 @@ static bool decrypt(const std::string& ssidInput, std::string& ssidOutput) {
assert(ssidInput.size() % 2 == 0);
auto* data = static_cast<uint8_t*>(malloc(ssidInput.size() / 2));
if (!readHex(ssidInput, data, ssidInput.size() / 2)) {
TT_LOG_E(TAG, "Failed to read hex");
LOGGER.error("Failed to read hex");
return false;
}
@@ -101,7 +102,7 @@ static bool decrypt(const std::string& ssidInput, std::string& ssidOutput) {
free(data);
if (decrypt_result != 0) {
TT_LOG_E(TAG, "Failed to decrypt credentials for \"%s\": %d", ssidInput.c_str(), decrypt_result);
LOGGER.error("Failed to decrypt credentials for \"{}s\": {}", ssidInput, decrypt_result);
free(result);
return false;
}
@@ -3,7 +3,7 @@
#include <Tactility/MountPoints.h>
#include <Tactility/file/File.h>
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#include <Tactility/service/wifi/WifiApSettings.h>
#include <dirent.h>
@@ -16,7 +16,7 @@
namespace tt::service::wifi {
constexpr auto* TAG = "WifiBootSplashInit";
static const auto LOGGER = Logger("WifiBootSplashInit");
constexpr auto* AP_PROPERTIES_KEY_SSID = "ssid";
constexpr auto* AP_PROPERTIES_KEY_PASSWORD = "password";
@@ -35,13 +35,13 @@ struct ApProperties {
static void importWifiAp(const std::string& filePath) {
std::map<std::string, std::string> map;
if (!file::loadPropertiesFile(filePath, map)) {
TT_LOG_E(TAG, "Failed to load AP properties at %s", filePath.c_str());
LOGGER.error("Failed to load AP properties at {}", filePath);
return;
}
const auto ssid_iterator = map.find(AP_PROPERTIES_KEY_SSID);
if (ssid_iterator == map.end()) {
TT_LOG_E(TAG, "%s is missing ssid", filePath.c_str());
LOGGER.error("{} is missing ssid", filePath);
return;
}
const auto ssid = ssid_iterator->second;
@@ -65,18 +65,18 @@ static void importWifiAp(const std::string& filePath) {
);
if (!settings::save(settings)) {
TT_LOG_E(TAG, "Failed to save settings for %s", ssid.c_str());
LOGGER.error("Failed to save settings for {}", ssid);
} else {
TT_LOG_I(TAG, "Imported %s from %s", ssid.c_str(), filePath.c_str());
LOGGER.info("Imported {} from {}", ssid, filePath);
}
}
const auto auto_remove_iterator = map.find(AP_PROPERTIES_KEY_AUTO_REMOVE);
if (auto_remove_iterator != map.end() && auto_remove_iterator->second == "true") {
if (!remove(filePath.c_str())) {
TT_LOG_E(TAG, "Failed to auto-remove %s", filePath.c_str());
LOGGER.error("Failed to auto-remove {}", filePath);
} else {
TT_LOG_I(TAG, "Auto-removed %s", filePath.c_str());
LOGGER.info("Auto-removed {}", filePath);
}
}
}
@@ -105,7 +105,7 @@ static void importWifiApSettingsFromDir(const std::string& path) {
}
if (dirent_list.empty()) {
TT_LOG_W(TAG, "No AP files found at %s", path.c_str());
LOGGER.warn("No AP files found at {}", path);
return;
}
@@ -128,7 +128,7 @@ void bootSplashInit() {
const std::string settings_path = file::getChildPath(sdcard->getMountPath(), "settings");
importWifiApSettingsFromDir(settings_path);
} else {
TT_LOG_W(TAG, "Skipping unmounted SD card %s", sdcard->getMountPath().c_str());
LOGGER.warn("Skipping unmounted SD card {}", sdcard->getMountPath());
}
}
});
+77 -74
View File
@@ -6,10 +6,12 @@
#include <Tactility/service/wifi/Wifi.h>
#include <Tactility/Timer.h>
#include <Tactility/EventGroup.h>
#include <Tactility/Logger.h>
#include <Tactility/LogMessages.h>
#include <Tactility/RecursiveMutex.h>
#include <Tactility/Tactility.h>
#include <Tactility/Timer.h>
#include <Tactility/kernel/SystemEvents.h>
#include <Tactility/service/ServiceContext.h>
#include <Tactility/service/wifi/WifiBootSplashInit.h>
@@ -24,7 +26,8 @@
namespace tt::service::wifi {
constexpr auto* TAG = "WifiService";
static const auto LOGGER = Logger("WifiService");
constexpr auto WIFI_CONNECTED_BIT = BIT0;
constexpr auto WIFI_FAIL_BIT = BIT1;
constexpr auto AUTO_SCAN_INTERVAL = 10000; // ms
@@ -170,7 +173,7 @@ std::string getConnectionTarget() {
}
void scan() {
TT_LOG_I(TAG, "scan()");
LOGGER.info("scan()");
auto wifi = wifi_singleton;
if (wifi == nullptr) {
return;
@@ -189,7 +192,7 @@ bool isScanning() {
}
void connect(const settings::WifiApSettings& ap, bool remember) {
TT_LOG_I(TAG, "connect(%s, %d)", ap.ssid.c_str(), remember);
LOGGER.info("connect({}, {})", ap.ssid, remember);
auto wifi = wifi_singleton;
if (wifi == nullptr) {
return;
@@ -213,7 +216,7 @@ void connect(const settings::WifiApSettings& ap, bool remember) {
}
void disconnect() {
TT_LOG_I(TAG, "disconnect()");
LOGGER.info("disconnect()");
auto wifi = wifi_singleton;
if (wifi == nullptr) {
return;
@@ -244,7 +247,7 @@ void clearIp() {
memset(&wifi->ip_info, 0, sizeof(esp_netif_ip_info_t));
}
void setScanRecords(uint16_t records) {
TT_LOG_I(TAG, "setScanRecords(%d)", records);
LOGGER.info("setScanRecords({})", records);
auto wifi = wifi_singleton;
if (wifi == nullptr) {
return;
@@ -262,7 +265,7 @@ void setScanRecords(uint16_t records) {
}
std::vector<ApRecord> getScanResults() {
TT_LOG_I(TAG, "getScanResults()");
LOGGER.info("getScanResults()");
auto wifi = wifi_singleton;
std::vector<ApRecord> records;
@@ -293,7 +296,7 @@ std::vector<ApRecord> getScanResults() {
}
void setEnabled(bool enabled) {
TT_LOG_I(TAG, "setEnabled(%d)", enabled);
LOGGER.info("setEnabled({})", enabled);
auto wifi = wifi_singleton;
if (wifi == nullptr) {
return;
@@ -390,7 +393,7 @@ static bool copy_scan_list(std::shared_ptr<Wifi> wifi) {
wifi->isScanActive();
if (!can_fetch_results) {
TT_LOG_I(TAG, "Skip scan result fetching");
LOGGER.info("Skip scan result fetching");
return false;
}
@@ -407,11 +410,11 @@ static bool copy_scan_list(std::shared_ptr<Wifi> wifi) {
if (scan_result == ESP_OK) {
uint16_t safe_record_count = std::min(wifi->scan_list_limit, record_count);
wifi->scan_list_count = safe_record_count;
TT_LOG_I(TAG, "Scanned %u APs. Showing %u:", record_count, safe_record_count);
LOGGER.info("Scanned {} APs. Showing {}:", record_count, safe_record_count);
for (uint16_t i = 0; i < safe_record_count; i++) {
wifi_ap_record_t* record = &wifi->scan_list[i];
TT_LOG_I(TAG, " - SSID %s, RSSI %d, channel %d, BSSID %02X%02X%02X%02X%02X%02X",
record->ssid,
LOGGER.info(" - SSID {}, RSSI {}, channel {}, BSSID {:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}",
reinterpret_cast<const char*>(record->ssid),
record->rssi,
record->primary,
record->bssid[0],
@@ -424,13 +427,13 @@ static bool copy_scan_list(std::shared_ptr<Wifi> wifi) {
}
return true;
} else {
TT_LOG_I(TAG, "Failed to get scanned records: %s", esp_err_to_name(scan_result));
LOGGER.info("Failed to get scanned records: {}", esp_err_to_name(scan_result));
return false;
}
}
static bool find_auto_connect_ap(std::shared_ptr<Wifi> wifi, settings::WifiApSettings& settings) {
TT_LOG_I(TAG, "find_auto_connect_ap()");
LOGGER.info("find_auto_connect_ap()");
auto lock = wifi->dataMutex.asScopedLock();
if (lock.lock(10 / portTICK_PERIOD_MS)) {
for (int i = 0; i < wifi->scan_list_count; ++i) {
@@ -442,7 +445,7 @@ static bool find_auto_connect_ap(std::shared_ptr<Wifi> wifi, settings::WifiApSet
return true;
}
} else {
TT_LOG_E(TAG, "Failed to load credentials for ssid %s", ssid);
LOGGER.error("Failed to load credentials for ssid {}", ssid);
}
break;
}
@@ -453,11 +456,11 @@ static bool find_auto_connect_ap(std::shared_ptr<Wifi> wifi, settings::WifiApSet
}
static void dispatchAutoConnect(std::shared_ptr<Wifi> wifi) {
TT_LOG_I(TAG, "dispatchAutoConnect()");
LOGGER.info("dispatchAutoConnect()");
settings::WifiApSettings settings;
if (find_auto_connect_ap(wifi, settings)) {
TT_LOG_I(TAG, "Auto-connecting to %s", settings.ssid.c_str());
LOGGER.info("Auto-connecting to {}", settings.ssid);
connect(settings, false);
// TODO: We currently have to manually reset it because connect() sets it.
// connect() assumes it's only being called by the user and not internally, so it disables auto-connect
@@ -468,23 +471,23 @@ static void dispatchAutoConnect(std::shared_ptr<Wifi> wifi) {
static void eventHandler(TT_UNUSED void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) {
auto wifi = wifi_singleton;
if (wifi == nullptr) {
TT_LOG_E(TAG, "eventHandler: no wifi instance");
LOGGER.error("eventHandler: no wifi instance");
return;
}
if (event_base == WIFI_EVENT) {
TT_LOG_I(TAG, "eventHandler: WIFI_EVENT (%ld)", event_id);
LOGGER.info("eventHandler: WIFI_EVENT {}", event_id);
} else if (event_base == IP_EVENT) {
TT_LOG_I(TAG, "eventHandler: IP_EVENT (%ld)", event_id);
LOGGER.info("eventHandler: IP_EVENT {}", event_id);
}
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) {
TT_LOG_I(TAG, "eventHandler: sta start");
LOGGER.info("eventHandler: STA_START");
if (wifi->getRadioState() == RadioState::ConnectionPending) {
esp_wifi_connect();
}
} else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) {
TT_LOG_I(TAG, "eventHandler: disconnected");
LOGGER.info("eventHandler: STA_DISCONNECTED");
clearIp();
switch (wifi->getRadioState()) {
case RadioState::ConnectionPending:
@@ -503,7 +506,7 @@ static void eventHandler(TT_UNUSED void* arg, esp_event_base_t event_base, int32
} else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
auto* event = static_cast<ip_event_got_ip_t*>(event_data);
memcpy(&wifi->ip_info, &event->ip_info, sizeof(esp_netif_ip_info_t));
TT_LOG_I(TAG, "eventHandler: got ip:" IPSTR, IP2STR(&event->ip_info.ip));
LOGGER.info("eventHandler: got ip: {}.{}.{}.{}", IP2STR(&event->ip_info.ip));
if (wifi->getRadioState() == RadioState::ConnectionPending) {
wifi->connection_wait_flags.set(WIFI_CONNECTED_BIT);
// We resume auto-connecting only when there was an explicit request by the user for the connection
@@ -513,7 +516,7 @@ static void eventHandler(TT_UNUSED void* arg, esp_event_base_t event_base, int32
kernel::publishSystemEvent(kernel::SystemEvent::NetworkConnected);
} else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_SCAN_DONE) {
auto* event = static_cast<wifi_event_sta_scan_done_t*>(event_data);
TT_LOG_I(TAG, "eventHandler: wifi scanning done (scan id %u)", event->scan_id);
LOGGER.info("eventHandler: wifi scanning done (scan id {})", event->scan_id);
bool copied_list = copy_scan_list(wifi);
auto state = wifi->getRadioState();
@@ -526,7 +529,7 @@ static void eventHandler(TT_UNUSED void* arg, esp_event_base_t event_base, int32
}
publish_event(wifi_singleton, WifiEvent::ScanFinished);
TT_LOG_I(TAG, "eventHandler: Finished scan");
LOGGER.info("eventHandler: Finished scan");
if (copied_list && wifi_singleton->getRadioState() == RadioState::On && !wifi->pause_auto_connect) {
getMainDispatcher().dispatch([wifi]() { dispatchAutoConnect(wifi); });
@@ -535,7 +538,7 @@ static void eventHandler(TT_UNUSED void* arg, esp_event_base_t event_base, int32
}
static void dispatchEnable(std::shared_ptr<Wifi> wifi) {
TT_LOG_I(TAG, "dispatchEnable()");
LOGGER.info("dispatchEnable()");
RadioState state = wifi->getRadioState();
if (
@@ -543,13 +546,13 @@ static void dispatchEnable(std::shared_ptr<Wifi> wifi) {
state == RadioState::OnPending ||
state == RadioState::OffPending
) {
TT_LOG_W(TAG, "Can't enable from current state");
LOGGER.warn("Can't enable from current state");
return;
}
auto lock = wifi->radioMutex.asScopedLock();
if (lock.lock(50 / portTICK_PERIOD_MS)) {
TT_LOG_I(TAG, "Enabling");
LOGGER.info("Enabling");
wifi->setRadioState(RadioState::OnPending);
publish_event(wifi, WifiEvent::RadioStateOnPending);
@@ -563,9 +566,9 @@ static void dispatchEnable(std::shared_ptr<Wifi> wifi) {
wifi_init_config_t config = WIFI_INIT_CONFIG_DEFAULT();
esp_err_t init_result = esp_wifi_init(&config);
if (init_result != ESP_OK) {
TT_LOG_E(TAG, "Wifi init failed");
LOGGER.error("Wifi init failed");
if (init_result == ESP_ERR_NO_MEM) {
TT_LOG_E(TAG, "Insufficient memory");
LOGGER.error("Insufficient memory");
}
wifi->setRadioState(RadioState::Off);
publish_event(wifi, WifiEvent::RadioStateOff);
@@ -593,7 +596,7 @@ static void dispatchEnable(std::shared_ptr<Wifi> wifi) {
));
if (esp_wifi_set_mode(WIFI_MODE_STA) != ESP_OK) {
TT_LOG_E(TAG, "Wifi mode setting failed");
LOGGER.error("Wifi mode setting failed");
wifi->setRadioState(RadioState::Off);
esp_wifi_deinit();
publish_event(wifi, WifiEvent::RadioStateOff);
@@ -602,9 +605,9 @@ static void dispatchEnable(std::shared_ptr<Wifi> wifi) {
esp_err_t start_result = esp_wifi_start();
if (start_result != ESP_OK) {
TT_LOG_E(TAG, "Wifi start failed");
LOGGER.error("Wifi start failed");
if (start_result == ESP_ERR_NO_MEM) {
TT_LOG_E(TAG, "Insufficient memory");
LOGGER.error("Insufficient memory");
}
wifi->setRadioState(RadioState::Off);
esp_wifi_set_mode(WIFI_MODE_NULL);
@@ -618,18 +621,18 @@ static void dispatchEnable(std::shared_ptr<Wifi> wifi) {
wifi->pause_auto_connect = false;
TT_LOG_I(TAG, "Enabled");
LOGGER.info("Enabled");
} else {
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED);
}
}
static void dispatchDisable(std::shared_ptr<Wifi> wifi) {
TT_LOG_I(TAG, "dispatchDisable()");
LOGGER.info("dispatchDisable()");
auto lock = wifi->radioMutex.asScopedLock();
if (!lock.lock(50 / portTICK_PERIOD_MS)) {
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "disable()");
LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "disable()");
return;
}
@@ -639,11 +642,11 @@ static void dispatchDisable(std::shared_ptr<Wifi> wifi) {
state == RadioState::OffPending ||
state == RadioState::OnPending
) {
TT_LOG_W(TAG, "Can't disable from current state");
LOGGER.warn("Can't disable from current state");
return;
}
TT_LOG_I(TAG, "Disabling");
LOGGER.info("Disabling");
wifi->setRadioState(RadioState::OffPending);
publish_event(wifi, WifiEvent::RadioStateOffPending);
@@ -651,14 +654,14 @@ static void dispatchDisable(std::shared_ptr<Wifi> wifi) {
scan_list_free_safely(wifi_singleton);
if (esp_wifi_stop() != ESP_OK) {
TT_LOG_E(TAG, "Failed to stop radio");
LOGGER.error("Failed to stop radio");
wifi->setRadioState(RadioState::On);
publish_event(wifi, WifiEvent::RadioStateOn);
return;
}
if (esp_wifi_set_mode(WIFI_MODE_NULL) != ESP_OK) {
TT_LOG_E(TAG, "Failed to unset mode");
LOGGER.error("Failed to unset mode");
}
if (esp_event_handler_instance_unregister(
@@ -666,7 +669,7 @@ static void dispatchDisable(std::shared_ptr<Wifi> wifi) {
ESP_EVENT_ANY_ID,
wifi->event_handler_any_id
) != ESP_OK) {
TT_LOG_E(TAG, "Failed to unregister id event handler");
LOGGER.error("Failed to unregister id event handler");
}
if (esp_event_handler_instance_unregister(
@@ -674,11 +677,11 @@ static void dispatchDisable(std::shared_ptr<Wifi> wifi) {
IP_EVENT_STA_GOT_IP,
wifi->event_handler_got_ip
) != ESP_OK) {
TT_LOG_E(TAG, "Failed to unregister ip event handler");
LOGGER.error("Failed to unregister ip event handler");
}
if (esp_wifi_deinit() != ESP_OK) {
TT_LOG_E(TAG, "Failed to deinit");
LOGGER.error("Failed to deinit");
}
assert(wifi->netif != nullptr);
@@ -687,26 +690,26 @@ static void dispatchDisable(std::shared_ptr<Wifi> wifi) {
wifi->setScanActive(false);
wifi->setRadioState(RadioState::Off);
publish_event(wifi, WifiEvent::RadioStateOff);
TT_LOG_I(TAG, "Disabled");
LOGGER.info("Disabled");
}
static void dispatchScan(std::shared_ptr<Wifi> wifi) {
TT_LOG_I(TAG, "dispatchScan()");
LOGGER.info("dispatchScan()");
auto lock = wifi->radioMutex.asScopedLock();
if (!lock.lock(10 / portTICK_PERIOD_MS)) {
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED);
return;
}
RadioState state = wifi->getRadioState();
if (state != RadioState::On && state != RadioState::ConnectionActive && state != RadioState::ConnectionPending) {
TT_LOG_W(TAG, "Scan unavailable: wifi not enabled");
LOGGER.warn("Scan unavailable: wifi not enabled");
return;
}
if (wifi->isScanActive()) {
TT_LOG_W(TAG, "Scan already pending");
LOGGER.warn("Scan already pending");
return;
}
@@ -714,25 +717,25 @@ static void dispatchScan(std::shared_ptr<Wifi> wifi) {
wifi->last_scan_time = tt::kernel::getTicks();
if (esp_wifi_scan_start(nullptr, false) != ESP_OK) {
TT_LOG_I(TAG, "Can't start scan");
LOGGER.info("Can't start scan");
return;
}
TT_LOG_I(TAG, "Starting scan");
LOGGER.info("Starting scan");
wifi->setScanActive(true);
publish_event(wifi, WifiEvent::ScanStarted);
}
static void dispatchConnect(std::shared_ptr<Wifi> wifi) {
TT_LOG_I(TAG, "dispatchConnect()");
LOGGER.info("dispatchConnect()");
auto lock = wifi->radioMutex.asScopedLock();
if (!lock.lock(50 / portTICK_PERIOD_MS)) {
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "dispatchConnect()");
LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "dispatchConnect()");
return;
}
TT_LOG_I(TAG, "Connecting to %s", wifi->connection_target.ssid.c_str());
LOGGER.info("Connecting to {}", wifi->connection_target.ssid);
// Stop radio first, if needed
RadioState radio_state = wifi->getRadioState();
@@ -741,11 +744,11 @@ static void dispatchConnect(std::shared_ptr<Wifi> wifi) {
radio_state == RadioState::ConnectionActive ||
radio_state == RadioState::ConnectionPending
) {
TT_LOG_I(TAG, "Connecting: Stopping radio first");
LOGGER.info("Connecting: Stopping radio first");
esp_err_t stop_result = esp_wifi_stop();
wifi->setScanActive(false);
if (stop_result != ESP_OK) {
TT_LOG_E(TAG, "Connecting: Failed to disconnect (%s)", esp_err_to_name(stop_result));
LOGGER.error("Connecting: Failed to disconnect ({})", esp_err_to_name(stop_result));
return;
}
}
@@ -771,20 +774,20 @@ static void dispatchConnect(std::shared_ptr<Wifi> wifi) {
config.sta.threshold.authmode = WIFI_AUTH_WPA2_PSK;
}
TT_LOG_I(TAG, "esp_wifi_set_config()");
LOGGER.info("esp_wifi_set_config()");
esp_err_t set_config_result = esp_wifi_set_config(WIFI_IF_STA, &config);
if (set_config_result != ESP_OK) {
wifi->setRadioState(RadioState::On);
TT_LOG_E(TAG, "Failed to set wifi config (%s)", esp_err_to_name(set_config_result));
LOGGER.error("Failed to set wifi config ({})", esp_err_to_name(set_config_result));
publish_event(wifi, WifiEvent::ConnectionFailed);
return;
}
TT_LOG_I(TAG, "esp_wifi_start()");
LOGGER.info("esp_wifi_start()");
esp_err_t wifi_start_result = esp_wifi_start();
if (wifi_start_result != ESP_OK) {
wifi->setRadioState(RadioState::On);
TT_LOG_E(TAG, "Failed to start wifi to begin connecting (%s)", esp_err_to_name(wifi_start_result));
LOGGER.error("Failed to start wifi to begin connecting ({})", esp_err_to_name(wifi_start_result));
publish_event(wifi, WifiEvent::ConnectionFailed);
return;
}
@@ -794,28 +797,28 @@ static void dispatchConnect(std::shared_ptr<Wifi> wifi) {
* The bits are set by wifi_event_handler() */
uint32_t bits;
if (wifi_singleton->connection_wait_flags.wait(WIFI_FAIL_BIT | WIFI_CONNECTED_BIT, false, true, kernel::MAX_TICKS, &bits)) {
TT_LOG_I(TAG, "Waiting for EventGroup by event_handler()");
LOGGER.info("Waiting for EventGroup by event_handler()");
if (bits & WIFI_CONNECTED_BIT) {
wifi->setSecureConnection(config.sta.password[0] != 0x00U);
wifi->setRadioState(RadioState::ConnectionActive);
publish_event(wifi, WifiEvent::ConnectionSuccess);
TT_LOG_I(TAG, "Connected to %s", wifi->connection_target.ssid.c_str());
LOGGER.info("Connected to {}", wifi->connection_target.ssid.c_str());
if (wifi->connection_target_remember) {
if (!settings::save(wifi->connection_target)) {
TT_LOG_E(TAG, "Failed to store credentials");
LOGGER.error("Failed to store credentials");
} else {
TT_LOG_I(TAG, "Stored credentials");
LOGGER.info("Stored credentials");
}
}
} else if (bits & WIFI_FAIL_BIT) {
wifi->setRadioState(RadioState::On);
publish_event(wifi, WifiEvent::ConnectionFailed);
TT_LOG_I(TAG, "Failed to connect to %s", wifi->connection_target.ssid.c_str());
LOGGER.info("Failed to connect to {}", wifi->connection_target.ssid.c_str());
} else {
wifi->setRadioState(RadioState::On);
publish_event(wifi, WifiEvent::ConnectionFailed);
TT_LOG_E(TAG, "UNEXPECTED EVENT");
LOGGER.error("UNEXPECTED EVENT");
}
wifi_singleton->connection_wait_flags.clear(WIFI_FAIL_BIT | WIFI_CONNECTED_BIT);
@@ -823,17 +826,17 @@ static void dispatchConnect(std::shared_ptr<Wifi> wifi) {
}
static void dispatchDisconnectButKeepActive(std::shared_ptr<Wifi> wifi) {
TT_LOG_I(TAG, "dispatchDisconnectButKeepActive()");
LOGGER.info("dispatchDisconnectButKeepActive()");
auto lock = wifi->radioMutex.asScopedLock();
if (!lock.lock(50 / portTICK_PERIOD_MS)) {
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED);
return;
}
esp_err_t stop_result = esp_wifi_stop();
if (stop_result != ESP_OK) {
TT_LOG_E(TAG, "Failed to disconnect (%s)", esp_err_to_name(stop_result));
LOGGER.error("Failed to disconnect ({})", esp_err_to_name(stop_result));
return;
}
@@ -849,7 +852,7 @@ static void dispatchDisconnectButKeepActive(std::shared_ptr<Wifi> wifi) {
if (set_config_result != ESP_OK) {
// TODO: disable radio, because radio state is in limbo between off and on
wifi->setRadioState(RadioState::Off);
TT_LOG_E(TAG, "failed to set wifi config (%s)", esp_err_to_name(set_config_result));
LOGGER.error("failed to set wifi config ({})", esp_err_to_name(set_config_result));
publish_event(wifi, WifiEvent::RadioStateOff);
return;
}
@@ -858,14 +861,14 @@ static void dispatchDisconnectButKeepActive(std::shared_ptr<Wifi> wifi) {
if (wifi_start_result != ESP_OK) {
// TODO: disable radio, because radio state is in limbo between off and on
wifi->setRadioState(RadioState::Off);
TT_LOG_E(TAG, "failed to start wifi to begin connecting (%s)", esp_err_to_name(wifi_start_result));
LOGGER.error("failed to start wifi to begin connecting ({})", esp_err_to_name(wifi_start_result));
publish_event(wifi, WifiEvent::RadioStateOff);
return;
}
wifi->setRadioState(RadioState::On);
publish_event(wifi, WifiEvent::Disconnected);
TT_LOG_I(TAG, "Disconnected");
LOGGER.info("Disconnected");
}
static bool shouldScanForAutoConnect(std::shared_ptr<Wifi> wifi) {
@@ -882,7 +885,7 @@ static bool shouldScanForAutoConnect(std::shared_ptr<Wifi> wifi) {
return false;
}
TickType_t current_time = tt::kernel::getTicks();
TickType_t current_time = kernel::getTicks();
bool scan_time_has_looped = (current_time < wifi->last_scan_time);
bool no_recent_scan = (current_time - wifi->last_scan_time) > (AUTO_SCAN_INTERVAL / portTICK_PERIOD_MS);
@@ -928,7 +931,7 @@ public:
wifi_singleton->autoConnectTimer->start();
if (settings::shouldEnableOnBoot()) {
TT_LOG_I(TAG, "Auto-enabling due to setting");
LOGGER.info("Auto-enabling due to setting");
getMainDispatcher().dispatch([] { dispatchEnable(wifi_singleton); });
}
@@ -8,15 +8,12 @@
#include <Tactility/PubSub.h>
#include <Tactility/Check.h>
#include <Tactility/Log.h>
#include <Tactility/RecursiveMutex.h>
#include <Tactility/service/Service.h>
#include <Tactility/service/ServiceManifest.h>
namespace tt::service::wifi {
constexpr auto* TAG = "Wifi";
struct Wifi {
/** @brief Locking mechanism for modifying the Wifi instance */
RecursiveMutex mutex;
@@ -1,14 +1,14 @@
#include <Tactility/service/wifi/WifiSettings.h>
#include <Tactility/Log.h>
#include <Tactility/file/File.h>
#include <Tactility/file/PropertiesFile.h>
#include <Tactility/Logger.h>
#include <Tactility/service/ServicePaths.h>
#include <Tactility/service/wifi/WifiPrivate.h>
namespace tt::service::wifi::settings {
constexpr auto* TAG = "WifiSettings";
static const auto LOGGER = Logger("WifiSettings");
constexpr auto* SETTINGS_KEY_ENABLE_ON_BOOT = "enableOnBoot";
struct WifiSettings {
@@ -56,7 +56,7 @@ static bool save(const WifiSettings& settings) {
WifiSettings getCachedOrLoad() {
if (!cached) {
if (!load(cachedSettings)) {
TT_LOG_E(TAG, "Failed to load");
LOGGER.error("Failed to load");
} else {
cached = true;
}
@@ -68,7 +68,7 @@ WifiSettings getCachedOrLoad() {
void setEnableOnBoot(bool enable) {
cachedSettings.enableOnBoot = enable;
if (!save(cachedSettings)) {
TT_LOG_E(TAG, "Failed to save");
LOGGER.error("Failed to save");
}
}
+4 -3
View File
@@ -2,7 +2,7 @@
#include <Tactility/file/File.h>
#include <Tactility/file/PropertiesFile.h>
#include <Tactility/hal/sdcard/SdCardDevice.h>
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#include <Tactility/settings/BootSettings.h>
#include <format>
@@ -11,7 +11,8 @@
namespace tt::settings {
constexpr auto* TAG = "BootSettings";
static const auto LOGGER = Logger("BootSettings");
constexpr auto* PROPERTIES_FILE_FORMAT = "{}/settings/boot.properties";
constexpr auto* PROPERTIES_KEY_LAUNCHER_APP_ID = "launcherAppId";
constexpr auto* PROPERTIES_KEY_AUTO_START_APP_ID = "autoStartAppId";
@@ -36,7 +37,7 @@ bool loadBootSettings(BootSettings& properties) {
properties.launcherAppId = value;
}
})) {
TT_LOG_E(TAG, "Failed to load %s", path.c_str());
LOGGER.error("Failed to load {}", path);
return false;
}

Some files were not shown because too many files have changed in this diff Show More