mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-08-20 17:05:06 +00:00
Logging changes and more
This commit is contained in:
parent
719f7bcece
commit
ec43eadb8f
@ -2,4 +2,4 @@ language=en-US
|
||||
timeFormat24h=true
|
||||
dateFormat=MM/DD/YYYY
|
||||
region=US
|
||||
timezone=America/Los_Angeles
|
||||
timezone=Europe/Amsterdam
|
||||
@ -1,20 +1,20 @@
|
||||
#include "PwmBacklight.h"
|
||||
#include "Tactility/kernel/SystemEvents.h"
|
||||
#include "Tactility/service/gps/GpsService.h"
|
||||
|
||||
#include <Tactility/TactilityCore.h>
|
||||
#include <Tactility/hal/gps/GpsConfiguration.h>
|
||||
#include <Tactility/settings/KeyboardSettings.h>
|
||||
|
||||
#include "devices/KeyboardBacklight.h"
|
||||
#include "devices/TrackballDevice.h"
|
||||
#include <KeyboardBacklight/KeyboardBacklight.h>
|
||||
|
||||
#include <Tactility/hal/gps/GpsConfiguration.h>
|
||||
#include <Tactility/kernel/SystemEvents.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/service/gps/GpsService.h>
|
||||
#include <Tactility/settings/KeyboardSettings.h>
|
||||
#include <Trackball/Trackball.h>
|
||||
|
||||
#define TAG "tdeck"
|
||||
#include <KeyboardBacklight/KeyboardBacklight.h>
|
||||
|
||||
static const auto LOGGER = tt::Logger("T-Deck");
|
||||
|
||||
// Power on
|
||||
#define TDECK_POWERON_GPIO GPIO_NUM_10
|
||||
constexpr auto TDECK_POWERON_GPIO = GPIO_NUM_10;
|
||||
|
||||
static bool powerOn() {
|
||||
gpio_config_t device_power_signal_config = {
|
||||
@ -37,9 +37,9 @@ static bool powerOn() {
|
||||
}
|
||||
|
||||
bool initBoot() {
|
||||
ESP_LOGI(TAG, LOG_MESSAGE_POWER_ON_START);
|
||||
LOGGER.info(LOG_MESSAGE_POWER_ON_START);
|
||||
if (!powerOn()) {
|
||||
TT_LOG_E(TAG, LOG_MESSAGE_POWER_ON_FAILED);
|
||||
LOGGER.error(LOG_MESSAGE_POWER_ON_FAILED);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -47,7 +47,7 @@ bool initBoot() {
|
||||
* when moving the brightness slider rapidly from a lower setting to 100%.
|
||||
* This is not a slider bug (data was debug-traced) */
|
||||
if (!driver::pwmbacklight::init(GPIO_NUM_42, 30000)) {
|
||||
TT_LOG_E(TAG, "Backlight init failed");
|
||||
LOGGER.error("Backlight init failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -58,9 +58,9 @@ bool initBoot() {
|
||||
gps_service->getGpsConfigurations(gps_configurations);
|
||||
if (gps_configurations.empty()) {
|
||||
if (gps_service->addGpsConfiguration(tt::hal::gps::GpsConfiguration {.uartName = "Grove", .baudRate = 38400, .model = tt::hal::gps::GpsModel::UBLOX10})) {
|
||||
TT_LOG_I(TAG, "Configured internal GPS");
|
||||
LOGGER.info("Configured internal GPS");
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Failed to configure internal GPS");
|
||||
LOGGER.error("Failed to configure internal GPS");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -69,23 +69,23 @@ bool initBoot() {
|
||||
tt::kernel::subscribeSystemEvent(tt::kernel::SystemEvent::BootSplash, [](tt::kernel::SystemEvent event) {
|
||||
auto kbBacklight = tt::hal::findDevice("Keyboard Backlight");
|
||||
if (kbBacklight != nullptr) {
|
||||
TT_LOG_I(TAG, "%s starting", kbBacklight->getName().c_str());
|
||||
LOGGER.info("{} starting", kbBacklight->getName());
|
||||
auto kbDevice = std::static_pointer_cast<KeyboardBacklightDevice>(kbBacklight);
|
||||
if (kbDevice->start()) {
|
||||
TT_LOG_I(TAG, "%s started", kbBacklight->getName().c_str());
|
||||
LOGGER.info("{} started", kbBacklight->getName());
|
||||
} else {
|
||||
TT_LOG_E(TAG, "%s start failed", kbBacklight->getName().c_str());
|
||||
LOGGER.error("{} start failed", kbBacklight->getName());
|
||||
}
|
||||
}
|
||||
|
||||
auto trackball = tt::hal::findDevice("Trackball");
|
||||
if (trackball != nullptr) {
|
||||
TT_LOG_I(TAG, "%s starting", trackball->getName().c_str());
|
||||
LOGGER.info("{} starting", trackball->getName());
|
||||
auto tbDevice = std::static_pointer_cast<TrackballDevice>(trackball);
|
||||
if (tbDevice->start()) {
|
||||
TT_LOG_I(TAG, "%s started", trackball->getName().c_str());
|
||||
LOGGER.info("{} started", trackball->getName());
|
||||
} else {
|
||||
TT_LOG_E(TAG, "%s start failed", trackball->getName().c_str());
|
||||
LOGGER.error("{} start failed", trackball->getName());
|
||||
}
|
||||
}
|
||||
|
||||
@ -99,7 +99,7 @@ bool initBoot() {
|
||||
auto kbSettings = tt::settings::keyboard::loadOrGetDefault();
|
||||
bool result = keyboardbacklight::setBrightness(kbSettings.backlightEnabled ? kbSettings.backlightBrightness : 0);
|
||||
if (!result) {
|
||||
TT_LOG_W(TAG, "Failed to set keyboard backlight brightness");
|
||||
LOGGER.warn("Failed to set keyboard backlight brightness");
|
||||
}
|
||||
|
||||
trackball::setEnabled(kbSettings.trackballEnabled);
|
||||
|
||||
@ -1,8 +1,11 @@
|
||||
#include "KeyboardBacklight.h"
|
||||
#include <esp_log.h>
|
||||
#include <cstring>
|
||||
|
||||
static const char* TAG = "KeyboardBacklight";
|
||||
#include <Tactility/Logger.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <esp_log.h>
|
||||
|
||||
static const auto LOGGER = tt::Logger("KeyboardBacklight");
|
||||
|
||||
namespace keyboardbacklight {
|
||||
|
||||
@ -18,16 +21,16 @@ bool init(i2c_port_t i2cPort, uint8_t slaveAddress) {
|
||||
g_i2cPort = i2cPort;
|
||||
g_slaveAddress = slaveAddress;
|
||||
|
||||
ESP_LOGI(TAG, "Keyboard backlight initialized on I2C port %d, address 0x%02X", g_i2cPort, g_slaveAddress);
|
||||
LOGGER.info("Initialized on I2C port {}, address 0x{:02X}", static_cast<int>(g_i2cPort), g_slaveAddress);
|
||||
|
||||
// Set a reasonable default brightness
|
||||
if (!setDefaultBrightness(127)) {
|
||||
ESP_LOGE(TAG, "Failed to set default brightness");
|
||||
LOGGER.error("Failed to set default brightness");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!setBrightness(127)) {
|
||||
ESP_LOGE(TAG, "Failed to set brightness");
|
||||
LOGGER.error("Failed to set brightness");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -36,7 +39,7 @@ bool init(i2c_port_t i2cPort, uint8_t slaveAddress) {
|
||||
|
||||
bool setBrightness(uint8_t brightness) {
|
||||
if (g_i2cPort >= I2C_NUM_MAX) {
|
||||
ESP_LOGE(TAG, "Keyboard backlight not initialized");
|
||||
LOGGER.error("Not initialized");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -45,7 +48,7 @@ bool setBrightness(uint8_t brightness) {
|
||||
return true;
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "Setting brightness to %d on I2C port %d, address 0x%02X", brightness, g_i2cPort, g_slaveAddress);
|
||||
LOGGER.info("Setting brightness to {} on I2C port {}, address 0x{:02X}", brightness, static_cast<int>(g_i2cPort), g_slaveAddress);
|
||||
|
||||
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
||||
i2c_master_start(cmd);
|
||||
@ -59,17 +62,17 @@ bool setBrightness(uint8_t brightness) {
|
||||
|
||||
if (ret == ESP_OK) {
|
||||
g_currentBrightness = brightness;
|
||||
ESP_LOGI(TAG, "Successfully set brightness to %d", brightness);
|
||||
LOGGER.info("Successfully set brightness to {}", brightness);
|
||||
return true;
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Failed to set brightness: %s (0x%x)", esp_err_to_name(ret), ret);
|
||||
LOGGER.error("Failed to set brightness: {} (0x%x)", esp_err_to_name(ret), ret);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool setDefaultBrightness(uint8_t brightness) {
|
||||
if (g_i2cPort >= I2C_NUM_MAX) {
|
||||
ESP_LOGE(TAG, "Keyboard backlight not initialized");
|
||||
LOGGER.error("Not initialized");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -89,17 +92,17 @@ bool setDefaultBrightness(uint8_t brightness) {
|
||||
i2c_cmd_link_delete(cmd);
|
||||
|
||||
if (ret == ESP_OK) {
|
||||
ESP_LOGD(TAG, "Set default brightness to %d", brightness);
|
||||
LOGGER.debug("Set default brightness to {}", brightness);
|
||||
return true;
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Failed to set default brightness: %s", esp_err_to_name(ret));
|
||||
LOGGER.error("Failed to set default brightness: {}", esp_err_to_name(ret));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t getBrightness() {
|
||||
if (g_i2cPort >= I2C_NUM_MAX) {
|
||||
ESP_LOGE(TAG, "Keyboard backlight not initialized");
|
||||
LOGGER.error("Not initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
#include "Trackball.h"
|
||||
#include <esp_log.h>
|
||||
|
||||
static const char* TAG = "Trackball";
|
||||
#include <Tactility/Logger.h>
|
||||
|
||||
static const auto LOGGER = tt::Logger("Trackball");
|
||||
|
||||
namespace trackball {
|
||||
|
||||
@ -72,7 +73,7 @@ static void read_cb(lv_indev_t* indev, lv_indev_data_t* data) {
|
||||
|
||||
lv_indev_t* init(const TrackballConfig& config) {
|
||||
if (g_initialized) {
|
||||
ESP_LOGW(TAG, "Trackball already initialized");
|
||||
LOGGER.warn("Already initialized");
|
||||
return g_indev;
|
||||
}
|
||||
|
||||
@ -109,16 +110,19 @@ lv_indev_t* init(const TrackballConfig& config) {
|
||||
lv_indev_set_type(g_indev, LV_INDEV_TYPE_ENCODER);
|
||||
lv_indev_set_read_cb(g_indev, read_cb);
|
||||
|
||||
if (g_indev) {
|
||||
if (g_indev != nullptr) {
|
||||
g_initialized = true;
|
||||
ESP_LOGI(TAG, "Trackball initialized as encoder (R:%d U:%d L:%d D:%d Click:%d)",
|
||||
config.pinRight, config.pinUp, config.pinLeft, config.pinDown,
|
||||
config.pinClick);
|
||||
return g_indev;
|
||||
LOGGER.info("Initialized as encoder (R:{} U:{} L:{} D:{} Click:{})",
|
||||
static_cast<int>(config.pinRight),
|
||||
static_cast<int>(config.pinUp),
|
||||
static_cast<int>(config.pinLeft),
|
||||
static_cast<int>(config.pinDown),
|
||||
static_cast<int>(config.pinClick));
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Failed to register LVGL input device");
|
||||
return nullptr;
|
||||
LOGGER.error("Failed to register LVGL input device");
|
||||
}
|
||||
|
||||
return g_indev;
|
||||
}
|
||||
|
||||
void deinit() {
|
||||
@ -127,19 +131,19 @@ void deinit() {
|
||||
g_indev = nullptr;
|
||||
}
|
||||
g_initialized = false;
|
||||
ESP_LOGI(TAG, "Trackball deinitialized");
|
||||
LOGGER.info("Deinitialized");
|
||||
}
|
||||
|
||||
void setMovementStep(uint8_t step) {
|
||||
if (step > 0) {
|
||||
g_config.movementStep = step;
|
||||
ESP_LOGD(TAG, "Movement step set to %d", step);
|
||||
LOGGER.debug("Movement step set to {}", step);
|
||||
}
|
||||
}
|
||||
|
||||
void setEnabled(bool enabled) {
|
||||
g_enabled = enabled;
|
||||
ESP_LOGI(TAG, "Trackball %s", enabled ? "enabled" : "disabled");
|
||||
LOGGER.info("{}", enabled ? "Enabled" : "Disabled");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
#include "EspLcdDisplay.h"
|
||||
#include "EspLcdDisplayDriver.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <cassert>
|
||||
#include <esp_lvgl_port_disp.h>
|
||||
#include <Tactility/Check.h>
|
||||
#include <Tactility/LogEsp.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/hal/touch/TouchDevice.h>
|
||||
|
||||
constexpr const char* TAG = "EspLcdDispDrv";
|
||||
static const auto LOGGER = tt::Logger("EspLcdDisplay");
|
||||
|
||||
EspLcdDisplay::~EspLcdDisplay() {
|
||||
if (displayDriver != nullptr && displayDriver.use_count() > 1) {
|
||||
@ -17,12 +17,12 @@ EspLcdDisplay::~EspLcdDisplay() {
|
||||
|
||||
bool EspLcdDisplay::start() {
|
||||
if (!createIoHandle(ioHandle)) {
|
||||
TT_LOG_E(TAG, "Failed to create IO handle");
|
||||
LOGGER.error("Failed to create IO handle");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!createPanelHandle(ioHandle, panelHandle)) {
|
||||
TT_LOG_E(TAG, "Failed to create panel handle");
|
||||
LOGGER.error("Failed to create panel handle");
|
||||
esp_lcd_panel_io_del(ioHandle);
|
||||
return false;
|
||||
}
|
||||
@ -45,7 +45,7 @@ bool EspLcdDisplay::stop() {
|
||||
}
|
||||
|
||||
if (displayDriver != nullptr && displayDriver.use_count() > 1) {
|
||||
TT_LOG_W(TAG, "DisplayDriver is still in use.");
|
||||
LOGGER.warn("DisplayDriver is still in use.");
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -55,7 +55,7 @@ bool EspLcdDisplay::startLvgl() {
|
||||
assert(lvglDisplay == nullptr);
|
||||
|
||||
if (displayDriver != nullptr && displayDriver.use_count() > 1) {
|
||||
TT_LOG_W(TAG, "DisplayDriver is still in use.");
|
||||
LOGGER.warn("DisplayDriver is still in use.");
|
||||
}
|
||||
|
||||
auto lvgl_port_config = getLvglPortDisplayConfig(ioHandle, panelHandle);
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
#include "EspLcdDisplayV2.h"
|
||||
#include "EspLcdDisplayDriver.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <cassert>
|
||||
#include <esp_lvgl_port_disp.h>
|
||||
#include <Tactility/Check.h>
|
||||
#include <Tactility/LogEsp.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/hal/touch/TouchDevice.h>
|
||||
|
||||
constexpr auto* TAG = "EspLcdDispV2";
|
||||
static const auto LOGGER = tt::Logger("EspLcdDispV2");
|
||||
|
||||
inline unsigned int getBufferSize(const std::shared_ptr<EspLcdConfiguration>& configuration) {
|
||||
if (configuration->bufferSize != DEFAULT_BUFFER_SIZE) {
|
||||
@ -25,17 +25,17 @@ EspLcdDisplayV2::~EspLcdDisplayV2() {
|
||||
|
||||
bool EspLcdDisplayV2::applyConfiguration() const {
|
||||
if (esp_lcd_panel_reset(panelHandle) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Failed to reset panel");
|
||||
LOGGER.error("Failed to reset panel");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (esp_lcd_panel_init(panelHandle) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Failed to init panel");
|
||||
LOGGER.error("Failed to init panel");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (esp_lcd_panel_invert_color(panelHandle, configuration->invertColor) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Failed to set panel to invert");
|
||||
LOGGER.error("Failed to set panel to invert");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -43,27 +43,27 @@ bool EspLcdDisplayV2::applyConfiguration() const {
|
||||
int gap_x = configuration->swapXY ? configuration->gapY : configuration->gapX;
|
||||
int gap_y = configuration->swapXY ? configuration->gapX : configuration->gapY;
|
||||
if (esp_lcd_panel_set_gap(panelHandle, gap_x, gap_y) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Failed to set panel gap");
|
||||
LOGGER.error("Failed to set panel gap");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (esp_lcd_panel_swap_xy(panelHandle, configuration->swapXY) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Failed to swap XY ");
|
||||
LOGGER.error("Failed to swap XY ");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (esp_lcd_panel_mirror(panelHandle, configuration->mirrorX, configuration->mirrorY) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Failed to set panel to mirror");
|
||||
LOGGER.error("Failed to set panel to mirror");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (esp_lcd_panel_invert_color(panelHandle, configuration->invertColor) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Failed to set panel to invert");
|
||||
LOGGER.error("Failed to set panel to invert");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (esp_lcd_panel_disp_on_off(panelHandle, true) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Failed to turn display on");
|
||||
LOGGER.error("Failed to turn display on");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -72,14 +72,14 @@ bool EspLcdDisplayV2::applyConfiguration() const {
|
||||
|
||||
bool EspLcdDisplayV2::start() {
|
||||
if (!createIoHandle(ioHandle)) {
|
||||
TT_LOG_E(TAG, "Failed to create IO handle");
|
||||
LOGGER.error("Failed to create IO handle");
|
||||
return false;
|
||||
}
|
||||
|
||||
esp_lcd_panel_dev_config_t panel_config = createPanelConfig(configuration, configuration->resetPin);
|
||||
|
||||
if (!createPanelHandle(ioHandle, panel_config, panelHandle)) {
|
||||
TT_LOG_E(TAG, "Failed to create panel handle");
|
||||
LOGGER.error("Failed to create panel handle");
|
||||
esp_lcd_panel_io_del(ioHandle);
|
||||
ioHandle = nullptr;
|
||||
return false;
|
||||
@ -111,7 +111,7 @@ bool EspLcdDisplayV2::stop() {
|
||||
}
|
||||
|
||||
if (displayDriver != nullptr && displayDriver.use_count() > 1) {
|
||||
TT_LOG_W(TAG, "DisplayDriver is still in use.");
|
||||
LOGGER.warn("DisplayDriver is still in use.");
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -121,7 +121,7 @@ bool EspLcdDisplayV2::startLvgl() {
|
||||
assert(lvglDisplay == nullptr);
|
||||
|
||||
if (displayDriver != nullptr && displayDriver.use_count() > 1) {
|
||||
TT_LOG_W(TAG, "DisplayDriver is still in use.");
|
||||
LOGGER.warn("DisplayDriver is still in use.");
|
||||
}
|
||||
|
||||
auto lvgl_port_config = getLvglPortDisplayConfig(configuration, ioHandle, panelHandle);
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
#include "EspLcdSpiDisplay.h"
|
||||
|
||||
#include <esp_lcd_panel_commands.h>
|
||||
#include <Tactility/LogEsp.h>
|
||||
#include <Tactility/Logger.h>
|
||||
|
||||
constexpr auto* TAG = "EspLcdSpiDsp";
|
||||
static const auto LOGGER = tt::Logger("EspLcdSpiDisplay");
|
||||
|
||||
bool EspLcdSpiDisplay::createIoHandle(esp_lcd_panel_io_handle_t& outHandle) {
|
||||
TT_LOG_I(TAG, "createIoHandle");
|
||||
LOGGER.info("createIoHandle");
|
||||
|
||||
const esp_lcd_panel_io_spi_config_t panel_io_config = {
|
||||
.cs_gpio_num = spiConfiguration->csPin,
|
||||
@ -33,7 +33,7 @@ bool EspLcdSpiDisplay::createIoHandle(esp_lcd_panel_io_handle_t& outHandle) {
|
||||
};
|
||||
|
||||
if (esp_lcd_new_panel_io_spi(spiConfiguration->spiHostDevice, &panel_io_config, &outHandle) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Failed to create panel");
|
||||
LOGGER.error("Failed to create panel");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -65,6 +65,6 @@ void EspLcdSpiDisplay::setGammaCurve(uint8_t index) {
|
||||
auto io_handle = getIoHandle();
|
||||
assert(io_handle != nullptr);
|
||||
if (esp_lcd_panel_io_tx_param(io_handle, LCD_CMD_GAMSET, param, 1) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Failed to set gamma");
|
||||
LOGGER.error("Failed to set gamma");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,21 +1,22 @@
|
||||
#include "EspLcdTouch.h"
|
||||
|
||||
#include <EspLcdTouchDriver.h>
|
||||
#include <esp_lvgl_port_touch.h>
|
||||
#include <Tactility/LogEsp.h>
|
||||
|
||||
constexpr const char* TAG = "EspLcdTouch";
|
||||
#include <EspLcdTouchDriver.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <esp_lvgl_port_touch.h>
|
||||
|
||||
static const auto LOGGER = tt::Logger("EspLcdTouch");
|
||||
|
||||
bool EspLcdTouch::start() {
|
||||
if (!createIoHandle(ioHandle) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Touch IO failed");
|
||||
LOGGER.error("Touch IO failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
config = createEspLcdTouchConfig();
|
||||
|
||||
if (!createTouchHandle(ioHandle, config, touchHandle)) {
|
||||
TT_LOG_E(TAG, "Driver init failed");
|
||||
LOGGER.error("Driver init failed");
|
||||
esp_lcd_panel_io_del(ioHandle);
|
||||
ioHandle = nullptr;
|
||||
return false;
|
||||
@ -48,7 +49,7 @@ bool EspLcdTouch::startLvgl(lv_disp_t* display) {
|
||||
}
|
||||
|
||||
if (touchDriver != nullptr && touchDriver.use_count() > 1) {
|
||||
TT_LOG_W(TAG, "TouchDriver is still in use.");
|
||||
LOGGER.warn("TouchDriver is still in use.");
|
||||
}
|
||||
|
||||
const lvgl_port_touch_cfg_t touch_cfg = {
|
||||
@ -56,10 +57,10 @@ bool EspLcdTouch::startLvgl(lv_disp_t* display) {
|
||||
.handle = touchHandle,
|
||||
};
|
||||
|
||||
TT_LOG_I(TAG, "Adding touch to LVGL");
|
||||
LOGGER.info("Adding touch to LVGL");
|
||||
lvglDevice = lvgl_port_add_touch(&touch_cfg);
|
||||
if (lvglDevice == nullptr) {
|
||||
TT_LOG_E(TAG, "Adding touch failed");
|
||||
LOGGER.error("Adding touch failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
#include "EspLcdTouchDriver.h"
|
||||
|
||||
#include <Tactility/LogEsp.h>
|
||||
#include <Tactility/Logger.h>
|
||||
|
||||
constexpr const char* TAG = "EspLcdTouchDriver";
|
||||
static const auto LOGGER = tt::Logger("EspLcdTouchDriver");
|
||||
|
||||
bool EspLcdTouchDriver::getTouchedPoints(uint16_t* x, uint16_t* y, uint16_t* _Nullable strength, uint8_t* pointCount, uint8_t maxPointCount) {
|
||||
if (esp_lcd_touch_read_data(handle) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Read data failed");
|
||||
LOGGER.error("Read data failed");
|
||||
return false;
|
||||
}
|
||||
return esp_lcd_touch_get_coordinates(handle, x, y, strength, pointCount, maxPointCount);
|
||||
|
||||
@ -2,14 +2,14 @@
|
||||
|
||||
#include "Tactility/PartitionsEsp.h"
|
||||
|
||||
#include <Tactility/Log.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 +41,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 +54,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 (%s)", 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 (%s)", 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;
|
||||
|
||||
@ -5,15 +5,16 @@
|
||||
#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/lvgl/LvglPrivate.h>
|
||||
#include <Tactility/MountPoints.h>
|
||||
#include <Tactility/network/NtpPrivate.h>
|
||||
#include <Tactility/service/ServiceManifest.h>
|
||||
#include <Tactility/service/ServiceRegistration.h>
|
||||
@ -29,7 +30,7 @@
|
||||
|
||||
namespace tt {
|
||||
|
||||
constexpr auto* TAG = "Tactility";
|
||||
static auto logger = Logger("Tactility");
|
||||
|
||||
static const Configuration* config_instance = nullptr;
|
||||
static Dispatcher mainDispatcher;
|
||||
@ -117,7 +118,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 +179,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 +205,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 +227,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 system services");
|
||||
addService(service::loader::manifest);
|
||||
addService(service::gui::manifest);
|
||||
addService(service::statusbar::manifest);
|
||||
@ -248,7 +249,7 @@ static void registerAndStartSecondaryServices() {
|
||||
}
|
||||
|
||||
static void registerAndStartPrimaryServices() {
|
||||
TT_LOG_I(TAG, "Registering and starting system services");
|
||||
logger.info("Registering and starting system services");
|
||||
addService(service::gps::manifest);
|
||||
if (hal::hasDevice(hal::Device::Type::SdCard)) {
|
||||
addService(service::sdcard::manifest);
|
||||
@ -269,15 +270,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_CPP, rootPath);
|
||||
}
|
||||
} else {
|
||||
TT_LOG_I(TAG, "Found existing %s", temp_path.c_str());
|
||||
logger.info("Found existing {}", temp_path);
|
||||
}
|
||||
}
|
||||
|
||||
@ -305,7 +306,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 +326,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();
|
||||
}
|
||||
|
||||
@ -3,8 +3,6 @@
|
||||
|
||||
namespace tt::app {
|
||||
|
||||
#define TAG "app"
|
||||
|
||||
void AppInstance::setState(State newState) {
|
||||
mutex.lock();
|
||||
state = newState;
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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());
|
||||
}
|
||||
};
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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.identifier);
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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");
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
}
|
||||
@ -110,7 +110,7 @@ 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());
|
||||
#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
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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("EspLcdDisplay");
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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("SPI");
|
||||
|
||||
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 %s", name.c_str());
|
||||
|
||||
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;
|
||||
|
||||
@ -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: %s", 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;
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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,8 +2,6 @@
|
||||
|
||||
#include "Tactility/hal/usb/Usb.h"
|
||||
|
||||
#define TAG "usb"
|
||||
|
||||
namespace tt::hal::usb {
|
||||
|
||||
bool startMassStorageWithSdmmc() { return false; }
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
});
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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,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;
|
||||
|
||||
@ -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)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -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 %s", path.c_str());
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@ -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 %f, speed: {}", deviceId, minmea_tocoord(&rmc.latitude), minmea_tocoord(&rmc.longitude), minmea_tofloat(&rmc.speed));
|
||||
}
|
||||
|
||||
State GpsService::getState() const {
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
#include <Tactility/service/gui/GuiService.h>
|
||||
|
||||
#include <Tactility/app/AppInstance.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/lvgl/LvglSync.h>
|
||||
#include <Tactility/lvgl/Statusbar.h>
|
||||
#include <Tactility/service/loader/Loader.h>
|
||||
@ -10,7 +11,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 +40,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 +101,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_CPP, "LVGL");
|
||||
}
|
||||
|
||||
unlock();
|
||||
@ -118,7 +116,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 +200,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 +224,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;
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
#include <Tactility/app/AppRegistration.h>
|
||||
|
||||
#include <Tactility/DispatcherThread.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/service/ServiceManifest.h>
|
||||
#include <Tactility/service/ServiceRegistration.h>
|
||||
|
||||
@ -16,7 +17,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 +43,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 +75,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 +90,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 +115,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 +181,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 +219,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 +235,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 +283,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,21 @@
|
||||
#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/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 +26,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 +35,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 +50,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 +102,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 +122,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 +132,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 +151,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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -6,10 +6,11 @@
|
||||
|
||||
#include <Tactility/service/wifi/Wifi.h>
|
||||
|
||||
#include <Tactility/Timer.h>
|
||||
#include <Tactility/EventGroup.h>
|
||||
#include <Tactility/Logger.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 +25,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 +172,7 @@ std::string getConnectionTarget() {
|
||||
}
|
||||
|
||||
void scan() {
|
||||
TT_LOG_I(TAG, "scan()");
|
||||
LOGGER.info("scan()");
|
||||
auto wifi = wifi_singleton;
|
||||
if (wifi == nullptr) {
|
||||
return;
|
||||
@ -189,7 +191,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 +215,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 +246,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 +264,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 +295,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 +392,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 +409,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 %u APs. Showing %u:", 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 +426,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 +444,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 +455,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 %s", settings.ssid.c_str());
|
||||
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 +470,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: disconnected");
|
||||
clearIp();
|
||||
switch (wifi->getRadioState()) {
|
||||
case RadioState::ConnectionPending:
|
||||
@ -503,7 +505,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: {} {}", IPSTR, 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 +515,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 +528,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 +537,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 +545,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 +565,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 +595,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 +604,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 +620,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_CPP, "disable()");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -639,11 +641,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 +653,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 +668,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 +676,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 +689,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 +716,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_CPP, "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 +743,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 +773,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 +796,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 %s", 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 +825,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 +851,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 +860,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 +884,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 +930,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); });
|
||||
}
|
||||
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/MountPoints.h>
|
||||
#include <Tactility/Mutex.h>
|
||||
#include <Tactility/file/FileLock.h>
|
||||
@ -6,11 +7,11 @@
|
||||
#include <Tactility/settings/SystemSettings.h>
|
||||
|
||||
#include <format>
|
||||
#include <Tactility/file/File.h>
|
||||
|
||||
namespace tt::settings {
|
||||
|
||||
constexpr auto* TAG = "SystemSettings";
|
||||
static const auto LOGGER = Logger("SystemSettings");
|
||||
|
||||
constexpr auto* FILE_PATH_FORMAT = "{}/settings/system.properties";
|
||||
|
||||
static Mutex mutex;
|
||||
@ -19,17 +20,17 @@ static SystemSettings cachedSettings;
|
||||
|
||||
static bool loadSystemSettingsFromFile(SystemSettings& properties) {
|
||||
auto file_path = std::format(FILE_PATH_FORMAT, file::MOUNT_POINT_DATA);
|
||||
TT_LOG_I(TAG, "System settings loading from %s", file_path.c_str());
|
||||
LOGGER.info("System settings loading from {}", file_path);
|
||||
std::map<std::string, std::string> map;
|
||||
if (!file::loadPropertiesFile(file_path, map)) {
|
||||
TT_LOG_E(TAG, "Failed to load %s", file_path.c_str());
|
||||
LOGGER.error("Failed to load {}", file_path);
|
||||
return false;
|
||||
}
|
||||
|
||||
auto language_entry = map.find("language");
|
||||
if (language_entry != map.end()) {
|
||||
if (!fromString(language_entry->second, properties.language)) {
|
||||
TT_LOG_W(TAG, "Unknown language \"%s\" in %s", language_entry->second.c_str(), file_path.c_str());
|
||||
LOGGER.warn("Unknown language \"{}\" in {}", language_entry->second, file_path);
|
||||
properties.language = Language::en_US;
|
||||
}
|
||||
} else {
|
||||
@ -46,7 +47,7 @@ static bool loadSystemSettingsFromFile(SystemSettings& properties) {
|
||||
if (date_format_entry != map.end() && !date_format_entry->second.empty()) {
|
||||
properties.dateFormat = date_format_entry->second;
|
||||
} else {
|
||||
TT_LOG_I(TAG, "dateFormat missing or empty, using default MM/DD/YYYY (likely from older system.properties)");
|
||||
LOGGER.info("dateFormat missing or empty, using default MM/DD/YYYY (likely from older system.properties)");
|
||||
properties.dateFormat = "MM/DD/YYYY";
|
||||
}
|
||||
|
||||
@ -55,11 +56,11 @@ static bool loadSystemSettingsFromFile(SystemSettings& properties) {
|
||||
if (region_entry != map.end() && !region_entry->second.empty()) {
|
||||
properties.region = region_entry->second;
|
||||
} else {
|
||||
TT_LOG_I(TAG, "region missing or empty, using default US");
|
||||
properties.region = "US";
|
||||
LOGGER.info("Region missing or empty, using default EU");
|
||||
properties.region = "EU";
|
||||
}
|
||||
|
||||
TT_LOG_I(TAG, "System settings loaded");
|
||||
LOGGER.info("System settings loaded");
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -84,7 +85,7 @@ bool saveSystemSettings(const SystemSettings& properties) {
|
||||
map["region"] = properties.region;
|
||||
|
||||
if (!file::savePropertiesFile(file_path, map)) {
|
||||
TT_LOG_E(TAG, "Failed to save %s", file_path.c_str());
|
||||
LOGGER.error("Failed to save {}", file_path);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -45,7 +45,7 @@ std::string getTimeZoneName() {
|
||||
if (preferences.optString(TIMEZONE_PREFERENCES_KEY_NAME, result)) {
|
||||
return result;
|
||||
} else {
|
||||
return "America/Los_Angeles"; // Default: Pacific Time (PST/PDT)
|
||||
return "Europe/Amsterdam";
|
||||
}
|
||||
}
|
||||
|
||||
@ -55,7 +55,7 @@ std::string getTimeZoneCode() {
|
||||
if (preferences.optString(TIMEZONE_PREFERENCES_KEY_CODE, result)) {
|
||||
return result;
|
||||
} else {
|
||||
return "PST8PDT,M3.2.0,M11.1.0"; // Default: Pacific Time POSIX string
|
||||
return "CET-1CEST,M3.5.0,M10.5.0/3"; // Default: Europe/Amsterdam
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -7,4 +7,3 @@
|
||||
#endif
|
||||
|
||||
#include "LogMessages.h"
|
||||
#include "LogCommon.h"
|
||||
|
||||
@ -2,8 +2,8 @@
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
|
||||
#include "LogCommon.h"
|
||||
#include <esp_log.h>
|
||||
#include "Tactility/LogCommon.h"
|
||||
|
||||
#define TT_LOG_E(tag, format, ...) \
|
||||
ESP_LOGE(tag, format, ##__VA_ARGS__)
|
||||
|
||||
@ -14,6 +14,7 @@
|
||||
// Mutex
|
||||
#define LOG_MESSAGE_MUTEX_LOCK_FAILED "Mutex acquisition timeout"
|
||||
#define LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT "Mutex acquisition timeout (%s)"
|
||||
#define LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT_CPP "Mutex acquisition timeout ({})"
|
||||
|
||||
// SPI
|
||||
#define LOG_MESSAGE_SPI_INIT_START_FMT "SPI %d init"
|
||||
|
||||
@ -5,7 +5,9 @@
|
||||
#include "LogCommon.h"
|
||||
|
||||
#include <cstdarg>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <sys/time.h>
|
||||
|
||||
namespace tt {
|
||||
|
||||
|
||||
72
TactilityCore/Include/Tactility/Logger.h
Normal file
72
TactilityCore/Include/Tactility/Logger.h
Normal file
@ -0,0 +1,72 @@
|
||||
#pragma once
|
||||
|
||||
#include "LoggerAdapter.h"
|
||||
#include "LoggerSettings.h"
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
#include "LoggerAdapterEsp.h"
|
||||
#else
|
||||
#include "LoggerAdapterGeneric.h"
|
||||
#endif
|
||||
|
||||
#include <format>
|
||||
|
||||
namespace tt {
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
static LoggerAdapter defaultLoggerAdapter = espLoggerAdapter;
|
||||
#else
|
||||
static LoggerAdapter defaultLoggerAdapter = genericLoggerAdapter;
|
||||
#endif
|
||||
|
||||
class Logger {
|
||||
|
||||
const char* tag;
|
||||
|
||||
public:
|
||||
|
||||
explicit Logger(const char* tag) : tag(tag) {}
|
||||
|
||||
template <typename... Args>
|
||||
void log(LogLevel level, std::format_string<Args...> format, Args&&... args) const {
|
||||
std::string message = std::format(format, std::forward<Args>(args)...);
|
||||
defaultLoggerAdapter(level, tag, message.c_str());
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void verbose(std::format_string<Args...> format, Args&&... args) const {
|
||||
log(LogLevel::Verbose, format, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void debug(std::format_string<Args...> format, Args&&... args) const {
|
||||
log(LogLevel::Debug, format, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void info(std::format_string<Args...> format, Args&&... args) const {
|
||||
log(LogLevel::Info, format, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void warn(std::format_string<Args...> format, Args&&... args) const {
|
||||
log(LogLevel::Warning, format, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void error(std::format_string<Args...> format, Args&&... args) const {
|
||||
log(LogLevel::Error, format, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
bool isLoggingVerbose() const { return LogLevel::Verbose <= LOG_LEVEL; }
|
||||
|
||||
bool isLoggingDebug() const { return LogLevel::Debug <= LOG_LEVEL; }
|
||||
|
||||
bool isLoggingInfo() const { return LogLevel::Info <= LOG_LEVEL; }
|
||||
|
||||
bool isLoggingWarning() const { return LogLevel::Warning <= LOG_LEVEL; }
|
||||
|
||||
bool isLoggingError() const { return LogLevel::Error <= LOG_LEVEL; }
|
||||
};
|
||||
|
||||
}
|
||||
10
TactilityCore/Include/Tactility/LoggerAdapter.h
Normal file
10
TactilityCore/Include/Tactility/LoggerAdapter.h
Normal file
@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "LogCommon.h"
|
||||
#include <functional>
|
||||
|
||||
namespace tt {
|
||||
|
||||
typedef std::function<void(LogLevel, const char* tag, const char*)> LoggerAdapter;
|
||||
|
||||
}
|
||||
35
TactilityCore/Include/Tactility/LoggerAdapterEsp.h
Normal file
35
TactilityCore/Include/Tactility/LoggerAdapterEsp.h
Normal file
@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include "LoggerAdapter.h"
|
||||
#include "LoggerAdapterShared.h"
|
||||
|
||||
#include <esp_log.h>
|
||||
#include <sstream>
|
||||
|
||||
namespace tt {
|
||||
|
||||
inline esp_log_level_t toEspLogLevel(LogLevel level) {
|
||||
switch (level) {
|
||||
case LogLevel::Error:
|
||||
return ESP_LOG_ERROR;
|
||||
case LogLevel::Warning:
|
||||
return ESP_LOG_WARN;
|
||||
case LogLevel::Info:
|
||||
return ESP_LOG_INFO;
|
||||
case LogLevel::Debug:
|
||||
return ESP_LOG_DEBUG;
|
||||
case LogLevel::Verbose:
|
||||
default:
|
||||
return ESP_LOG_VERBOSE;
|
||||
}
|
||||
}
|
||||
|
||||
static const LoggerAdapter espLoggerAdapter = [](LogLevel level, const char* tag, const char* message) {
|
||||
constexpr auto COLOR_RESET = "\033[0m";
|
||||
constexpr auto COLOR_GREY = "\033[37m";
|
||||
std::stringstream buffer;
|
||||
buffer << COLOR_GREY << esp_log_timestamp() << " [" << toTagColour(level) << toPrefix(level) << COLOR_GREY << "] [" << COLOR_RESET << tag << COLOR_GREY << "] " << toMessageColour(level) << message << COLOR_RESET << std::endl;
|
||||
esp_log_write(toEspLogLevel(level), tag, "%s", buffer.str().c_str());
|
||||
};
|
||||
|
||||
}
|
||||
30
TactilityCore/Include/Tactility/LoggerAdapterGeneric.h
Normal file
30
TactilityCore/Include/Tactility/LoggerAdapterGeneric.h
Normal file
@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include "LoggerAdapter.h"
|
||||
#include "LoggerAdapterShared.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <sys/time.h>
|
||||
|
||||
namespace tt {
|
||||
|
||||
static uint64_t getLogTimestamp() {
|
||||
static uint64_t base = 0U;
|
||||
timeval time {};
|
||||
gettimeofday(&time, nullptr);
|
||||
uint64_t now = ((uint64_t)time.tv_sec * 1000U) + (time.tv_usec / 1000U);
|
||||
if (base == 0U) {
|
||||
base = now;
|
||||
}
|
||||
return now - base;
|
||||
}
|
||||
|
||||
static const LoggerAdapter genericLoggerAdapter = [](LogLevel level, const char* tag, const char* message) {
|
||||
constexpr auto COLOR_RESET = "\033[0m";
|
||||
constexpr auto COLOR_GREY = "\033[37m";
|
||||
std::stringstream buffer;
|
||||
buffer << COLOR_GREY << getLogTimestamp() << " [" << toTagColour(level) << toPrefix(level) << COLOR_GREY << "] [" << COLOR_RESET << tag << COLOR_GREY << "] " << toMessageColour(level) << message << COLOR_RESET << std::endl;
|
||||
printf(buffer.str().c_str());
|
||||
};
|
||||
|
||||
}
|
||||
58
TactilityCore/Include/Tactility/LoggerAdapterShared.h
Normal file
58
TactilityCore/Include/Tactility/LoggerAdapterShared.h
Normal file
@ -0,0 +1,58 @@
|
||||
#pragma once
|
||||
|
||||
#include "LogCommon.h"
|
||||
|
||||
namespace tt {
|
||||
|
||||
inline const char* toTagColour(LogLevel level) {
|
||||
using enum LogLevel;
|
||||
switch (level) {
|
||||
case Error:
|
||||
return "\033[1;31m";
|
||||
case Warning:
|
||||
return "\033[1;33m";
|
||||
case Info:
|
||||
return "\033[32m";
|
||||
case Debug:
|
||||
return "\033[36m";
|
||||
case Verbose:
|
||||
return "\033[37m";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
inline const char* toMessageColour(LogLevel level) {
|
||||
using enum LogLevel;
|
||||
switch (level) {
|
||||
case Error:
|
||||
return "\033[1;31m";
|
||||
case Warning:
|
||||
return "\033[1;33m";
|
||||
case Info:
|
||||
case Debug:
|
||||
case Verbose:
|
||||
return "\033[0m";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
inline char toPrefix(LogLevel level) {
|
||||
using enum LogLevel;
|
||||
switch (level) {
|
||||
case Error:
|
||||
return 'E';
|
||||
case Warning:
|
||||
return 'W';
|
||||
case Info:
|
||||
return 'I';
|
||||
case Debug:
|
||||
return 'D';
|
||||
case Verbose:
|
||||
default:
|
||||
return 'V';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
9
TactilityCore/Include/Tactility/LoggerSettings.h
Normal file
9
TactilityCore/Include/Tactility/LoggerSettings.h
Normal file
@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "LogCommon.h"
|
||||
|
||||
namespace tt {
|
||||
|
||||
constexpr auto LOG_LEVEL = LogLevel::Info;
|
||||
|
||||
}
|
||||
@ -1,80 +1,19 @@
|
||||
#ifndef ESP_PLATFORM
|
||||
|
||||
#include "Tactility/Log.h"
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/LoggerAdapterShared.h>
|
||||
#include <Tactility/LoggerAdapterGeneric.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <sys/time.h>
|
||||
|
||||
namespace tt {
|
||||
|
||||
static char toPrefix(LogLevel level) {
|
||||
using enum LogLevel;
|
||||
switch (level) {
|
||||
case Error:
|
||||
return 'E';
|
||||
case Warning:
|
||||
return 'W';
|
||||
case Info:
|
||||
return 'I';
|
||||
case Debug:
|
||||
return 'D';
|
||||
case Verbose:
|
||||
return 'V';
|
||||
default:
|
||||
return ' ';
|
||||
}
|
||||
}
|
||||
|
||||
static const char* toTagColour(LogLevel level) {
|
||||
using enum LogLevel;
|
||||
switch (level) {
|
||||
case Error:
|
||||
return "\033[1;31m";
|
||||
case Warning:
|
||||
return "\033[1;33m";
|
||||
case Info:
|
||||
return "\033[32m";
|
||||
case Debug:
|
||||
return "\033[36m";
|
||||
case Verbose:
|
||||
return "\033[37m";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
static const char* toMessageColour(LogLevel level) {
|
||||
using enum LogLevel;
|
||||
switch (level) {
|
||||
case Error:
|
||||
return "\033[1;31m";
|
||||
case Warning:
|
||||
return "\033[1;33m";
|
||||
case Info:
|
||||
case Debug:
|
||||
case Verbose:
|
||||
return "\033[0m";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
static uint64_t getLogTimestamp() {
|
||||
static uint64_t base = 0U;
|
||||
struct timeval time {};
|
||||
gettimeofday(&time, nullptr);
|
||||
uint64_t now = ((uint64_t)time.tv_sec * 1000U) + (time.tv_usec / 1000U);
|
||||
if (base == 0U) {
|
||||
base = now;
|
||||
}
|
||||
return now - base;
|
||||
}
|
||||
|
||||
void log(LogLevel level, const char* tag, const char* format, ...) {
|
||||
constexpr auto COLOR_RESET = "\033[0m";
|
||||
constexpr auto COLOR_GREY = "\033[37m";
|
||||
std::stringstream buffer;
|
||||
buffer << getLogTimestamp() << " [" << toTagColour(level) << toPrefix(level) << "\033[0m" << "] [" << tag << "] " << toMessageColour(level) << format << "\033[0m\n";
|
||||
|
||||
buffer << COLOR_GREY << getLogTimestamp() << " [" << toTagColour(level) << toPrefix(level) << COLOR_GREY << "] [" << COLOR_RESET << tag << COLOR_GREY << "] " << toMessageColour(level) << format << COLOR_RESET << std::endl;
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vprintf(buffer.str().c_str(), args);
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
#include "Tactility/crypt/Crypt.h"
|
||||
#include <Tactility/crypt/Crypt.h>
|
||||
|
||||
#include "Tactility/Check.h"
|
||||
#include "Tactility/Log.h"
|
||||
#include <Tactility/Check.h>
|
||||
#include <Tactility/Logger.h>
|
||||
|
||||
#include <mbedtls/aes.h>
|
||||
#include <cstring>
|
||||
@ -15,7 +15,8 @@
|
||||
|
||||
namespace tt::crypt {
|
||||
|
||||
#define TAG "secure"
|
||||
static const auto LOGGER = Logger("Crypt");
|
||||
|
||||
#define TT_NVS_NAMESPACE "tt_secure"
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
@ -27,7 +28,7 @@ static void get_hardware_key(uint8_t key[32]) {
|
||||
uint8_t mac[8];
|
||||
// MAC can be 6 or 8 bytes
|
||||
size_t mac_length = esp_mac_addr_len_get(ESP_MAC_EFUSE_FACTORY);
|
||||
TT_LOG_I(TAG, "Using MAC with length %u", mac_length);
|
||||
LOGGER.info("Using MAC with length {}", mac_length);
|
||||
tt_check(mac_length <= 8);
|
||||
ESP_ERROR_CHECK(esp_read_mac(mac, ESP_MAC_EFUSE_FACTORY));
|
||||
|
||||
@ -66,13 +67,13 @@ static void get_nvs_key(uint8_t key[32]) {
|
||||
esp_err_t result = nvs_open(TT_NVS_NAMESPACE, NVS_READWRITE, &handle);
|
||||
|
||||
if (result != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Failed to get key from NVS (%s)", esp_err_to_name(result));
|
||||
LOGGER.error("Failed to get key from NVS ({})", esp_err_to_name(result));
|
||||
tt_crash("NVS error");
|
||||
}
|
||||
|
||||
size_t length = 32;
|
||||
if (nvs_get_blob(handle, "key", key, &length) == ESP_OK) {
|
||||
TT_LOG_I(TAG, "Fetched key from NVS (%d bytes)", length);
|
||||
LOGGER.info("Fetched key from NVS ({} bytes)", length);
|
||||
tt_check(length == 32);
|
||||
} else {
|
||||
// TODO: Improved randomness
|
||||
@ -83,7 +84,7 @@ static void get_nvs_key(uint8_t key[32]) {
|
||||
key[i] = (uint8_t)(rand());
|
||||
}
|
||||
ESP_ERROR_CHECK(nvs_set_blob(handle, "key", key, 32));
|
||||
TT_LOG_I(TAG, "Stored new key in NVS");
|
||||
LOGGER.info("Stored new key in NVS");
|
||||
}
|
||||
|
||||
nvs_close(handle);
|
||||
@ -109,8 +110,8 @@ static void xorKey(const uint8_t* inLeft, const uint8_t* inRight, uint8_t* out,
|
||||
*/
|
||||
static void getKey(uint8_t key[32]) {
|
||||
#if !defined(CONFIG_SECURE_BOOT) || !defined(CONFIG_SECURE_FLASH_ENC_ENABLED)
|
||||
TT_LOG_W(TAG, "Using tt_secure_* code with secure boot and/or flash encryption disabled.");
|
||||
TT_LOG_W(TAG, "An attacker with physical access to your ESP32 can decrypt your secure data.");
|
||||
LOGGER.warn("Using tt_secure_* code with secure boot and/or flash encryption disabled.");
|
||||
LOGGER.warn("An attacker with physical access to your ESP32 can decrypt your secure data.");
|
||||
#endif
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
@ -121,7 +122,7 @@ static void getKey(uint8_t key[32]) {
|
||||
get_nvs_key(nvs_key);
|
||||
xorKey(hardware_key, nvs_key, key, 32);
|
||||
#else
|
||||
TT_LOG_W(TAG, "Using unsafe key for debugging purposes.");
|
||||
LOGGER.warn("Using unsafe key for debugging purposes.");
|
||||
memset(key, 0, 32);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
#include "Tactility/file/File.h"
|
||||
#include <Tactility/file/File.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/StringUtils.h>
|
||||
|
||||
namespace tt::hal::sdcard {
|
||||
@ -11,7 +13,7 @@ class SdCardDevice;
|
||||
|
||||
namespace tt::file {
|
||||
|
||||
constexpr auto* TAG = "file";
|
||||
static const auto LOGGER = Logger("file");
|
||||
|
||||
class NoLock final : public Lock {
|
||||
bool lock(TickType_t timeout) const override { return true; }
|
||||
@ -23,7 +25,7 @@ static std::function<std::shared_ptr<Lock>(const std::string&)> findLockFunction
|
||||
|
||||
std::shared_ptr<Lock> getLock(const std::string& path) {
|
||||
if (findLockFunction == nullptr) {
|
||||
TT_LOG_W(TAG, "File lock function not set!");
|
||||
LOGGER.warn("File lock function not set!");
|
||||
return noLock;
|
||||
}
|
||||
|
||||
@ -69,10 +71,10 @@ bool listDirectory(
|
||||
auto lock = getLock(path)->asScopedLock();
|
||||
lock.lock();
|
||||
|
||||
TT_LOG_I(TAG, "listDir start %s", path.c_str());
|
||||
LOGGER.info("listDir start {}", path);
|
||||
DIR* dir = opendir(path.c_str());
|
||||
if (dir == nullptr) {
|
||||
TT_LOG_E(TAG, "Failed to open dir %s", path.c_str());
|
||||
LOGGER.error("Failed to open dir {}", path);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -83,7 +85,7 @@ bool listDirectory(
|
||||
|
||||
closedir(dir);
|
||||
|
||||
TT_LOG_I(TAG, "listDir stop %s", path.c_str());
|
||||
LOGGER.info("listDir stop {}", path);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -96,10 +98,10 @@ int scandir(
|
||||
auto lock = getLock(path)->asScopedLock();
|
||||
lock.lock();
|
||||
|
||||
TT_LOG_I(TAG, "scandir start");
|
||||
LOGGER.info("scandir start");
|
||||
DIR* dir = opendir(path.c_str());
|
||||
if (dir == nullptr) {
|
||||
TT_LOG_E(TAG, "Failed to open dir %s", path.c_str());
|
||||
LOGGER.error("Failed to open dir {}", path);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -116,7 +118,7 @@ int scandir(
|
||||
std::ranges::sort(outList, sortMethod);
|
||||
}
|
||||
|
||||
TT_LOG_I(TAG, "scandir finish");
|
||||
LOGGER.info("scandir finish");
|
||||
return outList.size();
|
||||
}
|
||||
|
||||
@ -125,18 +127,18 @@ long getSize(FILE* file) {
|
||||
long original_offset = ftell(file);
|
||||
|
||||
if (fseek(file, 0, SEEK_END) != 0) {
|
||||
TT_LOG_E(TAG, "fseek failed");
|
||||
LOGGER.error("fseek failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
long file_size = ftell(file);
|
||||
if (file_size == -1) {
|
||||
TT_LOG_E(TAG, "Could not get file length");
|
||||
LOGGER.error("Could not get file length");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (fseek(file, original_offset, SEEK_SET) != 0) {
|
||||
TT_LOG_E(TAG, "fseek Failed");
|
||||
LOGGER.error("fseek Failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -152,26 +154,26 @@ static std::unique_ptr<uint8_t[]> readBinaryInternal(const std::string& filepath
|
||||
FILE* file = fopen(filepath.c_str(), "rb");
|
||||
|
||||
if (file == nullptr) {
|
||||
TT_LOG_E(TAG, "Failed to open %s", filepath.c_str());
|
||||
LOGGER.error("Failed to open {}", filepath);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
long content_length = getSize(file);
|
||||
if (content_length == -1) {
|
||||
TT_LOG_E(TAG, "Failed to determine content length for %s", filepath.c_str());
|
||||
LOGGER.error("Failed to determine content length for {}", filepath);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto data = std::make_unique<uint8_t[]>(content_length + sizePadding);
|
||||
if (data == nullptr) {
|
||||
TT_LOG_E(TAG, "Insufficient memory. Failed to allocate %ldl bytes.", content_length);
|
||||
LOGGER.error("Insufficient memory. Failed to allocate {} bytes.", content_length);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
size_t buffer_offset = 0;
|
||||
while (buffer_offset < content_length) {
|
||||
size_t bytes_read = fread(&data.get()[buffer_offset], 1, content_length - buffer_offset, file);
|
||||
TT_LOG_D(TAG, "Read %d bytes", bytes_read);
|
||||
LOGGER.debug("Read {} bytes", bytes_read);
|
||||
if (bytes_read > 0) {
|
||||
buffer_offset += bytes_read;
|
||||
} else { // Something went wrong?
|
||||
@ -268,7 +270,7 @@ bool findOrCreateDirectory(const std::string& path, mode_t mode) {
|
||||
if (path.empty()) {
|
||||
return true;
|
||||
}
|
||||
TT_LOG_D(TAG, "findOrCreate: %s %lu", path.c_str(), mode);
|
||||
LOGGER.debug("findOrCreate: {} {}", path, mode);
|
||||
|
||||
const char separator_to_find[] = {SEPARATOR, 0x00};
|
||||
auto first_index = path[0] == SEPARATOR ? 1 : 0;
|
||||
@ -280,10 +282,10 @@ bool findOrCreateDirectory(const std::string& path, mode_t mode) {
|
||||
auto to_create = is_last_segment ? path : path.substr(0, separator_index);
|
||||
should_break = is_last_segment;
|
||||
if (!findOrCreateDirectoryInternal(to_create, mode)) {
|
||||
TT_LOG_E(TAG, "Failed to create %s", to_create.c_str());
|
||||
LOGGER.error("Failed to create {}", to_create);
|
||||
return false;
|
||||
} else {
|
||||
TT_LOG_D(TAG, " - got: %s", to_create.c_str());
|
||||
LOGGER.debug(" - got: {}", to_create);
|
||||
}
|
||||
|
||||
// Find next file separator index
|
||||
@ -309,7 +311,7 @@ bool deleteRecursively(const std::string& path) {
|
||||
if (isDirectory(path)) {
|
||||
std::vector<dirent> entries;
|
||||
if (scandir(path, entries) < 0) {
|
||||
TT_LOG_E(TAG, "Failed to scan directory %s", path.c_str());
|
||||
LOGGER.error("Failed to scan directory {}", path);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -319,16 +321,16 @@ bool deleteRecursively(const std::string& path) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
TT_LOG_I(TAG, "Deleting %s", path.c_str());
|
||||
LOGGER.info("Deleting {}", path);
|
||||
return deleteDirectory(path);
|
||||
} else if (isFile(path)) {
|
||||
TT_LOG_I(TAG, "Deleting %s", path.c_str());
|
||||
LOGGER.info("Deleting {}", path);
|
||||
return deleteFile(path);
|
||||
} else if (path == "/" || path == "." || path == "..") {
|
||||
// No-op
|
||||
return true;
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Failed to delete \"%s\": unknown type", path.c_str());
|
||||
LOGGER.error("Failed to delete \"{}\": unknown type", path);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user