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,17 +1,11 @@
|
|||
#ifndef EspNowControl_cpp
|
||||
#define EspNowControl_cpp
|
||||
#ifndef EspNowLightControlClient_cpp
|
||||
#define EspNowLightControlClient_cpp
|
||||
|
||||
#include <esp_now.h>
|
||||
#include <WiFi.h>
|
||||
#include "LightControlPayload.cpp"
|
||||
|
||||
class EspNowControl {
|
||||
typedef struct payload {
|
||||
int id;
|
||||
bool on;
|
||||
float brightness;
|
||||
unsigned long timer;
|
||||
} payload;
|
||||
|
||||
class EspNowLightControlClient {
|
||||
uint8_t broadcastAddress[6] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
|
||||
|
||||
public:
|
||||
|
@ -38,7 +32,7 @@ public:
|
|||
|
||||
void send() {
|
||||
for (int i = 1; i <= 5; i++) {
|
||||
payload data = payload();
|
||||
LightControlPayload data = LightControlPayload();
|
||||
data.id = i;
|
||||
data.brightness = 1;
|
||||
data.on = false;
|
|
@ -1,27 +1,21 @@
|
|||
#ifndef EspNowControl_cpp
|
||||
#define EspNowControl_cpp
|
||||
#ifndef EspNowLightControlServer_cpp
|
||||
#define EspNowLightControlServer_cpp
|
||||
|
||||
#include <esp_now.h>
|
||||
#include <WiFi.h>
|
||||
#include "LedManager.cpp"
|
||||
#include "LightControlPayload.cpp"
|
||||
|
||||
class EspNowControl {
|
||||
typedef struct payload {
|
||||
int id;
|
||||
bool on;
|
||||
float brightness;
|
||||
unsigned long timer;
|
||||
} payload;
|
||||
|
||||
class EspNowLightControlServer {
|
||||
static LedManager *_leds;
|
||||
|
||||
static void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) {
|
||||
payload data;
|
||||
LightControlPayload data;
|
||||
memcpy(&data, incomingData, sizeof(data));
|
||||
_leds->setLedProperties(data.id, data.on, data.brightness, data.timer);
|
||||
}
|
||||
|
||||
EspNowControl();
|
||||
EspNowLightControlServer();
|
||||
|
||||
public:
|
||||
static bool init(LedManager *leds) {
|
11
lib/EspNowLightControl/LightControlPayload.cpp
Normal file
11
lib/EspNowLightControl/LightControlPayload.cpp
Normal file
|
@ -0,0 +1,11 @@
|
|||
#ifndef LightControlPayload_cpp
|
||||
#define LightControlPayload_cpp
|
||||
|
||||
struct LightControlPayload {
|
||||
int id;
|
||||
bool on;
|
||||
float brightness;
|
||||
unsigned long timer;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,7 +1,7 @@
|
|||
#include <Arduino.h>
|
||||
#include "EspNowControl.cpp"
|
||||
#include "EspNowLightControlClient.cpp"
|
||||
|
||||
EspNowControl _control;
|
||||
EspNowLightControlClient _control;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
|
|
@ -3,13 +3,13 @@
|
|||
#include "BluetoothLEDCallback.cpp"
|
||||
#include "BluetoothLightControl.cpp"
|
||||
#include "BluetoothService.cpp"
|
||||
#include "EspNowControl.cpp"
|
||||
#include "EspNowLightControlServer.cpp"
|
||||
#include "LedManager.cpp"
|
||||
#include "TimerManager.cpp"
|
||||
#include "TouchInput.cpp"
|
||||
#include <Arduino.h>
|
||||
|
||||
LedManager *EspNowControl::_leds = 0; // WTF, C++?
|
||||
LedManager *EspNowLightControlServer::_leds = 0; // WTF, C++?
|
||||
|
||||
#define FADE_IN_DURATION 500
|
||||
#define FADE_OUT_DURATION 1000
|
||||
|
@ -65,7 +65,7 @@ void setup() {
|
|||
|
||||
_btService.init();
|
||||
_btService.start();
|
||||
EspNowControl::init(&_leds);
|
||||
EspNowLightControlServer::init(&_leds);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue