New logging and more (#446)
- `TT_LOG_*` macros are replaced by `Logger` via `#include<Tactility/Logger.h>` - Changed default timezone to Europe/Amsterdam - Fix for logic bug in unPhone hardware - Fix for init/deinit in DRV2605 driver - Other fixes - Removed optimization that broke unPhone (disabled the moving of heap-related functions to flash)
This commit is contained in:
committed by
GitHub
parent
719f7bcece
commit
f620255c41
@@ -1,6 +1,6 @@
|
||||
#include <Tactility/service/ServiceRegistration.h>
|
||||
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/Mutex.h>
|
||||
#include <Tactility/service/ServiceInstance.h>
|
||||
#include <Tactility/service/ServiceManifest.h>
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
namespace tt::service {
|
||||
|
||||
constexpr auto* TAG = "ServiceRegistry";
|
||||
static const auto LOGGER = Logger("ServiceRegistration");
|
||||
|
||||
typedef std::unordered_map<std::string, std::shared_ptr<const ServiceManifest>> ManifestMap;
|
||||
typedef std::unordered_map<std::string, std::shared_ptr<ServiceInstance>> ServiceInstanceMap;
|
||||
@@ -25,13 +25,13 @@ void addService(std::shared_ptr<const ServiceManifest> manifest, bool autoStart)
|
||||
// We'll move the manifest pointer, but we'll need to id later
|
||||
const auto& id = manifest->id;
|
||||
|
||||
TT_LOG_I(TAG, "Adding %s", id.c_str());
|
||||
LOGGER.info("Adding {}", id);
|
||||
|
||||
manifest_mutex.lock();
|
||||
if (service_manifest_map[id] == nullptr) {
|
||||
service_manifest_map[id] = std::move(manifest);
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Service id in use: %s", id.c_str());
|
||||
LOGGER.error("Service id in use: {}", id);
|
||||
}
|
||||
manifest_mutex.unlock();
|
||||
|
||||
@@ -62,10 +62,10 @@ static std::shared_ptr<ServiceInstance> _Nullable findServiceInstanceById(const
|
||||
|
||||
// TODO: Return proper error/status instead of BOOL?
|
||||
bool startService(const std::string& id) {
|
||||
TT_LOG_I(TAG, "Starting %s", id.c_str());
|
||||
LOGGER.info("Starting {}", id);
|
||||
auto manifest = findManifestById(id);
|
||||
if (manifest == nullptr) {
|
||||
TT_LOG_E(TAG, "manifest not found for service %s", id.c_str());
|
||||
LOGGER.error("manifest not found for service {}", id);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -80,14 +80,14 @@ bool startService(const std::string& id) {
|
||||
if (service_instance->getService()->onStart(*service_instance)) {
|
||||
service_instance->setState(State::Started);
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Starting %s failed", id.c_str());
|
||||
LOGGER.error("Starting {} failed", id);
|
||||
service_instance->setState(State::Stopped);
|
||||
instance_mutex.lock();
|
||||
service_instance_map.erase(manifest->id);
|
||||
instance_mutex.unlock();
|
||||
}
|
||||
|
||||
TT_LOG_I(TAG, "Started %s", id.c_str());
|
||||
LOGGER.info("Started {}", id);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -102,10 +102,10 @@ std::shared_ptr<Service> _Nullable findServiceById(const std::string& id) {
|
||||
}
|
||||
|
||||
bool stopService(const std::string& id) {
|
||||
TT_LOG_I(TAG, "Stopping %s", id.c_str());
|
||||
LOGGER.info("Stopping {}", id);
|
||||
auto service_instance = findServiceInstanceById(id);
|
||||
if (service_instance == nullptr) {
|
||||
TT_LOG_W(TAG, "Service not running: %s", id.c_str());
|
||||
LOGGER.warn("Service not running: {}", id);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -118,10 +118,10 @@ bool stopService(const std::string& id) {
|
||||
instance_mutex.unlock();
|
||||
|
||||
if (service_instance.use_count() > 1) {
|
||||
TT_LOG_W(TAG, "Possible memory leak: service %s still has %ld references", service_instance->getManifest().id.c_str(), service_instance.use_count() - 1);
|
||||
LOGGER.warn("Possible memory leak: service {} still has {} references", service_instance->getManifest().id, service_instance.use_count() - 1);
|
||||
}
|
||||
|
||||
TT_LOG_I(TAG, "Stopped %s", id.c_str());
|
||||
LOGGER.info("Stopped {}", id);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <Tactility/file/File.h>
|
||||
#include <Tactility/network/HttpdReq.h>
|
||||
#include <Tactility/network/Url.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/Paths.h>
|
||||
#include <Tactility/service/development/DevelopmentSettings.h>
|
||||
#include <Tactility/service/ServiceRegistration.h>
|
||||
@@ -19,7 +20,7 @@ namespace tt::service::development {
|
||||
|
||||
extern const ServiceManifest manifest;
|
||||
|
||||
constexpr const char* TAG = "DevService";
|
||||
static const auto LOGGER = Logger("DevService");
|
||||
|
||||
bool DevelopmentService::onStart(ServiceContext& service) {
|
||||
std::stringstream stream;
|
||||
@@ -65,26 +66,26 @@ bool DevelopmentService::isEnabled() const {
|
||||
// region endpoints
|
||||
|
||||
esp_err_t DevelopmentService::handleGetInfo(httpd_req_t* request) {
|
||||
TT_LOG_I(TAG, "GET /device");
|
||||
LOGGER.info("GET /device");
|
||||
|
||||
if (httpd_resp_set_type(request, "application/json") != ESP_OK) {
|
||||
TT_LOG_W(TAG, "Failed to send header");
|
||||
LOGGER.warn("Failed to send header");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
auto* service = static_cast<DevelopmentService*>(request->user_ctx);
|
||||
|
||||
if (httpd_resp_sendstr(request, service->deviceResponse.c_str()) != ESP_OK) {
|
||||
TT_LOG_W(TAG, "Failed to send response body");
|
||||
LOGGER.warn("Failed to send response body");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
TT_LOG_I(TAG, "[200] /device");
|
||||
LOGGER.info("[200] /device");
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t DevelopmentService::handleAppRun(httpd_req_t* request) {
|
||||
TT_LOG_I(TAG, "POST /app/run");
|
||||
LOGGER.info("POST /app/run");
|
||||
|
||||
std::string query;
|
||||
if (!network::getQueryOrSendError(request, query)) {
|
||||
@@ -94,7 +95,7 @@ esp_err_t DevelopmentService::handleAppRun(httpd_req_t* request) {
|
||||
auto parameters = network::parseUrlQuery(query);
|
||||
auto id_key_pos = parameters.find("id");
|
||||
if (id_key_pos == parameters.end()) {
|
||||
TT_LOG_W(TAG, "[400] /app/run id not specified");
|
||||
LOGGER.warn("[400] /app/run id not specified");
|
||||
httpd_resp_send_err(request, HTTPD_400_BAD_REQUEST, "id not specified");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
@@ -106,14 +107,14 @@ esp_err_t DevelopmentService::handleAppRun(httpd_req_t* request) {
|
||||
|
||||
app::start(app_id);
|
||||
|
||||
TT_LOG_I(TAG, "[200] /app/run %s", id_key_pos->second.c_str());
|
||||
LOGGER.info("[200] /app/run {}", id_key_pos->second);
|
||||
httpd_resp_send(request, nullptr, 0);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t DevelopmentService::handleAppInstall(httpd_req_t* request) {
|
||||
TT_LOG_I(TAG, "PUT /app/install");
|
||||
LOGGER.info("PUT /app/install");
|
||||
|
||||
std::string boundary;
|
||||
if (!network::getMultiPartBoundaryOrSendError(request, boundary)) {
|
||||
@@ -174,7 +175,7 @@ esp_err_t DevelopmentService::handleAppInstall(httpd_req_t* request) {
|
||||
content_left -= boundary_and_newlines_after_file.length();
|
||||
|
||||
if (content_left != 0) {
|
||||
TT_LOG_W(TAG, "We have more bytes at the end of the request parsing?!");
|
||||
LOGGER.warn("We have more bytes at the end of the request parsing?!");
|
||||
}
|
||||
|
||||
if (!app::install(file_path)) {
|
||||
@@ -182,11 +183,11 @@ esp_err_t DevelopmentService::handleAppInstall(httpd_req_t* request) {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
if (!file::deleteFile(file_path.c_str())) {
|
||||
TT_LOG_W(TAG, "Failed to delete %s", file_path.c_str());
|
||||
if (!file::deleteFile(file_path)) {
|
||||
LOGGER.warn("Failed to delete {}", file_path);
|
||||
}
|
||||
|
||||
TT_LOG_I(TAG, "[200] /app/install -> %s", file_path.c_str());
|
||||
LOGGER.info("[200] /app/install -> {}", file_path);
|
||||
|
||||
httpd_resp_send(request, nullptr, 0);
|
||||
|
||||
@@ -194,7 +195,7 @@ esp_err_t DevelopmentService::handleAppInstall(httpd_req_t* request) {
|
||||
}
|
||||
|
||||
esp_err_t DevelopmentService::handleAppUninstall(httpd_req_t* request) {
|
||||
TT_LOG_I(TAG, "PUT /app/uninstall");
|
||||
LOGGER.info("PUT /app/uninstall");
|
||||
|
||||
std::string query;
|
||||
if (!network::getQueryOrSendError(request, query)) {
|
||||
@@ -204,23 +205,23 @@ esp_err_t DevelopmentService::handleAppUninstall(httpd_req_t* request) {
|
||||
auto parameters = network::parseUrlQuery(query);
|
||||
auto id_key_pos = parameters.find("id");
|
||||
if (id_key_pos == parameters.end()) {
|
||||
TT_LOG_W(TAG, "[400] /app/uninstall id not specified");
|
||||
LOGGER.warn("[400] /app/uninstall id not specified");
|
||||
httpd_resp_send_err(request, HTTPD_400_BAD_REQUEST, "id not specified");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
if (!app::findAppManifestById(id_key_pos->second)) {
|
||||
TT_LOG_I(TAG, "[200] /app/uninstall %s (app wasn't installed)", id_key_pos->second.c_str());
|
||||
LOGGER.info("[200] /app/uninstall {} (app wasn't installed)", id_key_pos->second);
|
||||
httpd_resp_send(request, nullptr, 0);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
if (app::uninstall(id_key_pos->second)) {
|
||||
TT_LOG_I(TAG, "[200] /app/uninstall %s", id_key_pos->second.c_str());
|
||||
LOGGER.info("[200] /app/uninstall {}", id_key_pos->second);
|
||||
httpd_resp_send(request, nullptr, 0);
|
||||
return ESP_OK;
|
||||
} else {
|
||||
TT_LOG_W(TAG, "[500] /app/uninstall %s", id_key_pos->second.c_str());
|
||||
LOGGER.warn("[500] /app/uninstall {}", id_key_pos->second);
|
||||
httpd_resp_send_err(request, HTTPD_500_INTERNAL_SERVER_ERROR, "Failed to uninstall");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
#ifdef ESP_PLATFORM
|
||||
#include <Tactility/file/PropertiesFile.h>
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/service/development/DevelopmentSettings.h>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
namespace tt::service::development {
|
||||
|
||||
constexpr auto* TAG = "DevSettings";
|
||||
static const auto LOGGER = Logger("DevSettings");
|
||||
|
||||
constexpr auto* SETTINGS_FILE = "/data/settings/development.properties";
|
||||
constexpr auto* SETTINGS_KEY_ENABLE_ON_BOOT = "enableOnBoot";
|
||||
|
||||
@@ -39,7 +40,7 @@ static bool save(const DevelopmentSettings& settings) {
|
||||
void setEnableOnBoot(bool enable) {
|
||||
DevelopmentSettings properties { .enableOnBoot = enable };
|
||||
if (!save(properties)) {
|
||||
TT_LOG_E(TAG, "Failed to save %s", SETTINGS_FILE);
|
||||
LOGGER.error("Failed to save {}", SETTINGS_FILE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
#include <Tactility/CoreDefines.h>
|
||||
#include <Tactility/Timer.h>
|
||||
#include <Tactility/hal/display/DisplayDevice.h>
|
||||
#include <Tactility/lvgl/LvglSync.h>
|
||||
#include <Tactility/service/ServiceContext.h>
|
||||
#include <Tactility/service/ServiceManifest.h>
|
||||
#include <Tactility/service/ServiceRegistration.h>
|
||||
#include <Tactility/settings/DisplaySettings.h>
|
||||
#include <Tactility/Timer.h>
|
||||
|
||||
namespace tt::service::displayidle {
|
||||
|
||||
constexpr auto* TAG = "DisplayIdle";
|
||||
|
||||
class DisplayIdleService final : public Service {
|
||||
|
||||
std::unique_ptr<Timer> timer;
|
||||
|
||||
@@ -4,21 +4,21 @@
|
||||
|
||||
#ifdef CONFIG_ESP_WIFI_ENABLED
|
||||
|
||||
#include "Tactility/service/espnow/EspNow.h"
|
||||
#include "Tactility/service/espnow/EspNowService.h"
|
||||
#include <Tactility/service/espnow/EspNow.h>
|
||||
#include <Tactility/service/espnow/EspNowService.h>
|
||||
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/Logger.h>
|
||||
|
||||
namespace tt::service::espnow {
|
||||
|
||||
constexpr const char* TAG = "EspNow";
|
||||
static const auto LOGGER = Logger("EspNow");
|
||||
|
||||
void enable(const EspNowConfig& config) {
|
||||
auto service = findService();
|
||||
if (service != nullptr) {
|
||||
service->enable(config);
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Service not found");
|
||||
LOGGER.error("Service not found");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ void disable() {
|
||||
if (service != nullptr) {
|
||||
service->disable();
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Service not found");
|
||||
LOGGER.error("Service not found");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ bool addPeer(const esp_now_peer_info_t& peer) {
|
||||
if (service != nullptr) {
|
||||
return service->addPeer(peer);
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Service not found");
|
||||
LOGGER.error("Service not found");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -55,7 +55,7 @@ bool send(const uint8_t* address, const uint8_t* buffer, size_t bufferLength) {
|
||||
if (service != nullptr) {
|
||||
return service->send(address, buffer, bufferLength);
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Service not found");
|
||||
LOGGER.error("Service not found");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -65,7 +65,7 @@ ReceiverSubscription subscribeReceiver(std::function<void(const esp_now_recv_inf
|
||||
if (service != nullptr) {
|
||||
return service->subscribeReceiver(onReceive);
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Service not found");
|
||||
LOGGER.error("Service not found");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -75,7 +75,7 @@ void unsubscribeReceiver(ReceiverSubscription subscription) {
|
||||
if (service != nullptr) {
|
||||
service->unsubscribeReceiver(subscription);
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Service not found");
|
||||
LOGGER.error("Service not found");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#ifdef CONFIG_ESP_WIFI_ENABLED
|
||||
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/Tactility.h>
|
||||
#include <Tactility/service/espnow/EspNowService.h>
|
||||
#include <Tactility/service/ServiceManifest.h>
|
||||
@@ -18,10 +19,10 @@ namespace tt::service::espnow {
|
||||
|
||||
extern const ServiceManifest manifest;
|
||||
|
||||
constexpr const char* TAG = "EspNowService";
|
||||
constexpr TickType_t MAX_DELAY = 1000U / portTICK_PERIOD_MS;
|
||||
static const auto LOGGER = Logger("EspNowService");
|
||||
static uint8_t BROADCAST_MAC[ESP_NOW_ETH_ALEN];
|
||||
|
||||
constexpr TickType_t MAX_DELAY = 1000U / portTICK_PERIOD_MS;
|
||||
constexpr bool isBroadcastAddress(uint8_t address[ESP_NOW_ETH_ALEN]) { return memcmp(address, BROADCAST_MAC, ESP_NOW_ETH_ALEN) == 0; }
|
||||
|
||||
bool EspNowService::onStart(ServiceContext& service) {
|
||||
@@ -45,7 +46,7 @@ void EspNowService::onStop(ServiceContext& service) {
|
||||
// region Enable
|
||||
|
||||
void EspNowService::enable(const EspNowConfig& config) {
|
||||
getMainDispatcher().dispatch([this, config]() {
|
||||
getMainDispatcher().dispatch([this, config] {
|
||||
enableFromDispatcher(config);
|
||||
});
|
||||
}
|
||||
@@ -59,17 +60,17 @@ void EspNowService::enableFromDispatcher(const EspNowConfig& config) {
|
||||
}
|
||||
|
||||
if (!initWifi(config)) {
|
||||
TT_LOG_E(TAG, "initWifi() failed");
|
||||
LOGGER.error("initWifi() failed");
|
||||
return;
|
||||
}
|
||||
|
||||
if (esp_now_init() != ESP_OK) {
|
||||
TT_LOG_E(TAG, "esp_now_init() failed");
|
||||
LOGGER.error("esp_now_init() failed");
|
||||
return;
|
||||
}
|
||||
|
||||
if (esp_now_register_recv_cb(receiveCallback) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "esp_now_register_recv_cb() failed");
|
||||
LOGGER.error("esp_now_register_recv_cb() failed");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -79,7 +80,7 @@ void EspNowService::enableFromDispatcher(const EspNowConfig& config) {
|
||||
//#endif
|
||||
|
||||
if (esp_now_set_pmk(config.masterKey) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "esp_now_set_pmk() failed");
|
||||
LOGGER.error("esp_now_set_pmk() failed");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -111,11 +112,11 @@ void EspNowService::disableFromDispatcher() {
|
||||
}
|
||||
|
||||
if (esp_now_deinit() != ESP_OK) {
|
||||
TT_LOG_E(TAG, "esp_now_deinit() failed");
|
||||
LOGGER.error("esp_now_deinit() failed");
|
||||
}
|
||||
|
||||
if (!deinitWifi()) {
|
||||
TT_LOG_E(TAG, "deinitWifi() failed");
|
||||
LOGGER.error("deinitWifi() failed");
|
||||
}
|
||||
|
||||
enabled = false;
|
||||
@@ -128,7 +129,7 @@ void EspNowService::disableFromDispatcher() {
|
||||
void EspNowService::receiveCallback(const esp_now_recv_info_t* receiveInfo, const uint8_t* data, int length) {
|
||||
auto service = findService();
|
||||
if (service == nullptr) {
|
||||
TT_LOG_E(TAG, "Service not running");
|
||||
LOGGER.error("Service not running");
|
||||
return;
|
||||
}
|
||||
service->onReceive(receiveInfo, data, length);
|
||||
@@ -138,7 +139,7 @@ void EspNowService::onReceive(const esp_now_recv_info_t* receiveInfo, const uint
|
||||
auto lock = mutex.asScopedLock();
|
||||
lock.lock();
|
||||
|
||||
TT_LOG_D(TAG, "Received %d bytes", length);
|
||||
LOGGER.debug("Received {} bytes", length);
|
||||
|
||||
for (const auto& item: subscriptions) {
|
||||
item.onReceive(receiveInfo, data, length);
|
||||
@@ -155,10 +156,10 @@ bool EspNowService::isEnabled() const {
|
||||
|
||||
bool EspNowService::addPeer(const esp_now_peer_info_t& peer) {
|
||||
if (esp_now_add_peer(&peer) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Failed to add peer");
|
||||
LOGGER.error("Failed to add peer");
|
||||
return false;
|
||||
} else {
|
||||
TT_LOG_I(TAG, "Peer added");
|
||||
LOGGER.info("Peer added");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -188,7 +189,7 @@ ReceiverSubscription EspNowService::subscribeReceiver(std::function<void(const e
|
||||
return id;
|
||||
}
|
||||
|
||||
void EspNowService::unsubscribeReceiver(tt::service::espnow::ReceiverSubscription subscriptionId) {
|
||||
void EspNowService::unsubscribeReceiver(ReceiverSubscription subscriptionId) {
|
||||
auto lock = mutex.asScopedLock();
|
||||
lock.lock();
|
||||
std::erase_if(subscriptions, [subscriptionId](auto& subscription) { return subscription.id == subscriptionId; });
|
||||
@@ -196,7 +197,7 @@ void EspNowService::unsubscribeReceiver(tt::service::espnow::ReceiverSubscriptio
|
||||
|
||||
std::shared_ptr<EspNowService> findService() {
|
||||
return std::static_pointer_cast<EspNowService>(
|
||||
service::findServiceById(manifest.id)
|
||||
findServiceById(manifest.id)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#ifdef CONFIG_ESP_WIFI_ENABLED
|
||||
|
||||
#include <Tactility/kernel/Kernel.h>
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/service/espnow/EspNow.h>
|
||||
#include <Tactility/service/wifi/Wifi.h>
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
namespace tt::service::espnow {
|
||||
|
||||
constexpr const char* TAG = "EspNowService";
|
||||
static const auto LOGGER = Logger("EspNowService");
|
||||
|
||||
static bool disableWifiService() {
|
||||
auto wifi_state = wifi::getRadioState();
|
||||
@@ -43,7 +43,7 @@ bool initWifi(const EspNowConfig& config) {
|
||||
// If WiFi is already connected, keep it running and just add ESP-NOW on top
|
||||
if (!wifi_was_connected && wifi_state != wifi::RadioState::Off && wifi_state != wifi::RadioState::OffPending) {
|
||||
if (!disableWifiService()) {
|
||||
TT_LOG_E(TAG, "Failed to disable wifi");
|
||||
LOGGER.error("Failed to disable wifi");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -60,28 +60,28 @@ bool initWifi(const EspNowConfig& config) {
|
||||
if (wifi::getRadioState() == wifi::RadioState::Off) {
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
if (esp_wifi_init(&cfg) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "esp_wifi_init() failed");
|
||||
LOGGER.error("esp_wifi_init() failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (esp_wifi_set_storage(WIFI_STORAGE_RAM) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "esp_wifi_set_storage() failed");
|
||||
LOGGER.error("esp_wifi_set_storage() failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (esp_wifi_set_mode(mode) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "esp_wifi_set_mode() failed");
|
||||
LOGGER.error("esp_wifi_set_mode() failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (esp_wifi_start() != ESP_OK) {
|
||||
TT_LOG_E(TAG, "esp_wifi_start() failed");
|
||||
LOGGER.error("esp_wifi_start() failed");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (esp_wifi_set_channel(config.channel, WIFI_SECOND_CHAN_NONE) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "esp_wifi_set_channel() failed");
|
||||
LOGGER.error("esp_wifi_set_channel() failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -94,11 +94,11 @@ bool initWifi(const EspNowConfig& config) {
|
||||
}
|
||||
|
||||
if (esp_wifi_set_protocol(wifi_interface, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N | WIFI_PROTOCOL_LR) != ESP_OK) {
|
||||
TT_LOG_W(TAG, "esp_wifi_set_protocol() for long range failed");
|
||||
LOGGER.warn("esp_wifi_set_protocol() for long range failed");
|
||||
}
|
||||
}
|
||||
|
||||
TT_LOG_I(TAG, "WiFi initialized for ESP-NOW (preserved existing connection: %s)", wifi_was_connected ? "yes" : "no");
|
||||
LOGGER.info("WiFi initialized for ESP-NOW (preserved existing connection: {})", wifi_was_connected ? "yes" : "no");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ bool deinitWifi() {
|
||||
// Since we're only using WiFi for ESP-NOW, we can safely keep it in a minimal state
|
||||
// or shut it down. For now, keep it running to support STA + ESP-NOW coexistence.
|
||||
|
||||
TT_LOG_I(TAG, "ESP-NOW WiFi deinitialized (WiFi service continues independently)");
|
||||
LOGGER.info("ESP-NOW WiFi deinitialized (WiFi service continues independently)");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <Tactility/file/ObjectFile.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/service/gps/GpsService.h>
|
||||
#include <Tactility/service/ServicePaths.h>
|
||||
|
||||
@@ -9,16 +10,16 @@ using tt::hal::gps::GpsDevice;
|
||||
|
||||
namespace tt::service::gps {
|
||||
|
||||
constexpr const char* TAG = "GpsService";
|
||||
static const auto LOGGER = Logger("GpsService");
|
||||
|
||||
bool GpsService::getConfigurationFilePath(std::string& output) const {
|
||||
if (paths == nullptr) {
|
||||
TT_LOG_E(TAG, "Can't add configuration: service not started");
|
||||
LOGGER.error("Can't add configuration: service not started");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!file::findOrCreateDirectory(paths->getUserDataDirectory(), 0777)) {
|
||||
TT_LOG_E(TAG, "Failed to find or create path %s", paths->getUserDataDirectory().c_str());
|
||||
LOGGER.error("Failed to find or create path {}", paths->getUserDataDirectory());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -34,21 +35,21 @@ bool GpsService::getGpsConfigurations(std::vector<hal::gps::GpsConfiguration>& c
|
||||
|
||||
// If file does not exist, return empty list
|
||||
if (access(path.c_str(), F_OK) != 0) {
|
||||
TT_LOG_W(TAG, "No configurations (file not found: %s)", path.c_str());
|
||||
LOGGER.warn("No configurations (file not found: {})", path);
|
||||
return true;
|
||||
}
|
||||
|
||||
TT_LOG_I(TAG, "Reading configuration file %s", path.c_str());
|
||||
LOGGER.info("Reading configuration file {}", path);
|
||||
auto reader = file::ObjectFileReader(path, sizeof(hal::gps::GpsConfiguration));
|
||||
if (!reader.open()) {
|
||||
TT_LOG_E(TAG, "Failed to open configuration file");
|
||||
LOGGER.error("Failed to open configuration file");
|
||||
return false;
|
||||
}
|
||||
|
||||
hal::gps::GpsConfiguration configuration;
|
||||
while (reader.hasNext()) {
|
||||
if (!reader.readNext(&configuration)) {
|
||||
TT_LOG_E(TAG, "Failed to read configuration");
|
||||
LOGGER.error("Failed to read configuration");
|
||||
reader.close();
|
||||
return false;
|
||||
} else {
|
||||
@@ -67,12 +68,12 @@ bool GpsService::addGpsConfiguration(hal::gps::GpsConfiguration configuration) {
|
||||
|
||||
auto appender = file::ObjectFileWriter(path, sizeof(hal::gps::GpsConfiguration), 1, true);
|
||||
if (!appender.open()) {
|
||||
TT_LOG_E(TAG, "Failed to open/create configuration file");
|
||||
LOGGER.error("Failed to open/create configuration file");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!appender.write(&configuration)) {
|
||||
TT_LOG_E(TAG, "Failed to add configuration");
|
||||
LOGGER.error("Failed to add configuration");
|
||||
appender.close();
|
||||
return false;
|
||||
}
|
||||
@@ -89,7 +90,7 @@ bool GpsService::removeGpsConfiguration(hal::gps::GpsConfiguration configuration
|
||||
|
||||
std::vector<hal::gps::GpsConfiguration> configurations;
|
||||
if (!getGpsConfigurations(configurations)) {
|
||||
TT_LOG_E(TAG, "Failed to get gps configurations");
|
||||
LOGGER.error("Failed to get gps configurations");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -101,7 +102,7 @@ bool GpsService::removeGpsConfiguration(hal::gps::GpsConfiguration configuration
|
||||
|
||||
auto writer = file::ObjectFileWriter(path, sizeof(hal::gps::GpsConfiguration), 1, false);
|
||||
if (!writer.open()) {
|
||||
TT_LOG_E(TAG, "Failed to open configuration file");
|
||||
LOGGER.error("Failed to open configuration file");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <Tactility/service/gps/GpsService.h>
|
||||
|
||||
#include <Tactility/file/File.h>
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/service/ServicePaths.h>
|
||||
#include <Tactility/service/ServiceManifest.h>
|
||||
#include <Tactility/service/ServiceRegistration.h>
|
||||
@@ -10,7 +10,7 @@ using tt::hal::gps::GpsDevice;
|
||||
|
||||
namespace tt::service::gps {
|
||||
|
||||
constexpr const char* TAG = "GpsService";
|
||||
static const auto LOGGER = Logger("GpsService");
|
||||
extern const ServiceManifest manifest;
|
||||
|
||||
constexpr bool hasTimeElapsed(TickType_t now, TickType_t timeInThePast, TickType_t expireTimeInTicks) {
|
||||
@@ -73,7 +73,7 @@ void GpsService::onStop(ServiceContext& serviceContext) {
|
||||
}
|
||||
|
||||
bool GpsService::startGpsDevice(GpsDeviceRecord& record) {
|
||||
TT_LOG_I(TAG, "[device %lu] starting", record.device->getId());
|
||||
LOGGER.info("[device {}] starting", record.device->getId());
|
||||
|
||||
auto lock = mutex.asScopedLock();
|
||||
lock.lock();
|
||||
@@ -81,7 +81,7 @@ bool GpsService::startGpsDevice(GpsDeviceRecord& record) {
|
||||
auto device = record.device;
|
||||
|
||||
if (!device->start()) {
|
||||
TT_LOG_E(TAG, "[device %lu] starting failed", record.device->getId());
|
||||
LOGGER.error("[device {}] starting failed", record.device->getId());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ bool GpsService::startGpsDevice(GpsDeviceRecord& record) {
|
||||
}
|
||||
|
||||
bool GpsService::stopGpsDevice(GpsDeviceRecord& record) {
|
||||
TT_LOG_I(TAG, "[device %lu] stopping", record.device->getId());
|
||||
LOGGER.info("[device {}] stopping", record.device->getId());
|
||||
|
||||
auto device = record.device;
|
||||
|
||||
@@ -116,7 +116,7 @@ bool GpsService::stopGpsDevice(GpsDeviceRecord& record) {
|
||||
record.rmcSubscriptionId = -1;
|
||||
|
||||
if (!device->stop()) {
|
||||
TT_LOG_E(TAG, "[device %lu] stopping failed", record.device->getId());
|
||||
LOGGER.error("[device {}] stopping failed", record.device->getId());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -124,10 +124,10 @@ bool GpsService::stopGpsDevice(GpsDeviceRecord& record) {
|
||||
}
|
||||
|
||||
bool GpsService::startReceiving() {
|
||||
TT_LOG_I(TAG, "Start receiving");
|
||||
LOGGER.info("Start receiving");
|
||||
|
||||
if (getState() != State::Off) {
|
||||
TT_LOG_E(TAG, "Already receiving");
|
||||
LOGGER.error("Already receiving");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -140,13 +140,13 @@ bool GpsService::startReceiving() {
|
||||
|
||||
std::vector<hal::gps::GpsConfiguration> configurations;
|
||||
if (!getGpsConfigurations(configurations)) {
|
||||
TT_LOG_E(TAG, "Failed to get GPS configurations");
|
||||
LOGGER.error("Failed to get GPS configurations");
|
||||
setState(State::Off);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (configurations.empty()) {
|
||||
TT_LOG_E(TAG, "No GPS configurations");
|
||||
LOGGER.error("No GPS configurations");
|
||||
setState(State::Off);
|
||||
return false;
|
||||
}
|
||||
@@ -174,7 +174,7 @@ bool GpsService::startReceiving() {
|
||||
}
|
||||
|
||||
void GpsService::stopReceiving() {
|
||||
TT_LOG_I(TAG, "Stop receiving");
|
||||
LOGGER.info("Stop receiving");
|
||||
|
||||
setState(State::OffPending);
|
||||
|
||||
@@ -191,11 +191,11 @@ void GpsService::stopReceiving() {
|
||||
}
|
||||
|
||||
void GpsService::onGgaSentence(hal::Device::Id deviceId, const minmea_sentence_gga& gga) {
|
||||
TT_LOG_D(TAG, "[device %lu] LAT %f LON %f, satellites: %d", deviceId, minmea_tocoord(&gga.latitude), minmea_tocoord(&gga.longitude), gga.satellites_tracked);
|
||||
LOGGER.debug("[device {}] LAT {} LON {}, satellites: {}", deviceId, minmea_tocoord(&gga.latitude), minmea_tocoord(&gga.longitude), gga.satellites_tracked);
|
||||
}
|
||||
|
||||
void GpsService::onRmcSentence(hal::Device::Id deviceId, const minmea_sentence_rmc& rmc) {
|
||||
TT_LOG_D(TAG, "[device %lu] LAT %f LON %f, speed: %.2f", deviceId, minmea_tocoord(&rmc.latitude), minmea_tocoord(&rmc.longitude), minmea_tofloat(&rmc.speed));
|
||||
LOGGER.debug("[device {}] LAT {} LON {}, speed: {}", deviceId, minmea_tocoord(&rmc.latitude), minmea_tocoord(&rmc.longitude), minmea_tofloat(&rmc.speed));
|
||||
}
|
||||
|
||||
State GpsService::getState() const {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include <Tactility/service/gui/GuiService.h>
|
||||
|
||||
#include <Tactility/app/AppInstance.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/LogMessages.h>
|
||||
#include <Tactility/lvgl/LvglSync.h>
|
||||
#include <Tactility/lvgl/Statusbar.h>
|
||||
#include <Tactility/service/loader/Loader.h>
|
||||
@@ -10,7 +12,7 @@
|
||||
namespace tt::service::gui {
|
||||
|
||||
extern const ServiceManifest manifest;
|
||||
constexpr auto* TAG = "GuiService";
|
||||
static const auto LOGGER = Logger("GuiService");
|
||||
using namespace loader;
|
||||
|
||||
// region AppManifest
|
||||
@@ -39,10 +41,7 @@ int32_t GuiService::guiMain() {
|
||||
// Process and dispatch draw call
|
||||
if (flags & GUI_THREAD_FLAG_DRAW) {
|
||||
service->threadFlags.clear(GUI_THREAD_FLAG_DRAW);
|
||||
auto service = findService();
|
||||
if (service != nullptr) {
|
||||
service->redraw();
|
||||
}
|
||||
service->redraw();
|
||||
}
|
||||
|
||||
if (flags & GUI_THREAD_FLAG_EXIT) {
|
||||
@@ -103,13 +102,13 @@ void GuiService::redraw() {
|
||||
lv_obj_t* container = createAppViews(appRootWidget);
|
||||
appToRender->getApp()->onShow(*appToRender, container);
|
||||
} else {
|
||||
TT_LOG_W(TAG, "nothing to draw");
|
||||
LOGGER.warn("nothing to draw");
|
||||
}
|
||||
|
||||
// Unlock GUI and LVGL
|
||||
lvgl::unlock();
|
||||
} else {
|
||||
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "LVGL");
|
||||
LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "LVGL");
|
||||
}
|
||||
|
||||
unlock();
|
||||
@@ -118,7 +117,7 @@ void GuiService::redraw() {
|
||||
bool GuiService::onStart(TT_UNUSED ServiceContext& service) {
|
||||
auto* screen_root = lv_screen_active();
|
||||
if (screen_root == nullptr) {
|
||||
TT_LOG_E(TAG, "No display found");
|
||||
LOGGER.error("No display found");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -202,16 +201,16 @@ void GuiService::showApp(std::shared_ptr<app::AppInstance> app) {
|
||||
lock.lock();
|
||||
|
||||
if (!isStarted) {
|
||||
TT_LOG_E(TAG, "Failed to show app %s: GUI not started", app->getManifest().appId.c_str());
|
||||
LOGGER.error("Failed to show app {}: GUI not started", app->getManifest().appId);
|
||||
return;
|
||||
}
|
||||
|
||||
if (appToRender != nullptr && appToRender->getLaunchId() == app->getLaunchId()) {
|
||||
TT_LOG_W(TAG, "Already showing %s", app->getManifest().appId.c_str());
|
||||
LOGGER.warn("Already showing {}", app->getManifest().appId);
|
||||
return;
|
||||
}
|
||||
|
||||
TT_LOG_I(TAG, "Showing %s", app->getManifest().appId.c_str());
|
||||
LOGGER.info("Showing {}", app->getManifest().appId);
|
||||
// Ensure previous app triggers onHide() logic
|
||||
if (appToRender != nullptr) {
|
||||
hideApp();
|
||||
@@ -226,12 +225,12 @@ void GuiService::hideApp() {
|
||||
lock.lock();
|
||||
|
||||
if (!isStarted) {
|
||||
TT_LOG_E(TAG, "Failed to hide app: GUI not started");
|
||||
LOGGER.error("Failed to hide app: GUI not started");
|
||||
return;
|
||||
}
|
||||
|
||||
if (appToRender == nullptr) {
|
||||
TT_LOG_W(TAG, "hideApp() called but no app is currently shown");
|
||||
LOGGER.warn("hideApp() called but no app is currently shown");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,8 +15,6 @@ namespace keyboardbacklight {
|
||||
|
||||
namespace tt::service::keyboardidle {
|
||||
|
||||
constexpr auto* TAG = "KeyboardIdle";
|
||||
|
||||
class KeyboardIdleService final : public Service {
|
||||
|
||||
std::unique_ptr<Timer> timer;
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#include <Tactility/app/AppRegistration.h>
|
||||
|
||||
#include <Tactility/DispatcherThread.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/LogMessages.h>
|
||||
#include <Tactility/service/ServiceManifest.h>
|
||||
#include <Tactility/service/ServiceRegistration.h>
|
||||
|
||||
@@ -16,7 +18,8 @@
|
||||
|
||||
namespace tt::service::loader {
|
||||
|
||||
constexpr auto* TAG = "Loader";
|
||||
static const auto LOGGER = Logger("Boot");
|
||||
|
||||
constexpr auto LOADER_TIMEOUT = (100 / portTICK_PERIOD_MS);
|
||||
|
||||
// Forward declaration
|
||||
@@ -41,17 +44,17 @@ static const char* appStateToString(app::State state) {
|
||||
}
|
||||
|
||||
void LoaderService::onStartAppMessage(const std::string& id, app::LaunchId launchId, std::shared_ptr<const Bundle> parameters) {
|
||||
TT_LOG_I(TAG, "Start by id %s", id.c_str());
|
||||
LOGGER.info("Start by id {}", id);
|
||||
|
||||
auto app_manifest = app::findAppManifestById(id);
|
||||
if (app_manifest == nullptr) {
|
||||
TT_LOG_E(TAG, "App not found: %s", id.c_str());
|
||||
LOGGER.error("App not found: {}", id);
|
||||
return;
|
||||
}
|
||||
|
||||
auto lock = mutex.asScopedLock();
|
||||
if (!lock.lock(LOADER_TIMEOUT)) {
|
||||
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
||||
LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -73,14 +76,14 @@ void LoaderService::onStartAppMessage(const std::string& id, app::LaunchId launc
|
||||
void LoaderService::onStopTopAppMessage(const std::string& id) {
|
||||
auto lock = mutex.asScopedLock();
|
||||
if (!lock.lock(LOADER_TIMEOUT)) {
|
||||
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
||||
LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
||||
return;
|
||||
}
|
||||
|
||||
size_t original_stack_size = appStack.size();
|
||||
|
||||
if (original_stack_size == 0) {
|
||||
TT_LOG_E(TAG, "Stop app: no app running");
|
||||
LOGGER.error("Stop app: no app running");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -88,12 +91,12 @@ void LoaderService::onStopTopAppMessage(const std::string& id) {
|
||||
auto app_to_stop = appStack[appStack.size() - 1];
|
||||
|
||||
if (app_to_stop->getManifest().appId != id) {
|
||||
TT_LOG_E(TAG, "Stop app: id mismatch (wanted %s but found %s on top of stack)", id.c_str(), app_to_stop->getManifest().appId.c_str());
|
||||
LOGGER.error("Stop app: id mismatch (wanted {} but found {} on top of stack)", id, app_to_stop->getManifest().appId);
|
||||
return;
|
||||
}
|
||||
|
||||
if (original_stack_size == 1 && app_to_stop->getManifest().appName != "Boot") {
|
||||
TT_LOG_E(TAG, "Stop app: can't stop root app");
|
||||
LOGGER.error("Stop app: can't stop root app");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -113,16 +116,16 @@ void LoaderService::onStopTopAppMessage(const std::string& id) {
|
||||
|
||||
// We only expect the app to be referenced within the current scope
|
||||
if (app_to_stop.use_count() > 1) {
|
||||
TT_LOG_W(TAG, "Memory leak: Stopped %s, but use count is %ld", app_to_stop->getManifest().appId.c_str(), app_to_stop.use_count() - 1);
|
||||
LOGGER.warn("Memory leak: Stopped {}, but use count is {}", app_to_stop->getManifest().appId, app_to_stop.use_count() - 1);
|
||||
}
|
||||
|
||||
// Refcount is expected to be 2: 1 within app_to_stop and 1 within the current scope
|
||||
if (app_to_stop->getApp().use_count() > 2) {
|
||||
TT_LOG_W(TAG, "Memory leak: Stopped %s, but use count is %ld", app_to_stop->getManifest().appId.c_str(), app_to_stop->getApp().use_count() - 2);
|
||||
LOGGER.warn("Memory leak: Stopped {}, but use count is {}", app_to_stop->getManifest().appId, app_to_stop->getApp().use_count() - 2);
|
||||
}
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
TT_LOG_I(TAG, "Free heap: %zu", heap_caps_get_free_size(MALLOC_CAP_INTERNAL));
|
||||
LOGGER.info("Free heap: {}", heap_caps_get_free_size(MALLOC_CAP_INTERNAL));
|
||||
#endif
|
||||
|
||||
std::shared_ptr<app::AppInstance> instance_to_resume;
|
||||
@@ -179,18 +182,18 @@ int LoaderService::findAppInStack(const std::string& id) const {
|
||||
void LoaderService::onStopAllAppMessage(const std::string& id) {
|
||||
auto lock = mutex.asScopedLock();
|
||||
if (!lock.lock(LOADER_TIMEOUT)) {
|
||||
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
||||
LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isRunning(id)) {
|
||||
TT_LOG_E(TAG, "Stop all: %s not running", id.c_str());
|
||||
LOGGER.error("Stop all: {} not running", id);
|
||||
return;
|
||||
}
|
||||
|
||||
int app_to_stop_index = findAppInStack(id);
|
||||
if (app_to_stop_index < 0) {
|
||||
TT_LOG_E(TAG, "Stop all: %s not found in stack", id.c_str());
|
||||
LOGGER.error("Stop all: {} not found in stack", id);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -217,7 +220,7 @@ void LoaderService::onStopAllAppMessage(const std::string& id) {
|
||||
}
|
||||
|
||||
if (instance_to_resume != nullptr) {
|
||||
TT_LOG_I(TAG, "Resuming %s", instance_to_resume->getManifest().appId.c_str());
|
||||
LOGGER.info("Resuming {}", instance_to_resume->getManifest().appId);
|
||||
transitionAppToState(instance_to_resume, app::State::Showing);
|
||||
|
||||
instance_to_resume->getApp()->onResult(
|
||||
@@ -233,10 +236,8 @@ void LoaderService::transitionAppToState(const std::shared_ptr<app::AppInstance>
|
||||
const app::AppManifest& app_manifest = app->getManifest();
|
||||
const app::State old_state = app->getState();
|
||||
|
||||
TT_LOG_I(
|
||||
TAG,
|
||||
"App \"%s\" state: %s -> %s",
|
||||
app_manifest.appId.c_str(),
|
||||
LOGGER.info( "App \"{}\" state: {} -> {}",
|
||||
app_manifest.appId,
|
||||
appStateToString(old_state),
|
||||
appStateToString(state)
|
||||
);
|
||||
@@ -283,14 +284,14 @@ void LoaderService::stopTop() {
|
||||
}
|
||||
|
||||
void LoaderService::stopTop(const std::string& id) {
|
||||
TT_LOG_I(TAG, "dispatching stopTop(%s)", id.c_str());
|
||||
LOGGER.info("dispatching stopTop({})", id);
|
||||
dispatcherThread->dispatch([this, id] {
|
||||
onStopTopAppMessage(id);
|
||||
});
|
||||
}
|
||||
|
||||
void LoaderService::stopAll(const std::string& id) {
|
||||
TT_LOG_I(TAG, "dispatching stopAll(%s)", id.c_str());
|
||||
LOGGER.info("dispatching stopAll({})", id);
|
||||
dispatcherThread->dispatch([this, id] {
|
||||
onStopAllAppMessage(id);
|
||||
});
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#include <Tactility/Tactility.h>
|
||||
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/lvgl/Statusbar.h>
|
||||
#include <Tactility/service/ServiceContext.h>
|
||||
#include <Tactility/service/ServiceManifest.h>
|
||||
@@ -7,7 +9,7 @@
|
||||
|
||||
namespace tt::service::memorychecker {
|
||||
|
||||
constexpr const char* TAG = "MemoryChecker";
|
||||
static const auto LOGGER = Logger("MemoryChecker");
|
||||
|
||||
// Total memory (in bytes) that should be free before warnings occur
|
||||
constexpr auto TOTAL_FREE_THRESHOLD = 10'000;
|
||||
@@ -36,13 +38,13 @@ static bool isMemoryLow() {
|
||||
bool memory_low = false;
|
||||
const auto total_free = getInternalFree();
|
||||
if (total_free < TOTAL_FREE_THRESHOLD) {
|
||||
TT_LOG_W(TAG, "Internal memory low: %zu bytes", total_free);
|
||||
LOGGER.warn("Internal memory low: {} bytes", total_free);
|
||||
memory_low = true;
|
||||
}
|
||||
|
||||
const auto largest_block = getInternalLargestFreeBlock();
|
||||
if (largest_block < LARGEST_FREE_BLOCK_THRESHOLD) {
|
||||
TT_LOG_W(TAG, "Largest free internal memory block is %zu bytes", largest_block);
|
||||
LOGGER.warn("Largest free internal memory block is {} bytes", largest_block);
|
||||
memory_low = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#if TT_FEATURE_SCREENSHOT_ENABLED
|
||||
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/LogMessages.h>
|
||||
#include <Tactility/service/screenshot/Screenshot.h>
|
||||
#include <Tactility/service/ServiceRegistration.h>
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
namespace tt::service::screenshot {
|
||||
|
||||
constexpr auto* TAG = "ScreenshotService";
|
||||
static const auto LOGGER = Logger("ScreenshotService");
|
||||
|
||||
extern const ServiceManifest manifest;
|
||||
|
||||
@@ -23,7 +23,7 @@ std::shared_ptr<ScreenshotService> _Nullable optScreenshotService() {
|
||||
void ScreenshotService::startApps(const std::string& path) {
|
||||
auto lock = mutex.asScopedLock();
|
||||
if (!lock.lock(50 / portTICK_PERIOD_MS)) {
|
||||
TT_LOG_W(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
||||
LOGGER.warn(LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -32,14 +32,14 @@ void ScreenshotService::startApps(const std::string& path) {
|
||||
mode = Mode::Apps;
|
||||
task->startApps(path);
|
||||
} else {
|
||||
TT_LOG_W(TAG, "Screenshot task already running");
|
||||
LOGGER.warn("Screenshot task already running");
|
||||
}
|
||||
}
|
||||
|
||||
void ScreenshotService::startTimed(const std::string& path, uint8_t delayInSeconds, uint8_t amount) {
|
||||
auto lock = mutex.asScopedLock();
|
||||
if (!lock.lock(50 / portTICK_PERIOD_MS)) {
|
||||
TT_LOG_W(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
||||
LOGGER.warn(LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -48,13 +48,13 @@ void ScreenshotService::startTimed(const std::string& path, uint8_t delayInSecon
|
||||
mode = Mode::Timed;
|
||||
task->startTimed(path, delayInSeconds, amount);
|
||||
} else {
|
||||
TT_LOG_W(TAG, "Screenshot task already running");
|
||||
LOGGER.warn("Screenshot task already running");
|
||||
}
|
||||
}
|
||||
|
||||
bool ScreenshotService::onStart(ServiceContext& serviceContext) {
|
||||
if (lv_screen_active() == nullptr) {
|
||||
TT_LOG_E(TAG, "No display found");
|
||||
LOGGER.error("No display found");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ bool ScreenshotService::onStart(ServiceContext& serviceContext) {
|
||||
void ScreenshotService::stop() {
|
||||
auto lock = mutex.asScopedLock();
|
||||
if (!lock.lock(50 / portTICK_PERIOD_MS)) {
|
||||
TT_LOG_W(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
||||
LOGGER.warn(LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -72,14 +72,14 @@ void ScreenshotService::stop() {
|
||||
task = nullptr;
|
||||
mode = Mode::None;
|
||||
} else {
|
||||
TT_LOG_W(TAG, "Screenshot task not running");
|
||||
LOGGER.warn("Screenshot task not running");
|
||||
}
|
||||
}
|
||||
|
||||
Mode ScreenshotService::getMode() const {
|
||||
auto lock = mutex.asScopedLock();
|
||||
if (!lock.lock(50 / portTICK_PERIOD_MS)) {
|
||||
TT_LOG_W(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
||||
LOGGER.warn(LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
||||
return Mode::None;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
#include "Tactility/TactilityConfig.h"
|
||||
#include <Tactility/TactilityConfig.h>
|
||||
|
||||
#if TT_FEATURE_SCREENSHOT_ENABLED
|
||||
|
||||
#include "Tactility/service/screenshot/ScreenshotTask.h"
|
||||
|
||||
#include "Tactility/service/loader/Loader.h"
|
||||
#include "Tactility/lvgl/LvglSync.h"
|
||||
|
||||
#include <lv_screenshot.h>
|
||||
#include <Tactility/CpuAffinity.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/LogMessages.h>
|
||||
#include <Tactility/lvgl/LvglSync.h>
|
||||
#include <Tactility/service/screenshot/ScreenshotTask.h>
|
||||
#include <Tactility/service/loader/Loader.h>
|
||||
#include <Tactility/TactilityCore.h>
|
||||
|
||||
#include <lv_screenshot.h>
|
||||
|
||||
#include <format>
|
||||
#include <Tactility/CpuAffinity.h>
|
||||
|
||||
namespace tt::service::screenshot {
|
||||
|
||||
#define TAG "screenshot_task"
|
||||
static const auto LOGGER = Logger("ScreenshotTask");
|
||||
|
||||
ScreenshotTask::~ScreenshotTask() {
|
||||
if (thread) {
|
||||
@@ -26,7 +27,7 @@ ScreenshotTask::~ScreenshotTask() {
|
||||
bool ScreenshotTask::isInterrupted() {
|
||||
auto lock = mutex.asScopedLock();
|
||||
if (!lock.lock(50 / portTICK_PERIOD_MS)) {
|
||||
TT_LOG_W(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
||||
LOGGER.warn(LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
||||
return true;
|
||||
}
|
||||
return interrupted;
|
||||
@@ -35,7 +36,7 @@ bool ScreenshotTask::isInterrupted() {
|
||||
bool ScreenshotTask::isFinished() {
|
||||
auto lock = mutex.asScopedLock();
|
||||
if (!lock.lock(50 / portTICK_PERIOD_MS)) {
|
||||
TT_LOG_W(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
||||
LOGGER.warn(LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
||||
return false;
|
||||
}
|
||||
return finished;
|
||||
@@ -50,13 +51,13 @@ void ScreenshotTask::setFinished() {
|
||||
static void makeScreenshot(const std::string& filename) {
|
||||
if (lvgl::lock(50 / portTICK_PERIOD_MS)) {
|
||||
if (lv_screenshot_create(lv_scr_act(), LV_100ASK_SCREENSHOT_SV_PNG, filename.c_str())) {
|
||||
TT_LOG_I(TAG, "Screenshot saved to %s", filename.c_str());
|
||||
LOGGER.info("Screenshot saved to {}", filename);
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Screenshot not saved to %s", filename.c_str());
|
||||
LOGGER.error("Screenshot not saved to {}", filename);
|
||||
}
|
||||
lvgl::unlock();
|
||||
} else {
|
||||
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "LVGL");
|
||||
LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "LVGL");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,7 +103,7 @@ void ScreenshotTask::taskMain() {
|
||||
void ScreenshotTask::taskStart() {
|
||||
auto lock = mutex.asScopedLock();
|
||||
if (!lock.lock(50 / portTICK_PERIOD_MS)) {
|
||||
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
||||
LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -122,7 +123,7 @@ void ScreenshotTask::taskStart() {
|
||||
void ScreenshotTask::startApps(const std::string& path) {
|
||||
auto lock = mutex.asScopedLock();
|
||||
if (!lock.lock(50 / portTICK_PERIOD_MS)) {
|
||||
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
||||
LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -132,14 +133,14 @@ void ScreenshotTask::startApps(const std::string& path) {
|
||||
work.path = path;
|
||||
taskStart();
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Task was already running");
|
||||
LOGGER.error("Task was already running");
|
||||
}
|
||||
}
|
||||
|
||||
void ScreenshotTask::startTimed(const std::string& path, uint8_t delay_in_seconds, uint8_t amount) {
|
||||
auto lock = mutex.asScopedLock();
|
||||
if (!lock.lock(50 / portTICK_PERIOD_MS)) {
|
||||
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
||||
LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -151,7 +152,7 @@ void ScreenshotTask::startTimed(const std::string& path, uint8_t delay_in_second
|
||||
work.path = path;
|
||||
taskStart();
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Task was already running");
|
||||
LOGGER.error("Task was already running");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
#include <Tactility/hal/sdcard/SdCardDevice.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/LogMessages.h>
|
||||
#include <Tactility/Mutex.h>
|
||||
#include <Tactility/service/ServiceContext.h>
|
||||
#include <Tactility/service/ServiceRegistration.h>
|
||||
|
||||
#include <Tactility/Timer.h>
|
||||
#include <Tactility/Mutex.h>
|
||||
#include <Tactility/Tactility.h>
|
||||
#include <Tactility/hal/sdcard/SdCardDevice.h>
|
||||
#include <Tactility/Timer.h>
|
||||
|
||||
namespace tt::service::sdcard {
|
||||
|
||||
constexpr auto* TAG = "SdcardService";
|
||||
static const auto LOGGER = Logger("SdcardService");
|
||||
|
||||
extern const ServiceManifest manifest;
|
||||
|
||||
@@ -37,7 +38,7 @@ class SdCardService final : public Service {
|
||||
auto new_state = sdcard->getState();
|
||||
|
||||
if (new_state == hal::sdcard::SdCardDevice::State::Error) {
|
||||
TT_LOG_E(TAG, "Sdcard error - unmounting. Did you eject the card in an unsafe manner?");
|
||||
LOGGER.error("Sdcard error - unmounting. Did you eject the card in an unsafe manner?");
|
||||
sdcard->unmount();
|
||||
}
|
||||
|
||||
@@ -47,7 +48,7 @@ class SdCardService final : public Service {
|
||||
|
||||
unlock();
|
||||
} else {
|
||||
TT_LOG_W(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
||||
LOGGER.warn(LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +56,7 @@ public:
|
||||
|
||||
bool onStart(ServiceContext& serviceContext) override {
|
||||
if (hal::findFirstDevice<hal::sdcard::SdCardDevice>(hal::Device::Type::SdCard) == nullptr) {
|
||||
TT_LOG_W(TAG, "No SD card device found - not starting Service");
|
||||
LOGGER.warn("No SD card device found - not starting Service");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +1,21 @@
|
||||
#include <Tactility/lvgl/Statusbar.h>
|
||||
|
||||
#include <Tactility/Timer.h>
|
||||
#include <Tactility/Mutex.h>
|
||||
#include <Tactility/hal/power/PowerDevice.h>
|
||||
#include <Tactility/hal/sdcard/SdCardDevice.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/lvgl/Lvgl.h>
|
||||
#include <Tactility/lvgl/LvglSync.h>
|
||||
#include <Tactility/Mutex.h>
|
||||
#include <Tactility/service/ServiceContext.h>
|
||||
#include <Tactility/service/ServicePaths.h>
|
||||
#include <Tactility/service/ServiceRegistration.h>
|
||||
#include <Tactility/service/gps/GpsService.h>
|
||||
#include <Tactility/service/wifi/Wifi.h>
|
||||
#include <Tactility/Timer.h>
|
||||
|
||||
namespace tt::service::statusbar {
|
||||
|
||||
constexpr auto* TAG = "StatusbarService";
|
||||
static const auto LOGGER = Logger("StatusbarService");
|
||||
|
||||
// SD card status
|
||||
constexpr auto* STATUSBAR_ICON_SDCARD = "sdcard.png";
|
||||
@@ -252,7 +253,7 @@ public:
|
||||
|
||||
bool onStart(ServiceContext& serviceContext) override {
|
||||
if (lv_screen_active() == nullptr) {
|
||||
TT_LOG_E(TAG, "No display found");
|
||||
LOGGER.error("No display found");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <Tactility/crypt/Crypt.h>
|
||||
#include <Tactility/file/File.h>
|
||||
#include <Tactility/Logger.h>
|
||||
|
||||
#include <Tactility/service/ServicePaths.h>
|
||||
#include <format>
|
||||
@@ -14,7 +15,7 @@
|
||||
|
||||
namespace tt::service::wifi::settings {
|
||||
|
||||
constexpr auto* TAG = "WifiApSettings";
|
||||
static const auto LOGGER = Logger("WifiApSettings");
|
||||
|
||||
constexpr auto* AP_SETTINGS_FORMAT = "{}/{}.ap.properties";
|
||||
|
||||
@@ -33,7 +34,7 @@ std::string toHexString(const uint8_t *data, int length) {
|
||||
|
||||
bool readHex(const std::string& input, uint8_t* buffer, int length) {
|
||||
if (input.size() / 2 != length) {
|
||||
TT_LOG_E(TAG, "readHex() length mismatch");
|
||||
LOGGER.error("readHex() length mismatch");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -63,7 +64,7 @@ static bool encrypt(const std::string& ssidInput, std::string& ssidOutput) {
|
||||
|
||||
crypt::getIv(ssidInput.c_str(), ssidInput.size(), iv);
|
||||
if (crypt::encrypt(iv, reinterpret_cast<const uint8_t*>(ssidInput.c_str()), buffer, encrypted_length) != 0) {
|
||||
TT_LOG_E(TAG, "Failed to encrypt");
|
||||
LOGGER.error("Failed to encrypt");
|
||||
free(buffer);
|
||||
return false;
|
||||
}
|
||||
@@ -79,7 +80,7 @@ static bool decrypt(const std::string& ssidInput, std::string& ssidOutput) {
|
||||
assert(ssidInput.size() % 2 == 0);
|
||||
auto* data = static_cast<uint8_t*>(malloc(ssidInput.size() / 2));
|
||||
if (!readHex(ssidInput, data, ssidInput.size() / 2)) {
|
||||
TT_LOG_E(TAG, "Failed to read hex");
|
||||
LOGGER.error("Failed to read hex");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -101,7 +102,7 @@ static bool decrypt(const std::string& ssidInput, std::string& ssidOutput) {
|
||||
free(data);
|
||||
|
||||
if (decrypt_result != 0) {
|
||||
TT_LOG_E(TAG, "Failed to decrypt credentials for \"%s\": %d", ssidInput.c_str(), decrypt_result);
|
||||
LOGGER.error("Failed to decrypt credentials for \"{}s\": {}", ssidInput, decrypt_result);
|
||||
free(result);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <Tactility/MountPoints.h>
|
||||
#include <Tactility/file/File.h>
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/service/wifi/WifiApSettings.h>
|
||||
|
||||
#include <dirent.h>
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
namespace tt::service::wifi {
|
||||
|
||||
constexpr auto* TAG = "WifiBootSplashInit";
|
||||
static const auto LOGGER = Logger("WifiBootSplashInit");
|
||||
|
||||
constexpr auto* AP_PROPERTIES_KEY_SSID = "ssid";
|
||||
constexpr auto* AP_PROPERTIES_KEY_PASSWORD = "password";
|
||||
@@ -35,13 +35,13 @@ struct ApProperties {
|
||||
static void importWifiAp(const std::string& filePath) {
|
||||
std::map<std::string, std::string> map;
|
||||
if (!file::loadPropertiesFile(filePath, map)) {
|
||||
TT_LOG_E(TAG, "Failed to load AP properties at %s", filePath.c_str());
|
||||
LOGGER.error("Failed to load AP properties at {}", filePath);
|
||||
return;
|
||||
}
|
||||
|
||||
const auto ssid_iterator = map.find(AP_PROPERTIES_KEY_SSID);
|
||||
if (ssid_iterator == map.end()) {
|
||||
TT_LOG_E(TAG, "%s is missing ssid", filePath.c_str());
|
||||
LOGGER.error("{} is missing ssid", filePath);
|
||||
return;
|
||||
}
|
||||
const auto ssid = ssid_iterator->second;
|
||||
@@ -65,18 +65,18 @@ static void importWifiAp(const std::string& filePath) {
|
||||
);
|
||||
|
||||
if (!settings::save(settings)) {
|
||||
TT_LOG_E(TAG, "Failed to save settings for %s", ssid.c_str());
|
||||
LOGGER.error("Failed to save settings for {}", ssid);
|
||||
} else {
|
||||
TT_LOG_I(TAG, "Imported %s from %s", ssid.c_str(), filePath.c_str());
|
||||
LOGGER.info("Imported {} from {}", ssid, filePath);
|
||||
}
|
||||
}
|
||||
|
||||
const auto auto_remove_iterator = map.find(AP_PROPERTIES_KEY_AUTO_REMOVE);
|
||||
if (auto_remove_iterator != map.end() && auto_remove_iterator->second == "true") {
|
||||
if (!remove(filePath.c_str())) {
|
||||
TT_LOG_E(TAG, "Failed to auto-remove %s", filePath.c_str());
|
||||
LOGGER.error("Failed to auto-remove {}", filePath);
|
||||
} else {
|
||||
TT_LOG_I(TAG, "Auto-removed %s", filePath.c_str());
|
||||
LOGGER.info("Auto-removed {}", filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -105,7 +105,7 @@ static void importWifiApSettingsFromDir(const std::string& path) {
|
||||
}
|
||||
|
||||
if (dirent_list.empty()) {
|
||||
TT_LOG_W(TAG, "No AP files found at %s", path.c_str());
|
||||
LOGGER.warn("No AP files found at {}", path);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ void bootSplashInit() {
|
||||
const std::string settings_path = file::getChildPath(sdcard->getMountPath(), "settings");
|
||||
importWifiApSettingsFromDir(settings_path);
|
||||
} else {
|
||||
TT_LOG_W(TAG, "Skipping unmounted SD card %s", sdcard->getMountPath().c_str());
|
||||
LOGGER.warn("Skipping unmounted SD card {}", sdcard->getMountPath());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -6,10 +6,12 @@
|
||||
|
||||
#include <Tactility/service/wifi/Wifi.h>
|
||||
|
||||
#include <Tactility/Timer.h>
|
||||
#include <Tactility/EventGroup.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/LogMessages.h>
|
||||
#include <Tactility/RecursiveMutex.h>
|
||||
#include <Tactility/Tactility.h>
|
||||
#include <Tactility/Timer.h>
|
||||
#include <Tactility/kernel/SystemEvents.h>
|
||||
#include <Tactility/service/ServiceContext.h>
|
||||
#include <Tactility/service/wifi/WifiBootSplashInit.h>
|
||||
@@ -24,7 +26,8 @@
|
||||
|
||||
namespace tt::service::wifi {
|
||||
|
||||
constexpr auto* TAG = "WifiService";
|
||||
static const auto LOGGER = Logger("WifiService");
|
||||
|
||||
constexpr auto WIFI_CONNECTED_BIT = BIT0;
|
||||
constexpr auto WIFI_FAIL_BIT = BIT1;
|
||||
constexpr auto AUTO_SCAN_INTERVAL = 10000; // ms
|
||||
@@ -170,7 +173,7 @@ std::string getConnectionTarget() {
|
||||
}
|
||||
|
||||
void scan() {
|
||||
TT_LOG_I(TAG, "scan()");
|
||||
LOGGER.info("scan()");
|
||||
auto wifi = wifi_singleton;
|
||||
if (wifi == nullptr) {
|
||||
return;
|
||||
@@ -189,7 +192,7 @@ bool isScanning() {
|
||||
}
|
||||
|
||||
void connect(const settings::WifiApSettings& ap, bool remember) {
|
||||
TT_LOG_I(TAG, "connect(%s, %d)", ap.ssid.c_str(), remember);
|
||||
LOGGER.info("connect({}, {})", ap.ssid, remember);
|
||||
auto wifi = wifi_singleton;
|
||||
if (wifi == nullptr) {
|
||||
return;
|
||||
@@ -213,7 +216,7 @@ void connect(const settings::WifiApSettings& ap, bool remember) {
|
||||
}
|
||||
|
||||
void disconnect() {
|
||||
TT_LOG_I(TAG, "disconnect()");
|
||||
LOGGER.info("disconnect()");
|
||||
auto wifi = wifi_singleton;
|
||||
if (wifi == nullptr) {
|
||||
return;
|
||||
@@ -244,7 +247,7 @@ void clearIp() {
|
||||
memset(&wifi->ip_info, 0, sizeof(esp_netif_ip_info_t));
|
||||
}
|
||||
void setScanRecords(uint16_t records) {
|
||||
TT_LOG_I(TAG, "setScanRecords(%d)", records);
|
||||
LOGGER.info("setScanRecords({})", records);
|
||||
auto wifi = wifi_singleton;
|
||||
if (wifi == nullptr) {
|
||||
return;
|
||||
@@ -262,7 +265,7 @@ void setScanRecords(uint16_t records) {
|
||||
}
|
||||
|
||||
std::vector<ApRecord> getScanResults() {
|
||||
TT_LOG_I(TAG, "getScanResults()");
|
||||
LOGGER.info("getScanResults()");
|
||||
auto wifi = wifi_singleton;
|
||||
|
||||
std::vector<ApRecord> records;
|
||||
@@ -293,7 +296,7 @@ std::vector<ApRecord> getScanResults() {
|
||||
}
|
||||
|
||||
void setEnabled(bool enabled) {
|
||||
TT_LOG_I(TAG, "setEnabled(%d)", enabled);
|
||||
LOGGER.info("setEnabled({})", enabled);
|
||||
auto wifi = wifi_singleton;
|
||||
if (wifi == nullptr) {
|
||||
return;
|
||||
@@ -390,7 +393,7 @@ static bool copy_scan_list(std::shared_ptr<Wifi> wifi) {
|
||||
wifi->isScanActive();
|
||||
|
||||
if (!can_fetch_results) {
|
||||
TT_LOG_I(TAG, "Skip scan result fetching");
|
||||
LOGGER.info("Skip scan result fetching");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -407,11 +410,11 @@ static bool copy_scan_list(std::shared_ptr<Wifi> wifi) {
|
||||
if (scan_result == ESP_OK) {
|
||||
uint16_t safe_record_count = std::min(wifi->scan_list_limit, record_count);
|
||||
wifi->scan_list_count = safe_record_count;
|
||||
TT_LOG_I(TAG, "Scanned %u APs. Showing %u:", record_count, safe_record_count);
|
||||
LOGGER.info("Scanned {} APs. Showing {}:", record_count, safe_record_count);
|
||||
for (uint16_t i = 0; i < safe_record_count; i++) {
|
||||
wifi_ap_record_t* record = &wifi->scan_list[i];
|
||||
TT_LOG_I(TAG, " - SSID %s, RSSI %d, channel %d, BSSID %02X%02X%02X%02X%02X%02X",
|
||||
record->ssid,
|
||||
LOGGER.info(" - SSID {}, RSSI {}, channel {}, BSSID {:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}",
|
||||
reinterpret_cast<const char*>(record->ssid),
|
||||
record->rssi,
|
||||
record->primary,
|
||||
record->bssid[0],
|
||||
@@ -424,13 +427,13 @@ static bool copy_scan_list(std::shared_ptr<Wifi> wifi) {
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
TT_LOG_I(TAG, "Failed to get scanned records: %s", esp_err_to_name(scan_result));
|
||||
LOGGER.info("Failed to get scanned records: {}", esp_err_to_name(scan_result));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static bool find_auto_connect_ap(std::shared_ptr<Wifi> wifi, settings::WifiApSettings& settings) {
|
||||
TT_LOG_I(TAG, "find_auto_connect_ap()");
|
||||
LOGGER.info("find_auto_connect_ap()");
|
||||
auto lock = wifi->dataMutex.asScopedLock();
|
||||
if (lock.lock(10 / portTICK_PERIOD_MS)) {
|
||||
for (int i = 0; i < wifi->scan_list_count; ++i) {
|
||||
@@ -442,7 +445,7 @@ static bool find_auto_connect_ap(std::shared_ptr<Wifi> wifi, settings::WifiApSet
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Failed to load credentials for ssid %s", ssid);
|
||||
LOGGER.error("Failed to load credentials for ssid {}", ssid);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -453,11 +456,11 @@ static bool find_auto_connect_ap(std::shared_ptr<Wifi> wifi, settings::WifiApSet
|
||||
}
|
||||
|
||||
static void dispatchAutoConnect(std::shared_ptr<Wifi> wifi) {
|
||||
TT_LOG_I(TAG, "dispatchAutoConnect()");
|
||||
LOGGER.info("dispatchAutoConnect()");
|
||||
|
||||
settings::WifiApSettings settings;
|
||||
if (find_auto_connect_ap(wifi, settings)) {
|
||||
TT_LOG_I(TAG, "Auto-connecting to %s", settings.ssid.c_str());
|
||||
LOGGER.info("Auto-connecting to {}", settings.ssid);
|
||||
connect(settings, false);
|
||||
// TODO: We currently have to manually reset it because connect() sets it.
|
||||
// connect() assumes it's only being called by the user and not internally, so it disables auto-connect
|
||||
@@ -468,23 +471,23 @@ static void dispatchAutoConnect(std::shared_ptr<Wifi> wifi) {
|
||||
static void eventHandler(TT_UNUSED void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) {
|
||||
auto wifi = wifi_singleton;
|
||||
if (wifi == nullptr) {
|
||||
TT_LOG_E(TAG, "eventHandler: no wifi instance");
|
||||
LOGGER.error("eventHandler: no wifi instance");
|
||||
return;
|
||||
}
|
||||
|
||||
if (event_base == WIFI_EVENT) {
|
||||
TT_LOG_I(TAG, "eventHandler: WIFI_EVENT (%ld)", event_id);
|
||||
LOGGER.info("eventHandler: WIFI_EVENT {}", event_id);
|
||||
} else if (event_base == IP_EVENT) {
|
||||
TT_LOG_I(TAG, "eventHandler: IP_EVENT (%ld)", event_id);
|
||||
LOGGER.info("eventHandler: IP_EVENT {}", event_id);
|
||||
}
|
||||
|
||||
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) {
|
||||
TT_LOG_I(TAG, "eventHandler: sta start");
|
||||
LOGGER.info("eventHandler: STA_START");
|
||||
if (wifi->getRadioState() == RadioState::ConnectionPending) {
|
||||
esp_wifi_connect();
|
||||
}
|
||||
} else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) {
|
||||
TT_LOG_I(TAG, "eventHandler: disconnected");
|
||||
LOGGER.info("eventHandler: STA_DISCONNECTED");
|
||||
clearIp();
|
||||
switch (wifi->getRadioState()) {
|
||||
case RadioState::ConnectionPending:
|
||||
@@ -503,7 +506,7 @@ static void eventHandler(TT_UNUSED void* arg, esp_event_base_t event_base, int32
|
||||
} else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
|
||||
auto* event = static_cast<ip_event_got_ip_t*>(event_data);
|
||||
memcpy(&wifi->ip_info, &event->ip_info, sizeof(esp_netif_ip_info_t));
|
||||
TT_LOG_I(TAG, "eventHandler: got ip:" IPSTR, IP2STR(&event->ip_info.ip));
|
||||
LOGGER.info("eventHandler: got ip: {}.{}.{}.{}", IP2STR(&event->ip_info.ip));
|
||||
if (wifi->getRadioState() == RadioState::ConnectionPending) {
|
||||
wifi->connection_wait_flags.set(WIFI_CONNECTED_BIT);
|
||||
// We resume auto-connecting only when there was an explicit request by the user for the connection
|
||||
@@ -513,7 +516,7 @@ static void eventHandler(TT_UNUSED void* arg, esp_event_base_t event_base, int32
|
||||
kernel::publishSystemEvent(kernel::SystemEvent::NetworkConnected);
|
||||
} else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_SCAN_DONE) {
|
||||
auto* event = static_cast<wifi_event_sta_scan_done_t*>(event_data);
|
||||
TT_LOG_I(TAG, "eventHandler: wifi scanning done (scan id %u)", event->scan_id);
|
||||
LOGGER.info("eventHandler: wifi scanning done (scan id {})", event->scan_id);
|
||||
bool copied_list = copy_scan_list(wifi);
|
||||
|
||||
auto state = wifi->getRadioState();
|
||||
@@ -526,7 +529,7 @@ static void eventHandler(TT_UNUSED void* arg, esp_event_base_t event_base, int32
|
||||
}
|
||||
|
||||
publish_event(wifi_singleton, WifiEvent::ScanFinished);
|
||||
TT_LOG_I(TAG, "eventHandler: Finished scan");
|
||||
LOGGER.info("eventHandler: Finished scan");
|
||||
|
||||
if (copied_list && wifi_singleton->getRadioState() == RadioState::On && !wifi->pause_auto_connect) {
|
||||
getMainDispatcher().dispatch([wifi]() { dispatchAutoConnect(wifi); });
|
||||
@@ -535,7 +538,7 @@ static void eventHandler(TT_UNUSED void* arg, esp_event_base_t event_base, int32
|
||||
}
|
||||
|
||||
static void dispatchEnable(std::shared_ptr<Wifi> wifi) {
|
||||
TT_LOG_I(TAG, "dispatchEnable()");
|
||||
LOGGER.info("dispatchEnable()");
|
||||
|
||||
RadioState state = wifi->getRadioState();
|
||||
if (
|
||||
@@ -543,13 +546,13 @@ static void dispatchEnable(std::shared_ptr<Wifi> wifi) {
|
||||
state == RadioState::OnPending ||
|
||||
state == RadioState::OffPending
|
||||
) {
|
||||
TT_LOG_W(TAG, "Can't enable from current state");
|
||||
LOGGER.warn("Can't enable from current state");
|
||||
return;
|
||||
}
|
||||
|
||||
auto lock = wifi->radioMutex.asScopedLock();
|
||||
if (lock.lock(50 / portTICK_PERIOD_MS)) {
|
||||
TT_LOG_I(TAG, "Enabling");
|
||||
LOGGER.info("Enabling");
|
||||
wifi->setRadioState(RadioState::OnPending);
|
||||
publish_event(wifi, WifiEvent::RadioStateOnPending);
|
||||
|
||||
@@ -563,9 +566,9 @@ static void dispatchEnable(std::shared_ptr<Wifi> wifi) {
|
||||
wifi_init_config_t config = WIFI_INIT_CONFIG_DEFAULT();
|
||||
esp_err_t init_result = esp_wifi_init(&config);
|
||||
if (init_result != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Wifi init failed");
|
||||
LOGGER.error("Wifi init failed");
|
||||
if (init_result == ESP_ERR_NO_MEM) {
|
||||
TT_LOG_E(TAG, "Insufficient memory");
|
||||
LOGGER.error("Insufficient memory");
|
||||
}
|
||||
wifi->setRadioState(RadioState::Off);
|
||||
publish_event(wifi, WifiEvent::RadioStateOff);
|
||||
@@ -593,7 +596,7 @@ static void dispatchEnable(std::shared_ptr<Wifi> wifi) {
|
||||
));
|
||||
|
||||
if (esp_wifi_set_mode(WIFI_MODE_STA) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Wifi mode setting failed");
|
||||
LOGGER.error("Wifi mode setting failed");
|
||||
wifi->setRadioState(RadioState::Off);
|
||||
esp_wifi_deinit();
|
||||
publish_event(wifi, WifiEvent::RadioStateOff);
|
||||
@@ -602,9 +605,9 @@ static void dispatchEnable(std::shared_ptr<Wifi> wifi) {
|
||||
|
||||
esp_err_t start_result = esp_wifi_start();
|
||||
if (start_result != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Wifi start failed");
|
||||
LOGGER.error("Wifi start failed");
|
||||
if (start_result == ESP_ERR_NO_MEM) {
|
||||
TT_LOG_E(TAG, "Insufficient memory");
|
||||
LOGGER.error("Insufficient memory");
|
||||
}
|
||||
wifi->setRadioState(RadioState::Off);
|
||||
esp_wifi_set_mode(WIFI_MODE_NULL);
|
||||
@@ -618,18 +621,18 @@ static void dispatchEnable(std::shared_ptr<Wifi> wifi) {
|
||||
|
||||
wifi->pause_auto_connect = false;
|
||||
|
||||
TT_LOG_I(TAG, "Enabled");
|
||||
LOGGER.info("Enabled");
|
||||
} else {
|
||||
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
||||
LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
||||
}
|
||||
}
|
||||
|
||||
static void dispatchDisable(std::shared_ptr<Wifi> wifi) {
|
||||
TT_LOG_I(TAG, "dispatchDisable()");
|
||||
LOGGER.info("dispatchDisable()");
|
||||
auto lock = wifi->radioMutex.asScopedLock();
|
||||
|
||||
if (!lock.lock(50 / portTICK_PERIOD_MS)) {
|
||||
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "disable()");
|
||||
LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "disable()");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -639,11 +642,11 @@ static void dispatchDisable(std::shared_ptr<Wifi> wifi) {
|
||||
state == RadioState::OffPending ||
|
||||
state == RadioState::OnPending
|
||||
) {
|
||||
TT_LOG_W(TAG, "Can't disable from current state");
|
||||
LOGGER.warn("Can't disable from current state");
|
||||
return;
|
||||
}
|
||||
|
||||
TT_LOG_I(TAG, "Disabling");
|
||||
LOGGER.info("Disabling");
|
||||
wifi->setRadioState(RadioState::OffPending);
|
||||
publish_event(wifi, WifiEvent::RadioStateOffPending);
|
||||
|
||||
@@ -651,14 +654,14 @@ static void dispatchDisable(std::shared_ptr<Wifi> wifi) {
|
||||
scan_list_free_safely(wifi_singleton);
|
||||
|
||||
if (esp_wifi_stop() != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Failed to stop radio");
|
||||
LOGGER.error("Failed to stop radio");
|
||||
wifi->setRadioState(RadioState::On);
|
||||
publish_event(wifi, WifiEvent::RadioStateOn);
|
||||
return;
|
||||
}
|
||||
|
||||
if (esp_wifi_set_mode(WIFI_MODE_NULL) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Failed to unset mode");
|
||||
LOGGER.error("Failed to unset mode");
|
||||
}
|
||||
|
||||
if (esp_event_handler_instance_unregister(
|
||||
@@ -666,7 +669,7 @@ static void dispatchDisable(std::shared_ptr<Wifi> wifi) {
|
||||
ESP_EVENT_ANY_ID,
|
||||
wifi->event_handler_any_id
|
||||
) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Failed to unregister id event handler");
|
||||
LOGGER.error("Failed to unregister id event handler");
|
||||
}
|
||||
|
||||
if (esp_event_handler_instance_unregister(
|
||||
@@ -674,11 +677,11 @@ static void dispatchDisable(std::shared_ptr<Wifi> wifi) {
|
||||
IP_EVENT_STA_GOT_IP,
|
||||
wifi->event_handler_got_ip
|
||||
) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Failed to unregister ip event handler");
|
||||
LOGGER.error("Failed to unregister ip event handler");
|
||||
}
|
||||
|
||||
if (esp_wifi_deinit() != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Failed to deinit");
|
||||
LOGGER.error("Failed to deinit");
|
||||
}
|
||||
|
||||
assert(wifi->netif != nullptr);
|
||||
@@ -687,26 +690,26 @@ static void dispatchDisable(std::shared_ptr<Wifi> wifi) {
|
||||
wifi->setScanActive(false);
|
||||
wifi->setRadioState(RadioState::Off);
|
||||
publish_event(wifi, WifiEvent::RadioStateOff);
|
||||
TT_LOG_I(TAG, "Disabled");
|
||||
LOGGER.info("Disabled");
|
||||
}
|
||||
|
||||
static void dispatchScan(std::shared_ptr<Wifi> wifi) {
|
||||
TT_LOG_I(TAG, "dispatchScan()");
|
||||
LOGGER.info("dispatchScan()");
|
||||
auto lock = wifi->radioMutex.asScopedLock();
|
||||
|
||||
if (!lock.lock(10 / portTICK_PERIOD_MS)) {
|
||||
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
||||
LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
||||
return;
|
||||
}
|
||||
|
||||
RadioState state = wifi->getRadioState();
|
||||
if (state != RadioState::On && state != RadioState::ConnectionActive && state != RadioState::ConnectionPending) {
|
||||
TT_LOG_W(TAG, "Scan unavailable: wifi not enabled");
|
||||
LOGGER.warn("Scan unavailable: wifi not enabled");
|
||||
return;
|
||||
}
|
||||
|
||||
if (wifi->isScanActive()) {
|
||||
TT_LOG_W(TAG, "Scan already pending");
|
||||
LOGGER.warn("Scan already pending");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -714,25 +717,25 @@ static void dispatchScan(std::shared_ptr<Wifi> wifi) {
|
||||
wifi->last_scan_time = tt::kernel::getTicks();
|
||||
|
||||
if (esp_wifi_scan_start(nullptr, false) != ESP_OK) {
|
||||
TT_LOG_I(TAG, "Can't start scan");
|
||||
LOGGER.info("Can't start scan");
|
||||
return;
|
||||
}
|
||||
|
||||
TT_LOG_I(TAG, "Starting scan");
|
||||
LOGGER.info("Starting scan");
|
||||
wifi->setScanActive(true);
|
||||
publish_event(wifi, WifiEvent::ScanStarted);
|
||||
}
|
||||
|
||||
static void dispatchConnect(std::shared_ptr<Wifi> wifi) {
|
||||
TT_LOG_I(TAG, "dispatchConnect()");
|
||||
LOGGER.info("dispatchConnect()");
|
||||
auto lock = wifi->radioMutex.asScopedLock();
|
||||
|
||||
if (!lock.lock(50 / portTICK_PERIOD_MS)) {
|
||||
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "dispatchConnect()");
|
||||
LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "dispatchConnect()");
|
||||
return;
|
||||
}
|
||||
|
||||
TT_LOG_I(TAG, "Connecting to %s", wifi->connection_target.ssid.c_str());
|
||||
LOGGER.info("Connecting to {}", wifi->connection_target.ssid);
|
||||
|
||||
// Stop radio first, if needed
|
||||
RadioState radio_state = wifi->getRadioState();
|
||||
@@ -741,11 +744,11 @@ static void dispatchConnect(std::shared_ptr<Wifi> wifi) {
|
||||
radio_state == RadioState::ConnectionActive ||
|
||||
radio_state == RadioState::ConnectionPending
|
||||
) {
|
||||
TT_LOG_I(TAG, "Connecting: Stopping radio first");
|
||||
LOGGER.info("Connecting: Stopping radio first");
|
||||
esp_err_t stop_result = esp_wifi_stop();
|
||||
wifi->setScanActive(false);
|
||||
if (stop_result != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Connecting: Failed to disconnect (%s)", esp_err_to_name(stop_result));
|
||||
LOGGER.error("Connecting: Failed to disconnect ({})", esp_err_to_name(stop_result));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -771,20 +774,20 @@ static void dispatchConnect(std::shared_ptr<Wifi> wifi) {
|
||||
config.sta.threshold.authmode = WIFI_AUTH_WPA2_PSK;
|
||||
}
|
||||
|
||||
TT_LOG_I(TAG, "esp_wifi_set_config()");
|
||||
LOGGER.info("esp_wifi_set_config()");
|
||||
esp_err_t set_config_result = esp_wifi_set_config(WIFI_IF_STA, &config);
|
||||
if (set_config_result != ESP_OK) {
|
||||
wifi->setRadioState(RadioState::On);
|
||||
TT_LOG_E(TAG, "Failed to set wifi config (%s)", esp_err_to_name(set_config_result));
|
||||
LOGGER.error("Failed to set wifi config ({})", esp_err_to_name(set_config_result));
|
||||
publish_event(wifi, WifiEvent::ConnectionFailed);
|
||||
return;
|
||||
}
|
||||
|
||||
TT_LOG_I(TAG, "esp_wifi_start()");
|
||||
LOGGER.info("esp_wifi_start()");
|
||||
esp_err_t wifi_start_result = esp_wifi_start();
|
||||
if (wifi_start_result != ESP_OK) {
|
||||
wifi->setRadioState(RadioState::On);
|
||||
TT_LOG_E(TAG, "Failed to start wifi to begin connecting (%s)", esp_err_to_name(wifi_start_result));
|
||||
LOGGER.error("Failed to start wifi to begin connecting ({})", esp_err_to_name(wifi_start_result));
|
||||
publish_event(wifi, WifiEvent::ConnectionFailed);
|
||||
return;
|
||||
}
|
||||
@@ -794,28 +797,28 @@ static void dispatchConnect(std::shared_ptr<Wifi> wifi) {
|
||||
* The bits are set by wifi_event_handler() */
|
||||
uint32_t bits;
|
||||
if (wifi_singleton->connection_wait_flags.wait(WIFI_FAIL_BIT | WIFI_CONNECTED_BIT, false, true, kernel::MAX_TICKS, &bits)) {
|
||||
TT_LOG_I(TAG, "Waiting for EventGroup by event_handler()");
|
||||
LOGGER.info("Waiting for EventGroup by event_handler()");
|
||||
|
||||
if (bits & WIFI_CONNECTED_BIT) {
|
||||
wifi->setSecureConnection(config.sta.password[0] != 0x00U);
|
||||
wifi->setRadioState(RadioState::ConnectionActive);
|
||||
publish_event(wifi, WifiEvent::ConnectionSuccess);
|
||||
TT_LOG_I(TAG, "Connected to %s", wifi->connection_target.ssid.c_str());
|
||||
LOGGER.info("Connected to {}", wifi->connection_target.ssid.c_str());
|
||||
if (wifi->connection_target_remember) {
|
||||
if (!settings::save(wifi->connection_target)) {
|
||||
TT_LOG_E(TAG, "Failed to store credentials");
|
||||
LOGGER.error("Failed to store credentials");
|
||||
} else {
|
||||
TT_LOG_I(TAG, "Stored credentials");
|
||||
LOGGER.info("Stored credentials");
|
||||
}
|
||||
}
|
||||
} else if (bits & WIFI_FAIL_BIT) {
|
||||
wifi->setRadioState(RadioState::On);
|
||||
publish_event(wifi, WifiEvent::ConnectionFailed);
|
||||
TT_LOG_I(TAG, "Failed to connect to %s", wifi->connection_target.ssid.c_str());
|
||||
LOGGER.info("Failed to connect to {}", wifi->connection_target.ssid.c_str());
|
||||
} else {
|
||||
wifi->setRadioState(RadioState::On);
|
||||
publish_event(wifi, WifiEvent::ConnectionFailed);
|
||||
TT_LOG_E(TAG, "UNEXPECTED EVENT");
|
||||
LOGGER.error("UNEXPECTED EVENT");
|
||||
}
|
||||
|
||||
wifi_singleton->connection_wait_flags.clear(WIFI_FAIL_BIT | WIFI_CONNECTED_BIT);
|
||||
@@ -823,17 +826,17 @@ static void dispatchConnect(std::shared_ptr<Wifi> wifi) {
|
||||
}
|
||||
|
||||
static void dispatchDisconnectButKeepActive(std::shared_ptr<Wifi> wifi) {
|
||||
TT_LOG_I(TAG, "dispatchDisconnectButKeepActive()");
|
||||
LOGGER.info("dispatchDisconnectButKeepActive()");
|
||||
auto lock = wifi->radioMutex.asScopedLock();
|
||||
|
||||
if (!lock.lock(50 / portTICK_PERIOD_MS)) {
|
||||
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
||||
LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
||||
return;
|
||||
}
|
||||
|
||||
esp_err_t stop_result = esp_wifi_stop();
|
||||
if (stop_result != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Failed to disconnect (%s)", esp_err_to_name(stop_result));
|
||||
LOGGER.error("Failed to disconnect ({})", esp_err_to_name(stop_result));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -849,7 +852,7 @@ static void dispatchDisconnectButKeepActive(std::shared_ptr<Wifi> wifi) {
|
||||
if (set_config_result != ESP_OK) {
|
||||
// TODO: disable radio, because radio state is in limbo between off and on
|
||||
wifi->setRadioState(RadioState::Off);
|
||||
TT_LOG_E(TAG, "failed to set wifi config (%s)", esp_err_to_name(set_config_result));
|
||||
LOGGER.error("failed to set wifi config ({})", esp_err_to_name(set_config_result));
|
||||
publish_event(wifi, WifiEvent::RadioStateOff);
|
||||
return;
|
||||
}
|
||||
@@ -858,14 +861,14 @@ static void dispatchDisconnectButKeepActive(std::shared_ptr<Wifi> wifi) {
|
||||
if (wifi_start_result != ESP_OK) {
|
||||
// TODO: disable radio, because radio state is in limbo between off and on
|
||||
wifi->setRadioState(RadioState::Off);
|
||||
TT_LOG_E(TAG, "failed to start wifi to begin connecting (%s)", esp_err_to_name(wifi_start_result));
|
||||
LOGGER.error("failed to start wifi to begin connecting ({})", esp_err_to_name(wifi_start_result));
|
||||
publish_event(wifi, WifiEvent::RadioStateOff);
|
||||
return;
|
||||
}
|
||||
|
||||
wifi->setRadioState(RadioState::On);
|
||||
publish_event(wifi, WifiEvent::Disconnected);
|
||||
TT_LOG_I(TAG, "Disconnected");
|
||||
LOGGER.info("Disconnected");
|
||||
}
|
||||
|
||||
static bool shouldScanForAutoConnect(std::shared_ptr<Wifi> wifi) {
|
||||
@@ -882,7 +885,7 @@ static bool shouldScanForAutoConnect(std::shared_ptr<Wifi> wifi) {
|
||||
return false;
|
||||
}
|
||||
|
||||
TickType_t current_time = tt::kernel::getTicks();
|
||||
TickType_t current_time = kernel::getTicks();
|
||||
bool scan_time_has_looped = (current_time < wifi->last_scan_time);
|
||||
bool no_recent_scan = (current_time - wifi->last_scan_time) > (AUTO_SCAN_INTERVAL / portTICK_PERIOD_MS);
|
||||
|
||||
@@ -928,7 +931,7 @@ public:
|
||||
wifi_singleton->autoConnectTimer->start();
|
||||
|
||||
if (settings::shouldEnableOnBoot()) {
|
||||
TT_LOG_I(TAG, "Auto-enabling due to setting");
|
||||
LOGGER.info("Auto-enabling due to setting");
|
||||
getMainDispatcher().dispatch([] { dispatchEnable(wifi_singleton); });
|
||||
}
|
||||
|
||||
|
||||
@@ -8,15 +8,12 @@
|
||||
|
||||
#include <Tactility/PubSub.h>
|
||||
#include <Tactility/Check.h>
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/RecursiveMutex.h>
|
||||
#include <Tactility/service/Service.h>
|
||||
#include <Tactility/service/ServiceManifest.h>
|
||||
|
||||
namespace tt::service::wifi {
|
||||
|
||||
constexpr auto* TAG = "Wifi";
|
||||
|
||||
struct Wifi {
|
||||
/** @brief Locking mechanism for modifying the Wifi instance */
|
||||
RecursiveMutex mutex;
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
#include <Tactility/service/wifi/WifiSettings.h>
|
||||
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/file/File.h>
|
||||
#include <Tactility/file/PropertiesFile.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/service/ServicePaths.h>
|
||||
#include <Tactility/service/wifi/WifiPrivate.h>
|
||||
|
||||
namespace tt::service::wifi::settings {
|
||||
|
||||
constexpr auto* TAG = "WifiSettings";
|
||||
static const auto LOGGER = Logger("WifiSettings");
|
||||
constexpr auto* SETTINGS_KEY_ENABLE_ON_BOOT = "enableOnBoot";
|
||||
|
||||
struct WifiSettings {
|
||||
@@ -56,7 +56,7 @@ static bool save(const WifiSettings& settings) {
|
||||
WifiSettings getCachedOrLoad() {
|
||||
if (!cached) {
|
||||
if (!load(cachedSettings)) {
|
||||
TT_LOG_E(TAG, "Failed to load");
|
||||
LOGGER.error("Failed to load");
|
||||
} else {
|
||||
cached = true;
|
||||
}
|
||||
@@ -68,7 +68,7 @@ WifiSettings getCachedOrLoad() {
|
||||
void setEnableOnBoot(bool enable) {
|
||||
cachedSettings.enableOnBoot = enable;
|
||||
if (!save(cachedSettings)) {
|
||||
TT_LOG_E(TAG, "Failed to save");
|
||||
LOGGER.error("Failed to save");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user