spejsiot/spejsiot/endpoints/OutputEndpoint.cpp

21 lines
659 B
C++
Raw Normal View History

2017-03-06 16:56:37 +00:00
#include <endpoints/OutputEndpoint.h>
2017-09-29 17:34:23 +00:00
#include <SpejsNode.h>
2017-03-06 16:56:37 +00:00
EndpointResult OutputEndpoint::onValue(String property, String value) {
if (value == "1" or value == "on" or value == "true") {
currentValue = 1;
} else if (value == "0" or value == "off" or value == "false") {
currentValue = 0;
} else {
return 400;
}
2017-09-29 17:34:23 +00:00
if (currentValue != (parent->statusLED.blinkOn > parent->statusLED.blinkRate/2)) {
parent->statusLED.blinkOn = parent->statusLED.blinkRate - parent->statusLED.blinkOn;
}
2017-03-06 16:56:37 +00:00
digitalWrite(pin, inverted ^ currentValue);
notify("on", currentValue ? "true" : "false");
return 200;
}