-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlexaDevice.cpp
52 lines (42 loc) · 1.02 KB
/
AlexaDevice.cpp
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
#include "AlexaDevice.h"
AlexaDevice::AlexaDevice(){
AlexaDevice("", -1);
}
AlexaDevice::AlexaDevice(String name, int outputPin){
this->name = name;
this->outputPin = outputPin;
}
void AlexaDevice::init(){
espalexa.addDevice(name, [&](uint8_t brightness) {
setLight(brightness);
});
espalexa.begin();
}
void AlexaDevice::setLight(uint8_t brightness){
brightness == 255
? turnOn()
: turnOff();
}
void AlexaDevice::toggleLight(){
toggleLightStatus()
? turnOn()
: turnOff();
}
void AlexaDevice::loop(){espalexa.loop();}
void AlexaDevice::turnOn(){
setLightStatus(true);
digitalWrite(outputPin, HIGH);
Serial.println("Device1 ON");
}
void AlexaDevice::turnOff(){
setLightStatus(false);
digitalWrite(outputPin, LOW);
Serial.println("Device1 OFF");
}
/**Private methods***/
bool AlexaDevice::getLightStatus(){return lightState;}
void AlexaDevice::setLightStatus(bool state){lightState = state;}
bool AlexaDevice::toggleLightStatus(){
lightState = !lightState;
return lightState;
}