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
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user