/
light.h
105 lines (97 loc) · 3.29 KB
/
light.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
* light.h - Light half of library for talking to the light blubs.
*/
#ifndef _light_h
#define _light_h
// includes
#include "common.h"
class light{
public:
// Members
struct Header
{
// frame
uint16_t size;
uint16_t protocol:12;
uint8_t addressable:1;
uint8_t tagged:1;
uint8_t origin:2;
uint32_t source;
// frame address
uint8_t target[8];
uint8_t reservedA[6];
uint8_t res_required:1;
uint8_t ack_required:1;
uint8_t reservedB:6;
uint8_t sequence;
// protocol header
uint64_t reservedC;
uint16_t type;
uint16_t reservedD;
}__attribute__ ((__packed__));
struct Lamp {
uint8_t ip[4];
uint8_t mac[6];
uint32_t port;
uint16_t level;
uint64_t time;
uint8_t service;
uint32_t tx;
uint32_t rx;
uint64_t build;
uint32_t version;
uint32_t vendor;
uint32_t product;
uint64_t uptime;
uint64_t downtime;
HSBK hsbk;
HSBK lastWhiteHsbk;
HSBK lastColorHsbk;
bool colorMode;
float signal;
char lable[32];
}__attribute__ ((__packed__));
// Member Functions
light();
// lifx Functions
void setUDP(UDP &udpRef);
void setBroadcastIP(IPAddress broadcastIP);
void setRemotePort(uint16_t remotePort);
void setIP(uint8_t ip[4]);
void setMAC(uint8_t mac[6]);
void setPort(uint32_t port);
void get();
void setColor(HSBK hsbk);
void setColor(HSBK hsbk, uint32_t duration);
void setColor(uint16_t hue, uint16_t saturation, uint16_t brightness, uint16_t kelvin);
void setColor(uint16_t hue, uint16_t saturation, uint16_t brightness, uint16_t kelvin, uint32_t duration);
void setPower(uint16_t onOff);
void setPower(uint16_t onOff, uint32_t duration);
void state(uint8_t msg[]);
void statePower(byte msg[]);
// Switch Functions
bool matchMac(byte mac[6]);
void setPowerLevel(uint16_t powerLevel);
uint16_t getPowerLevel();
void setHSBK(HSBK hsbk);
HSBK getHSBK();
void setLastWhiteHSBK(HSBK hsbk);
HSBK getLastWhiteHSBK();
void setLastColorHSBK(HSBK hsbk);
HSBK getLastColorHSBK();
void setSignal(float signal);
float getSignal();
void setTx(uint32_t tx);
uint32_t getTx();
void setRx(uint32_t rx);
uint32_t getRx();
void setColorMode(bool mode);
bool getColorMode();
private:
Lamp _lamp;
IPAddress _broadcastIP;
uint16_t _remotePort;
uint16_t _powerState;
UDP _lightUdp;
};
#endif