|
|
@ -25,54 +25,10 @@ bool recursive = false; |
|
|
|
unsigned char _dual_status = 0; |
|
|
|
#endif
|
|
|
|
|
|
|
|
#if RELAY_PROVIDER == RELAY_PROVIDER_MY9291
|
|
|
|
#include <my9291.h>
|
|
|
|
my9291 * _my9291; |
|
|
|
Ticker colorTicker; |
|
|
|
#endif
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// PROVIDER
|
|
|
|
// RELAY PROVIDERS
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#if RELAY_PROVIDER == RELAY_PROVIDER_MY9291
|
|
|
|
|
|
|
|
void setLightColor(unsigned char red, unsigned char green, unsigned char blue, unsigned char white) { |
|
|
|
|
|
|
|
// Set new color (if light is open it will automatically change)
|
|
|
|
_my9291->setColor((my9291_color_t) { red, green, blue, white }); |
|
|
|
|
|
|
|
// Delay saving to EEPROM 5 seconds to avoid wearing it out unnecessarily
|
|
|
|
colorTicker.once(5, saveLightColor); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
String getLightColor() { |
|
|
|
char buffer[16]; |
|
|
|
my9291_color_t color = _my9291->getColor(); |
|
|
|
sprintf(buffer, "%d,%d,%d,%d", color.red, color.green, color.blue, color.white); |
|
|
|
return String(buffer); |
|
|
|
} |
|
|
|
|
|
|
|
void saveLightColor() { |
|
|
|
my9291_color_t color = _my9291->getColor(); |
|
|
|
setSetting("colorRed", color.red); |
|
|
|
setSetting("colorGreen", color.green); |
|
|
|
setSetting("colorBlue", color.blue); |
|
|
|
setSetting("colorWhite", color.white); |
|
|
|
saveSettings(); |
|
|
|
} |
|
|
|
|
|
|
|
void retrieveLightColor() { |
|
|
|
unsigned int red = getSetting("colorRed", MY9291_COLOR_RED).toInt(); |
|
|
|
unsigned int green = getSetting("colorGreen", MY9291_COLOR_GREEN).toInt(); |
|
|
|
unsigned int blue = getSetting("colorBlue", MY9291_COLOR_BLUE).toInt(); |
|
|
|
unsigned int white = getSetting("colorWhite", MY9291_COLOR_WHITE).toInt(); |
|
|
|
_my9291->setColor((my9291_color_t) { red, green, blue, white }); |
|
|
|
} |
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void relayProviderStatus(unsigned char id, bool status) { |
|
|
|
|
|
|
|
#if RELAY_PROVIDER == RELAY_PROVIDER_DUAL
|
|
|
@ -85,8 +41,8 @@ void relayProviderStatus(unsigned char id, bool status) { |
|
|
|
Serial.flush(); |
|
|
|
#endif
|
|
|
|
|
|
|
|
#if RELAY_PROVIDER == RELAY_PROVIDER_MY9291
|
|
|
|
_my9291->setState(status); |
|
|
|
#if RELAY_PROVIDER == RELAY_PROVIDER_LIGHT
|
|
|
|
lightState(status); |
|
|
|
#endif
|
|
|
|
|
|
|
|
#if RELAY_PROVIDER == RELAY_PROVIDER_RELAY
|
|
|
@ -102,8 +58,8 @@ bool relayProviderStatus(unsigned char id) { |
|
|
|
return ((_dual_status & (1 << id)) > 0); |
|
|
|
#endif
|
|
|
|
|
|
|
|
#if RELAY_PROVIDER == RELAY_PROVIDER_MY9291
|
|
|
|
return _my9291->getState(); |
|
|
|
#if RELAY_PROVIDER == RELAY_PROVIDER_LIGHT
|
|
|
|
return lightState(); |
|
|
|
#endif
|
|
|
|
|
|
|
|
#if RELAY_PROVIDER == RELAY_PROVIDER_RELAY
|
|
|
@ -444,11 +400,6 @@ void relayMQTTCallback(unsigned int type, const char * topic, const char * paylo |
|
|
|
sprintf(buffer, "%s/+%s", MQTT_RELAY_TOPIC, mqttSetter.c_str()); |
|
|
|
mqttSubscribe(buffer); |
|
|
|
|
|
|
|
#if RELAY_PROVIDER == RELAY_PROVIDER_MY9291
|
|
|
|
sprintf(buffer, "%s%s", MQTT_COLOR_TOPIC, mqttSetter.c_str()); |
|
|
|
mqttSubscribe(buffer); |
|
|
|
#endif
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (type == MQTT_MESSAGE_EVENT) { |
|
|
@ -458,33 +409,6 @@ void relayMQTTCallback(unsigned int type, const char * topic, const char * paylo |
|
|
|
int len = mqttSetter.length(); |
|
|
|
if (strncmp(t + strlen(t) - len, mqttSetter.c_str(), len) != 0) return; |
|
|
|
|
|
|
|
// Color topic
|
|
|
|
#if RELAY_PROVIDER == RELAY_PROVIDER_MY9291
|
|
|
|
if (strncmp(t, MQTT_COLOR_TOPIC, strlen(MQTT_COLOR_TOPIC)) == 0) { |
|
|
|
|
|
|
|
unsigned char red, green, blue = 0; |
|
|
|
|
|
|
|
char * p; |
|
|
|
p = strtok((char *) payload, ","); |
|
|
|
red = atoi(p); |
|
|
|
p = strtok(NULL, ","); |
|
|
|
if (p != NULL) { |
|
|
|
green = atoi(p); |
|
|
|
p = strtok(NULL, ","); |
|
|
|
if (p != NULL) blue = atoi(p); |
|
|
|
} else { |
|
|
|
green = blue = red; |
|
|
|
} |
|
|
|
if ((red == green) && (green == blue)) { |
|
|
|
setLightColor(0, 0, 0, red); |
|
|
|
} else { |
|
|
|
setLightColor(red, green, blue, 0); |
|
|
|
} |
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
#endif
|
|
|
|
|
|
|
|
// Relay topic
|
|
|
|
if (strncmp(t, MQTT_RELAY_TOPIC, strlen(MQTT_RELAY_TOPIC)) == 0) { |
|
|
|
|
|
|
@ -555,11 +479,6 @@ void relaySetup() { |
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if RELAY_PROVIDER == RELAY_PROVIDER_MY9291
|
|
|
|
_my9291 = new my9291(MY9291_DI_PIN, MY9291_DCKI_PIN, MY9291_COMMAND); |
|
|
|
retrieveLightColor(); |
|
|
|
#endif
|
|
|
|
|
|
|
|
byte relayMode = getSetting("relayMode", RELAY_MODE).toInt(); |
|
|
|
for (unsigned int i=0; i < _relays.size(); i++) { |
|
|
|
pinMode(_relays[i].pin, OUTPUT); |
|
|
|