-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIrBroadcast.h
52 lines (42 loc) · 1.49 KB
/
IrBroadcast.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#pragma once
#include <Arduino.h>
#include <esp_now.h>
#include <PowerFunctions.h>
#include <WiFi.h>
using namespace std::placeholders;
enum struct PowerFunctionsCall
{
SinglePwm,
SingleIncrement,
SingleDecrement,
ComboPwm
};
struct PowerFunctionsIrMessage
{
PowerFunctionsCall call;
PowerFunctionsPort port;
PowerFunctionsPwm pwm;
uint8_t channel;
};
typedef void (*PowerFunctionsIrRecvCallback)(PowerFunctionsIrMessage message);
class PowerFunctionsIrBroadcast
{
private:
static PowerFunctionsIrMessage _recvMessage;
bool _broadcastEnabled = false;
PowerFunctionsIrMessage _message;
uint8_t _broadcastAddress[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
esp_now_peer_info_t _broadcastPeerInfo;
void _broadcastMessage(PowerFunctionsCall call, PowerFunctionsPort port, PowerFunctionsPwm pwm, uint8_t channel);
public:
static void _onDataRecv(const uint8_t *mac, const uint8_t *incomingData, int len);
PowerFunctionsIrBroadcast() {}
void single_pwm(PowerFunctionsPort port, PowerFunctionsPwm pwm, uint8_t channel, bool rebroadcast = true);
void single_increment(PowerFunctionsPort port, uint8_t channel, bool rebroadcast = true);
void single_decrement(PowerFunctionsPort port, uint8_t channel, bool rebroadcast = true);
PowerFunctionsPwm speedToPwm(byte speed);
void registerRecvCallback(PowerFunctionsIrRecvCallback callback = nullptr);
void unregisterRecvCallback();
void disableBroadcast();
void enableBroadcast();
};