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
35
lib/EspNowLightControl/EspNowLightControlServer.cpp
Normal file
35
lib/EspNowLightControl/EspNowLightControlServer.cpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
#ifndef EspNowLightControlServer_cpp
|
||||
#define EspNowLightControlServer_cpp
|
||||
|
||||
#include <esp_now.h>
|
||||
#include <WiFi.h>
|
||||
#include "LedManager.cpp"
|
||||
#include "LightControlPayload.cpp"
|
||||
|
||||
class EspNowLightControlServer {
|
||||
static LedManager *_leds;
|
||||
|
||||
static void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) {
|
||||
LightControlPayload data;
|
||||
memcpy(&data, incomingData, sizeof(data));
|
||||
_leds->setLedProperties(data.id, data.on, data.brightness, data.timer);
|
||||
}
|
||||
|
||||
EspNowLightControlServer();
|
||||
|
||||
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