-
Notifications
You must be signed in to change notification settings - Fork 6
/
BulbManager.h
52 lines (40 loc) · 2.38 KB
/
BulbManager.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
/* Yeelight Smart Switch App for ESP8266
* Bulb manager definitions
* (c) DNS 2018-2021
*/
#ifndef BULBMANAGER_H
#define BULBMANAGER_H
#include <vector> // Dynamic array
#include "YeelightDS.h" // Yeelight support
class BulbManager {
protected:
std::vector<ds::YBulb *> bulbs; // List of known bulbs
uint8_t nabulbs; // Number of active bulbs
static const uint8_t EEPROM_FORMAT_VERSION = 49; // The first version of the format stored 1 bulb id right after the marker. ID stars with ASCII '0' == 48
ds::YBulb* find(const String&) const; // Find a bulb by ID
ds::YBulb* find(const ds::YBulb&) const; // Find a bulb with the same ID
public:
typedef enum Event { EVENT_FLIP, EVENT_ON, EVENT_OFF } event_t; // Possible actions
BulbManager() : nabulbs(0) {} // Constructor
~BulbManager(); // Destructor
void begin(); // Start operation
void processEvent(event_t, const String&); // Process external event
void load(); // Load stored configuration
void save(); // Save new configuration
uint8_t discover(); // Discover bulbs. Returns number of known bulbs
bool turnOn(); // Turn on bulbs. Returns true on full success
bool turnOff(); // Turn off bulbs. Returns true on full success
bool flip(); // Flip bulbs. Returns true on full success
bool isOn() const; // Return true if lights are on
bool isOff() const { return !isOn(); } // Return true if lights are off
void activateAll(); // Activate all bulbs
void deactivateAll(); // Deactivate all bulbs
uint8_t getNum() const { return bulbs.size(); } // Return number of known bulbs
uint8_t getNumActive() const { return nabulbs; } // Return number of active bulbs
bool isLinked() const { return nabulbs; } // Return true if there are linked bulbs
void printStatusHTML(String &) const; // Print bulbs status in HTML
void printConfHTML(String &) const; // Print bulb configuration controls in HTML
};
// Declare a singleton-like instance
extern BulbManager bulb_manager; // Global bulb manager
#endif // BULBMANAGER_H