Move ESP-NOW lighting control to lib
This commit is contained in:
parent
5b69f482c3
commit
76b8fed961
5 changed files with 33 additions and 34 deletions
|
@ -1,41 +0,0 @@
|
|||
#ifndef EspNowControl_cpp
|
||||
#define EspNowControl_cpp
|
||||
|
||||
#include <esp_now.h>
|
||||
#include <WiFi.h>
|
||||
#include "LedManager.cpp"
|
||||
|
||||
class EspNowControl {
|
||||
typedef struct payload {
|
||||
int id;
|
||||
bool on;
|
||||
float brightness;
|
||||
unsigned long timer;
|
||||
} payload;
|
||||
|
||||
static LedManager *_leds;
|
||||
|
||||
static void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) {
|
||||
payload data;
|
||||
memcpy(&data, incomingData, sizeof(data));
|
||||
_leds->setLedProperties(data.id, data.on, data.brightness, data.timer);
|
||||
}
|
||||
|
||||
EspNowControl();
|
||||
|
||||
public:
|
||||
static bool init(LedManager *leds) {
|
||||
_leds = leds;
|
||||
|
||||
WiFi.mode(WIFI_STA);
|
||||
|
||||
if (esp_now_init() != ESP_OK)
|
||||
return false;
|
||||
|
||||
esp_now_register_recv_cb(OnDataRecv);
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue