Move to new folder in preparation for more controllers
This commit is contained in:
parent
bcea2ee550
commit
ae3c20b59d
18 changed files with 59 additions and 4 deletions
41
lighting/src/EspNowControl.cpp
Normal file
41
lighting/src/EspNowControl.cpp
Normal file
|
@ -0,0 +1,41 @@
|
|||
#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