From c4f0c134b29a6da72993dc26cc0f0f6a91fc5d64 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Mon, 5 Jan 2026 19:52:58 +0100 Subject: [PATCH] Updates --- .../Source/devices/Display.cpp | 1 - .../cyd-8048s043c/Source/devices/Display.cpp | 1 - .../Source/devices/Display.cpp | 1 - .../Source/devices/Display.cpp | 1 - .../Source/devices/Display.cpp | 1 - .../Source/Configuration.cpp | 4 +- Devices/lilygo-tdeck/Source/Init.cpp | 1 + .../Source/devices/CardputerPower.cpp | 20 +++---- .../Source/devices/CardputerKeyboard.cpp | 6 +- .../Source/devices/CardputerPower.cpp | 20 +++---- Devices/m5stack-cores3/Source/InitBoot.cpp | 24 ++++---- .../m5stack-cores3/Source/devices/Display.cpp | 6 +- .../Source/devices/Display.cpp | 7 ++- Devices/simulator/Source/LvglTask.cpp | 10 ++-- Devices/simulator/Source/Main.cpp | 8 +-- Devices/unphone/Source/InitBoot.cpp | 26 ++++---- Devices/unphone/Source/UnPhoneFeatures.cpp | 38 ++++++------ .../unphone/Source/devices/Hx8357Display.cpp | 23 +++---- Devices/unphone/Source/devices/Touch.cpp | 2 - .../Source/Init.cpp | 1 + .../Source/devices/Jd9853Display.cpp | 22 +++---- Drivers/AXP2101/Source/Axp2101.cpp | 1 - Drivers/BQ24295/Source/Bq24295.cpp | 10 ++-- Drivers/BQ25896/Source/Bq25896.cpp | 8 +-- Drivers/BQ27220/Source/Bq27220.cpp | 24 ++++---- .../ButtonControl/Source/ButtonControl.cpp | 10 ++-- Drivers/DRV2605/Source/Drv2605.cpp | 10 +++- Drivers/DRV2605/Source/Drv2605.h | 5 +- .../Source/ChargeFromAdcVoltage.cpp | 15 ++--- .../Source/ChargeFromVoltage.cpp | 6 +- Drivers/FT5x06/Source/Ft5x06Touch.cpp | 4 -- Drivers/FT6x36/Source/Ft6x36Touch.cpp | 10 ++-- Drivers/GC9A01/Source/Gc9a01Display.cpp | 22 +++---- Drivers/GT911/Source/Gt911Touch.cpp | 6 +- Drivers/ILI9488/Source/Ili9488Display.cpp | 18 +++--- Drivers/PwmBacklight/Source/PwmBacklight.cpp | 12 ++-- Drivers/RgbDisplay/Source/RgbDisplay.cpp | 28 ++++----- Drivers/SSD1306/Source/Ssd1306Display.cpp | 14 ++--- Drivers/ST7735/Source/St7735Display.cpp | 26 ++++---- .../Source/St7789i8080Display.cpp | 50 ++++++++-------- .../Source/St7796i8080Display.cpp | 48 +++++++-------- Drivers/ST7796/Source/St7796Display.cpp | 22 +++---- Drivers/TCA8418/Source/Tca8418.cpp | 3 - Drivers/XPT2046/Source/Xpt2046Power.cpp | 13 ++-- Drivers/XPT2046/Source/Xpt2046Touch.cpp | 1 - .../XPT2046SoftSPI/Source/Xpt2046SoftSpi.cpp | 52 ++++++++-------- Tactility/Source/Tactility.cpp | 3 +- Tactility/Source/app/addgps/AddGps.cpp | 21 +++---- .../Source/app/alertdialog/AlertDialog.cpp | 8 +-- Tactility/Source/app/apphub/AppHubApp.cpp | 9 +-- Tactility/Source/app/apphub/AppHubEntry.cpp | 11 ++-- .../app/apphubdetails/AppHubDetailsApp.cpp | 28 +++++---- Tactility/Source/app/chat/ChatApp.cpp | 5 +- .../app/crashdiagnostics/CrashDiagnostics.cpp | 27 +++++---- .../Source/app/development/Development.cpp | 5 +- Tactility/Source/app/display/Display.cpp | 5 +- Tactility/Source/app/files/State.cpp | 22 +++---- Tactility/Source/app/files/View.cpp | 60 +++++++++---------- Tactility/Source/app/fileselection/State.cpp | 16 ++--- Tactility/Source/app/fileselection/View.cpp | 31 +++++----- .../Source/app/gpssettings/GpsSettings.cpp | 17 +++--- .../Source/app/i2cscanner/I2cScanner.cpp | 43 ++++++------- .../Source/app/imageviewer/ImageViewer.cpp | 6 +- .../Source/app/inputdialog/InputDialog.cpp | 4 +- Tactility/Source/app/launcher/Launcher.cpp | 4 +- Tactility/Source/app/notes/Notes.cpp | 14 ++--- .../Source/app/screenshot/Screenshot.cpp | 21 +++---- .../app/selectiondialog/SelectionDialog.cpp | 12 ++-- .../app/timedatesettings/TimeDateSettings.cpp | 7 ++- Tactility/Source/app/timezone/TimeZone.cpp | 22 +++---- .../app/wifiapsettings/WifiApSettings.cpp | 17 +++--- Tactility/Source/app/wificonnect/View.cpp | 7 ++- .../Source/app/wificonnect/WifiConnect.cpp | 8 ++- Tactility/Source/app/wifimanage/View.cpp | 24 ++++---- .../Source/app/wifimanage/WifiManage.cpp | 14 +++-- Tactility/Source/hal/gps/GpsInit.cpp | 16 ++--- Tactility/Source/hal/gps/Probe.cpp | 30 +++++----- Tactility/Source/hal/gps/Ublox.cpp | 8 +-- Tactility/Source/lvgl/Spinner.cpp | 1 - Tactility/Source/lvgl/Statusbar.cpp | 16 ++--- Tactility/Source/network/HttpdReq.cpp | 1 + Tactility/Source/network/Ntp.cpp | 2 + Tactility/Source/network/Url.cpp | 2 - Tactility/Source/service/gui/GuiService.cpp | 3 +- Tactility/Source/service/loader/Loader.cpp | 1 + .../service/screenshot/ScreenshotTask.cpp | 1 + Tactility/Source/service/sdcard/Sdcard.cpp | 1 + Tactility/Source/service/wifi/WifiEsp.cpp | 5 +- TactilityC/Source/tt_app.cpp | 14 ++--- TactilityCore/Include/Tactility/Check.h | 14 ++--- TactilityCore/Include/Tactility/Log.h | 9 --- TactilityCore/Include/Tactility/LogEsp.h | 19 ------ TactilityCore/Include/Tactility/LogMessages.h | 14 +---- .../Include/Tactility/LogSimulator.h | 29 --------- .../Include/Tactility/LoggerAdapter.h | 2 +- .../Include/Tactility/LoggerAdapterEsp.h | 2 +- .../Include/Tactility/LoggerAdapterGeneric.h | 2 +- .../Include/Tactility/LoggerAdapterShared.h | 2 +- .../Tactility/{LogCommon.h => LoggerCommon.h} | 0 .../Include/Tactility/LoggerSettings.h | 2 +- .../Include/Tactility/TactilityCore.h | 5 +- TactilityCore/Source/LogSimulator.cpp | 25 -------- 102 files changed, 635 insertions(+), 703 deletions(-) delete mode 100644 TactilityCore/Include/Tactility/Log.h delete mode 100644 TactilityCore/Include/Tactility/LogEsp.h delete mode 100644 TactilityCore/Include/Tactility/LogSimulator.h rename TactilityCore/Include/Tactility/{LogCommon.h => LoggerCommon.h} (100%) delete mode 100644 TactilityCore/Source/LogSimulator.cpp diff --git a/Devices/btt-panda-touch/Source/devices/Display.cpp b/Devices/btt-panda-touch/Source/devices/Display.cpp index 94f68a3b..7da8e901 100644 --- a/Devices/btt-panda-touch/Source/devices/Display.cpp +++ b/Devices/btt-panda-touch/Source/devices/Display.cpp @@ -3,7 +3,6 @@ #include #include #include -#include std::shared_ptr _Nullable createTouch() { // Note for future changes: Reset pin is 41 and interrupt pin is 40 diff --git a/Devices/cyd-8048s043c/Source/devices/Display.cpp b/Devices/cyd-8048s043c/Source/devices/Display.cpp index 6ce9afe4..65a2c522 100644 --- a/Devices/cyd-8048s043c/Source/devices/Display.cpp +++ b/Devices/cyd-8048s043c/Source/devices/Display.cpp @@ -3,7 +3,6 @@ #include #include #include -#include std::shared_ptr _Nullable createTouch() { // Note for future changes: Reset pin is 38 and interrupt pin is 18 diff --git a/Devices/cyd-jc8048w550c/Source/devices/Display.cpp b/Devices/cyd-jc8048w550c/Source/devices/Display.cpp index 6ce9afe4..65a2c522 100644 --- a/Devices/cyd-jc8048w550c/Source/devices/Display.cpp +++ b/Devices/cyd-jc8048w550c/Source/devices/Display.cpp @@ -3,7 +3,6 @@ #include #include #include -#include std::shared_ptr _Nullable createTouch() { // Note for future changes: Reset pin is 38 and interrupt pin is 18 diff --git a/Devices/elecrow-crowpanel-advance-50/Source/devices/Display.cpp b/Devices/elecrow-crowpanel-advance-50/Source/devices/Display.cpp index 57197196..9440b3d9 100644 --- a/Devices/elecrow-crowpanel-advance-50/Source/devices/Display.cpp +++ b/Devices/elecrow-crowpanel-advance-50/Source/devices/Display.cpp @@ -2,7 +2,6 @@ #include #include -#include std::shared_ptr _Nullable createTouch() { // Note for future changes: Reset pin is 38 and interrupt pin is 18 diff --git a/Devices/elecrow-crowpanel-basic-50/Source/devices/Display.cpp b/Devices/elecrow-crowpanel-basic-50/Source/devices/Display.cpp index 94689d66..72771a1a 100644 --- a/Devices/elecrow-crowpanel-basic-50/Source/devices/Display.cpp +++ b/Devices/elecrow-crowpanel-basic-50/Source/devices/Display.cpp @@ -3,7 +3,6 @@ #include #include #include -#include std::shared_ptr _Nullable createTouch() { // Note for future changes: Reset pin is 38 and interrupt pin is 18 diff --git a/Devices/heltec-wifi-lora-32-v3/Source/Configuration.cpp b/Devices/heltec-wifi-lora-32-v3/Source/Configuration.cpp index 5c3ee000..081f0d7a 100644 --- a/Devices/heltec-wifi-lora-32-v3/Source/Configuration.cpp +++ b/Devices/heltec-wifi-lora-32-v3/Source/Configuration.cpp @@ -7,6 +7,8 @@ #include #include +#include + #include "driver/gpio.h" #include "driver/i2c.h" #include "freertos/FreeRTOS.h" @@ -24,7 +26,7 @@ static void enableOledPower() { gpio_set_level(DISPLAY_PIN_POWER, 0); // Active low vTaskDelay(pdMS_TO_TICKS(500)); // Add a small delay for power to stabilize - Logger("HeltecV3").info("OLED power enabled"); + tt::Logger("HeltecV3").info("OLED power enabled"); } static bool initBoot() { diff --git a/Devices/lilygo-tdeck/Source/Init.cpp b/Devices/lilygo-tdeck/Source/Init.cpp index 90d8086c..8b88c405 100644 --- a/Devices/lilygo-tdeck/Source/Init.cpp +++ b/Devices/lilygo-tdeck/Source/Init.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include diff --git a/Devices/m5stack-cardputer-adv/Source/devices/CardputerPower.cpp b/Devices/m5stack-cardputer-adv/Source/devices/CardputerPower.cpp index ebd3b65d..a607f010 100644 --- a/Devices/m5stack-cardputer-adv/Source/devices/CardputerPower.cpp +++ b/Devices/m5stack-cardputer-adv/Source/devices/CardputerPower.cpp @@ -1,24 +1,24 @@ #include "CardputerPower.h" -#include +#include #include -constexpr auto* TAG = "CardputerPower"; +static const auto LOGGER = tt::Logger("CardputerPower"); bool CardputerPower::adcInitCalibration() { bool calibrated = false; esp_err_t efuse_read_result = esp_adc_cal_check_efuse(ESP_ADC_CAL_VAL_EFUSE_TP_FIT); if (efuse_read_result == ESP_ERR_NOT_SUPPORTED) { - TT_LOG_W(TAG, "Calibration scheme not supported, skip software calibration"); + LOGGER.warn("Calibration scheme not supported, skip software calibration"); } else if (efuse_read_result == ESP_ERR_INVALID_VERSION) { - TT_LOG_W(TAG, "eFuse not burnt, skip software calibration"); + LOGGER.warn("eFuse not burnt, skip software calibration"); } else if (efuse_read_result == ESP_OK) { calibrated = true; - TT_LOG_I(TAG, "Calibration success"); + LOGGER.info("Calibration success"); esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_DB_11, static_cast(ADC_WIDTH_BIT_DEFAULT), 0, &adcCharacteristics); } else { - TT_LOG_W(TAG, "eFuse read failed, skipping calibration"); + LOGGER.warn("eFuse read failed, skipping calibration"); } return calibrated; @@ -26,11 +26,11 @@ bool CardputerPower::adcInitCalibration() { uint32_t CardputerPower::adcReadValue() const { int adc_raw = adc1_get_raw(ADC1_CHANNEL_9); - TT_LOG_D(TAG, "Raw data: %d", adc_raw); + LOGGER.debug("Raw data: {}", adc_raw); float voltage; if (calibrated) { voltage = esp_adc_cal_raw_to_voltage(adc_raw, &adcCharacteristics); - TT_LOG_D(TAG, "Calibrated data: %d mV", voltage); + LOGGER.debug("Calibrated data: {} mV", voltage); } else { voltage = 0.0f; } @@ -42,11 +42,11 @@ bool CardputerPower::ensureInitialized() { calibrated = adcInitCalibration(); if (adc1_config_width(static_cast(ADC_WIDTH_BIT_DEFAULT)) != ESP_OK) { - TT_LOG_E(TAG, "ADC1 config width failed"); + LOGGER.error("ADC1 config width failed"); return false; } if (adc1_config_channel_atten(ADC1_CHANNEL_9, ADC_ATTEN_DB_11) != ESP_OK) { - TT_LOG_E(TAG, "ADC1 config attenuation failed"); + LOGGER.error("ADC1 config attenuation failed"); return false; } diff --git a/Devices/m5stack-cardputer/Source/devices/CardputerKeyboard.cpp b/Devices/m5stack-cardputer/Source/devices/CardputerKeyboard.cpp index 1e2a0a32..c0466db1 100644 --- a/Devices/m5stack-cardputer/Source/devices/CardputerKeyboard.cpp +++ b/Devices/m5stack-cardputer/Source/devices/CardputerKeyboard.cpp @@ -1,8 +1,8 @@ #include "CardputerKeyboard.h" -#include +#include -constexpr auto* TAG = "Keyboard"; +static const auto LOGGER = tt::Logger("Keyboard"); bool CardputerKeyboard::startLvgl(lv_display_t* display) { keyboard.init(); @@ -56,7 +56,7 @@ void CardputerKeyboard::readCallback(lv_indev_t* indev, lv_indev_data_t* data) { } } else { if (self->keyboard.keysState().del) { - TT_LOG_I(TAG, "del"); + LOGGER.info("del"); data->key = LV_KEY_DEL; data->state = LV_INDEV_STATE_PRESSED; } else { diff --git a/Devices/m5stack-cardputer/Source/devices/CardputerPower.cpp b/Devices/m5stack-cardputer/Source/devices/CardputerPower.cpp index ebd3b65d..a607f010 100644 --- a/Devices/m5stack-cardputer/Source/devices/CardputerPower.cpp +++ b/Devices/m5stack-cardputer/Source/devices/CardputerPower.cpp @@ -1,24 +1,24 @@ #include "CardputerPower.h" -#include +#include #include -constexpr auto* TAG = "CardputerPower"; +static const auto LOGGER = tt::Logger("CardputerPower"); bool CardputerPower::adcInitCalibration() { bool calibrated = false; esp_err_t efuse_read_result = esp_adc_cal_check_efuse(ESP_ADC_CAL_VAL_EFUSE_TP_FIT); if (efuse_read_result == ESP_ERR_NOT_SUPPORTED) { - TT_LOG_W(TAG, "Calibration scheme not supported, skip software calibration"); + LOGGER.warn("Calibration scheme not supported, skip software calibration"); } else if (efuse_read_result == ESP_ERR_INVALID_VERSION) { - TT_LOG_W(TAG, "eFuse not burnt, skip software calibration"); + LOGGER.warn("eFuse not burnt, skip software calibration"); } else if (efuse_read_result == ESP_OK) { calibrated = true; - TT_LOG_I(TAG, "Calibration success"); + LOGGER.info("Calibration success"); esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_DB_11, static_cast(ADC_WIDTH_BIT_DEFAULT), 0, &adcCharacteristics); } else { - TT_LOG_W(TAG, "eFuse read failed, skipping calibration"); + LOGGER.warn("eFuse read failed, skipping calibration"); } return calibrated; @@ -26,11 +26,11 @@ bool CardputerPower::adcInitCalibration() { uint32_t CardputerPower::adcReadValue() const { int adc_raw = adc1_get_raw(ADC1_CHANNEL_9); - TT_LOG_D(TAG, "Raw data: %d", adc_raw); + LOGGER.debug("Raw data: {}", adc_raw); float voltage; if (calibrated) { voltage = esp_adc_cal_raw_to_voltage(adc_raw, &adcCharacteristics); - TT_LOG_D(TAG, "Calibrated data: %d mV", voltage); + LOGGER.debug("Calibrated data: {} mV", voltage); } else { voltage = 0.0f; } @@ -42,11 +42,11 @@ bool CardputerPower::ensureInitialized() { calibrated = adcInitCalibration(); if (adc1_config_width(static_cast(ADC_WIDTH_BIT_DEFAULT)) != ESP_OK) { - TT_LOG_E(TAG, "ADC1 config width failed"); + LOGGER.error("ADC1 config width failed"); return false; } if (adc1_config_channel_atten(ADC1_CHANNEL_9, ADC_ATTEN_DB_11) != ESP_OK) { - TT_LOG_E(TAG, "ADC1 config attenuation failed"); + LOGGER.error("ADC1 config attenuation failed"); return false; } diff --git a/Devices/m5stack-cores3/Source/InitBoot.cpp b/Devices/m5stack-cores3/Source/InitBoot.cpp index 956ab56f..e6d786af 100644 --- a/Devices/m5stack-cores3/Source/InitBoot.cpp +++ b/Devices/m5stack-cores3/Source/InitBoot.cpp @@ -1,9 +1,9 @@ #include "InitBoot.h" -#include +#include #include -constexpr auto* TAG = "CoreS3"; +static const auto LOGGER = tt::Logger("CoreS3"); std::shared_ptr axp2101; std::shared_ptr aw9523; @@ -13,7 +13,7 @@ std::shared_ptr aw9523; * and schematic: https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/docs/datasheet/core/K128%20CoreS3/Sch_M5_CoreS3_v1.0.pdf */ bool initGpioExpander() { - TT_LOG_I(TAG, "AW9523 init"); + LOGGER.info("AW9523 init"); /** * P0 pins: @@ -58,33 +58,33 @@ bool initGpioExpander() { /* AW9523 P0 is in push-pull mode */ if (!aw9523->writeCTL(0x10)) { - TT_LOG_E(TAG, "AW9523: Failed to set CTL"); + LOGGER.error("AW9523: Failed to set CTL"); return false; } if (!aw9523->writeP0(p0_state)) { - TT_LOG_E(TAG, "AW9523: Failed to set P0"); + LOGGER.error("AW9523: Failed to set P0"); return false; } if (!aw9523->writeP1(p1_state)) { - TT_LOG_E(TAG, "AW9523: Failed to set P1"); + LOGGER.error("AW9523: Failed to set P1"); return false; } if (axp2101->isVBus()) { float voltage = 0.0f; axp2101->getVBusVoltage(voltage); - TT_LOG_I(TAG, "AXP2101: VBus at %.2f", voltage); + LOGGER.info("AXP2101: VBus at %.2f", voltage); } else { - TT_LOG_W(TAG, "AXP2101: VBus disabled"); + LOGGER.warn("AXP2101: VBus disabled"); } return true; } bool initPowerControl() { - TT_LOG_I(TAG, "Init power control (AXP2101)"); + LOGGER.info("Init power control (AXP2101)"); // Source: https://github.com/m5stack/M5Unified/blob/b8cfec7fed046242da7f7b8024a4e92004a51ff7/src/utility/Power_Class.cpp#L61 aw9523->bitOnP1(0b10000000); // SY7088 boost enable @@ -135,16 +135,16 @@ bool initPowerControl() { }; if (axp2101->setRegisters((uint8_t*)reg_data_array, sizeof(reg_data_array))) { - TT_LOG_I(TAG, "AXP2101 initialized with %d registers", sizeof(reg_data_array) / 2); + LOGGER.info("AXP2101 initialized with {} registers", sizeof(reg_data_array) / 2); return true; } else { - TT_LOG_E(TAG, "AXP2101: Failed to set registers"); + LOGGER.error("AXP2101: Failed to set registers"); return false; } } bool initBoot() { - TT_LOG_I(TAG, "initBoot()"); + LOGGER.info("initBoot()"); axp2101 = std::make_shared(I2C_NUM_0); aw9523 = std::make_shared(I2C_NUM_0); diff --git a/Devices/m5stack-cores3/Source/devices/Display.cpp b/Devices/m5stack-cores3/Source/devices/Display.cpp index b7350d11..b7e71677 100644 --- a/Devices/m5stack-cores3/Source/devices/Display.cpp +++ b/Devices/m5stack-cores3/Source/devices/Display.cpp @@ -3,16 +3,16 @@ #include #include #include -#include +#include #include -constexpr auto* TAG = "CoreS3Display"; +static const auto LOGGER = tt::Logger("CoreS3Display"); static void setBacklightDuty(uint8_t backlightDuty) { const uint8_t voltage = 20 + ((8 * backlightDuty) / 255); // [0b00000, 0b11100] - under 20 is too dark // TODO: Refactor to use Axp2102 driver subproject. Reference: https://github.com/m5stack/M5Unified/blob/b8cfec7fed046242da7f7b8024a4e92004a51ff7/src/utility/AXP2101_Class.cpp#L42 if (!tt::hal::i2c::masterWriteRegister(I2C_NUM_0, AXP2101_ADDRESS, 0x99, &voltage, 1, 1000)) { // Sets DLD01 - TT_LOG_E(TAG, "Failed to set display backlight voltage"); + LOGGER.error("Failed to set display backlight voltage"); } } diff --git a/Devices/m5stack-stickc-plus/Source/devices/Display.cpp b/Devices/m5stack-stickc-plus/Source/devices/Display.cpp index c05719ff..f6fba81a 100644 --- a/Devices/m5stack-stickc-plus/Source/devices/Display.cpp +++ b/Devices/m5stack-stickc-plus/Source/devices/Display.cpp @@ -1,18 +1,19 @@ #include "Display.h" - #include "Power.h" +#include + #include #include -constexpr auto* TAG = "StickCPlus"; +static const auto LOGGER = tt::Logger("StickCPlus"); static void setBacklightOn(bool on) { const auto axp = getAxp192(); const auto* driver = axp->getAxp192(); uint8_t state; if (axp192_read(driver, AXP192_DCDC13_LDO23_CONTROL, &state) != AXP192_OK) { - TT_LOG_I(TAG, "Failed to read LCD brightness state"); + LOGGER.info("Failed to read LCD brightness state"); return; } std::bitset<8> new_state = state; diff --git a/Devices/simulator/Source/LvglTask.cpp b/Devices/simulator/Source/LvglTask.cpp index 8946df34..b0631dc6 100644 --- a/Devices/simulator/Source/LvglTask.cpp +++ b/Devices/simulator/Source/LvglTask.cpp @@ -1,14 +1,14 @@ #include "LvglTask.h" +#include #include -#include +#include #include #include -#include #include -constexpr auto TAG = "lvgl_task"; +static const auto LOGGER = tt::Logger("LvglTask"); // Mutex for LVGL drawing static tt::RecursiveMutex lvgl_mutex; @@ -58,7 +58,7 @@ void lvgl_task_interrupt() { } void lvgl_task_start() { - TT_LOG_I(TAG, "lvgl task starting"); + LOGGER.info("LVGL task starting"); tt::lvgl::syncSet(&lvgl_lock, &lvgl_unlock); @@ -76,7 +76,7 @@ void lvgl_task_start() { } static void lvgl_task(TT_UNUSED void* arg) { - TT_LOG_I(TAG, "lvgl task started"); + LOGGER.info("LVGL task started"); /** Ideally. the display handle would be created during Simulator.start(), * but somehow that doesn't work. Waiting here from a ThreadFlag when that happens diff --git a/Devices/simulator/Source/Main.cpp b/Devices/simulator/Source/Main.cpp index bebf8326..62d9ce8d 100644 --- a/Devices/simulator/Source/Main.cpp +++ b/Devices/simulator/Source/Main.cpp @@ -5,7 +5,7 @@ #include "FreeRTOS.h" #include "task.h" -#define TAG "freertos" +static const auto LOGGER = tt::Logger("FreeRTOS"); namespace simulator { @@ -16,10 +16,10 @@ void setMain(MainFunction newMainFunction) { } static void freertosMainTask(TT_UNUSED void* parameter) { - TT_LOG_I(TAG, "starting app_main()"); + LOGGER.info("starting app_main()"); assert(simulator::mainFunction); mainFunction(); - TT_LOG_I(TAG, "returned from app_main()"); + LOGGER.info("returned from app_main()"); vTaskDelete(nullptr); } @@ -49,7 +49,7 @@ void vAssertCalled(unsigned long line, const char* const file) { static portBASE_TYPE xPrinted = pdFALSE; volatile uint32_t set_to_nonzero_in_debugger_to_continue = 0; - TT_LOG_E(TAG, "assert triggered at %s:%d", file, line); + LOGGER.error("assert triggered at %s:%d", file, line); taskENTER_CRITICAL(); { // Step out by attaching a debugger and setting set_to_nonzero_in_debugger_to_continue diff --git a/Devices/unphone/Source/InitBoot.cpp b/Devices/unphone/Source/InitBoot.cpp index 3f60a4e6..ddcfe6d6 100644 --- a/Devices/unphone/Source/InitBoot.cpp +++ b/Devices/unphone/Source/InitBoot.cpp @@ -1,9 +1,11 @@ #include "UnPhoneFeatures.h" +#include +#include #include #include #include -constexpr auto* TAG = "unPhone"; +static const auto LOGGER = tt::Logger("unPhone"); std::shared_ptr unPhoneFeatures; static std::unique_ptr powerThread; @@ -46,10 +48,10 @@ public: } void printInfo() { - TT_LOG_I("TAG", "Device stats:"); - TT_LOG_I("TAG", " boot: %ld", getValue(bootCountKey)); - TT_LOG_I("TAG", " power off: %ld", getValue(powerOffCountKey)); - TT_LOG_I("TAG", " power sleep: %ld", getValue(powerSleepKey)); + LOGGER.info("Device stats:"); + LOGGER.info(" boot: {}", getValue(bootCountKey)); + LOGGER.info(" power off: {}", getValue(powerOffCountKey)); + LOGGER.info(" power sleep: {}", getValue(powerSleepKey)); } }; @@ -89,11 +91,11 @@ static void updatePowerSwitch() { if (!unPhoneFeatures->isPowerSwitchOn()) { if (last_state != PowerState::Off) { last_state = PowerState::Off; - TT_LOG_W(TAG, "Power off"); + LOGGER.warn("Power off"); } if (!unPhoneFeatures->isUsbPowerConnected()) { // and usb unplugged we go into shipping mode - TT_LOG_W(TAG, "Shipping mode until USB connects"); + LOGGER.warn("Shipping mode until USB connects"); #if DEBUG_POWER_STATES unPhoneFeatures.setExpanderPower(true); @@ -107,7 +109,7 @@ static void updatePowerSwitch() { unPhoneFeatures->setShipping(true); // tell BM to stop supplying power until USB connects } else { // When power switch is off, but USB is plugged in, we wait (deep sleep) until USB is unplugged. - TT_LOG_W(TAG, "Waiting for USB disconnect to power off"); + LOGGER.warn("Waiting for USB disconnect to power off"); #if DEBUG_POWER_STATES powerInfoBuzz(2); @@ -126,7 +128,7 @@ static void updatePowerSwitch() { } else { if (last_state != PowerState::On) { last_state = PowerState::On; - TT_LOG_W(TAG, "Power on"); + LOGGER.warn("Power on"); #if DEBUG_POWER_STATES powerInfoBuzz(1); @@ -163,7 +165,7 @@ static bool unPhonePowerOn() { unPhoneFeatures = std::make_shared(bq24295); if (!unPhoneFeatures->init()) { - TT_LOG_E(TAG, "UnPhoneFeatures init failed"); + LOGGER.error("UnPhoneFeatures init failed"); return false; } @@ -183,10 +185,10 @@ static bool unPhonePowerOn() { } bool initBoot() { - ESP_LOGI(TAG, LOG_MESSAGE_POWER_ON_START); + LOGGER.info(LOG_MESSAGE_POWER_ON_START); if (!unPhonePowerOn()) { - TT_LOG_E(TAG, LOG_MESSAGE_POWER_ON_FAILED); + LOGGER.error(LOG_MESSAGE_POWER_ON_FAILED); return false; } diff --git a/Devices/unphone/Source/UnPhoneFeatures.cpp b/Devices/unphone/Source/UnPhoneFeatures.cpp index 186d58e2..f87ecb48 100644 --- a/Devices/unphone/Source/UnPhoneFeatures.cpp +++ b/Devices/unphone/Source/UnPhoneFeatures.cpp @@ -1,6 +1,6 @@ #include "UnPhoneFeatures.h" -#include +#include #include #include @@ -9,6 +9,8 @@ #include #include +static const auto LOGGER = tt::Logger("unPhoneFeatures"); + namespace pin { static const gpio_num_t BUTTON1 = GPIO_NUM_45; // left button static const gpio_num_t BUTTON2 = GPIO_NUM_0; // middle button @@ -27,8 +29,6 @@ namespace expanderpin { static const esp_io_expander_pin_num_t VIBE = IO_EXPANDER_PIN_NUM_7; } // namespace expanderpin -#define TAG "unhpone_features" - // TODO: Make part of a new type of UnPhoneFeatures data struct that holds all the thread-related data QueueHandle_t interruptQueue; @@ -42,7 +42,7 @@ static int32_t buttonHandlingThreadMain(const bool* interrupted) { while (!*interrupted) { if (xQueueReceive(interruptQueue, &pinNumber, portMAX_DELAY)) { // The buttons might generate more than 1 click because of how they are built - TT_LOG_I(TAG, "Pressed button %d", pinNumber); + LOGGER.info("Pressed button %d", pinNumber); if (pinNumber == pin::BUTTON1) { tt::app::stop(); } @@ -75,7 +75,7 @@ bool UnPhoneFeatures::initPowerSwitch() { }; if (gpio_config(&config) != ESP_OK) { - TT_LOG_E(TAG, "Power pin init failed"); + LOGGER.error("Power pin init failed"); return false; } @@ -83,14 +83,14 @@ bool UnPhoneFeatures::initPowerSwitch() { rtc_gpio_pulldown_en(pin::POWER_SWITCH) == ESP_OK) { return true; } else { - TT_LOG_E(TAG, "Failed to set RTC for power switch"); + LOGGER.error("Failed to set RTC for power switch"); return false; } } bool UnPhoneFeatures::initNavButtons() { if (!initGpioExpander()) { - TT_LOG_E(TAG, "GPIO expander init failed"); + LOGGER.error("GPIO expander init failed"); return false; } @@ -125,7 +125,7 @@ bool UnPhoneFeatures::initNavButtons() { }; if (gpio_config(&config) != ESP_OK) { - TT_LOG_E(TAG, "Nav button pin init failed"); + LOGGER.error("Nav button pin init failed"); return false; } @@ -135,7 +135,7 @@ bool UnPhoneFeatures::initNavButtons() { gpio_isr_handler_add(pin::BUTTON2, navButtonInterruptHandler, (void*)pin::BUTTON2) != ESP_OK || gpio_isr_handler_add(pin::BUTTON3, navButtonInterruptHandler, (void*)pin::BUTTON3) != ESP_OK ) { - TT_LOG_E(TAG, "Nav buttons ISR init failed"); + LOGGER.error("Nav buttons ISR init failed"); return false; } @@ -156,7 +156,7 @@ bool UnPhoneFeatures::initOutputPins() { }; if (gpio_config(&config) != ESP_OK) { - TT_LOG_E(TAG, "Output pin init failed"); + LOGGER.error("Output pin init failed"); return false; } @@ -167,7 +167,7 @@ bool UnPhoneFeatures::initGpioExpander() { // ESP_IO_EXPANDER_I2C_TCA9555_ADDRESS_110 corresponds with 0x26 from the docs at // https://gitlab.com/hamishcunningham/unphonelibrary/-/blob/main/unPhone.h?ref_type=heads#L206 if (esp_io_expander_new_i2c_tca95xx_16bit(I2C_NUM_0, ESP_IO_EXPANDER_I2C_TCA9555_ADDRESS_110, &ioExpander) != ESP_OK) { - TT_LOG_E(TAG, "IO expander init failed"); + LOGGER.error("IO expander init failed"); return false; } assert(ioExpander != nullptr); @@ -201,25 +201,25 @@ bool UnPhoneFeatures::initGpioExpander() { } bool UnPhoneFeatures::init() { - TT_LOG_I(TAG, "init"); + LOGGER.info("init"); if (!initGpioExpander()) { - TT_LOG_E(TAG, "GPIO expander init failed"); + LOGGER.error("GPIO expander init failed"); return false; } if (!initNavButtons()) { - TT_LOG_E(TAG, "Input pin init failed"); + LOGGER.error("Input pin init failed"); return false; } if (!initOutputPins()) { - TT_LOG_E(TAG, "Output pin init failed"); + LOGGER.error("Output pin init failed"); return false; } if (!initPowerSwitch()) { - TT_LOG_E(TAG, "Power button init failed"); + LOGGER.error("Power button init failed"); return false; } @@ -231,7 +231,7 @@ void UnPhoneFeatures::printInfo() const { batteryManagement->printInfo(); bool backlight_power; const char* backlight_power_state = getBacklightPower(backlight_power) && backlight_power ? "on" : "off"; - TT_LOG_I(TAG, "Backlight: %s", backlight_power_state); + LOGGER.info("Backlight: %s", backlight_power_state); } bool UnPhoneFeatures::setRgbLed(bool red, bool green, bool blue) const { @@ -286,11 +286,11 @@ void UnPhoneFeatures::turnPeripheralsOff() const { bool UnPhoneFeatures::setShipping(bool on) const { if (on) { - TT_LOG_W(TAG, "setShipping: on"); + LOGGER.warn("setShipping: on"); batteryManagement->setWatchDogTimer(Bq24295::WatchDogTimer::Disabled); batteryManagement->setBatFetOn(false); } else { - TT_LOG_W(TAG, "setShipping: off"); + LOGGER.warn("setShipping: off"); batteryManagement->setWatchDogTimer(Bq24295::WatchDogTimer::Enabled40s); batteryManagement->setBatFetOn(true); } diff --git a/Devices/unphone/Source/devices/Hx8357Display.cpp b/Devices/unphone/Source/devices/Hx8357Display.cpp index 323f37ae..3bd0f0ff 100644 --- a/Devices/unphone/Source/devices/Hx8357Display.cpp +++ b/Devices/unphone/Source/devices/Hx8357Display.cpp @@ -2,18 +2,19 @@ #include "Touch.h" #include -#include +#include #include #include -constexpr auto TAG = "Hx8357Display"; +static const auto LOGGER = tt::Logger("Hx8357Display"); + constexpr auto BUFFER_SIZE = (UNPHONE_LCD_HORIZONTAL_RESOLUTION * UNPHONE_LCD_DRAW_BUFFER_HEIGHT * LV_COLOR_DEPTH / 8); extern std::shared_ptr unPhoneFeatures; bool Hx8357Display::start() { - TT_LOG_I(TAG, "start"); + LOGGER.info("start"); disp_spi_add_device(SPI2_HOST); @@ -26,16 +27,16 @@ bool Hx8357Display::start() { } bool Hx8357Display::stop() { - TT_LOG_I(TAG, "stop"); + LOGGER.info("stop"); disp_spi_remove_device(); return true; } bool Hx8357Display::startLvgl() { - TT_LOG_I(TAG, "startLvgl"); + LOGGER.info("startLvgl"); if (lvglDisplay != nullptr) { - TT_LOG_W(TAG, "LVGL was already started"); + LOGGER.warn("LVGL was already started"); return false; } @@ -58,7 +59,7 @@ bool Hx8357Display::startLvgl() { lv_display_set_flush_cb(lvglDisplay, hx8357_flush); if (lvglDisplay == nullptr) { - TT_LOG_I(TAG, "Failed"); + LOGGER.info("Failed"); return false; } @@ -73,10 +74,10 @@ bool Hx8357Display::startLvgl() { } bool Hx8357Display::stopLvgl() { - TT_LOG_I(TAG, "stopLvgl"); + LOGGER.info("stopLvgl"); if (lvglDisplay == nullptr) { - TT_LOG_W(TAG, "LVGL was already stopped"); + LOGGER.warn("LVGL was already stopped"); return false; } @@ -85,7 +86,7 @@ bool Hx8357Display::stopLvgl() { auto touch_device = getTouchDevice(); if (touch_device != nullptr && touch_device->getLvglIndev() != nullptr) { - TT_LOG_I(TAG, "Stopping touch device"); + LOGGER.info("Stopping touch device"); touch_device->stopLvgl(); } @@ -101,7 +102,7 @@ bool Hx8357Display::stopLvgl() { std::shared_ptr _Nullable Hx8357Display::getTouchDevice() { if (touchDevice == nullptr) { touchDevice = std::reinterpret_pointer_cast(createTouch()); - TT_LOG_I(TAG, "Created touch device"); + LOGGER.info("Created touch device"); } return touchDevice; diff --git a/Devices/unphone/Source/devices/Touch.cpp b/Devices/unphone/Source/devices/Touch.cpp index 6e189068..8c9a19b4 100644 --- a/Devices/unphone/Source/devices/Touch.cpp +++ b/Devices/unphone/Source/devices/Touch.cpp @@ -1,7 +1,5 @@ #include "Touch.h" -#include - std::shared_ptr createTouch() { auto configuration = std::make_unique( SPI2_HOST, diff --git a/Devices/waveshare-s3-touch-lcd-147/Source/Init.cpp b/Devices/waveshare-s3-touch-lcd-147/Source/Init.cpp index 99080dab..d12fe4e7 100644 --- a/Devices/waveshare-s3-touch-lcd-147/Source/Init.cpp +++ b/Devices/waveshare-s3-touch-lcd-147/Source/Init.cpp @@ -1,3 +1,4 @@ +#include #include #include diff --git a/Devices/waveshare-s3-touch-lcd-147/Source/devices/Jd9853Display.cpp b/Devices/waveshare-s3-touch-lcd-147/Source/devices/Jd9853Display.cpp index 1f7b1299..c7466ba8 100644 --- a/Devices/waveshare-s3-touch-lcd-147/Source/devices/Jd9853Display.cpp +++ b/Devices/waveshare-s3-touch-lcd-147/Source/devices/Jd9853Display.cpp @@ -1,12 +1,12 @@ #include "Jd9853Display.h" -#include +#include #include #include #include -constexpr const char* TAG = "JD9853"; +static const auto LOGGER = tt::Logger("JD9853"); bool Jd9853Display::createIoHandle(esp_lcd_panel_io_handle_t& outHandle) { const esp_lcd_panel_io_spi_config_t panel_io_config = { @@ -54,42 +54,42 @@ bool Jd9853Display::createPanelHandle(esp_lcd_panel_io_handle_t ioHandle, esp_lc }; if (esp_lcd_new_panel_jd9853(ioHandle, &panel_config, &panelHandle) != ESP_OK) { - TT_LOG_E(TAG, "Failed to create panel"); + LOGGER.error("Failed to create panel"); return false; } 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_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; } if (esp_lcd_panel_set_gap(panelHandle, 34, 0) != ESP_OK) { - TT_LOG_E(TAG, "Failed to set panel gap"); + LOGGER.error("Failed to set panel gap"); return false; } @@ -157,6 +157,6 @@ void Jd9853Display::setGammaCurve(uint8_t index) { }; if (esp_lcd_panel_io_tx_param(getIoHandle() , LCD_CMD_GAMSET, param, 1) != ESP_OK) { - TT_LOG_E(TAG, "Failed to set gamma"); + LOGGER.error("Failed to set gamma"); } } diff --git a/Drivers/AXP2101/Source/Axp2101.cpp b/Drivers/AXP2101/Source/Axp2101.cpp index f4e15c49..e43cf7b5 100644 --- a/Drivers/AXP2101/Source/Axp2101.cpp +++ b/Drivers/AXP2101/Source/Axp2101.cpp @@ -1,5 +1,4 @@ #include "Axp2101.h" -#include bool Axp2101::getBatteryVoltage(float& vbatMillis) const { return readRegister14(0x34, vbatMillis); diff --git a/Drivers/BQ24295/Source/Bq24295.cpp b/Drivers/BQ24295/Source/Bq24295.cpp index 4dfae7bf..a2eb3d55 100644 --- a/Drivers/BQ24295/Source/Bq24295.cpp +++ b/Drivers/BQ24295/Source/Bq24295.cpp @@ -1,7 +1,7 @@ #include "Bq24295.h" -#include +#include -#define TAG "bq24295" +static const auto LOGGER = tt::Logger("BQ24295"); /** Reference: * https://www.ti.com/lit/ds/symlink/bq24295.pdf @@ -50,7 +50,7 @@ bool Bq24295::setWatchDogTimer(WatchDogTimer in) const { uint8_t bits_to_set = 0b00110000 & static_cast(in); uint8_t value_cleared = value & 0b11001111; uint8_t to_set = bits_to_set & value_cleared; - TT_LOG_I(TAG, "WatchDogTimer: %02x -> %02x", value, to_set); + LOGGER.info("WatchDogTimer: {:02x} -> {:02x}", value, to_set); return writeRegister8(registers::CHARGE_TERMINATION, to_set); } @@ -96,9 +96,9 @@ bool Bq24295::getVersion(uint8_t& value) const { void Bq24295::printInfo() const { uint8_t version, status, charge_termination; if (getStatus(status) && getVersion(version) && readChargeTermination(charge_termination)) { - TT_LOG_I(TAG, "Version %d, status %02x, charge termination %02x", version, status, charge_termination); + LOGGER.info("Version {}, status {:02x}, charge termination {:02x}", version, status, charge_termination); } else { - TT_LOG_E(TAG, "Failed to retrieve version and/or status"); + LOGGER.error("Failed to retrieve version and/or status"); } } diff --git a/Drivers/BQ25896/Source/Bq25896.cpp b/Drivers/BQ25896/Source/Bq25896.cpp index 0b305495..e860e10d 100644 --- a/Drivers/BQ25896/Source/Bq25896.cpp +++ b/Drivers/BQ25896/Source/Bq25896.cpp @@ -1,15 +1,15 @@ #include "Bq25896.h" -#include +#include -constexpr auto* TAG = "BQ25896"; +static const auto LOGGER = tt::Logger("BQ25896"); void Bq25896::powerOff() { - TT_LOG_I(TAG, "Power off"); + LOGGER.info("Power off"); bitOn(0x09, BIT(5)); } void Bq25896::powerOn() { - TT_LOG_I(TAG, "Power on"); + LOGGER.info("Power on"); bitOff(0x09, BIT(5)); } diff --git a/Drivers/BQ27220/Source/Bq27220.cpp b/Drivers/BQ27220/Source/Bq27220.cpp index 1596af07..b2d08697 100644 --- a/Drivers/BQ27220/Source/Bq27220.cpp +++ b/Drivers/BQ27220/Source/Bq27220.cpp @@ -1,9 +1,9 @@ #include "Bq27220.h" -#include +#include #include "esp_sleep.h" -#define TAG "bq27220" +static const auto LOGGER = tt::Logger("BQ27220"); #define ARRAYSIZE(a) (sizeof(a) / sizeof(*(a))) @@ -93,14 +93,14 @@ bool Bq27220::configureCapacity(uint16_t designCapacity, uint16_t fullChargeCapa return performConfigUpdate([this, designCapacity, fullChargeCapacity]() { // Set the design capacity if (!writeConfig16(registers::ROM_DESIGN_CAPACITY, designCapacity)) { - TT_LOG_E(TAG, "Failed to set design capacity!"); + LOGGER.error("Failed to set design capacity!"); return false; } vTaskDelay(10 / portTICK_PERIOD_MS); // Set full charge capacity if (!writeConfig16(registers::ROM_FULL_CHARGE_CAPACITY, fullChargeCapacity)) { - TT_LOG_E(TAG, "Failed to set full charge capacity!"); + LOGGER.error("Failed to set full charge capacity!"); return false; } vTaskDelay(10 / portTICK_PERIOD_MS); @@ -260,7 +260,7 @@ bool Bq27220::sendSubCommand(uint16_t subCmd, bool waitConfirm) } vTaskDelay(100 / portTICK_PERIOD_MS); } - TT_LOG_E(TAG, "Subcommand x%X failed!", subCmd); + LOGGER.error("Subcommand 0x{:04X} failed!", subCmd); return false; } @@ -298,28 +298,28 @@ bool Bq27220::configPreamble(bool &isSealed) { // Check access settings if(!getOperationStatus(status)) { - TT_LOG_E(TAG, "Cannot read initial operation status!"); + LOGGER.error("Cannot read initial operation status!"); return false; } if (status.reg.SEC == OperationStatusSecSealed) { isSealed = true; if (!unsealDevice()) { - TT_LOG_E(TAG, "Unsealing device failure!"); + LOGGER.error("Unsealing device failure!"); return false; } } if (status.reg.SEC != OperationStatusSecFull) { if (!unsealFullAccess()) { - TT_LOG_E(TAG, "Unsealing full access failure!"); + LOGGER.error("Unsealing full access failure!"); return false; } } // Send ENTER_CFG_UPDATE command (0x0090) if (!sendSubCommand(registers::SUBCMD_ENTER_CFG_UPDATE)) { - TT_LOG_E(TAG, "Config Update Subcommand failure!"); + LOGGER.error("Config Update Subcommand failure!"); } // Confirm CFUPDATE mode by polling the OperationStatus() register until Bit 2 is set. @@ -333,7 +333,7 @@ bool Bq27220::configPreamble(bool &isSealed) { vTaskDelay(100 / portTICK_PERIOD_MS); } if (!isConfigUpdate) { - TT_LOG_E(TAG, "Update Mode timeout, maybe the access key for full permissions is invalid!"); + LOGGER.error("Update Mode timeout, maybe the access key for full permissions is invalid!"); return false; } @@ -357,13 +357,13 @@ bool Bq27220::configEpilouge(const bool isSealed) { vTaskDelay(100 / portTICK_PERIOD_MS); } if (timeout == 0) { - TT_LOG_E(TAG, "Timed out waiting to exit update mode."); + LOGGER.error("Timed out waiting to exit update mode."); return false; } // If the device was previously in SEALED state, return to SEALED mode by sending the Control(0x0030) subcommand if (isSealed) { - TT_LOG_D(TAG, "Restore Safe Mode!"); + LOGGER.debug("Restore Safe Mode!"); exitSealMode(); } return true; diff --git a/Drivers/ButtonControl/Source/ButtonControl.cpp b/Drivers/ButtonControl/Source/ButtonControl.cpp index b8e4a2a9..e7607b5b 100644 --- a/Drivers/ButtonControl/Source/ButtonControl.cpp +++ b/Drivers/ButtonControl/Source/ButtonControl.cpp @@ -1,10 +1,10 @@ #include "ButtonControl.h" -#include +#include #include -constexpr auto* TAG = "ButtonControl"; +static const auto LOGGER = tt::Logger("ButtonControl"); ButtonControl::ButtonControl(const std::vector& pinConfigurations) : pinConfigurations(pinConfigurations) { pinStates.resize(pinConfigurations.size()); @@ -73,7 +73,7 @@ void ButtonControl::updatePin(std::vector::const_reference con if (state.pressState) { auto time_passed = tt::kernel::getMillis() - state.pressStartTime; if (time_passed < 500) { - TT_LOG_D(TAG, "Trigger short press"); + LOGGER.debug("Trigger short press"); state.triggerShortPress = true; } state.pressState = false; @@ -103,7 +103,7 @@ bool ButtonControl::shouldInterruptDriverThread() const { } void ButtonControl::startThread() { - TT_LOG_I(TAG, "Start"); + LOGGER.info("Start"); mutex.lock(); @@ -120,7 +120,7 @@ void ButtonControl::startThread() { } void ButtonControl::stopThread() { - TT_LOG_I(TAG, "Stop"); + LOGGER.info("Stop"); mutex.lock(); interruptDriverThread = true; diff --git a/Drivers/DRV2605/Source/Drv2605.cpp b/Drivers/DRV2605/Source/Drv2605.cpp index a554ce02..4535d786 100644 --- a/Drivers/DRV2605/Source/Drv2605.cpp +++ b/Drivers/DRV2605/Source/Drv2605.cpp @@ -1,16 +1,20 @@ #include "Drv2605.h" +#include + +static const auto LOGGER = tt::Logger("DRV2605"); + bool Drv2605::init() { uint8_t status; if (!readRegister8(static_cast(Register::Status), status)) { - TT_LOG_E(TAG, "Failed to read status"); + LOGGER.error("Failed to read status"); return false; } status >>= 5; ChipId chip_id = static_cast(status); if (chip_id != ChipId::DRV2604 && chip_id != ChipId::DRV2604L && chip_id != ChipId::DRV2605 && chip_id != ChipId::DRV2605L) { - TT_LOG_E(TAG, "Unknown chip id %02x", chip_id); + LOGGER.error("Unknown chip id {:02x}", chip_id); return false; } @@ -25,7 +29,7 @@ bool Drv2605::init() { uint8_t feedback; if (!readRegister(Register::Feedback, feedback)) { - TT_LOG_E(TAG, "Failed to read feedback"); + LOGGER.error("Failed to read feedback"); return false; } diff --git a/Drivers/DRV2605/Source/Drv2605.h b/Drivers/DRV2605/Source/Drv2605.h index 781f95fb..3ec8e862 100644 --- a/Drivers/DRV2605/Source/Drv2605.h +++ b/Drivers/DRV2605/Source/Drv2605.h @@ -1,11 +1,10 @@ #pragma once #include -#include class Drv2605 : public tt::hal::i2c::I2cDevice { - static constexpr auto* TAG = "DRV2605"; + const tt::Logger logger = tt::Logger("DRV2605"); static constexpr auto ADDRESS = 0x5A; bool autoPlayStartupBuzz; @@ -66,7 +65,7 @@ public: explicit Drv2605(i2c_port_t port, bool autoPlayStartupBuzz = true) : I2cDevice(port, ADDRESS), autoPlayStartupBuzz(autoPlayStartupBuzz) { if (!init()) { - TT_LOG_E(TAG, "Failed to initialize DRV2605"); + logger.error("Failed to initialize DRV2605"); } if (autoPlayStartupBuzz) { diff --git a/Drivers/EstimatedPower/Source/ChargeFromAdcVoltage.cpp b/Drivers/EstimatedPower/Source/ChargeFromAdcVoltage.cpp index c4318c8a..d747bce8 100644 --- a/Drivers/EstimatedPower/Source/ChargeFromAdcVoltage.cpp +++ b/Drivers/EstimatedPower/Source/ChargeFromAdcVoltage.cpp @@ -1,8 +1,7 @@ #include "ChargeFromAdcVoltage.h" -#include -#include +#include -constexpr auto TAG = "ChargeFromAdcV"; +static const auto LOGGER = tt::Logger("ChargeFromAdcV"); constexpr auto MAX_VOLTAGE_SAMPLES = 15; ChargeFromAdcVoltage::ChargeFromAdcVoltage( @@ -11,12 +10,12 @@ ChargeFromAdcVoltage::ChargeFromAdcVoltage( float voltageMax ) : configuration(configuration), chargeFromVoltage(voltageMin, voltageMax) { if (adc_oneshot_new_unit(&configuration.adcConfig, &adcHandle) != ESP_OK) { - TT_LOG_E(TAG, "ADC config failed"); + LOGGER.error("ADC config failed"); return; } if (adc_oneshot_config_channel(adcHandle, configuration.adcChannel, &configuration.adcChannelConfig) != ESP_OK) { - TT_LOG_E(TAG, "ADC channel config failed"); + LOGGER.error("ADC channel config failed"); adc_oneshot_del_unit(adcHandle); return; @@ -33,10 +32,12 @@ bool ChargeFromAdcVoltage::readBatteryVoltageOnce(uint32_t& output) const { int raw; if (adc_oneshot_read(adcHandle, configuration.adcChannel, &raw) == ESP_OK) { output = configuration.adcMultiplier * ((1000.f * configuration.adcRefVoltage) / 4096.f) * (float)raw; - TT_LOG_V(TAG, "Raw = %d, voltage = %lu", raw, output); + if (LOGGER.isLoggingVerbose()) { + LOGGER.verbose("Raw = {}, voltage = {}", raw, output); + } return true; } else { - TT_LOG_E(TAG, "Read failed"); + LOGGER.error("Read failed"); return false; } } diff --git a/Drivers/EstimatedPower/Source/ChargeFromVoltage.cpp b/Drivers/EstimatedPower/Source/ChargeFromVoltage.cpp index a8dbd03a..a9715787 100644 --- a/Drivers/EstimatedPower/Source/ChargeFromVoltage.cpp +++ b/Drivers/EstimatedPower/Source/ChargeFromVoltage.cpp @@ -1,9 +1,9 @@ #include "ChargeFromVoltage.h" +#include #include -#include -constexpr auto* TAG = "ChargeFromVoltage"; +const static auto LOGGER = tt::Logger("ChargeFromVoltage"); uint8_t ChargeFromVoltage::estimateCharge(uint32_t milliVolt) const { const float volts = std::min((float)milliVolt / 1000.f, batteryVoltageMax); @@ -13,6 +13,6 @@ uint8_t ChargeFromVoltage::estimateCharge(uint32_t milliVolt) const { const float voltage_percentage = (volts - batteryVoltageMin) / (batteryVoltageMax - batteryVoltageMin); const float voltage_factor = std::min(1.0f, voltage_percentage); const auto charge_level = (uint8_t) (voltage_factor * 100.f); - TT_LOG_D(TAG, "mV = %lu, scaled = %.2f, factor = %.2f, result = %d", milliVolt, volts, voltage_factor, charge_level); + LOGGER.debug("mV = {}, scaled = {}, factor = {:.2f}, result = {}", milliVolt, volts, voltage_factor, charge_level); return charge_level; } diff --git a/Drivers/FT5x06/Source/Ft5x06Touch.cpp b/Drivers/FT5x06/Source/Ft5x06Touch.cpp index 12f6339a..974c70a6 100644 --- a/Drivers/FT5x06/Source/Ft5x06Touch.cpp +++ b/Drivers/FT5x06/Source/Ft5x06Touch.cpp @@ -1,13 +1,9 @@ #include "Ft5x06Touch.h" -#include - #include #include #include -#define TAG "ft5x06" - bool Ft5x06Touch::createIoHandle(esp_lcd_panel_io_handle_t& outHandle) { esp_lcd_panel_io_i2c_config_t io_config = ESP_LCD_TOUCH_IO_I2C_FT5x06_CONFIG(); return esp_lcd_new_panel_io_i2c(configuration->port, &io_config, &outHandle) == ESP_OK; diff --git a/Drivers/FT6x36/Source/Ft6x36Touch.cpp b/Drivers/FT6x36/Source/Ft6x36Touch.cpp index ed4ef07a..0ff7848a 100644 --- a/Drivers/FT6x36/Source/Ft6x36Touch.cpp +++ b/Drivers/FT6x36/Source/Ft6x36Touch.cpp @@ -1,12 +1,12 @@ #include "Ft6x36Touch.h" #include -#include +#include #include #include -#define TAG "ft6x36" +static const auto LOGGER = tt::Logger("FT6x36"); void Ft6x36Touch::touchReadCallback(lv_indev_t* indev, lv_indev_data_t* data) { auto* touch = (Ft6x36Touch*)lv_indev_get_driver_data(indev); @@ -71,10 +71,10 @@ bool Ft6x36Touch::shouldInterruptDriverThread() const { } bool Ft6x36Touch::start() { - TT_LOG_I(TAG, "Start"); + LOGGER.info("Start"); if (!driver.begin(FT6X36_DEFAULT_THRESHOLD, configuration->width, configuration->height)) { - TT_LOG_E(TAG, "driver.begin() failed"); + LOGGER.error("driver.begin() failed"); return false; } @@ -95,7 +95,7 @@ bool Ft6x36Touch::start() { } bool Ft6x36Touch::stop() { - TT_LOG_I(TAG, "Stop"); + LOGGER.info("Stop"); mutex.lock(); interruptDriverThread = true; diff --git a/Drivers/GC9A01/Source/Gc9a01Display.cpp b/Drivers/GC9A01/Source/Gc9a01Display.cpp index e6f17f8f..44fe1a93 100644 --- a/Drivers/GC9A01/Source/Gc9a01Display.cpp +++ b/Drivers/GC9A01/Source/Gc9a01Display.cpp @@ -1,15 +1,15 @@ #include "Gc9a01Display.h" -#include +#include #include #include #include -constexpr auto TAG = "GC9A01"; +static const auto LOGGER = tt::Logger("GC9A01"); bool Gc9a01Display::createIoHandle(esp_lcd_panel_io_handle_t& outHandle) { - TT_LOG_I(TAG, "Starting"); + LOGGER.info("Starting"); const esp_lcd_panel_io_spi_config_t panel_io_config = { .cs_gpio_num = configuration->csPin, @@ -36,7 +36,7 @@ bool Gc9a01Display::createIoHandle(esp_lcd_panel_io_handle_t& outHandle) { }; if (esp_lcd_new_panel_io_spi(configuration->spiHostDevice, &panel_io_config, &outHandle) != ESP_OK) { - TT_LOG_E(TAG, "Failed to create panel"); + LOGGER.error("Failed to create panel"); return false; } @@ -56,37 +56,37 @@ bool Gc9a01Display::createPanelHandle(esp_lcd_panel_io_handle_t ioHandle, esp_lc }; if (esp_lcd_new_panel_gc9a01(ioHandle, &panel_config, &panelHandle) != ESP_OK) { - TT_LOG_E(TAG, "Failed to create panel"); + LOGGER.error("Failed to create panel"); return false; } 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_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; } diff --git a/Drivers/GT911/Source/Gt911Touch.cpp b/Drivers/GT911/Source/Gt911Touch.cpp index b2959a9e..06fbf660 100644 --- a/Drivers/GT911/Source/Gt911Touch.cpp +++ b/Drivers/GT911/Source/Gt911Touch.cpp @@ -1,12 +1,12 @@ #include "Gt911Touch.h" -#include +#include #include #include #include -#define TAG "GT911" +static const auto LOGGER = tt::Logger("GT911"); bool Gt911Touch::createIoHandle(esp_lcd_panel_io_handle_t& outHandle) { esp_lcd_panel_io_i2c_config_t io_config = ESP_LCD_TOUCH_IO_I2C_GT911_CONFIG(); @@ -21,7 +21,7 @@ bool Gt911Touch::createIoHandle(esp_lcd_panel_io_handle_t& outHandle) { } else if (tt::hal::i2c::masterHasDeviceAtAddress(configuration->port, ESP_LCD_TOUCH_IO_I2C_GT911_ADDRESS_BACKUP)) { io_config.dev_addr = ESP_LCD_TOUCH_IO_I2C_GT911_ADDRESS_BACKUP; } else { - TT_LOG_E(TAG, "No device found on I2C bus"); + LOGGER.error("No device found on I2C bus"); return false; } diff --git a/Drivers/ILI9488/Source/Ili9488Display.cpp b/Drivers/ILI9488/Source/Ili9488Display.cpp index 6773c832..577bcc1a 100644 --- a/Drivers/ILI9488/Source/Ili9488Display.cpp +++ b/Drivers/ILI9488/Source/Ili9488Display.cpp @@ -1,12 +1,12 @@ #include "Ili9488Display.h" -#include +#include #include #include #include -#define TAG "ILI9488" +static const auto LOGGER = tt::Logger("ILI9488"); bool Ili9488Display::createIoHandle(esp_lcd_panel_io_handle_t& outHandle) { const esp_lcd_panel_io_spi_config_t panel_io_config = { @@ -50,37 +50,37 @@ bool Ili9488Display::createPanelHandle(esp_lcd_panel_io_handle_t ioHandle, esp_l }; if (esp_lcd_new_panel_ili9488(ioHandle, &panel_config, configuration->bufferSize, &panelHandle) != ESP_OK) { - TT_LOG_E(TAG, "Failed to create panel"); + LOGGER.error("Failed to create panel"); return false; } 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_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; } diff --git a/Drivers/PwmBacklight/Source/PwmBacklight.cpp b/Drivers/PwmBacklight/Source/PwmBacklight.cpp index b19c1836..15443f25 100644 --- a/Drivers/PwmBacklight/Source/PwmBacklight.cpp +++ b/Drivers/PwmBacklight/Source/PwmBacklight.cpp @@ -1,8 +1,8 @@ #include "PwmBacklight.h" -#include +#include -#define TAG "pwm_backlight" +static const auto LOGGER = tt::Logger("PwmBacklight"); namespace driver::pwmbacklight { @@ -16,7 +16,7 @@ bool init(gpio_num_t pin, uint32_t frequencyHz, ledc_timer_t timer, ledc_channel backlightTimer = timer; backlightChannel = channel; - TT_LOG_I(TAG, "Init"); + LOGGER.info("Init"); ledc_timer_config_t ledc_timer = { .speed_mode = LEDC_LOW_SPEED_MODE, .duty_resolution = LEDC_TIMER_8_BIT, @@ -27,7 +27,7 @@ bool init(gpio_num_t pin, uint32_t frequencyHz, ledc_timer_t timer, ledc_channel }; if (ledc_timer_config(&ledc_timer) != ESP_OK) { - TT_LOG_E(TAG, "Timer config failed"); + LOGGER.error("Timer config failed"); return false; } @@ -46,7 +46,7 @@ bool init(gpio_num_t pin, uint32_t frequencyHz, ledc_timer_t timer, ledc_channel }; if (ledc_channel_config(&ledc_channel) != ESP_OK) { - TT_LOG_E(TAG, "Channel config failed"); + LOGGER.error("Channel config failed"); } isBacklightInitialized = true; @@ -56,7 +56,7 @@ bool init(gpio_num_t pin, uint32_t frequencyHz, ledc_timer_t timer, ledc_channel bool setBacklightDuty(uint8_t duty) { if (!isBacklightInitialized) { - TT_LOG_E(TAG, "Not initialized"); + LOGGER.error("Not initialized"); return false; } return ledc_set_duty(LEDC_LOW_SPEED_MODE, backlightChannel, duty) == ESP_OK && diff --git a/Drivers/RgbDisplay/Source/RgbDisplay.cpp b/Drivers/RgbDisplay/Source/RgbDisplay.cpp index 88007e3d..fdd4499e 100644 --- a/Drivers/RgbDisplay/Source/RgbDisplay.cpp +++ b/Drivers/RgbDisplay/Source/RgbDisplay.cpp @@ -1,15 +1,15 @@ #include "RgbDisplay.h" -#include +#include +#include +#include #include #include #include #include -#include -#include -constexpr auto TAG = "RgbDisplay"; +static const auto LOGGER = tt::Logger("RgbDisplay"); RgbDisplay::~RgbDisplay() { if (displayDriver != nullptr && displayDriver.use_count() > 1) { @@ -18,35 +18,35 @@ RgbDisplay::~RgbDisplay() { } bool RgbDisplay::start() { - TT_LOG_I(TAG, "Starting"); + LOGGER.info("Starting"); if (esp_lcd_new_rgb_panel(&configuration->panelConfig, &panelHandle) != ESP_OK) { - TT_LOG_E(TAG, "Failed to create panel"); + LOGGER.error("Failed to create panel"); return false; } 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_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; } @@ -64,7 +64,7 @@ bool RgbDisplay::stop() { } if (displayDriver != nullptr && displayDriver.use_count() > 1) { - TT_LOG_W(TAG, "DisplayDriver is still in use."); + LOGGER.warn("DisplayDriver is still in use."); } auto touch_device = getTouchDevice(); @@ -80,7 +80,7 @@ bool RgbDisplay::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 display_config = getLvglPortDisplayConfig(); @@ -93,7 +93,7 @@ bool RgbDisplay::startLvgl() { }; lvglDisplay = lvgl_port_add_disp_rgb(&display_config, &rgb_config); - TT_LOG_I(TAG, "Finished"); + LOGGER.info("Finished"); auto touch_device = getTouchDevice(); if (touch_device != nullptr) { diff --git a/Drivers/SSD1306/Source/Ssd1306Display.cpp b/Drivers/SSD1306/Source/Ssd1306Display.cpp index 930441cb..7cda1adb 100644 --- a/Drivers/SSD1306/Source/Ssd1306Display.cpp +++ b/Drivers/SSD1306/Source/Ssd1306Display.cpp @@ -1,6 +1,6 @@ #include "Ssd1306Display.h" -#include +#include #include #include #include @@ -10,7 +10,7 @@ #include #include -#define TAG "ssd1306_display" +static const auto LOGGER = tt::Logger("Ssd1306Display"); // SSD1306 commands #define SSD1306_CMD_SET_CHARGE_PUMP 0x8D @@ -31,7 +31,7 @@ static bool ssd1306_i2c_send_cmd(i2c_port_t port, uint8_t addr, uint8_t cmd) { uint8_t data[2] = {0x00, cmd}; // 0x00 = command mode esp_err_t ret = i2c_master_write_to_device(port, addr, data, sizeof(data), pdMS_TO_TICKS(1000)); if (ret != ESP_OK) { - TT_LOG_E(TAG, "Failed to send command 0x%02X: %d", cmd, ret); + LOGGER.error("Failed to send command 0x{:02X}: {}", cmd, ret); return false; } return true; @@ -49,7 +49,7 @@ bool Ssd1306Display::createIoHandle(esp_lcd_panel_io_handle_t& ioHandle) { }; if (esp_lcd_new_panel_io_i2c((esp_lcd_i2c_bus_handle_t)configuration->port, &io_config, &ioHandle) != ESP_OK) { - TT_LOG_E(TAG, "Failed to create IO handle"); + LOGGER.error("Failed to create IO handle"); return false; } @@ -93,7 +93,7 @@ bool Ssd1306Display::createPanelHandle(esp_lcd_panel_io_handle_t ioHandle, esp_l #endif if (esp_lcd_new_panel_ssd1306(ioHandle, &panel_config, &panelHandle) != ESP_OK) { - TT_LOG_E(TAG, "Failed to create panel"); + LOGGER.error("Failed to create panel"); return false; } @@ -103,7 +103,7 @@ bool Ssd1306Display::createPanelHandle(esp_lcd_panel_io_handle_t ioHandle, esp_l auto port = configuration->port; auto addr = configuration->deviceAddress; - TT_LOG_I(TAG, "Sending Heltec V3 custom init sequence"); + LOGGER.info("Sending Heltec V3 custom init sequence"); // Display off while configuring ssd1306_i2c_send_cmd(port, addr, 0xAE); @@ -170,7 +170,7 @@ bool Ssd1306Display::createPanelHandle(esp_lcd_panel_io_handle_t ioHandle, esp_l vTaskDelay(pdMS_TO_TICKS(100)); // Let display stabilize - TT_LOG_I(TAG, "Heltec V3 display initialized successfully"); + LOGGER.info("Heltec V3 display initialized successfully"); return true; } diff --git a/Drivers/ST7735/Source/St7735Display.cpp b/Drivers/ST7735/Source/St7735Display.cpp index 32503b9e..39aa6abd 100644 --- a/Drivers/ST7735/Source/St7735Display.cpp +++ b/Drivers/ST7735/Source/St7735Display.cpp @@ -1,16 +1,16 @@ #include "St7735Display.h" -#include +#include #include #include #include #include -constexpr auto TAG = "ST7735"; +static const auto LOGGER = tt::Logger("ST7735"); bool St7735Display::createIoHandle(esp_lcd_panel_io_handle_t& outHandle) { - TT_LOG_I(TAG, "Starting"); + LOGGER.info("Starting"); const esp_lcd_panel_io_spi_config_t panel_io_config = { .cs_gpio_num = configuration->csPin, @@ -37,7 +37,7 @@ bool St7735Display::createIoHandle(esp_lcd_panel_io_handle_t& outHandle) { }; if (esp_lcd_new_panel_io_spi(configuration->spiHostDevice, &panel_io_config, &outHandle) != ESP_OK) { - TT_LOG_E(TAG, "Failed to create panel"); + LOGGER.error("Failed to create panel"); return false; } @@ -58,22 +58,22 @@ bool St7735Display::createPanelHandle(esp_lcd_panel_io_handle_t ioHandle, esp_lc }; if (esp_lcd_new_panel_st7735(ioHandle, &panel_config, &panelHandle) != ESP_OK) { - TT_LOG_E(TAG, "Failed to create panel"); + LOGGER.error("Failed to create panel"); return false; } 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; } @@ -81,22 +81,22 @@ bool St7735Display::createPanelHandle(esp_lcd_panel_io_handle_t ioHandle, esp_lc 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_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; } @@ -165,6 +165,6 @@ void St7735Display::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"); } } diff --git a/Drivers/ST7789-i8080/Source/St7789i8080Display.cpp b/Drivers/ST7789-i8080/Source/St7789i8080Display.cpp index c0995ee2..1c730f84 100644 --- a/Drivers/ST7789-i8080/Source/St7789i8080Display.cpp +++ b/Drivers/ST7789-i8080/Source/St7789i8080Display.cpp @@ -1,5 +1,5 @@ #include "St7789i8080Display.h" -#include +#include #include #include #include @@ -8,7 +8,7 @@ #include #include -constexpr auto TAG = "St7789i8080Display"; +static const auto LOGGER = tt::Logger("St7789i8080Display"); static St7789i8080Display* g_display_instance = nullptr; // ST7789 initialization commands @@ -51,13 +51,13 @@ St7789i8080Display::St7789i8080Display(const Configuration& config) // Validate configuration if (!configuration.isValid()) { - TT_LOG_E(TAG, "Invalid configuration: resolution must be set"); + LOGGER.error("Invalid configuration: resolution must be set"); return; } } bool St7789i8080Display::createI80Bus() { - TT_LOG_I(TAG, "Creating I80 bus"); + LOGGER.info("Creating I80 bus"); // Create I80 bus configuration esp_lcd_i80_bus_config_t bus_cfg = { @@ -78,7 +78,7 @@ bool St7789i8080Display::createI80Bus() { esp_err_t ret = esp_lcd_new_i80_bus(&bus_cfg, &i80BusHandle); if (ret != ESP_OK) { - TT_LOG_E(TAG, "Failed to create I80 bus: %s", esp_err_to_name(ret)); + LOGGER.error("Failed to create I80 bus: {}", esp_err_to_name(ret)); return false; } @@ -86,7 +86,7 @@ bool St7789i8080Display::createI80Bus() { } bool St7789i8080Display::createPanelIO() { - TT_LOG_I(TAG, "Creating panel IO"); + LOGGER.info("Creating panel IO"); // Create panel IO with proper callback esp_lcd_panel_io_i80_config_t io_cfg = { @@ -114,7 +114,7 @@ bool St7789i8080Display::createPanelIO() { esp_err_t ret = esp_lcd_new_panel_io_i80(i80BusHandle, &io_cfg, &ioHandle); if (ret != ESP_OK) { - TT_LOG_E(TAG, "Failed to create panel IO: %s", esp_err_to_name(ret)); + LOGGER.error("Failed to create panel IO: {}", esp_err_to_name(ret)); return false; } @@ -122,7 +122,7 @@ bool St7789i8080Display::createPanelIO() { } bool St7789i8080Display::createPanel() { - TT_LOG_I(TAG, "Configuring panel"); + LOGGER.info("Configuring panel"); // Create ST7789 panel esp_lcd_panel_dev_config_t panel_config = { @@ -138,49 +138,49 @@ bool St7789i8080Display::createPanel() { esp_err_t ret = esp_lcd_new_panel_st7789(ioHandle, &panel_config, &panelHandle); if (ret != ESP_OK) { - TT_LOG_E(TAG, "Failed to create ST7789 panel: %s", esp_err_to_name(ret)); + LOGGER.error("Failed to create ST7789 panel: {}", esp_err_to_name(ret)); return false; } // Reset panel ret = esp_lcd_panel_reset(panelHandle); if (ret != ESP_OK) { - TT_LOG_E(TAG, "Failed to reset panel: %s", esp_err_to_name(ret)); + LOGGER.error("Failed to reset panel: {}", esp_err_to_name(ret)); return false; } // Initialize panel ret = esp_lcd_panel_init(panelHandle); if (ret != ESP_OK) { - TT_LOG_E(TAG, "Failed to init panel: %s", esp_err_to_name(ret)); + LOGGER.error("Failed to init panel: {}", esp_err_to_name(ret)); return false; } // Set gap ret = esp_lcd_panel_set_gap(panelHandle, configuration.gapX, configuration.gapY); if (ret != ESP_OK) { - TT_LOG_E(TAG, "Failed to set panel gap: %s", esp_err_to_name(ret)); + LOGGER.error("Failed to set panel gap: {}", esp_err_to_name(ret)); return false; } // Set inversion ret = esp_lcd_panel_invert_color(panelHandle, configuration.invertColor); if (ret != ESP_OK) { - TT_LOG_E(TAG, "Failed to set panel inversion: %s", esp_err_to_name(ret)); + LOGGER.error("Failed to set panel inversion: {}", esp_err_to_name(ret)); return false; } // Set mirror ret = esp_lcd_panel_mirror(panelHandle, configuration.mirrorX, configuration.mirrorY); if (ret != ESP_OK) { - TT_LOG_E(TAG, "Failed to set panel mirror: %s", esp_err_to_name(ret)); + LOGGER.error("Failed to set panel mirror: {}", esp_err_to_name(ret)); return false; } // Turn on display ret = esp_lcd_panel_disp_on_off(panelHandle, true); if (ret != ESP_OK) { - TT_LOG_E(TAG, "Failed to turn display on: %s", esp_err_to_name(ret)); + LOGGER.error("Failed to turn display on: {}", esp_err_to_name(ret)); return false; } @@ -188,7 +188,7 @@ bool St7789i8080Display::createPanel() { } void St7789i8080Display::sendInitCommands() { - TT_LOG_I(TAG, "Sending ST7789 init commands"); + LOGGER.info("Sending ST7789 init commands"); for (const auto& cmd : st7789_init_cmds) { esp_lcd_panel_io_tx_param(ioHandle, cmd.cmd, cmd.data, cmd.len & 0x7F); if (cmd.len & 0x80) { @@ -198,7 +198,7 @@ void St7789i8080Display::sendInitCommands() { } bool St7789i8080Display::start() { - TT_LOG_I(TAG, "Initializing I8080 ST7789 Display hardware..."); + LOGGER.info("Initializing I8080 ST7789 Display hardware..."); // Configure RD pin if needed if (configuration.rdPin != GPIO_NUM_NC) { @@ -220,7 +220,7 @@ bool St7789i8080Display::start() { size_t buffer_size = configuration.bufferSize * LV_COLOR_FORMAT_GET_SIZE(LV_COLOR_FORMAT_RGB565); buf1 = (uint8_t*)heap_caps_malloc(buffer_size, MALLOC_CAP_DMA); if (!buf1) { - TT_LOG_E(TAG, "Failed to allocate display buffer"); + LOGGER.error("Failed to allocate display buffer"); return false; } @@ -239,7 +239,7 @@ bool St7789i8080Display::start() { return false; } - TT_LOG_I(TAG, "Display hardware initialized"); + LOGGER.info("Display hardware initialized"); return true; } @@ -278,17 +278,17 @@ bool St7789i8080Display::stop() { } bool St7789i8080Display::startLvgl() { - TT_LOG_I(TAG, "Initializing LVGL for ST7789 display"); + LOGGER.info("Initializing LVGL for ST7789 display"); // Don't reinitialize hardware if it's already done if (!ioHandle) { - TT_LOG_I(TAG, "Hardware not initialized, calling start()"); + LOGGER.info("Hardware not initialized, calling start()"); if (!start()) { - TT_LOG_E(TAG, "Hardware initialization failed"); + LOGGER.error("Hardware initialization failed"); return false; } } else { - TT_LOG_I(TAG, "Hardware already initialized, skipping"); + LOGGER.info("Hardware already initialized, skipping"); } // Create LVGL display using lvgl_port @@ -321,7 +321,7 @@ bool St7789i8080Display::startLvgl() { // Create the LVGL display lvglDisplay = lvgl_port_add_disp(&display_cfg); if (!lvglDisplay) { - TT_LOG_E(TAG, "Failed to create LVGL display"); + LOGGER.error("Failed to create LVGL display"); return false; } @@ -332,7 +332,7 @@ bool St7789i8080Display::startLvgl() { esp_lcd_panel_io_register_event_callbacks(ioHandle, &cbs, lvglDisplay); g_display_instance = this; - TT_LOG_I(TAG, "LVGL display created successfully"); + LOGGER.info("LVGL display created successfully"); return true; } diff --git a/Drivers/ST7796-i8080/Source/St7796i8080Display.cpp b/Drivers/ST7796-i8080/Source/St7796i8080Display.cpp index bd0784e8..1cf9055b 100644 --- a/Drivers/ST7796-i8080/Source/St7796i8080Display.cpp +++ b/Drivers/ST7796-i8080/Source/St7796i8080Display.cpp @@ -1,5 +1,5 @@ #include "St7796i8080Display.h" -#include +#include #include #include #include @@ -8,7 +8,7 @@ #include #include -constexpr auto TAG = "St7796i8080Display"; +static const auto LOGGER = tt::Logger("St7796i8080Display"); static St7796i8080Display* g_display_instance = nullptr; St7796i8080Display::St7796i8080Display(const Configuration& config) @@ -16,13 +16,13 @@ St7796i8080Display::St7796i8080Display(const Configuration& config) // Validate configuration if (!configuration.isValid()) { - TT_LOG_E(TAG, "Invalid configuration: resolution must be set"); + LOGGER.error("Invalid configuration: resolution must be set"); return; } } bool St7796i8080Display::createI80Bus() { - TT_LOG_I(TAG, "Creating I80 bus"); + LOGGER.info("Creating I80 bus"); // Create I80 bus configuration esp_lcd_i80_bus_config_t bus_cfg = { @@ -42,7 +42,7 @@ bool St7796i8080Display::createI80Bus() { }; if (esp_lcd_new_i80_bus(&bus_cfg, &i80BusHandle) != ESP_OK) { - TT_LOG_E(TAG, "Failed to create I80 bus"); + LOGGER.error("Failed to create I80 bus"); return false; } @@ -50,7 +50,7 @@ bool St7796i8080Display::createI80Bus() { } bool St7796i8080Display::createPanelIO() { - TT_LOG_I(TAG, "Creating panel IO"); + LOGGER.info("Creating panel IO"); // Create panel IO esp_lcd_panel_io_i80_config_t io_cfg = { @@ -77,7 +77,7 @@ bool St7796i8080Display::createPanelIO() { }; if (esp_lcd_new_panel_io_i80(i80BusHandle, &io_cfg, &ioHandle) != ESP_OK) { - TT_LOG_E(TAG, "Failed to create panel"); + LOGGER.error("Failed to create panel"); return false; } @@ -85,7 +85,7 @@ bool St7796i8080Display::createPanelIO() { } bool St7796i8080Display::createPanel() { - TT_LOG_I(TAG, "Configuring panel"); + LOGGER.info("Configuring panel"); // Create ST7796 panel esp_lcd_panel_dev_config_t panel_config = { @@ -100,43 +100,43 @@ bool St7796i8080Display::createPanel() { }; if (esp_lcd_new_panel_st7796(ioHandle, &panel_config, &panelHandle) != ESP_OK) { - TT_LOG_E(TAG, "Failed to create panel"); + LOGGER.error("Failed to create panel"); return false; } // Reset panel if (esp_lcd_panel_reset(panelHandle) != ESP_OK) { - TT_LOG_E(TAG, "Failed to reset panel"); + LOGGER.error("Failed to reset panel"); return false; } // Initialize panel if (esp_lcd_panel_init(panelHandle) != ESP_OK) { - TT_LOG_E(TAG, "Failed to init panel"); + LOGGER.error("Failed to init panel"); return false; } // Set swap XY 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; } // Set mirror 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; } // Set inversion 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; } // Turn on display 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; } @@ -144,7 +144,7 @@ bool St7796i8080Display::createPanel() { } bool St7796i8080Display::start() { - TT_LOG_I(TAG, "Initializing I8080 ST7796 Display hardware..."); + LOGGER.info("Initializing I8080 ST7796 Display hardware..."); // Calculate buffer size if needed configuration.calculateBufferSize(); @@ -153,7 +153,7 @@ bool St7796i8080Display::start() { size_t buffer_size = configuration.bufferSize * LV_COLOR_FORMAT_GET_SIZE(LV_COLOR_FORMAT_RGB565); displayBuffer = (uint8_t*)heap_caps_malloc(buffer_size, MALLOC_CAP_DMA); if (!displayBuffer) { - TT_LOG_E(TAG, "Failed to allocate display buffer"); + LOGGER.error("Failed to allocate display buffer"); return false; } @@ -175,7 +175,7 @@ bool St7796i8080Display::start() { return false; } - TT_LOG_I(TAG, "Display hardware initialized"); + LOGGER.info("Display hardware initialized"); return true; } @@ -214,17 +214,17 @@ bool St7796i8080Display::stop() { } bool St7796i8080Display::startLvgl() { - TT_LOG_I(TAG, "Initializing LVGL for ST7796 display"); + LOGGER.info("Initializing LVGL for ST7796 display"); // Don't reinitialize hardware if it's already done if (!ioHandle) { - TT_LOG_I(TAG, "Hardware not initialized, calling start()"); + LOGGER.info("Hardware not initialized, calling start()"); if (!start()) { - TT_LOG_E(TAG, "Hardware initialization failed"); + LOGGER.error("Hardware initialization failed"); return false; } } else { - TT_LOG_I(TAG, "Hardware already initialized, skipping"); + LOGGER.info("Hardware already initialized, skipping"); } // Create LVGL display using lvgl_port @@ -257,12 +257,12 @@ bool St7796i8080Display::startLvgl() { // Create the LVGL display lvglDisplay = lvgl_port_add_disp(&display_cfg); if (!lvglDisplay) { - TT_LOG_E(TAG, "Failed to create LVGL display"); + LOGGER.error("Failed to create LVGL display"); return false; } g_display_instance = this; - TT_LOG_I(TAG, "LVGL display created successfully"); + LOGGER.info("LVGL display created successfully"); return true; } diff --git a/Drivers/ST7796/Source/St7796Display.cpp b/Drivers/ST7796/Source/St7796Display.cpp index ccb5c1c3..43bd22c6 100644 --- a/Drivers/ST7796/Source/St7796Display.cpp +++ b/Drivers/ST7796/Source/St7796Display.cpp @@ -1,12 +1,12 @@ #include "St7796Display.h" -#include +#include #include #include #include -constexpr auto TAG = "ST7796"; +static const auto LOGGER = tt::Logger("ST7796"); bool St7796Display::createIoHandle(esp_lcd_panel_io_handle_t& ioHandle) { const esp_lcd_panel_io_spi_config_t panel_io_config = { @@ -74,42 +74,42 @@ bool St7796Display::createPanelHandle(esp_lcd_panel_io_handle_t ioHandle, esp_lc }; if (esp_lcd_new_panel_st7796(ioHandle, &panel_config, &panelHandle) != ESP_OK) { - TT_LOG_E(TAG, "Failed to create panel"); + LOGGER.error("Failed to create panel"); return false; } 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; } 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_set_gap(panelHandle, configuration->gapX, configuration->gapY) != ESP_OK) { - TT_LOG_E(TAG, "Failed to set panel gap"); + LOGGER.error("Failed to set panel gap"); 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; } @@ -168,6 +168,6 @@ void St7796Display::setGammaCurve(uint8_t index) { }; /*if (esp_lcd_panel_io_tx_param(ioHandle , LCD_CMD_GAMSET, param, 1) != ESP_OK) { - TT_LOG_E(TAG, "Failed to set gamma"); + LOGGER.error("Failed to set gamma"); }*/ } diff --git a/Drivers/TCA8418/Source/Tca8418.cpp b/Drivers/TCA8418/Source/Tca8418.cpp index da0c6522..2e6e1b6a 100644 --- a/Drivers/TCA8418/Source/Tca8418.cpp +++ b/Drivers/TCA8418/Source/Tca8418.cpp @@ -1,7 +1,4 @@ #include "Tca8418.h" -#include - -constexpr auto TAG = "TCA8418"; namespace registers { static const uint8_t CFG = 0x01U; diff --git a/Drivers/XPT2046/Source/Xpt2046Power.cpp b/Drivers/XPT2046/Source/Xpt2046Power.cpp index a2e0126d..ebf040f6 100644 --- a/Drivers/XPT2046/Source/Xpt2046Power.cpp +++ b/Drivers/XPT2046/Source/Xpt2046Power.cpp @@ -1,10 +1,11 @@ #include "Xpt2046Power.h" #include "Xpt2046Touch.h" -#include +#include #include -constexpr auto TAG = "Xpt2046Power"; +static const auto LOGGER = tt::Logger("Xpt2046Power"); + constexpr auto BATTERY_VOLTAGE_MIN = 3.2f; constexpr auto BATTERY_VOLTAGE_MAX = 4.2f; constexpr auto MAX_VOLTAGE_SAMPLES = 15; @@ -13,12 +14,12 @@ static std::shared_ptr findXp2046TouchDevice() { // Make a safe copy auto touch = tt::hal::findFirstDevice(tt::hal::Device::Type::Touch); if (touch == nullptr) { - TT_LOG_E(TAG, "Touch device not found"); + LOGGER.error("Touch device not found"); return nullptr; } if (touch->getName() != "XPT2046") { - TT_LOG_E(TAG, "Touch device name mismatch"); + LOGGER.error("Touch device name mismatch"); return nullptr; } @@ -30,7 +31,7 @@ static uint8_t estimateChargeLevelFromVoltage(uint32_t milliVolt) { float voltage_percentage = (volts - BATTERY_VOLTAGE_MIN) / (BATTERY_VOLTAGE_MAX - BATTERY_VOLTAGE_MIN); float voltage_factor = std::min(1.0f, voltage_percentage); auto charge_level = (uint8_t) (voltage_factor * 100.f); - TT_LOG_V(TAG, "mV = %lu, scaled = %.2f, factor = %.2f, result = %d", milliVolt, volts, voltage_factor, charge_level); + LOGGER.verbose("mV = {}, scaled = {}, factor = {}, result = {}", milliVolt, volts, voltage_factor, charge_level); return charge_level; } @@ -68,7 +69,7 @@ bool Xpt2046Power::readBatteryVoltageOnce(uint32_t& output) { if (xptTouch == nullptr) { xptTouch = findXp2046TouchDevice(); if (xptTouch == nullptr) { - TT_LOG_E(TAG, "XPT2046 touch device not found"); + LOGGER.error("XPT2046 touch device not found"); return false; } } diff --git a/Drivers/XPT2046/Source/Xpt2046Touch.cpp b/Drivers/XPT2046/Source/Xpt2046Touch.cpp index 16980d5d..50c5ca15 100644 --- a/Drivers/XPT2046/Source/Xpt2046Touch.cpp +++ b/Drivers/XPT2046/Source/Xpt2046Touch.cpp @@ -1,6 +1,5 @@ #include "Xpt2046Touch.h" -#include #include #include diff --git a/Drivers/XPT2046SoftSPI/Source/Xpt2046SoftSpi.cpp b/Drivers/XPT2046SoftSPI/Source/Xpt2046SoftSpi.cpp index 174d916c..d26f1fa9 100644 --- a/Drivers/XPT2046SoftSPI/Source/Xpt2046SoftSpi.cpp +++ b/Drivers/XPT2046SoftSPI/Source/Xpt2046SoftSpi.cpp @@ -1,6 +1,6 @@ #include "Xpt2046SoftSpi.h" -#include +#include #include #include @@ -13,7 +13,7 @@ #include #include -constexpr auto* TAG = "Xpt2046SoftSpi"; +static const auto LOGGER = tt::Logger("Xpt2046SoftSpi"); constexpr auto RERUN_CALIBRATE = false; constexpr auto CMD_READ_Y = 0x90; // Try different commands if these don't work @@ -55,7 +55,7 @@ static void ensureNvsInitialized() { bool Xpt2046SoftSpi::start() { ensureNvsInitialized(); - TT_LOG_I(TAG, "Starting Xpt2046SoftSpi touch driver"); + LOGGER.info("Starting Xpt2046SoftSpi touch driver"); // Configure GPIO pins gpio_config_t io_conf = {}; @@ -70,7 +70,7 @@ bool Xpt2046SoftSpi::start() { io_conf.pull_up_en = GPIO_PULLUP_DISABLE; if (gpio_config(&io_conf) != ESP_OK) { - TT_LOG_E(TAG, "Failed to configure output pins"); + LOGGER.error("Failed to configure output pins"); return false; } @@ -80,7 +80,7 @@ bool Xpt2046SoftSpi::start() { io_conf.pull_up_en = GPIO_PULLUP_ENABLE; if (gpio_config(&io_conf) != ESP_OK) { - TT_LOG_E(TAG, "Failed to configure input pin"); + LOGGER.error("Failed to configure input pin"); return false; } @@ -89,31 +89,31 @@ bool Xpt2046SoftSpi::start() { gpio_set_level(configuration->clkPin, 0); // CLK low gpio_set_level(configuration->mosiPin, 0); // MOSI low - TT_LOG_I(TAG, "GPIO configured: MOSI=%d, MISO=%d, CLK=%d, CS=%d", configuration->mosiPin, configuration->misoPin, configuration->clkPin, configuration->csPin); + LOGGER.info("GPIO configured: MOSI={}, MISO={}, CLK={}, CS={}", configuration->mosiPin, configuration->misoPin, configuration->clkPin, configuration->csPin); // Load or perform calibration bool calibrationValid = true; //loadCalibration() && !RERUN_CALIBRATE; if (calibrationValid) { // Check if calibration values are valid (xMin != xMax, yMin != yMax) if (cal.xMin == cal.xMax || cal.yMin == cal.yMax) { - TT_LOG_W(TAG, "Invalid calibration detected: xMin=%d, xMax=%d, yMin=%d, yMax=%d", cal.xMin, cal.xMax, cal.yMin, cal.yMax); + LOGGER.warn("Invalid calibration detected: xMin={}, xMax={}, yMin={}, yMax={}", cal.xMin, cal.xMax, cal.yMin, cal.yMax); calibrationValid = false; } } if (!calibrationValid) { - TT_LOG_W(TAG, "Calibration data not found, invalid, or forced recalibration"); + LOGGER.warn("Calibration data not found, invalid, or forced recalibration"); calibrate(); saveCalibration(); } else { - TT_LOG_I(TAG, "Loaded calibration: xMin=%d, yMin=%d, xMax=%d, yMax=%d", cal.xMin, cal.yMin, cal.xMax, cal.yMax); + LOGGER.info("Loaded calibration: xMin={}, yMin={}, xMax={}, yMax={}", cal.xMin, cal.yMin, cal.xMax, cal.yMax); } return true; } bool Xpt2046SoftSpi::stop() { - TT_LOG_I(TAG, "Stopping Xpt2046SoftSpi touch driver"); + LOGGER.info("Stopping Xpt2046SoftSpi touch driver"); // Stop LVLG if needed if (lvglDevice != nullptr) { @@ -125,13 +125,13 @@ bool Xpt2046SoftSpi::stop() { bool Xpt2046SoftSpi::startLvgl(lv_display_t* display) { if (lvglDevice != nullptr) { - TT_LOG_E(TAG, "LVGL was already started"); + LOGGER.error("LVGL was already started"); return false; } lvglDevice = lv_indev_create(); if (!lvglDevice) { - TT_LOG_E(TAG, "Failed to create LVGL input device"); + LOGGER.error("Failed to create LVGL input device"); return false; } @@ -139,7 +139,7 @@ bool Xpt2046SoftSpi::startLvgl(lv_display_t* display) { lv_indev_set_read_cb(lvglDevice, touchReadCallback); lv_indev_set_user_data(lvglDevice, this); - TT_LOG_I(TAG, "Xpt2046SoftSpi touch driver started successfully"); + LOGGER.info("Xpt2046SoftSpi touch driver started successfully"); return true; } @@ -186,9 +186,9 @@ int Xpt2046SoftSpi::readSPI(uint8_t command) { void Xpt2046SoftSpi::calibrate() { const int samples = 8; // More samples for better accuracy - TT_LOG_I(TAG, "Calibration starting..."); + LOGGER.info("Calibration starting..."); - TT_LOG_I(TAG, "Touch TOP-LEFT corner"); + LOGGER.info("Touch TOP-LEFT corner"); while (!isTouched()) { vTaskDelay(pdMS_TO_TICKS(50)); @@ -203,9 +203,9 @@ void Xpt2046SoftSpi::calibrate() { cal.xMin = sumX / samples; cal.yMin = sumY / samples; - TT_LOG_I(TAG, "Top-left calibrated: xMin=%d, yMin=%d", cal.xMin, cal.yMin); + LOGGER.info("Top-left calibrated: xMin={}, yMin={}", cal.xMin, cal.yMin); - TT_LOG_I(TAG, "Touch BOTTOM-RIGHT corner"); + LOGGER.info("Touch BOTTOM-RIGHT corner"); while (!isTouched()) { vTaskDelay(pdMS_TO_TICKS(50)); @@ -220,13 +220,13 @@ void Xpt2046SoftSpi::calibrate() { cal.xMax = sumX / samples; cal.yMax = sumY / samples; - TT_LOG_I(TAG, "Bottom-right calibrated: xMax=%d, yMax=%d", cal.xMax, cal.yMax); + LOGGER.info("Bottom-right calibrated: xMax={}, yMax={}", cal.xMax, cal.yMax); - TT_LOG_I(TAG, "Calibration completed! xMin=%d, yMin=%d, xMax=%d, yMax=%d", cal.xMin, cal.yMin, cal.xMax, cal.yMax); + LOGGER.info("Calibration completed! xMin={}, yMin={}, xMax={}, yMax={}", cal.xMin, cal.yMin, cal.xMax, cal.yMax); } bool Xpt2046SoftSpi::loadCalibration() { - TT_LOG_W(TAG, "Calibration load disabled (using fresh calibration only)."); + LOGGER.warn("Calibration load disabled (using fresh calibration only)."); return false; } @@ -234,16 +234,16 @@ void Xpt2046SoftSpi::saveCalibration() { nvs_handle_t handle; esp_err_t err = nvs_open("xpt2046", NVS_READWRITE, &handle); if (err != ESP_OK) { - TT_LOG_E(TAG, "Failed to open NVS for writing (%s)", esp_err_to_name(err)); + LOGGER.error("Failed to open NVS for writing ({})", esp_err_to_name(err)); return; } err = nvs_set_blob(handle, "cal", &cal, sizeof(cal)); if (err == ESP_OK) { nvs_commit(handle); - TT_LOG_I(TAG, "Calibration saved to NVS"); + LOGGER.info("Calibration saved to NVS"); } else { - TT_LOG_E(TAG, "Failed to write calibration data to NVS (%s)", esp_err_to_name(err)); + LOGGER.error("Failed to write calibration data to NVS ({})", esp_err_to_name(err)); } nvs_close(handle); @@ -254,7 +254,7 @@ void Xpt2046SoftSpi::setCalibration(int xMin, int yMin, int xMax, int yMax) { cal.yMin = yMin; cal.xMax = xMax; cal.yMax = yMax; - TT_LOG_I(TAG, "Manual calibration set: xMin=%d, yMin=%d, xMax=%d, yMax=%d", xMin, yMin, xMax, yMax); + LOGGER.info("Manual calibration set: xMin={}, yMin={}, xMax={}, yMax={}", xMin, yMin, xMax, yMax); } bool Xpt2046SoftSpi::getTouchPoint(Point& point) { @@ -292,7 +292,7 @@ bool Xpt2046SoftSpi::getTouchPoint(Point& point) { const int yRange = cal.yMax - cal.yMin; if (xRange <= 0 || yRange <= 0) { - TT_LOG_W(TAG, "Invalid calibration: xRange=%d, yRange=%d", xRange, yRange); + LOGGER.warn("Invalid calibration: xRange={}, yRange={}", xRange, yRange); return false; } @@ -337,7 +337,7 @@ bool Xpt2046SoftSpi::isTouched() { // Debug logging (remove this once working) if (touched) { - TT_LOG_D(TAG, "Touch detected: validSamples=%d, avgX=%d, avgY=%d", validSamples, xTotal / validSamples, yTotal / validSamples); + LOGGER.debug("Touch detected: validSamples={}, avgX={}, avgY={}", validSamples, xTotal / validSamples, yTotal / validSamples); } return touched; diff --git a/Tactility/Source/Tactility.cpp b/Tactility/Source/Tactility.cpp index ea523417..0d1a1a9d 100644 --- a/Tactility/Source/Tactility.cpp +++ b/Tactility/Source/Tactility.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -275,7 +276,7 @@ void createTempDirectory(const std::string& rootPath) { LOGGER.error("Failed to create {}", temp_path); } } else { - LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT_CPP, rootPath); + LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, rootPath); } } else { LOGGER.info("Found existing {}", temp_path); diff --git a/Tactility/Source/app/addgps/AddGps.cpp b/Tactility/Source/app/addgps/AddGps.cpp index 079efb41..c589580c 100644 --- a/Tactility/Source/app/addgps/AddGps.cpp +++ b/Tactility/Source/app/addgps/AddGps.cpp @@ -1,18 +1,19 @@ -#include "Tactility/StringUtils.h" -#include "Tactility/app/AppManifest.h" -#include "Tactility/app/alertdialog/AlertDialog.h" -#include "Tactility/hal/gps/GpsDevice.h" -#include "Tactility/hal/uart/Uart.h" -#include "Tactility/lvgl/Style.h" -#include "Tactility/lvgl/Toolbar.h" -#include "Tactility/service/gps/GpsService.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include namespace tt::app::addgps { -constexpr const char* TAG = "AddGps"; +static const auto LOGGER = Logger("AddGps"); class AddGpsApp final : public App { @@ -46,7 +47,7 @@ class AddGpsApp final : public App { return; } - TT_LOG_I(TAG, "Saving: uart=%s, model=%lu, baud=%lu", new_configuration.uartName, (uint32_t)new_configuration.model, new_configuration.baudRate); + LOGGER.info("Saving: uart={}, model={}, baud={}", new_configuration.uartName, (uint32_t)new_configuration.model, new_configuration.baudRate); auto service = service::gps::findGpsService(); std::vector configurations; diff --git a/Tactility/Source/app/alertdialog/AlertDialog.cpp b/Tactility/Source/app/alertdialog/AlertDialog.cpp index 27c09f9a..bbd09359 100644 --- a/Tactility/Source/app/alertdialog/AlertDialog.cpp +++ b/Tactility/Source/app/alertdialog/AlertDialog.cpp @@ -3,8 +3,8 @@ #include "Tactility/lvgl/Toolbar.h" #include "Tactility/service/loader/Loader.h" +#include #include -#include #include @@ -16,9 +16,9 @@ namespace tt::app::alertdialog { #define RESULT_BUNDLE_KEY_INDEX "index" #define PARAMETER_ITEM_CONCATENATION_TOKEN ";;" -#define DEFAULT_TITLE "Select..." +#define DEFAULT_TITLE "" -#define TAG "selection_dialog" +static const auto LOGGER = Logger("AlertDialog"); extern const AppManifest manifest; @@ -74,7 +74,7 @@ class AlertDialogApp : public App { void onButtonClicked(lv_event_t* e) { auto index = reinterpret_cast(lv_event_get_user_data(e)); - TT_LOG_I(TAG, "Selected item at index %d", index); + LOGGER.info("Selected item at index {}", index); auto bundle = std::make_unique(); bundle->putInt32(RESULT_BUNDLE_KEY_INDEX, (int32_t)index); diff --git a/Tactility/Source/app/apphub/AppHubApp.cpp b/Tactility/Source/app/apphub/AppHubApp.cpp index 0a5ee588..f14ccf39 100644 --- a/Tactility/Source/app/apphub/AppHubApp.cpp +++ b/Tactility/Source/app/apphub/AppHubApp.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -16,7 +17,7 @@ namespace tt::app::apphub { -constexpr auto* TAG = "AppHub"; +static const auto LOGGER = Logger("AppHub"); extern const AppManifest manifest; @@ -55,7 +56,7 @@ class AppHubApp final : public App { } void onRefreshSuccess() { - TT_LOG_I(TAG, "Request success"); + LOGGER.info("Request success"); auto lock = lvgl::getSyncLock()->asScopedLock(); lock.lock(); @@ -63,7 +64,7 @@ class AppHubApp final : public App { } void onRefreshError(const char* error) { - TT_LOG_E(TAG, "Request failed: %s", error); + LOGGER.error("Request failed: {}", error); auto lock = lvgl::getSyncLock()->asScopedLock(); lock.lock(); @@ -106,7 +107,7 @@ class AppHubApp final : public App { lv_obj_set_size(list, LV_PCT(100), LV_SIZE_CONTENT); for (int i = 0; i < entries.size(); i++) { auto& entry = entries[i]; - TT_LOG_I(TAG, "Adding %s", entry.appName.c_str()); + LOGGER.info("Adding {}", entry.appName.c_str()); const char* icon = findAppManifestById(entry.appId) != nullptr ? LV_SYMBOL_OK : nullptr; auto* entry_button = lv_list_add_button(list, icon, entry.appName.c_str()); auto int_as_voidptr = reinterpret_cast(i); diff --git a/Tactility/Source/app/apphub/AppHubEntry.cpp b/Tactility/Source/app/apphub/AppHubEntry.cpp index 68c6ada0..8f291f73 100644 --- a/Tactility/Source/app/apphub/AppHubEntry.cpp +++ b/Tactility/Source/app/apphub/AppHubEntry.cpp @@ -1,10 +1,11 @@ #include #include #include +#include namespace tt::app::apphub { -constexpr auto* TAG = "AppHubJson"; +static const auto LOGGER = Logger("AppHubJson"); static bool parseEntry(const cJSON* object, AppHubEntry& entry) { const json::Reader reader(object); @@ -24,21 +25,21 @@ bool parseJson(const std::string& filePath, std::vector& entries) { auto data = file::readString(filePath); if (data == nullptr) { - TT_LOG_E(TAG, "Failed to read %s", filePath.c_str()); + LOGGER.error("Failed to read {}", filePath); return false; } auto data_ptr = reinterpret_cast(data.get()); auto* json = cJSON_Parse(data_ptr); if (json == nullptr) { - TT_LOG_E(TAG, "Failed to parse %s", filePath.c_str()); + LOGGER.error("Failed to parse {}", filePath); return false; } const cJSON* apps_json = cJSON_GetObjectItemCaseSensitive(json, "apps"); if (!cJSON_IsArray(apps_json)) { cJSON_Delete(json); - TT_LOG_E(TAG, "apps is not an array"); + LOGGER.error("apps is not an array"); return false; } @@ -48,7 +49,7 @@ bool parseJson(const std::string& filePath, std::vector& entries) { auto& entry = entries.at(i); auto* entry_json = cJSON_GetArrayItem(apps_json, i); if (!parseEntry(entry_json, entry)) { - TT_LOG_E(TAG, "Failed to read entry"); + LOGGER.error("Failed to read entry"); cJSON_Delete(json); return false; } diff --git a/Tactility/Source/app/apphubdetails/AppHubDetailsApp.cpp b/Tactility/Source/app/apphubdetails/AppHubDetailsApp.cpp index 1bde0a75..980bb8e2 100644 --- a/Tactility/Source/app/apphubdetails/AppHubDetailsApp.cpp +++ b/Tactility/Source/app/apphubdetails/AppHubDetailsApp.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -15,8 +16,9 @@ namespace tt::app::apphubdetails { +static const auto LOGGER = Logger("AppHubDetails"); + extern const AppManifest manifest; -constexpr auto* TAG = "AppHubDetails"; static std::shared_ptr toBundle(const apphub::AppHubEntry& entry) { auto bundle = std::make_shared(); @@ -83,7 +85,7 @@ class AppHubDetailsApp final : public App { } void uninstallApp() { - TT_LOG_I(TAG, "Uninstall"); + LOGGER.info("Uninstall"); lvgl::getSyncLock()->lock(); lv_obj_remove_flag(spinner, LV_OBJ_FLAG_HIDDEN); @@ -107,10 +109,10 @@ class AppHubDetailsApp final : public App { [this, temp_file_path] { install(temp_file_path); - if (!file::deleteFile(temp_file_path.c_str())) { - TT_LOG_W(TAG, "Failed to remove %s", temp_file_path.c_str()); + if (!file::deleteFile(temp_file_path)) { + LOGGER.warn("Failed to remove {}", temp_file_path); } else { - TT_LOG_I(TAG, "Deleted temporary file %s", temp_file_path.c_str()); + LOGGER.info("Deleted temporary file {}", temp_file_path); } lvgl::getSyncLock()->lock(); @@ -118,18 +120,18 @@ class AppHubDetailsApp final : public App { lvgl::getSyncLock()->unlock(); }, [temp_file_path](const char* errorMessage) { - TT_LOG_E(TAG, "Download failed: %s", errorMessage); + LOGGER.error("Download failed: {}", errorMessage); alertdialog::start("Error", "Failed to install app"); if (file::isFile(temp_file_path) && !file::deleteFile(temp_file_path.c_str())) { - TT_LOG_W(TAG, "Failed to remove %s", temp_file_path.c_str()); + LOGGER.warn("Failed to remove {}", temp_file_path); } } ); } void installApp() { - TT_LOG_I(TAG, "Install"); + LOGGER.info("Install"); lvgl::getSyncLock()->lock(); lv_obj_remove_flag(spinner, LV_OBJ_FLAG_HIDDEN); @@ -139,15 +141,15 @@ class AppHubDetailsApp final : public App { } void updateApp() { - TT_LOG_I(TAG, "Update"); + LOGGER.info("Update"); lvgl::getSyncLock()->lock(); lv_obj_remove_flag(spinner, LV_OBJ_FLAG_HIDDEN); lvgl::getSyncLock()->unlock(); - TT_LOG_I(TAG, "Removing previous version"); + LOGGER.info("Removing previous version"); uninstall(entry.appId); - TT_LOG_I(TAG, "Installing new version"); + LOGGER.info("Installing new version"); doInstall(); } @@ -173,13 +175,13 @@ public: void onCreate(AppContext& appContext) override { auto parameters = appContext.getParameters(); if (parameters == nullptr) { - TT_LOG_E(TAG, "No parameters"); + LOGGER.error("No parameters"); stop(); return; } if (!fromBundle(*parameters.get(), entry)) { - TT_LOG_E(TAG, "Invalid parameters"); + LOGGER.error("Invalid parameters"); stop(); } } diff --git a/Tactility/Source/app/chat/ChatApp.cpp b/Tactility/Source/app/chat/ChatApp.cpp index 885db4bf..d79d91fa 100644 --- a/Tactility/Source/app/chat/ChatApp.cpp +++ b/Tactility/Source/app/chat/ChatApp.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include "Tactility/lvgl/LvglSync.h" @@ -18,7 +19,7 @@ namespace tt::app::chat { -constexpr const char* TAG = "ChatApp"; +static const auto LOGGER = Logger("ChatApp"); constexpr uint8_t BROADCAST_ADDRESS[ESP_NOW_ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; class ChatApp : public App { @@ -46,7 +47,7 @@ class ChatApp : public App { self->addMessage(msg); if (!service::espnow::send(BROADCAST_ADDRESS, reinterpret_cast(msg), msg_len)) { - TT_LOG_E(TAG, "Failed to send message"); + LOGGER.error("Failed to send message"); } lv_textarea_set_text(self->input_field, ""); diff --git a/Tactility/Source/app/crashdiagnostics/CrashDiagnostics.cpp b/Tactility/Source/app/crashdiagnostics/CrashDiagnostics.cpp index e179e3ee..3444f77a 100644 --- a/Tactility/Source/app/crashdiagnostics/CrashDiagnostics.cpp +++ b/Tactility/Source/app/crashdiagnostics/CrashDiagnostics.cpp @@ -6,15 +6,16 @@ #include #include #include +#include #include #include #include -#define TAG "CrashDiagnostics" - namespace tt::app::crashdiagnostics { +static const auto LOGGER = Logger("CrashDiagnostics"); + extern const AppManifest manifest; void onContinuePressed(TT_UNUSED lv_event_t* event) { @@ -44,38 +45,38 @@ public: lv_obj_align(bottom_label, LV_ALIGN_BOTTOM_MID, 0, -2); std::string url = getUrlFromCrashData(); - TT_LOG_I(TAG, "%s", url.c_str()); + LOGGER.info("{}", url); size_t url_length = url.length(); int qr_version; if (!getQrVersionForBinaryDataLength(url_length, qr_version)) { - TT_LOG_E(TAG, "QR is too large"); + LOGGER.error("QR is too large"); stop(manifest.appId); return; } - TT_LOG_I(TAG, "QR version %d (length: %d)", qr_version, url_length); + LOGGER.info("QR version {} (length: {})", qr_version, url_length); auto qrcodeData = std::make_shared(qrcode_getBufferSize(qr_version)); if (qrcodeData == nullptr) { - TT_LOG_E(TAG, "Failed to allocate QR buffer"); + LOGGER.error("Failed to allocate QR buffer"); stop(); return; } QRCode qrcode; - TT_LOG_I(TAG, "QR init text"); + LOGGER.info("QR init text"); if (qrcode_initText(&qrcode, qrcodeData.get(), qr_version, ECC_LOW, url.c_str()) != 0) { - TT_LOG_E(TAG, "QR init text failed"); + LOGGER.error("QR init text failed"); stop(manifest.appId); return; } - TT_LOG_I(TAG, "QR size: %d", qrcode.size); + LOGGER.info("QR size: {}", qrcode.size); // Calculate QR dot size int32_t top_label_height = lv_obj_get_height(top_label) + 2; int32_t bottom_label_height = lv_obj_get_height(bottom_label) + 2; - TT_LOG_I(TAG, "Create canvas"); + LOGGER.info("Create canvas"); int32_t available_height = parent_height - top_label_height - bottom_label_height; int32_t available_width = lv_display_get_horizontal_resolution(display); int32_t smallest_size = std::min(available_height, available_width); @@ -85,7 +86,7 @@ public: } else if (qrcode.size <= smallest_size) { pixel_size = 1; } else { - TT_LOG_E(TAG, "QR code won't fit screen"); + LOGGER.error("QR code won't fit screen"); stop(manifest.appId); return; } @@ -97,10 +98,10 @@ public: lv_obj_set_content_height(canvas, qrcode.size * pixel_size); lv_obj_set_content_width(canvas, qrcode.size * pixel_size); - TT_LOG_I(TAG, "Create draw buffer"); + LOGGER.info("Create draw buffer"); auto* draw_buf = lv_draw_buf_create(pixel_size * qrcode.size, pixel_size * qrcode.size, LV_COLOR_FORMAT_RGB565, LV_STRIDE_AUTO); if (draw_buf == nullptr) { - TT_LOG_E(TAG, "Draw buffer alloc"); + LOGGER.error("Draw buffer alloc"); stop(manifest.appId); return; } diff --git a/Tactility/Source/app/development/Development.cpp b/Tactility/Source/app/development/Development.cpp index 6ca32ca5..d2ddf5d4 100644 --- a/Tactility/Source/app/development/Development.cpp +++ b/Tactility/Source/app/development/Development.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -17,7 +18,7 @@ namespace tt::app::development { -constexpr const char* TAG = "Development"; +static const auto LOGGER = Logger("Development"); extern const AppManifest manifest; class DevelopmentApp final : public App { @@ -84,7 +85,7 @@ public: void onCreate(AppContext& appContext) override { service = service::development::findService(); if (service == nullptr) { - TT_LOG_E(TAG, "Service not found"); + LOGGER.error("Service not found"); stop(manifest.appId); } } diff --git a/Tactility/Source/app/display/Display.cpp b/Tactility/Source/app/display/Display.cpp index 3dbcd5b5..4361329e 100644 --- a/Tactility/Source/app/display/Display.cpp +++ b/Tactility/Source/app/display/Display.cpp @@ -3,13 +3,14 @@ #include #include #include +#include #include #include namespace tt::app::display { -constexpr auto* TAG = "Display"; +static const auto LOGGER = Logger("Display"); static std::shared_ptr getHalDisplay() { return hal::findFirstDevice(hal::Device::Type::Display); @@ -54,7 +55,7 @@ class DisplayApp final : public App { auto* app = static_cast(lv_event_get_user_data(event)); auto* dropdown = static_cast(lv_event_get_target(event)); uint32_t selected_index = lv_dropdown_get_selected(dropdown); - TT_LOG_I(TAG, "Selected %ld", selected_index); + LOGGER.info("Selected {}", selected_index); auto selected_orientation = static_cast(selected_index); if (selected_orientation != app->displaySettings.orientation) { app->displaySettings.orientation = selected_orientation; diff --git a/Tactility/Source/app/files/State.cpp b/Tactility/Source/app/files/State.cpp index 115d61c2..8a7bb485 100644 --- a/Tactility/Source/app/files/State.cpp +++ b/Tactility/Source/app/files/State.cpp @@ -3,18 +3,19 @@ #include #include #include -#include +#include +#include #include #include #include +#include #include #include -#include namespace tt::app::files { -constexpr auto* TAG = "Files"; +static const auto LOGGER = Logger("Files"); State::State() { if (kernel::getPlatform() == kernel::PlatformSimulator) { @@ -22,7 +23,7 @@ State::State() { if (getcwd(cwd, sizeof(cwd)) != nullptr) { setEntriesForPath(cwd); } else { - TT_LOG_E(TAG, "Failed to get current work directory files"); + LOGGER.error("Failed to get current work directory files"); setEntriesForPath("/"); } } else { @@ -37,11 +38,11 @@ std::string State::getSelectedChildPath() const { bool State::setEntriesForPath(const std::string& path) { auto lock = mutex.asScopedLock(); if (!lock.lock(100)) { - TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "setEntriesForPath"); + LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "setEntriesForPath"); return false; } - TT_LOG_I(TAG, "Changing path: %s -> %s", current_path.c_str(), path.c_str()); + LOGGER.info("Changing path: {} -> {}", current_path, path); /** * On PC, the root entry point ("/") is a folder. @@ -49,7 +50,7 @@ bool State::setEntriesForPath(const std::string& path) { */ bool get_mount_points = (kernel::getPlatform() == kernel::PlatformEsp) && (path == "/"); if (get_mount_points) { - TT_LOG_I(TAG, "Setting custom root"); + LOGGER.info("Setting custom root"); dir_entries = file::getMountPoints(); current_path = path; selected_child_entry = ""; @@ -59,13 +60,13 @@ bool State::setEntriesForPath(const std::string& path) { dir_entries.clear(); int count = file::scandir(path, dir_entries, &file::direntFilterDotEntries, file::direntSortAlphaAndType); if (count >= 0) { - TT_LOG_I(TAG, "%s has %u entries", path.c_str(), count); + LOGGER.info("{} has {} entries", path, count); current_path = path; selected_child_entry = ""; action = ActionNone; return true; } else { - TT_LOG_E(TAG, "Failed to fetch entries for %s", path.c_str()); + LOGGER.error("Failed to fetch entries for {}", path); return false; } } @@ -73,7 +74,7 @@ bool State::setEntriesForPath(const std::string& path) { bool State::setEntriesForChildPath(const std::string& childPath) { auto path = file::getChildPath(current_path, childPath); - TT_LOG_I(TAG, "Navigating from %s to %s", current_path.c_str(), path.c_str()); + LOGGER.info("Navigating from {} to {}", current_path, path); return setEntriesForPath(path); } @@ -90,4 +91,5 @@ bool State::getDirent(uint32_t index, dirent& dirent) { return false; } } + } diff --git a/Tactility/Source/app/files/View.cpp b/Tactility/Source/app/files/View.cpp index 24839a62..1ed0450d 100644 --- a/Tactility/Source/app/files/View.cpp +++ b/Tactility/Source/app/files/View.cpp @@ -2,21 +2,21 @@ #include #include -#include #include #include #include #include #include #include -#include +#include +#include #include #include #include #include -#include #include +#include #include #ifdef ESP_PLATFORM @@ -25,7 +25,7 @@ namespace tt::app::files { -constexpr auto* TAG = "Files"; +static const auto LOGGER = Logger("Files"); // region Callbacks @@ -84,11 +84,11 @@ void View::viewFile(const std::string& path, const std::string& filename) { if (kernel::getPlatform() == kernel::PlatformSimulator) { char cwd[PATH_MAX]; if (getcwd(cwd, sizeof(cwd)) == nullptr) { - TT_LOG_E(TAG, "Failed to get current working directory"); + LOGGER.error("Failed to get current working directory"); return; } if (!file_path.starts_with(cwd)) { - TT_LOG_E(TAG, "Can only work with files in working directory %s", cwd); + LOGGER.error("Can only work with files in working directory {}", cwd); return; } processed_filepath = file_path.substr(strlen(cwd)); @@ -96,7 +96,7 @@ void View::viewFile(const std::string& path, const std::string& filename) { processed_filepath = file_path; } - TT_LOG_I(TAG, "Clicked %s", file_path.c_str()); + LOGGER.info("Clicked {}", file_path); if (isSupportedAppFile(filename)) { #ifdef ESP_PLATFORM @@ -116,7 +116,7 @@ void View::viewFile(const std::string& path, const std::string& filename) { notes::start(processed_filepath.substr(1)); } } else { - TT_LOG_W(TAG, "opening files of this type is not supported"); + LOGGER.warn("opening files of this type is not supported"); } onNavigate(); @@ -125,7 +125,7 @@ void View::viewFile(const std::string& path, const std::string& filename) { void View::onDirEntryPressed(uint32_t index) { dirent dir_entry; if (state->getDirent(index, dir_entry)) { - TT_LOG_I(TAG, "Pressed %s %d", dir_entry.d_name, dir_entry.d_type); + LOGGER.info("Pressed {} {}", dir_entry.d_name, dir_entry.d_type); state->setSelectedChildEntry(dir_entry.d_name); using namespace tt::file; switch (dir_entry.d_type) { @@ -136,7 +136,7 @@ void View::onDirEntryPressed(uint32_t index) { update(); break; case TT_DT_LNK: - TT_LOG_W(TAG, "opening links is not supported"); + LOGGER.warn("opening links is not supported"); break; case TT_DT_REG: viewFile(state->getCurrentPath(), dir_entry.d_name); @@ -155,7 +155,7 @@ void View::onDirEntryPressed(uint32_t index) { void View::onDirEntryLongPressed(int32_t index) { dirent dir_entry; if (state->getDirent(index, dir_entry)) { - TT_LOG_I(TAG, "Pressed %s %d", dir_entry.d_name, dir_entry.d_type); + LOGGER.info("Pressed {} {}", dir_entry.d_name, dir_entry.d_type); state->setSelectedChildEntry(dir_entry.d_name); using namespace file; switch (dir_entry.d_type) { @@ -164,7 +164,7 @@ void View::onDirEntryLongPressed(int32_t index) { showActionsForDirectory(); break; case TT_DT_LNK: - TT_LOG_W(TAG, "opening links is not supported"); + LOGGER.warn("Opening links is not supported"); break; case TT_DT_REG: showActionsForFile(); @@ -228,7 +228,7 @@ void View::createDirEntryWidget(lv_obj_t* list, dirent& dir_entry) { void View::onNavigateUpPressed() { if (state->getCurrentPath() != "/") { - TT_LOG_I(TAG, "Navigating upwards"); + LOGGER.info("Navigating upwards"); std::string new_absolute_path; if (string::getPathParent(state->getCurrentPath(), new_absolute_path)) { state->setEntriesForPath(new_absolute_path); @@ -240,14 +240,14 @@ void View::onNavigateUpPressed() { void View::onRenamePressed() { std::string entry_name = state->getSelectedChildEntry(); - TT_LOG_I(TAG, "Pending rename %s", entry_name.c_str()); + LOGGER.info("Pending rename {}", entry_name); state->setPendingAction(State::ActionRename); inputdialog::start("Rename", "", entry_name); } void View::onDeletePressed() { std::string file_path = state->getSelectedChildPath(); - TT_LOG_I(TAG, "Pending delete %s", file_path.c_str()); + LOGGER.info("Pending delete {}", file_path); state->setPendingAction(State::ActionDelete); std::string message = "Do you want to delete this?\n" + file_path; const std::vector choices = { "Yes", "No" }; @@ -255,13 +255,13 @@ void View::onDeletePressed() { } void View::onNewFilePressed() { - TT_LOG_I(TAG, "Creating new file"); + LOGGER.info("Creating new file"); state->setPendingAction(State::ActionCreateFile); inputdialog::start("New File", "Enter filename:", ""); } void View::onNewFolderPressed() { - TT_LOG_I(TAG, "Creating new folder"); + LOGGER.info("Creating new folder"); state->setPendingAction(State::ActionCreateFolder); inputdialog::start("New Folder", "Enter folder name:", ""); } @@ -295,7 +295,7 @@ void View::update() { state->withEntries([this](const std::vector& entries) { for (auto entry : entries) { - TT_LOG_D(TAG, "Entry: %s %d", entry.d_name, entry.d_type); + LOGGER.debug("Entry: {} {}", entry.d_name, entry.d_type); createDirEntryWidget(dir_entry_list, entry); } }); @@ -306,7 +306,7 @@ void View::update() { lv_obj_remove_flag(navigate_up_button, LV_OBJ_FLAG_HIDDEN); } } else { - TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "lvgl"); + LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "lvgl"); } } @@ -369,20 +369,20 @@ void View::onResult(LaunchId launchId, Result result, std::unique_ptr bu } std::string filepath = state->getSelectedChildPath(); - TT_LOG_I(TAG, "Result for %s", filepath.c_str()); + LOGGER.info("Result for {}", filepath); switch (state->getPendingAction()) { case State::ActionDelete: { if (alertdialog::getResultIndex(*bundle) == 0) { if (file::isDirectory(filepath)) { if (!file::deleteRecursively(filepath)) { - TT_LOG_W(TAG, "Failed to delete %s", filepath.c_str()); + LOGGER.warn("Failed to delete {}", filepath); } } else if (file::isFile(filepath)) { auto lock = file::getLock(filepath); lock->lock(); if (remove(filepath.c_str()) <= 0) { - TT_LOG_W(TAG, "Failed to delete %s", filepath.c_str()); + LOGGER.warn("Failed to delete {}", filepath); } lock->unlock(); } @@ -399,9 +399,9 @@ void View::onResult(LaunchId launchId, Result result, std::unique_ptr bu lock->lock(); std::string rename_to = file::getChildPath(state->getCurrentPath(), new_name); if (rename(filepath.c_str(), rename_to.c_str())) { - TT_LOG_I(TAG, "Renamed \"%s\" to \"%s\"", filepath.c_str(), rename_to.c_str()); + LOGGER.info("Renamed \"{}\" to \"{}\"", filepath, rename_to); } else { - TT_LOG_E(TAG, "Failed to rename \"%s\" to \"%s\"", filepath.c_str(), rename_to.c_str()); + LOGGER.error("Failed to rename \"{}\" to \"{}\"", filepath, rename_to); } lock->unlock(); @@ -420,7 +420,7 @@ void View::onResult(LaunchId launchId, Result result, std::unique_ptr bu struct stat st; if (stat(new_file_path.c_str(), &st) == 0) { - TT_LOG_W(TAG, "File already exists: \"%s\"", new_file_path.c_str()); + LOGGER.warn("File already exists: \"{}\"", new_file_path); lock->unlock(); break; } @@ -428,9 +428,9 @@ void View::onResult(LaunchId launchId, Result result, std::unique_ptr bu FILE* new_file = fopen(new_file_path.c_str(), "w"); if (new_file) { fclose(new_file); - TT_LOG_I(TAG, "Created file \"%s\"", new_file_path.c_str()); + LOGGER.info("Created file \"{}\"", new_file_path); } else { - TT_LOG_E(TAG, "Failed to create file \"%s\"", new_file_path.c_str()); + LOGGER.error("Failed to create file \"{}\"", new_file_path); } lock->unlock(); @@ -449,15 +449,15 @@ void View::onResult(LaunchId launchId, Result result, std::unique_ptr bu struct stat st; if (stat(new_folder_path.c_str(), &st) == 0) { - TT_LOG_W(TAG, "Folder already exists: \"%s\"", new_folder_path.c_str()); + LOGGER.warn("Folder already exists: \"{}\"", new_folder_path); lock->unlock(); break; } if (mkdir(new_folder_path.c_str(), 0755) == 0) { - TT_LOG_I(TAG, "Created folder \"%s\"", new_folder_path.c_str()); + LOGGER.info("Created folder \"{}\"", new_folder_path); } else { - TT_LOG_E(TAG, "Failed to create folder \"%s\"", new_folder_path.c_str()); + LOGGER.error("Failed to create folder \"{}\"", new_folder_path); } lock->unlock(); diff --git a/Tactility/Source/app/fileselection/State.cpp b/Tactility/Source/app/fileselection/State.cpp index cc3c2b89..78b99747 100644 --- a/Tactility/Source/app/fileselection/State.cpp +++ b/Tactility/Source/app/fileselection/State.cpp @@ -2,7 +2,7 @@ #include #include "Tactility/hal/sdcard/SdCardDevice.h" -#include +#include #include #include @@ -13,7 +13,7 @@ namespace tt::app::fileselection { -constexpr auto* TAG = "FileSelection"; +static const auto LOGGER = Logger("FileSelection"); State::State() { if (kernel::getPlatform() == kernel::PlatformSimulator) { @@ -21,7 +21,7 @@ State::State() { if (getcwd(cwd, sizeof(cwd)) != nullptr) { setEntriesForPath(cwd); } else { - TT_LOG_E(TAG, "Failed to get current work directory files"); + LOGGER.error("Failed to get current work directory files"); setEntriesForPath("/"); } } else { @@ -34,7 +34,7 @@ std::string State::getSelectedChildPath() const { } bool State::setEntriesForPath(const std::string& path) { - TT_LOG_I(TAG, "Changing path: %s -> %s", current_path.c_str(), path.c_str()); + LOGGER.info("Changing path: {} -> {}", current_path, path); /** * ESP32 does not have a root directory, so we have to create it manually. @@ -42,7 +42,7 @@ bool State::setEntriesForPath(const std::string& path) { */ bool show_custom_root = (kernel::getPlatform() == kernel::PlatformEsp) && (path == "/"); if (show_custom_root) { - TT_LOG_I(TAG, "Setting custom root"); + LOGGER.info("Setting custom root"); dir_entries = file::getMountPoints(); current_path = path; selected_child_entry = ""; @@ -51,12 +51,12 @@ bool State::setEntriesForPath(const std::string& path) { dir_entries.clear(); int count = file::scandir(path, dir_entries, &file::direntFilterDotEntries, file::direntSortAlphaAndType); if (count >= 0) { - TT_LOG_I(TAG, "%s has %u entries", path.c_str(), count); + LOGGER.info("{} has {} entries", path, count); current_path = path; selected_child_entry = ""; return true; } else { - TT_LOG_E(TAG, "Failed to fetch entries for %s", path.c_str()); + LOGGER.error("Failed to fetch entries for {}", path); return false; } } @@ -64,7 +64,7 @@ bool State::setEntriesForPath(const std::string& path) { bool State::setEntriesForChildPath(const std::string& childPath) { auto path = file::getChildPath(current_path, childPath); - TT_LOG_I(TAG, "Navigating from %s to %s", current_path.c_str(), path.c_str()); + LOGGER.info("Navigating from {} to {}", current_path, path); return setEntriesForPath(path); } diff --git a/Tactility/Source/app/fileselection/View.cpp b/Tactility/Source/app/fileselection/View.cpp index 136f72ec..95cd43e8 100644 --- a/Tactility/Source/app/fileselection/View.cpp +++ b/Tactility/Source/app/fileselection/View.cpp @@ -1,14 +1,15 @@ #include #include +#include +#include +#include #include #include - -#include -#include -#include - #include +#include +#include + #include #include @@ -18,7 +19,7 @@ namespace tt::app::fileselection { -constexpr auto* TAG = "FileSelection"; +const static Logger LOGGER = Logger("FileSelection"); // region Callbacks @@ -45,11 +46,11 @@ void View::onTapFile(const std::string& path, const std::string& filename) { if (kernel::getPlatform() == kernel::PlatformSimulator) { char cwd[PATH_MAX]; if (getcwd(cwd, sizeof(cwd)) == nullptr) { - TT_LOG_E(TAG, "Failed to get current working directory"); + LOGGER.error("Failed to get current working directory"); return; } if (!file_path.starts_with(cwd)) { - TT_LOG_E(TAG, "Can only work with files in working directory %s", cwd); + LOGGER.error("Can only work with files in working directory {}", cwd); return; } processed_filepath = file_path.substr(strlen(cwd)); @@ -57,7 +58,7 @@ void View::onTapFile(const std::string& path, const std::string& filename) { processed_filepath = file_path; } - TT_LOG_I(TAG, "Clicked %s", processed_filepath.c_str()); + LOGGER.info("Clicked {}", processed_filepath); lv_textarea_set_text(path_textarea, processed_filepath.c_str()); } @@ -65,7 +66,7 @@ void View::onTapFile(const std::string& path, const std::string& filename) { void View::onDirEntryPressed(uint32_t index) { dirent dir_entry; if (state->getDirent(index, dir_entry)) { - TT_LOG_I(TAG, "Pressed %s %d", dir_entry.d_name, dir_entry.d_type); + LOGGER.info("Pressed {} {}", dir_entry.d_name, dir_entry.d_type); state->setSelectedChildEntry(dir_entry.d_name); using namespace tt::file; switch (dir_entry.d_type) { @@ -76,7 +77,7 @@ void View::onDirEntryPressed(uint32_t index) { update(); break; case TT_DT_LNK: - TT_LOG_W(TAG, "opening links is not supported"); + LOGGER.warn("Opening links is not supported"); break; case TT_DT_REG: onTapFile(state->getCurrentPath(), dir_entry.d_name); @@ -94,7 +95,7 @@ void View::onSelectButtonPressed(lv_event_t* event) { auto* view = static_cast(lv_event_get_user_data(event)); const char* path = lv_textarea_get_text(view->path_textarea); if (path == nullptr || strlen(path) == 0) { - TT_LOG_W(TAG, "Select pressed, but not path found in textarea"); + LOGGER.warn("Select pressed, but not path found in textarea"); return; } @@ -138,7 +139,7 @@ void View::createDirEntryWidget(lv_obj_t* list, dirent& dir_entry) { void View::onNavigateUpPressed() { if (state->getCurrentPath() != "/") { - TT_LOG_I(TAG, "Navigating upwards"); + LOGGER.info("Navigating upwards"); std::string new_absolute_path; if (string::getPathParent(state->getCurrentPath(), new_absolute_path)) { state->setEntriesForPath(new_absolute_path); @@ -159,7 +160,7 @@ void View::update() { state->withEntries([this](const std::vector& entries) { for (auto entry : entries) { - TT_LOG_D(TAG, "Entry: %s %d", entry.d_name, entry.d_type); + LOGGER.debug("Entry: {} {}", entry.d_name, entry.d_type); createDirEntryWidget(dir_entry_list, entry); } }); @@ -170,7 +171,7 @@ void View::update() { lv_obj_remove_flag(navigate_up_button, LV_OBJ_FLAG_HIDDEN); } } else { - TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "lvgl"); + LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "lvgl"); } } diff --git a/Tactility/Source/app/gpssettings/GpsSettings.cpp b/Tactility/Source/app/gpssettings/GpsSettings.cpp index 54bc89b2..2be6102d 100644 --- a/Tactility/Source/app/gpssettings/GpsSettings.cpp +++ b/Tactility/Source/app/gpssettings/GpsSettings.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -23,7 +24,7 @@ extern const AppManifest manifest; class GpsSettingsApp final : public App { - static constexpr auto* TAG = "GpsSettings"; + const Logger logger = Logger("GpsSettings"); std::unique_ptr timer; std::shared_ptr appReference = std::make_shared(this); @@ -92,7 +93,7 @@ class GpsSettingsApp final : public App { std::vector configurations; auto gps_service = service::gps::findGpsService(); if (gps_service && gps_service->getGpsConfigurations(configurations)) { - TT_LOG_I(TAG, "Found service and configs %d %d", index, configurations.size()); + Logger("GpsSettings").info("Found service and configs {} {}", index, configurations.size()); if (index <= configurations.size()) { if (gps_service->removeGpsConfiguration(configurations[index])) { app->updateViews(); @@ -154,7 +155,7 @@ class GpsSettingsApp final : public App { // Update toolbar switch (state) { case service::gps::State::OnPending: - TT_LOG_D(TAG, "OnPending"); + logger.debug("OnPending"); lv_obj_remove_flag(spinnerWidget, LV_OBJ_FLAG_HIDDEN); lv_obj_add_state(switchWidget, LV_STATE_CHECKED); lv_obj_add_state(switchWidget, LV_STATE_DISABLED); @@ -163,7 +164,7 @@ class GpsSettingsApp final : public App { lv_obj_add_flag(addGpsWrapper, LV_OBJ_FLAG_HIDDEN); break; case service::gps::State::On: - TT_LOG_D(TAG, "On"); + logger.debug("On"); lv_obj_add_flag(spinnerWidget, LV_OBJ_FLAG_HIDDEN); lv_obj_add_state(switchWidget, LV_STATE_CHECKED); lv_obj_remove_state(switchWidget, LV_STATE_DISABLED); @@ -172,7 +173,7 @@ class GpsSettingsApp final : public App { lv_obj_add_flag(addGpsWrapper, LV_OBJ_FLAG_HIDDEN); break; case service::gps::State::OffPending: - TT_LOG_D(TAG, "OffPending"); + logger.debug("OffPending"); lv_obj_remove_flag(spinnerWidget, LV_OBJ_FLAG_HIDDEN); lv_obj_remove_state(switchWidget, LV_STATE_CHECKED); lv_obj_add_state(switchWidget, LV_STATE_DISABLED); @@ -181,7 +182,7 @@ class GpsSettingsApp final : public App { lv_obj_remove_flag(addGpsWrapper, LV_OBJ_FLAG_HIDDEN); break; case service::gps::State::Off: - TT_LOG_D(TAG, "Off"); + logger.debug("Off"); lv_obj_add_flag(spinnerWidget, LV_OBJ_FLAG_HIDDEN); lv_obj_remove_state(switchWidget, LV_STATE_CHECKED); lv_obj_remove_state(switchWidget, LV_STATE_DISABLED); @@ -254,11 +255,11 @@ class GpsSettingsApp final : public App { if (wants_on != is_on) { // start/stop are potentially blocking calls, so we use a dispatcher to not block the UI if (wants_on) { - getMainDispatcher().dispatch([this]() { + getMainDispatcher().dispatch([this] { service->startReceiving(); }); } else { - getMainDispatcher().dispatch([this]() { + getMainDispatcher().dispatch([this] { service->stopReceiving(); }); } diff --git a/Tactility/Source/app/i2cscanner/I2cScanner.cpp b/Tactility/Source/app/i2cscanner/I2cScanner.cpp index fea6fba7..061155c7 100644 --- a/Tactility/Source/app/i2cscanner/I2cScanner.cpp +++ b/Tactility/Source/app/i2cscanner/I2cScanner.cpp @@ -1,17 +1,18 @@ #include #include -#include +#include #include #include +#include +#include #include #include -#include - -#include -#include +#include #include +#include #include +#include #include @@ -21,6 +22,8 @@ extern const AppManifest manifest; class I2cScannerApp final : public App { + const Logger logger = Logger("I2cScanner"); + static constexpr auto* START_SCAN_TEXT = "Scan"; static constexpr auto* STOP_SCAN_TEXT = "Stop scan"; @@ -189,7 +192,7 @@ bool I2cScannerApp::getPort(i2c_port_t* outPort) { mutex.unlock(); return true; } else { - TT_LOG_W(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "getPort"); + logger.warn(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "getPort"); return false; } } @@ -200,7 +203,7 @@ bool I2cScannerApp::addAddressToList(uint8_t address) { mutex.unlock(); return true; } else { - TT_LOG_W(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "addAddressToList"); + logger.warn(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "addAddressToList"); return false; } } @@ -216,24 +219,24 @@ bool I2cScannerApp::shouldStopScanTimer() { } void I2cScannerApp::onScanTimer() { - TT_LOG_I(TAG, "Scan thread started"); + logger.info("Scan thread started"); i2c_port_t safe_port; if (!getPort(&safe_port)) { - TT_LOG_E(TAG, "Failed to get I2C port"); + logger.error("Failed to get I2C port"); onScanTimerFinished(); return; } if (!hal::i2c::isStarted(safe_port)) { - TT_LOG_E(TAG, "I2C port not started"); + logger.error("I2C port not started"); onScanTimerFinished(); return; } for (uint8_t address = 0; address < 128; ++address) { if (hal::i2c::masterHasDeviceAtAddress(port, address, 10 / portTICK_PERIOD_MS)) { - TT_LOG_I(TAG, "Found device at address 0x%02X", address); + logger.info("Found device at address 0x{:02X}", address); if (!shouldStopScanTimer()) { addAddressToList(address); } else { @@ -246,11 +249,11 @@ void I2cScannerApp::onScanTimer() { } } - TT_LOG_I(TAG, "Scan thread finalizing"); + logger.info("Scan thread finalizing"); onScanTimerFinished(); - TT_LOG_I(TAG, "Scan timer done"); + logger.info("Scan timer done"); } bool I2cScannerApp::hasScanThread() { @@ -261,7 +264,7 @@ bool I2cScannerApp::hasScanThread() { return has_thread; } else { // Unsafe way - TT_LOG_W(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "hasScanTimer"); + logger.warn(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "hasScanTimer"); return scanTimer != nullptr; } } @@ -284,7 +287,7 @@ void I2cScannerApp::startScanning() { scanTimer->start(); mutex.unlock(); } else { - TT_LOG_W(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "startScanning"); + logger.warn(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "startScanning"); } } void I2cScannerApp::stopScanning() { @@ -293,7 +296,7 @@ void I2cScannerApp::stopScanning() { scanState = ScanStateStopped; mutex.unlock(); } else { - TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED); + logger.error(LOG_MESSAGE_MUTEX_LOCK_FAILED); } } @@ -314,7 +317,7 @@ void I2cScannerApp::selectBus(int32_t selected) { mutex.unlock(); } - TT_LOG_I(TAG, "Selected %ld", selected); + logger.info("Selected {}", selected); setLastBusIndex(selected); startScanning(); @@ -377,7 +380,7 @@ void I2cScannerApp::updateViews() { mutex.unlock(); } else { - TT_LOG_W(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "updateViews"); + logger.warn(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "updateViews"); } } @@ -386,7 +389,7 @@ void I2cScannerApp::updateViewsSafely() { updateViews(); lvgl::unlock(); } else { - TT_LOG_W(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "updateViewsSafely"); + logger.warn(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "updateViewsSafely"); } } @@ -399,7 +402,7 @@ void I2cScannerApp::onScanTimerFinished() { updateViewsSafely(); } else { - TT_LOG_W(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "onScanTimerFinished"); + logger.warn(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "onScanTimerFinished"); } } diff --git a/Tactility/Source/app/imageviewer/ImageViewer.cpp b/Tactility/Source/app/imageviewer/ImageViewer.cpp index 1922239f..401d30ad 100644 --- a/Tactility/Source/app/imageviewer/ImageViewer.cpp +++ b/Tactility/Source/app/imageviewer/ImageViewer.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include @@ -11,7 +11,7 @@ namespace tt::app::imageviewer { extern const AppManifest manifest; -constexpr auto* TAG = "ImageViewer"; +static const auto LOGGER = Logger("ImageViewer"); constexpr auto* IMAGE_VIEWER_FILE_ARGUMENT = "file"; class ImageViewerApp final : public App { @@ -49,7 +49,7 @@ class ImageViewerApp final : public App { std::string file_argument; if (bundle->optString(IMAGE_VIEWER_FILE_ARGUMENT, file_argument)) { std::string prefixed_path = lvgl::PATH_PREFIX + file_argument; - TT_LOG_I(TAG, "Opening %s", prefixed_path.c_str()); + LOGGER.info("Opening {}", prefixed_path); lv_img_set_src(image, prefixed_path.c_str()); auto path = string::getLastPathSegment(file_argument); lv_label_set_text(file_label, path.c_str()); diff --git a/Tactility/Source/app/inputdialog/InputDialog.cpp b/Tactility/Source/app/inputdialog/InputDialog.cpp index 75f3b207..a330bb52 100644 --- a/Tactility/Source/app/inputdialog/InputDialog.cpp +++ b/Tactility/Source/app/inputdialog/InputDialog.cpp @@ -15,7 +15,7 @@ constexpr auto* RESULT_BUNDLE_KEY_RESULT = "result"; constexpr auto* DEFAULT_TITLE = "Input"; -constexpr auto* TAG = "InputDialog"; +static const auto LOGGER = Logger("InputDialog"); extern const AppManifest manifest; class InputDialogApp; @@ -62,7 +62,7 @@ class InputDialogApp final : public App { void onButtonClicked(lv_event_t* e) { auto user_data = lv_event_get_user_data(e); int index = (user_data != 0) ? 0 : 1; - TT_LOG_I(TAG, "Selected item at index %d", index); + LOGGER.info("Selected item at index {}", index); if (index == 0) { auto bundle = std::make_unique(); const char* text = lv_textarea_get_text((lv_obj_t*)user_data); diff --git a/Tactility/Source/app/launcher/Launcher.cpp b/Tactility/Source/app/launcher/Launcher.cpp index dee92d9f..6bb705aa 100644 --- a/Tactility/Source/app/launcher/Launcher.cpp +++ b/Tactility/Source/app/launcher/Launcher.cpp @@ -12,7 +12,7 @@ namespace tt::app::launcher { -constexpr auto* TAG = "Launcher"; +static const auto LOGGER = Logger("Launcher"); static int getButtonSize(hal::UiScale scale) { if (scale == hal::UiScale::Smallest) { @@ -93,7 +93,7 @@ public: void onCreate(TT_UNUSED AppContext& app) override { settings::BootSettings boot_properties; if (settings::loadBootSettings(boot_properties) && !boot_properties.autoStartAppId.empty()) { - TT_LOG_I(TAG, "Starting %s", boot_properties.autoStartAppId.c_str()); + LOGGER.info("Starting {}", boot_properties.autoStartAppId); start(boot_properties.autoStartAppId); } } diff --git a/Tactility/Source/app/notes/Notes.cpp b/Tactility/Source/app/notes/Notes.cpp index f40f0679..b798bbcc 100644 --- a/Tactility/Source/app/notes/Notes.cpp +++ b/Tactility/Source/app/notes/Notes.cpp @@ -12,7 +12,7 @@ namespace tt::app::notes { -constexpr auto* TAG = "Notes"; +static const auto LOGGER = Logger("Notes"); constexpr auto* NOTES_FILE_ARGUMENT = "file"; class NotesApp final : public App { @@ -52,11 +52,11 @@ class NotesApp final : public App { saveBuffer = lv_textarea_get_text(uiNoteText); lvgl::getSyncLock()->unlock(); saveFileLaunchId = fileselection::startForExistingOrNewFile(); - TT_LOG_I(TAG, "launched with id %d", loadFileLaunchId); + LOGGER.info("launched with id {}", loadFileLaunchId); break; case 3: // Load loadFileLaunchId = fileselection::startForExistingFile(); - TT_LOG_I(TAG, "launched with id %d", loadFileLaunchId); + LOGGER.info("launched with id {}", loadFileLaunchId); break; } } else { @@ -64,7 +64,7 @@ class NotesApp final : public App { if (obj == cont) return; if (lv_obj_get_child(cont, 1)) { saveFileLaunchId = fileselection::startForExistingOrNewFile(); - TT_LOG_I(TAG, "launched with id %d", loadFileLaunchId); + LOGGER.info("launched with id {}", loadFileLaunchId); } else { //Reset resetFileContent(); } @@ -91,7 +91,7 @@ class NotesApp final : public App { lv_textarea_set_text(uiNoteText, reinterpret_cast(data.get())); lv_label_set_text(uiCurrentFileName, path.c_str()); filePath = path; - TT_LOG_I(TAG, "Loaded from %s", path.c_str()); + LOGGER.info("Loaded from %s", path.c_str()); } }); } @@ -101,7 +101,7 @@ class NotesApp final : public App { bool result = false; file::getLock(path)->withLock([&result, this, path] { if (file::writeString(path, saveBuffer.c_str())) { - TT_LOG_I(TAG, "Saved to %s", path.c_str()); + LOGGER.info("Saved to %s", path.c_str()); filePath = path; result = true; } @@ -186,7 +186,7 @@ class NotesApp final : public App { } void onResult(AppContext& appContext, LaunchId launchId, Result result, std::unique_ptr resultData) override { - TT_LOG_I(TAG, "Result for launch id %d", launchId); + LOGGER.info("Result for launch id {}", launchId); if (launchId == loadFileLaunchId) { loadFileLaunchId = 0; if (result == Result::Ok && resultData != nullptr) { diff --git a/Tactility/Source/app/screenshot/Screenshot.cpp b/Tactility/Source/app/screenshot/Screenshot.cpp index 346a0025..82d172e9 100644 --- a/Tactility/Source/app/screenshot/Screenshot.cpp +++ b/Tactility/Source/app/screenshot/Screenshot.cpp @@ -9,15 +9,16 @@ #include #include #include +#include #include #include #include #include -constexpr auto* TAG = "Screenshot"; - namespace tt::app::screenshot { +static const auto LOGGER = Logger("Screenshot"); + extern const AppManifest manifest; class ScreenshotApp final : public App { @@ -97,27 +98,27 @@ void ScreenshotApp::onModeSet() { void ScreenshotApp::onStartPressed() { auto service = service::screenshot::optScreenshotService(); if (service == nullptr) { - TT_LOG_E(TAG, "Service not found/running"); + LOGGER.error("Service not found/running"); return; } if (service->isTaskStarted()) { - TT_LOG_I(TAG, "Stop screenshot"); + LOGGER.info("Stop screenshot"); service->stop(); } else { uint32_t selected = lv_dropdown_get_selected(modeDropdown); const char* path = lv_textarea_get_text(pathTextArea); if (selected == 0) { - TT_LOG_I(TAG, "Start timed screenshots"); + LOGGER.info("Start timed screenshots"); const char* delay_text = lv_textarea_get_text(delayTextArea); int delay = atoi(delay_text); if (delay > 0) { service->startTimed(path, delay, 1); } else { - TT_LOG_W(TAG, "Ignored screenshot start because delay was 0"); + LOGGER.warn("Ignored screenshot start because delay was 0"); } } else { - TT_LOG_I(TAG, "Start app screenshots"); + LOGGER.info("Start app screenshots"); service->startApps(path); } } @@ -128,7 +129,7 @@ void ScreenshotApp::onStartPressed() { void ScreenshotApp::updateScreenshotMode() { auto service = service::screenshot::optScreenshotService(); if (service == nullptr) { - TT_LOG_E(TAG, "Service not found/running"); + LOGGER.error("Service not found/running"); return; } @@ -151,7 +152,7 @@ void ScreenshotApp::updateScreenshotMode() { void ScreenshotApp::createModeSettingWidgets(lv_obj_t* parent) { auto service = service::screenshot::optScreenshotService(); if (service == nullptr) { - TT_LOG_E(TAG, "Service not found/running"); + LOGGER.error("Service not found/running"); return; } @@ -203,7 +204,7 @@ void ScreenshotApp::createFilePathWidgets(lv_obj_t* parent) { if (kernel::getPlatform() == kernel::PlatformEsp) { auto sdcard_devices = tt::hal::findDevices(tt::hal::Device::Type::SdCard); if (sdcard_devices.size() > 1) { - TT_LOG_W(TAG, "Found multiple SD card devices - picking first"); + LOGGER.warn("Found multiple SD card devices - picking first"); } if (!sdcard_devices.empty() && sdcard_devices.front()->isMounted()) { std::string lvgl_mount_path = lvgl::PATH_PREFIX + sdcard_devices.front()->getMountPath(); diff --git a/Tactility/Source/app/selectiondialog/SelectionDialog.cpp b/Tactility/Source/app/selectiondialog/SelectionDialog.cpp index 4bae6773..0cd15a70 100644 --- a/Tactility/Source/app/selectiondialog/SelectionDialog.cpp +++ b/Tactility/Source/app/selectiondialog/SelectionDialog.cpp @@ -1,9 +1,9 @@ #include +#include #include #include #include -#include #include @@ -16,7 +16,7 @@ constexpr auto* RESULT_BUNDLE_KEY_INDEX = "index"; constexpr auto* PARAMETER_ITEM_CONCATENATION_TOKEN = ";;"; constexpr auto* DEFAULT_TITLE = "Select..."; -constexpr auto* TAG = "SelectionDialog"; +static const auto LOGGER = Logger("SelectionDialog"); extern const AppManifest manifest; @@ -53,7 +53,7 @@ class SelectionDialogApp final : public App { void onListItemSelected(lv_event_t* e) { auto index = reinterpret_cast(lv_event_get_user_data(e)); - TT_LOG_I(TAG, "Selected item at index %d", index); + LOGGER.info("Selected item at index {}", index); auto bundle = std::make_unique(); bundle->putInt32(RESULT_BUNDLE_KEY_INDEX, (int32_t)index); setResult(Result::Ok, std::move(bundle)); @@ -85,7 +85,7 @@ public: if (parameters->optString(PARAMETER_BUNDLE_KEY_ITEMS, items_concatenated)) { std::vector items = string::split(items_concatenated, PARAMETER_ITEM_CONCATENATION_TOKEN); if (items.empty() || items.front().empty()) { - TT_LOG_E(TAG, "No items provided"); + LOGGER.error("No items provided"); setResult(Result::Error); stop(manifest.appId); } else if (items.size() == 1) { @@ -93,7 +93,7 @@ public: result_bundle->putInt32(RESULT_BUNDLE_KEY_INDEX, 0); setResult(Result::Ok, std::move(result_bundle)); stop(manifest.appId); - TT_LOG_W(TAG, "Auto-selecting single item"); + LOGGER.warn("Auto-selecting single item"); } else { size_t index = 0; for (const auto& item: items) { @@ -101,7 +101,7 @@ public: } } } else { - TT_LOG_E(TAG, "No items provided"); + LOGGER.error("No items provided"); setResult(Result::Error); stop(manifest.appId); } diff --git a/Tactility/Source/app/timedatesettings/TimeDateSettings.cpp b/Tactility/Source/app/timedatesettings/TimeDateSettings.cpp index bc521ebb..df98d8bc 100644 --- a/Tactility/Source/app/timedatesettings/TimeDateSettings.cpp +++ b/Tactility/Source/app/timedatesettings/TimeDateSettings.cpp @@ -1,9 +1,10 @@ #include #include #include +#include #include -#include #include +#include #include #include #include @@ -12,7 +13,7 @@ namespace tt::app::timedatesettings { -constexpr auto* TAG = "TimeDate"; +static const auto LOGGER = Logger("TimeDate"); extern const AppManifest manifest; @@ -137,7 +138,7 @@ public: if (result == Result::Ok && bundle != nullptr) { const auto name = timezone::getResultName(*bundle); const auto code = timezone::getResultCode(*bundle); - TT_LOG_I(TAG, "Result name=%s code=%s", name.c_str(), code.c_str()); + LOGGER.info("Result name={} code={}", name, code); settings::setTimeZone(name, code); if (!name.empty()) { diff --git a/Tactility/Source/app/timezone/TimeZone.cpp b/Tactility/Source/app/timezone/TimeZone.cpp index 7de026c8..5059cb9a 100644 --- a/Tactility/Source/app/timezone/TimeZone.cpp +++ b/Tactility/Source/app/timezone/TimeZone.cpp @@ -2,21 +2,23 @@ #include #include #include +#include +#include #include #include #include -#include - -#include #include +#include #include +#include #include #include namespace tt::app::timezone { -constexpr auto* TAG = "TimeZone"; +static const auto LOGGER = Logger("TimeZone"); + constexpr auto* RESULT_BUNDLE_CODE_INDEX = "code"; constexpr auto* RESULT_BUNDLE_NAME_INDEX = "name"; @@ -96,7 +98,7 @@ class TimeZoneApp final : public App { } void onListItemSelected(std::size_t index) { - TT_LOG_I(TAG, "Selected item at index %zu", index); + LOGGER.info("Selected item at index {}", index); auto& entry = entries[index]; @@ -117,7 +119,7 @@ class TimeZoneApp final : public App { auto path = std::string(file::MOUNT_POINT_SYSTEM) + "/timezones.csv"; auto* file = fopen(path.c_str(), "rb"); if (file == nullptr) { - TT_LOG_E(TAG, "Failed to open %s", path.c_str()); + LOGGER.error("Failed to open {}", path); return; } char line[96]; @@ -138,7 +140,7 @@ class TimeZoneApp final : public App { } } } else { - TT_LOG_E(TAG, "Parse error at line %lu", count); + LOGGER.error("Parse error at line {}", count); } } @@ -148,10 +150,10 @@ class TimeZoneApp final : public App { entries = std::move(new_entries); mutex.unlock(); } else { - TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED); + LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED); } - TT_LOG_I(TAG, "Processed %lu entries", count); + LOGGER.info("Processed {} entries", count); } void updateList() { @@ -160,7 +162,7 @@ class TimeZoneApp final : public App { readTimeZones(filter); lvgl::unlock(); } else { - TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "LVGL"); + LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "LVGL"); return; } diff --git a/Tactility/Source/app/wifiapsettings/WifiApSettings.cpp b/Tactility/Source/app/wifiapsettings/WifiApSettings.cpp index bb2e8f02..eba75f7c 100644 --- a/Tactility/Source/app/wifiapsettings/WifiApSettings.cpp +++ b/Tactility/Source/app/wifiapsettings/WifiApSettings.cpp @@ -6,15 +6,16 @@ #include #include #include +#include +#include #include #include -#include #include namespace tt::app::wifiapsettings { -constexpr auto* TAG = "WifiApSettings"; +static const auto LOGGER = Logger("WifiApSettings"); extern const AppManifest manifest; @@ -50,10 +51,10 @@ class WifiApSettings : public App { if (service::wifi::settings::load(self->ssid.c_str(), settings)) { settings.autoConnect = is_on; if (!service::wifi::settings::save(settings)) { - TT_LOG_E(TAG, "Failed to save settings"); + LOGGER.error("Failed to save settings"); } } else { - TT_LOG_E(TAG, "Failed to load settings"); + LOGGER.error("Failed to load settings"); } } @@ -89,7 +90,7 @@ class WifiApSettings : public App { updateViews(); lvgl::unlock(); } else { - TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "LVGL"); + LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "LVGL"); } } } @@ -192,7 +193,7 @@ public: lv_obj_remove_state(auto_connect_switch, LV_STATE_CHECKED); } } else { - TT_LOG_W(TAG, "No settings found"); + LOGGER.warn("No settings found"); lv_obj_add_flag(forget_button, LV_OBJ_FLAG_HIDDEN); lv_obj_add_flag(auto_connect_wrapper, LV_OBJ_FLAG_HIDDEN); } @@ -223,11 +224,11 @@ public: std::string ssid = parameters->getString("ssid"); if (!service::wifi::settings::remove(ssid.c_str())) { - TT_LOG_E(TAG, "Failed to remove SSID"); + LOGGER.error("Failed to remove SSID"); return; } - TT_LOG_I(TAG, "Removed SSID"); + LOGGER.info("Removed SSID"); if ( service::wifi::getRadioState() == service::wifi::RadioState::ConnectionActive && service::wifi::getConnectionTarget() == ssid diff --git a/Tactility/Source/app/wificonnect/View.cpp b/Tactility/Source/app/wificonnect/View.cpp index 92c2c048..366d0a37 100644 --- a/Tactility/Source/app/wificonnect/View.cpp +++ b/Tactility/Source/app/wificonnect/View.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -12,7 +13,7 @@ namespace tt::app::wificonnect { -constexpr auto* TAG = "WifiConnect"; +static const auto LOGGER = Logger("WifiConnect"); void View::resetErrors() { lv_obj_add_flag(password_error, LV_OBJ_FLAG_HIDDEN); @@ -30,7 +31,7 @@ static void onConnect(TT_UNUSED lv_event_t* event) { const char* ssid = lv_textarea_get_text(view.ssid_textarea); size_t ssid_len = strlen(ssid); if (ssid_len > TT_WIFI_SSID_LIMIT) { - TT_LOG_E(TAG, "SSID too long"); + LOGGER.error("SSID too long"); lv_label_set_text(view.ssid_error, "SSID too long"); lv_obj_remove_flag(view.ssid_error, LV_OBJ_FLAG_HIDDEN); return; @@ -39,7 +40,7 @@ static void onConnect(TT_UNUSED lv_event_t* event) { const char* password = lv_textarea_get_text(view.password_textarea); size_t password_len = strlen(password); if (password_len > TT_WIFI_CREDENTIALS_PASSWORD_LIMIT) { - TT_LOG_E(TAG, "Password too long"); + LOGGER.error("Password too long"); lv_label_set_text(view.password_error, "Password too long"); lv_obj_remove_flag(view.password_error, LV_OBJ_FLAG_HIDDEN); return; diff --git a/Tactility/Source/app/wificonnect/WifiConnect.cpp b/Tactility/Source/app/wificonnect/WifiConnect.cpp index 65b6fb28..3bd24f7a 100644 --- a/Tactility/Source/app/wificonnect/WifiConnect.cpp +++ b/Tactility/Source/app/wificonnect/WifiConnect.cpp @@ -1,13 +1,15 @@ #include +#include +#include #include +#include #include #include -#include namespace tt::app::wificonnect { -constexpr auto* TAG = "WifiConnect"; +static const auto LOGGER = Logger("WifiConnect"); constexpr auto* WIFI_CONNECT_PARAM_SSID = "ssid"; // String constexpr auto* WIFI_CONNECT_PARAM_PASSWORD = "password"; // String @@ -72,7 +74,7 @@ void WifiConnect::requestViewUpdate() { view.update(); lvgl::unlock(); } else { - TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "LVGL"); + LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "LVGL"); } } unlock(); diff --git a/Tactility/Source/app/wifimanage/View.cpp b/Tactility/Source/app/wifimanage/View.cpp index b921db24..159d839e 100644 --- a/Tactility/Source/app/wifimanage/View.cpp +++ b/Tactility/Source/app/wifimanage/View.cpp @@ -1,24 +1,20 @@ #include #include - -#include #include - +#include #include #include - -#include #include +#include #include #include #include -#include namespace tt::app::wifimanage { -constexpr auto* TAG = "WifiManageView"; +static const auto LOGGER = Logger("WifiManageView"); std::shared_ptr _Nullable optWifiManage(); @@ -70,16 +66,16 @@ static void onConnectToHiddenClicked(lv_event_t* event) { // region Secondary updates void View::connect(lv_event_t* event) { - TT_LOG_D(TAG, "connect()"); + LOGGER.debug("connect()"); auto* widget = lv_event_get_current_target_obj(event); auto index = reinterpret_cast(lv_obj_get_user_data(widget)); auto* self = static_cast(lv_event_get_user_data(event)); auto ap_records = self->state->getApRecords(); if (index < ap_records.size()) { - TT_LOG_I(TAG, "Clicked %d/%d", index, ap_records.size() - 1); + LOGGER.info("Clicked {}/{}", index, ap_records.size() - 1); auto& ssid = ap_records[index].ssid; - TT_LOG_I(TAG, "Clicked AP: %s", ssid.c_str()); + LOGGER.info("Clicked AP: {}", ssid); std::string connection_target = service::wifi::getConnectionTarget(); if (connection_target == ssid) { self->bindings->onDisconnect(); @@ -87,12 +83,12 @@ void View::connect(lv_event_t* event) { self->bindings->onConnectSsid(ssid); } } else { - TT_LOG_W(TAG, "Clicked AP: record %d/%d does not exist", index, ap_records.size() - 1); + LOGGER.warn("Clicked AP: record {}/{} does not exist", index, ap_records.size() - 1); } } void View::showDetails(lv_event_t* event) { - TT_LOG_D(TAG, "showDetails()"); + LOGGER.debug("showDetails()"); auto* widget = lv_event_get_current_target_obj(event); auto index = reinterpret_cast(lv_obj_get_user_data(widget)); auto* self = static_cast(lv_event_get_user_data(event)); @@ -100,10 +96,10 @@ void View::showDetails(lv_event_t* event) { if (index < ap_records.size()) { auto& ssid = ap_records[index].ssid; - TT_LOG_I(TAG, "Clicked AP: %s", ssid.c_str()); + LOGGER.info("Clicked AP: {}", ssid); self->bindings->onShowApSettings(ssid); } else { - TT_LOG_W(TAG, "Clicked AP: record %d/%d does not exist", index, ap_records.size() - 1); + LOGGER.warn("Clicked AP: record {}/{} does not exist", index, ap_records.size() - 1); } } diff --git a/Tactility/Source/app/wifimanage/WifiManage.cpp b/Tactility/Source/app/wifimanage/WifiManage.cpp index e411d936..252815c9 100644 --- a/Tactility/Source/app/wifimanage/WifiManage.cpp +++ b/Tactility/Source/app/wifimanage/WifiManage.cpp @@ -4,22 +4,24 @@ #include #include #include +#include +#include #include #include namespace tt::app::wifimanage { -constexpr auto TAG = "WifiManage"; +static const auto LOGGER = Logger("WifiManage"); extern const AppManifest manifest; static void onConnect(const std::string& ssid) { service::wifi::settings::WifiApSettings settings; if (service::wifi::settings::load(ssid, settings)) { - TT_LOG_I(TAG, "Connecting with known credentials"); + LOGGER.info("Connecting with known credentials"); service::wifi::connect(settings, false); } else { - TT_LOG_I(TAG, "Starting connection dialog"); + LOGGER.info("Starting connection dialog"); wificonnect::start(ssid); } } @@ -65,7 +67,7 @@ void WifiManage::requestViewUpdate() { view.update(); lvgl::unlock(); } else { - TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "LVGL"); + LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "LVGL"); } } unlock(); @@ -73,7 +75,7 @@ void WifiManage::requestViewUpdate() { void WifiManage::onWifiEvent(service::wifi::WifiEvent event) { auto radio_state = service::wifi::getRadioState(); - TT_LOG_I(TAG, "Update with state %s", service::wifi::radioStateToString(radio_state)); + LOGGER.info("Update with state {}", service::wifi::radioStateToString(radio_state)); getState().setRadioState(radio_state); switch (event) { using enum service::wifi::WifiEvent; @@ -118,7 +120,7 @@ void WifiManage::onShow(AppContext& app, lv_obj_t* parent) { bool can_scan = radio_state == service::wifi::RadioState::On || radio_state == service::wifi::RadioState::ConnectionPending || radio_state == service::wifi::RadioState::ConnectionActive; - TT_LOG_I(TAG, "%s %d", service::wifi::radioStateToString(radio_state), (int)service::wifi::isScanning()); + LOGGER.info("{} {}", service::wifi::radioStateToString(radio_state), service::wifi::isScanning()); if (can_scan && !service::wifi::isScanning()) { service::wifi::scan(); } diff --git a/Tactility/Source/hal/gps/GpsInit.cpp b/Tactility/Source/hal/gps/GpsInit.cpp index de5dc06d..6b07e872 100644 --- a/Tactility/Source/hal/gps/GpsInit.cpp +++ b/Tactility/Source/hal/gps/GpsInit.cpp @@ -3,13 +3,13 @@ #include #include #include -#include +#include #include namespace tt::hal::gps { -constexpr auto TAG = "gps"; +static const auto LOGGER = Logger("Gps"); bool initMtk(uart::Uart& uart); bool initMtkL76b(uart::Uart& uart); @@ -112,7 +112,7 @@ GpsResponse getACKCas(uart::Uart& uart, uint8_t class_id, uint8_t msg_id, uint32 // Check for an ACK-ACK for the specified class and message id if ((msg_cls == 0x05) && (msg_msg_id == 0x01) && payload_cls == class_id && payload_msg == msg_id) { #ifdef GPS_DEBUG - LOG_INFO("Got ACK for class %02X message %02X in %dms", class_id, msg_id, millis() - startTime); + LOGGER.info("Got ACK for class {:02X} message {:02X} in {} ms", class_id, msg_id, millis() - startTime); #endif return GpsResponse::Ok; } @@ -120,7 +120,7 @@ GpsResponse getACKCas(uart::Uart& uart, uint8_t class_id, uint8_t msg_id, uint32 // Check for an ACK-NACK for the specified class and message id if ((msg_cls == 0x05) && (msg_msg_id == 0x00) && payload_cls == class_id && payload_msg == msg_id) { #ifdef GPS_DEBUG - LOG_WARN("Got NACK for class %02X message %02X in %dms", class_id, msg_id, millis() - startTime); + LOGGER.warn("Got NACK for class {:02X} message {:02X} in {} ms", class_id, msg_id, millis() - startTime); #endif return GpsResponse::NotAck; } @@ -163,7 +163,7 @@ bool init(uart::Uart& uart, GpsModel type) { return initUc6580(uart); } - TT_LOG_I(TAG, "Init not implemented %d", static_cast(type)); + LOGGER.info("Init not implemented {}", static_cast(type)); return false; } @@ -213,14 +213,14 @@ bool initAtgm336h(uart::Uart& uart) { int msglen = makeCASPacket(buffer, 0x06, 0x07, sizeof(_message_CAS_CFG_NAVX_CONF), _message_CAS_CFG_NAVX_CONF); uart.writeBytes(buffer, msglen); if (getACKCas(uart, 0x06, 0x07, 250) != GpsResponse::Ok) { - TT_LOG_W(TAG, "ATGM336H: Could not set Config"); + LOGGER.warn("ATGM336H: Could not set Config"); } // Set the update frequence to 1Hz msglen = makeCASPacket(buffer, 0x06, 0x04, sizeof(_message_CAS_CFG_RATE_1HZ), _message_CAS_CFG_RATE_1HZ); uart.writeBytes(buffer, msglen); if (getACKCas(uart, 0x06, 0x04, 250) != GpsResponse::Ok) { - TT_LOG_W(TAG, "ATGM336H: Could not set Update Frequency"); + LOGGER.warn("ATGM336H: Could not set Update Frequency"); } // Set the NEMA output messages @@ -232,7 +232,7 @@ bool initAtgm336h(uart::Uart& uart) { msglen = makeCASPacket(buffer, 0x06, 0x01, sizeof(cas_cfg_msg_packet), cas_cfg_msg_packet); uart.writeBytes(buffer, msglen); if (getACKCas(uart, 0x06, 0x01, 250) != GpsResponse::Ok) { - TT_LOG_W(TAG, "ATGM336H: Could not enable NMEA MSG: %d", fields[i]); + LOGGER.warn("ATGM336H: Could not enable NMEA MSG: {}", fields[i]); } } return true; diff --git a/Tactility/Source/hal/gps/Probe.cpp b/Tactility/Source/hal/gps/Probe.cpp index 71142c37..b63080fa 100644 --- a/Tactility/Source/hal/gps/Probe.cpp +++ b/Tactility/Source/hal/gps/Probe.cpp @@ -1,11 +1,13 @@ #include "Tactility/hal/gps/GpsDevice.h" #include "Tactility/hal/gps/Ublox.h" -#include +#include #include #include + #include -#define TAG "gps" +static const auto LOGGER = tt::Logger("Gps"); + #define GPS_UART_BUFFER_SIZE 256 using namespace tt; @@ -59,13 +61,13 @@ GpsResponse getAck(uart::Uart& uart, const char* message, uint32_t waitMillis) { if ((bytesRead == 767) || (b == '\r')) { if (strnstr((char*)buffer, message, bytesRead) != nullptr) { #ifdef GPS_DEBUG - LOG_DEBUG("Found: %s", message); // Log the found message + LOGGER.debug("Found: {}", message); // Log the found message #endif return GpsResponse::Ok; } else { bytesRead = 0; #ifdef GPS_DEBUG - LOG_DEBUG(debugmsg.c_str()); + LOGGER.debug(debugmsg); #endif } } @@ -77,15 +79,15 @@ GpsResponse getAck(uart::Uart& uart, const char* message, uint32_t waitMillis) { /** * From: https://github.com/meshtastic/firmware/blob/f81d3b045dd1b7e3ca7870af3da915ff4399ea98/src/gps/GPS.cpp */ -#define PROBE_SIMPLE(UART, CHIP, TOWRITE, RESPONSE, DRIVER, TIMEOUT, ...) \ - do { \ - TT_LOG_I(TAG, "Probing for %s (%s)", CHIP, TOWRITE); \ - UART.flushInput(); \ - UART.writeString(TOWRITE "\r\n", TIMEOUT); \ - if (getAck(UART, RESPONSE, TIMEOUT) == GpsResponse::Ok) { \ - TT_LOG_I(TAG, "Probe detected %s %s", CHIP, #DRIVER); \ - return DRIVER; \ - } \ +#define PROBE_SIMPLE(UART, CHIP, TOWRITE, RESPONSE, DRIVER, TIMEOUT, ...) \ + do { \ + LOGGER.info("Probing for {} ({})", CHIP, TOWRITE); \ + UART.flushInput(); \ + UART.writeString(TOWRITE "\r\n", TIMEOUT); \ + if (getAck(UART, RESPONSE, TIMEOUT) == GpsResponse::Ok) { \ + LOGGER.info("Probe detected {} {}", CHIP, #DRIVER); \ + return DRIVER; \ + } \ } while (0) /** @@ -132,7 +134,7 @@ GpsModel probe(uart::Uart& uart) { if (ublox_result != GpsModel::Unknown) { return ublox_result; } else { - TT_LOG_W(TAG, "No GNSS Module (baudrate %lu)", uart.getBaudRate()); + LOGGER.warn("No GNSS Module (baudrate %lu)", uart.getBaudRate()); return GpsModel::Unknown; } } diff --git a/Tactility/Source/hal/gps/Ublox.cpp b/Tactility/Source/hal/gps/Ublox.cpp index f830344f..778f71c9 100644 --- a/Tactility/Source/hal/gps/Ublox.cpp +++ b/Tactility/Source/hal/gps/Ublox.cpp @@ -93,7 +93,7 @@ GpsResponse getAck(uart::Uart& uart, uint8_t class_id, uint8_t msg_id, uint32_t if (sCounter == 26) { #ifdef GPS_DEBUG - TT_LOG_I(TAG, "%s", debugmsg.c_str()); + LOGGER.info("%s", debugmsg.c_str()); #endif return GpsResponse::FrameErrors; } @@ -108,7 +108,7 @@ GpsResponse getAck(uart::Uart& uart, uint8_t class_id, uint8_t msg_id, uint32_t } else { if (ack == 3 && b == 0x00) { // UBX-ACK-NAK message #ifdef GPS_DEBUG - TT_LOG_I(TAG, "%s", debugmsg.c_str()); + LOGGER.info("%s", debugmsg.c_str()); #endif LOGGER.warn("Got NAK for class {:02X} message {:02X}", class_id, msg_id); return GpsResponse::NotAck; // NAK received @@ -118,8 +118,8 @@ GpsResponse getAck(uart::Uart& uart, uint8_t class_id, uint8_t msg_id, uint32_t } } #ifdef GPS_DEBUG - TT_LOG_I(TAG, "%s", debugmsg.c_str()); - TT_LOG_W(TAG, "No response for class %02X message %02X", class_id, msg_id); + LOGGER.info("%s", debugmsg.c_str()); + LOGGER.warn("No response for class %02X message %02X", class_id, msg_id); #endif return GpsResponse::None; // No response received within timeout } diff --git a/Tactility/Source/lvgl/Spinner.cpp b/Tactility/Source/lvgl/Spinner.cpp index 111f32aa..205eb162 100644 --- a/Tactility/Source/lvgl/Spinner.cpp +++ b/Tactility/Source/lvgl/Spinner.cpp @@ -2,7 +2,6 @@ #include #include -#include #include diff --git a/Tactility/Source/lvgl/Statusbar.cpp b/Tactility/Source/lvgl/Statusbar.cpp index 35b9388c..649fefab 100644 --- a/Tactility/Source/lvgl/Statusbar.cpp +++ b/Tactility/Source/lvgl/Statusbar.cpp @@ -1,17 +1,17 @@ #define LV_USE_PRIVATE_API 1 // For actual lv_obj_t declaration -#include -#include - -#include -#include -#include -#include #include +#include +#include #include #include #include +#include +#include #include +#include +#include +#include #include @@ -112,7 +112,7 @@ static void statusbar_pubsub_event(Statusbar* statusbar) { lv_obj_invalidate(&statusbar->obj); unlock(); } else { - LOGGER.warn(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT_CPP, "Statusbar"); + LOGGER.warn(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "Statusbar"); } } diff --git a/Tactility/Source/network/HttpdReq.cpp b/Tactility/Source/network/HttpdReq.cpp index 8388322f..8f965e27 100644 --- a/Tactility/Source/network/HttpdReq.cpp +++ b/Tactility/Source/network/HttpdReq.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include diff --git a/Tactility/Source/network/Ntp.cpp b/Tactility/Source/network/Ntp.cpp index 24a2e6cd..09633841 100644 --- a/Tactility/Source/network/Ntp.cpp +++ b/Tactility/Source/network/Ntp.cpp @@ -2,6 +2,8 @@ #include #include +#include + #ifdef ESP_PLATFORM #include #include diff --git a/Tactility/Source/network/Url.cpp b/Tactility/Source/network/Url.cpp index 7cbdca85..cc3525d6 100644 --- a/Tactility/Source/network/Url.cpp +++ b/Tactility/Source/network/Url.cpp @@ -1,7 +1,5 @@ #include "Tactility/network/Url.h" -#include - namespace tt::network { std::map parseUrlQuery(std::string query) { diff --git a/Tactility/Source/service/gui/GuiService.cpp b/Tactility/Source/service/gui/GuiService.cpp index 21ad14d0..2a98df34 100644 --- a/Tactility/Source/service/gui/GuiService.cpp +++ b/Tactility/Source/service/gui/GuiService.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -107,7 +108,7 @@ void GuiService::redraw() { // Unlock GUI and LVGL lvgl::unlock(); } else { - LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT_CPP, "LVGL"); + LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "LVGL"); } unlock(); diff --git a/Tactility/Source/service/loader/Loader.cpp b/Tactility/Source/service/loader/Loader.cpp index e8aa73e9..dc4cccc4 100644 --- a/Tactility/Source/service/loader/Loader.cpp +++ b/Tactility/Source/service/loader/Loader.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include diff --git a/Tactility/Source/service/screenshot/ScreenshotTask.cpp b/Tactility/Source/service/screenshot/ScreenshotTask.cpp index 848dd861..00511628 100644 --- a/Tactility/Source/service/screenshot/ScreenshotTask.cpp +++ b/Tactility/Source/service/screenshot/ScreenshotTask.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include diff --git a/Tactility/Source/service/sdcard/Sdcard.cpp b/Tactility/Source/service/sdcard/Sdcard.cpp index 9ec5c729..1cbddb82 100644 --- a/Tactility/Source/service/sdcard/Sdcard.cpp +++ b/Tactility/Source/service/sdcard/Sdcard.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include diff --git a/Tactility/Source/service/wifi/WifiEsp.cpp b/Tactility/Source/service/wifi/WifiEsp.cpp index 9b109c38..fe70032f 100644 --- a/Tactility/Source/service/wifi/WifiEsp.cpp +++ b/Tactility/Source/service/wifi/WifiEsp.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -631,7 +632,7 @@ static void dispatchDisable(std::shared_ptr wifi) { auto lock = wifi->radioMutex.asScopedLock(); if (!lock.lock(50 / portTICK_PERIOD_MS)) { - LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT_CPP, "disable()"); + LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "disable()"); return; } @@ -730,7 +731,7 @@ static void dispatchConnect(std::shared_ptr wifi) { auto lock = wifi->radioMutex.asScopedLock(); if (!lock.lock(50 / portTICK_PERIOD_MS)) { - LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT_CPP, "dispatchConnect()"); + LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "dispatchConnect()"); return; } diff --git a/TactilityC/Source/tt_app.cpp b/TactilityC/Source/tt_app.cpp index 0c400477..4e9df28f 100644 --- a/TactilityC/Source/tt_app.cpp +++ b/TactilityC/Source/tt_app.cpp @@ -3,13 +3,13 @@ #include #include #include -#include +#include #include -extern "C" { +static const auto LOGGER = tt::Logger("tt_app"); -constexpr auto* TAG = "tt_app"; +extern "C" { #define HANDLE_AS_APP_CONTEXT(handle) ((tt::app::AppContext*)(handle)) @@ -65,7 +65,7 @@ void tt_app_get_user_data_path(AppHandle handle, char* buffer, size_t* size) { const auto data_path = paths->getUserDataPath(); const auto expected_length = data_path.length() + 1; if (*size < expected_length) { - TT_LOG_E(TAG, "Path buffer not large enough (%d < %d)", *size, expected_length); + LOGGER.error("Path buffer not large enough ({} < {})", *size, expected_length); *size = 0; buffer[0] = 0; return; @@ -83,7 +83,7 @@ void tt_app_get_user_data_child_path(AppHandle handle, const char* childPath, ch const auto resolved_path = paths->getUserDataPath(childPath); const auto resolved_path_length = resolved_path.length(); if (*size < (resolved_path_length + 1)) { - TT_LOG_E(TAG, "Path buffer not large enough (%d < %d)", *size, (resolved_path_length + 1)); + LOGGER.error("Path buffer not large enough ({} < {})", *size, (resolved_path_length + 1)); *size = 0; buffer[0] = 0; return; @@ -101,7 +101,7 @@ void tt_app_get_assets_path(AppHandle handle, char* buffer, size_t* size) { const auto assets_path = paths->getAssetsPath(); const auto expected_length = assets_path.length() + 1; if (*size < expected_length) { - TT_LOG_E(TAG, "Path buffer not large enough (%d < %d)", *size, expected_length); + LOGGER.error("Path buffer not large enough ({} < {})", *size, expected_length); *size = 0; buffer[0] = 0; return; @@ -119,7 +119,7 @@ void tt_app_get_assets_child_path(AppHandle handle, const char* childPath, char* const auto resolved_path = paths->getAssetsPath(childPath); const auto resolved_path_length = resolved_path.length(); if (*size < (resolved_path_length + 1)) { - TT_LOG_E(TAG, "Path buffer not large enough (%d < %d)", *size, (resolved_path_length + 1)); + LOGGER.error("Path buffer not large enough ({} < {})", *size, (resolved_path_length + 1)); *size = 0; buffer[0] = 0; return; diff --git a/TactilityCore/Include/Tactility/Check.h b/TactilityCore/Include/Tactility/Check.h index c5078d50..dd14fb51 100644 --- a/TactilityCore/Include/Tactility/Check.h +++ b/TactilityCore/Include/Tactility/Check.h @@ -14,7 +14,7 @@ #pragma once #include "CoreDefines.h" -#include "Log.h" +#include "Logger.h" #include @@ -32,13 +32,13 @@ namespace tt { #define tt_crash(...) TT_ARG_CAT(_tt_crash,TT_ARGCOUNT(__VA_ARGS__))(__VA_ARGS__) #define _tt_crash0() do { \ - TT_LOG_E("crash", "at %s:%d", __FILE__, __LINE__); \ + tt::Logger("Kernel").error("Crash at {}:{}", __FILE__, __LINE__); \ tt::_crash(); \ } while (0) -#define _tt_crash1(message) do { \ - TT_LOG_E("crash", "%s\n\tat %s:%d", message, __FILE__, __LINE__); \ - tt::_crash(); \ +#define _tt_crash1(message) do { \ + tt::Logger("Kernel").error("Crash: {}\n\tat {}:{}", message, __FILE__, __LINE__); \ + tt::_crash(); \ } while (0) /** Halt the system @@ -50,7 +50,7 @@ namespace tt { #define tt_check_internal(__e, __m) \ do { \ if (!(__e)) { \ - TT_LOG_E("check", "%s", #__e); \ + tt::Logger("Kernel").error("Check failed: {}", #__e); \ if (__m) { \ tt_crash_internal(#__m); \ } else { \ @@ -65,4 +65,4 @@ namespace tt { * @param[in] optional message (const char*) */ -#define tt_check(x, ...) if (!(x)) { TT_LOG_E("check", "Failed: %s", #x); tt::_crash(); } +#define tt_check(x, ...) if (!(x)) { tt::Logger("Kernel").error("Check failed: {}", #x); tt::_crash(); } diff --git a/TactilityCore/Include/Tactility/Log.h b/TactilityCore/Include/Tactility/Log.h deleted file mode 100644 index ede99d52..00000000 --- a/TactilityCore/Include/Tactility/Log.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -#ifdef ESP_PLATFORM -#include "LogEsp.h" -#else -#include "LogSimulator.h" -#endif - -#include "LogMessages.h" diff --git a/TactilityCore/Include/Tactility/LogEsp.h b/TactilityCore/Include/Tactility/LogEsp.h deleted file mode 100644 index 014fec03..00000000 --- a/TactilityCore/Include/Tactility/LogEsp.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#ifdef ESP_PLATFORM - -#include "LogCommon.h" -#include - -#define TT_LOG_E(tag, format, ...) \ - ESP_LOGE(tag, format, ##__VA_ARGS__) -#define TT_LOG_W(tag, format, ...) \ - ESP_LOGW(tag, format, ##__VA_ARGS__) -#define TT_LOG_I(tag, format, ...) \ - ESP_LOGI(tag, format, ##__VA_ARGS__) -#define TT_LOG_D(tag, format, ...) \ - ESP_LOGD(tag, format, ##__VA_ARGS__) -#define TT_LOG_V(tag, format, ...) \ - ESP_LOGV(tag, format, ##__VA_ARGS__) - -#endif // ESP_PLATFORM diff --git a/TactilityCore/Include/Tactility/LogMessages.h b/TactilityCore/Include/Tactility/LogMessages.h index 3d18ebba..ec48ce80 100644 --- a/TactilityCore/Include/Tactility/LogMessages.h +++ b/TactilityCore/Include/Tactility/LogMessages.h @@ -9,21 +9,11 @@ // Alloc #define LOG_MESSAGE_ALLOC_FAILED "Out of memory" -#define LOG_MESSAGE_ALLOC_FAILED_FMT "Out of memory (failed to allocated %zu bytes)" +#define LOG_MESSAGE_ALLOC_FAILED_FMT "Out of memory (failed to allocated {} bytes)" // 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" -#define LOG_MESSAGE_SPI_INIT_FAILED_FMT "SPI %d init failed" - -// I2C -#define LOG_MESSAGE_I2C_INIT_START "I2C init" -#define LOG_MESSAGE_I2C_INIT_CONFIG_FAILED "I2C config failed" -#define LOG_MESSAGE_I2C_INIT_DRIVER_INSTALL_FAILED "I2C driver install failed" +#define LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT "Mutex acquisition timeout ({})" // Power on #define LOG_MESSAGE_POWER_ON_START "Power on" diff --git a/TactilityCore/Include/Tactility/LogSimulator.h b/TactilityCore/Include/Tactility/LogSimulator.h deleted file mode 100644 index 89d2f31a..00000000 --- a/TactilityCore/Include/Tactility/LogSimulator.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#ifndef ESP_PLATFORM - -#include "LogCommon.h" - -#include -#include -#include -#include - -namespace tt { - -void log(LogLevel level, const char* tag, const char* format, ...); - -} // namespace - -#define TT_LOG_E(tag, format, ...) \ - tt::log(tt::LogLevel::Error, tag, format, ##__VA_ARGS__) -#define TT_LOG_W(tag, format, ...) \ - tt::log(tt::LogLevel::Warning, tag, format, ##__VA_ARGS__) -#define TT_LOG_I(tag, format, ...) \ - tt::log(tt::LogLevel::Info, tag, format, ##__VA_ARGS__) -#define TT_LOG_D(tag, format, ...) \ - tt::log(tt::LogLevel::Debug, tag, format, ##__VA_ARGS__) -#define TT_LOG_V(tag, format, ...) \ - tt::log(tt::LogLevel::Verbose, tag, format, ##__VA_ARGS__) - -#endif // ESP_PLATFORM diff --git a/TactilityCore/Include/Tactility/LoggerAdapter.h b/TactilityCore/Include/Tactility/LoggerAdapter.h index a8d97337..2288bca5 100644 --- a/TactilityCore/Include/Tactility/LoggerAdapter.h +++ b/TactilityCore/Include/Tactility/LoggerAdapter.h @@ -1,6 +1,6 @@ #pragma once -#include "LogCommon.h" +#include "LoggerCommon.h" #include namespace tt { diff --git a/TactilityCore/Include/Tactility/LoggerAdapterEsp.h b/TactilityCore/Include/Tactility/LoggerAdapterEsp.h index bd4179a2..f9861034 100644 --- a/TactilityCore/Include/Tactility/LoggerAdapterEsp.h +++ b/TactilityCore/Include/Tactility/LoggerAdapterEsp.h @@ -28,7 +28,7 @@ static const LoggerAdapter espLoggerAdapter = [](LogLevel level, const char* tag 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; + 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()); }; diff --git a/TactilityCore/Include/Tactility/LoggerAdapterGeneric.h b/TactilityCore/Include/Tactility/LoggerAdapterGeneric.h index f0125b0a..6ed0a26f 100644 --- a/TactilityCore/Include/Tactility/LoggerAdapterGeneric.h +++ b/TactilityCore/Include/Tactility/LoggerAdapterGeneric.h @@ -28,7 +28,7 @@ static const LoggerAdapter genericLoggerAdapter = [](LogLevel level, const char* 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; + 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()); }; diff --git a/TactilityCore/Include/Tactility/LoggerAdapterShared.h b/TactilityCore/Include/Tactility/LoggerAdapterShared.h index 3d8346a1..af4527cc 100644 --- a/TactilityCore/Include/Tactility/LoggerAdapterShared.h +++ b/TactilityCore/Include/Tactility/LoggerAdapterShared.h @@ -1,6 +1,6 @@ #pragma once -#include "LogCommon.h" +#include "LoggerCommon.h" namespace tt { diff --git a/TactilityCore/Include/Tactility/LogCommon.h b/TactilityCore/Include/Tactility/LoggerCommon.h similarity index 100% rename from TactilityCore/Include/Tactility/LogCommon.h rename to TactilityCore/Include/Tactility/LoggerCommon.h diff --git a/TactilityCore/Include/Tactility/LoggerSettings.h b/TactilityCore/Include/Tactility/LoggerSettings.h index 71adab2b..3bb5105a 100644 --- a/TactilityCore/Include/Tactility/LoggerSettings.h +++ b/TactilityCore/Include/Tactility/LoggerSettings.h @@ -1,6 +1,6 @@ #pragma once -#include "LogCommon.h" +#include "LoggerCommon.h" namespace tt { diff --git a/TactilityCore/Include/Tactility/TactilityCore.h b/TactilityCore/Include/Tactility/TactilityCore.h index d107dc4a..88ccddf9 100644 --- a/TactilityCore/Include/Tactility/TactilityCore.h +++ b/TactilityCore/Include/Tactility/TactilityCore.h @@ -2,9 +2,6 @@ #include -#include "Tactility/Thread.h" #include "Check.h" #include "CoreDefines.h" -#include "Log.h" - -#include +#include "Logger.h" diff --git a/TactilityCore/Source/LogSimulator.cpp b/TactilityCore/Source/LogSimulator.cpp deleted file mode 100644 index ea1b5413..00000000 --- a/TactilityCore/Source/LogSimulator.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef ESP_PLATFORM - -#include -#include -#include - -#include -#include - -namespace tt { - -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 << 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); - va_end(args); -} - -} // namespace tt - -#endif \ No newline at end of file