84049658db
## New features - Implemented support for app packaging in firmware and `tactility.py`: load `.app` files instead of `.elf` files. Install apps remotely or via `FileBrowser`. - Ensure headless mode works: all services that require LVGL can deal with the absence of a display - Service `onStart()` is now allowed to fail (return `bool` result) - Added and improved various file-related helper functions ## Improvements - Completely revamped the SystemInfo app UI - Improved Calculator UI of internal and external variant - Fix Chat UI and removed the emoji buttons for now - Fix for toolbar bottom padding issue in all apps ## Fixes - Fix for allowing recursive locking for certain SPI SD cards & more
74 lines
1.8 KiB
C++
74 lines
1.8 KiB
C++
#pragma once
|
|
#ifdef ESP_PLATFORM
|
|
|
|
#include "Tactility/MessageQueue.h"
|
|
#include "Tactility/service/Service.h"
|
|
#include "Tactility/service/espnow/EspNow.h"
|
|
|
|
#include <Tactility/Mutex.h>
|
|
|
|
#include <functional>
|
|
|
|
namespace tt::service::espnow {
|
|
|
|
class EspNowService final : public Service {
|
|
|
|
private:
|
|
|
|
struct ReceiverSubscriptionData {
|
|
ReceiverSubscription id;
|
|
std::function<void(const esp_now_recv_info_t* receiveInfo, const uint8_t* data, int length)> onReceive;
|
|
};
|
|
|
|
struct SendCallback {
|
|
uint8_t macAddress[ESP_NOW_ETH_ALEN];
|
|
bool success;
|
|
};
|
|
|
|
Mutex mutex = Mutex(Mutex::Type::Recursive);
|
|
std::vector<ReceiverSubscriptionData> subscriptions;
|
|
ReceiverSubscription lastSubscriptionId = 0;
|
|
bool enabled = false;
|
|
|
|
// Dispatcher calls this and forwards to non-static function
|
|
void enableFromDispatcher(const EspNowConfig& config);
|
|
|
|
void disableFromDispatcher();
|
|
|
|
static void receiveCallback(const esp_now_recv_info_t* receiveInfo, const uint8_t* data, int length);
|
|
void onReceive(const esp_now_recv_info_t* receiveInfo, const uint8_t* data, int length);
|
|
|
|
public:
|
|
|
|
// region Overrides
|
|
|
|
bool onStart(ServiceContext& service) override;
|
|
void onStop(ServiceContext& service) override;
|
|
|
|
// endregion Overrides
|
|
|
|
// region Internal API
|
|
|
|
void enable(const EspNowConfig& config);
|
|
|
|
void disable();
|
|
|
|
bool isEnabled() const;
|
|
|
|
bool addPeer(const esp_now_peer_info_t& peer);
|
|
|
|
bool send(const uint8_t* address, const uint8_t* buffer, size_t bufferLength);
|
|
|
|
ReceiverSubscription subscribeReceiver(std::function<void(const esp_now_recv_info_t* receiveInfo, const uint8_t* data, int length)> onReceive);
|
|
|
|
void unsubscribeReceiver(ReceiverSubscription subscription);
|
|
|
|
// region Internal API
|
|
};
|
|
|
|
std::shared_ptr<EspNowService> findService();
|
|
|
|
}
|
|
|
|
#endif // ESP_PLATFORM
|