|
|
@ -205,6 +205,34 @@ void _relayProcess(bool mode) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#if defined(ITEAD_SONOFF_IFAN02)
|
|
|
|
|
|
|
|
unsigned char _relay_ifan02_speeds[] = {0, 1, 3, 5}; |
|
|
|
|
|
|
|
unsigned char getSpeed() { |
|
|
|
unsigned char speed = |
|
|
|
(_relays[1].target_status ? 1 : 0) + |
|
|
|
(_relays[2].target_status ? 2 : 0) + |
|
|
|
(_relays[3].target_status ? 4 : 0); |
|
|
|
for (unsigned char i=0; i<4; i++) { |
|
|
|
if (_relay_ifan02_speeds[i] == speed) return i; |
|
|
|
} |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
void setSpeed(unsigned char speed) { |
|
|
|
if ((0 <= speed) & (speed <= 3)) { |
|
|
|
if (getSpeed() == speed) return; |
|
|
|
unsigned char states = _relay_ifan02_speeds[speed]; |
|
|
|
for (unsigned char i=0; i<3; i++) { |
|
|
|
relayStatus(i+1, states & 1 == 1); |
|
|
|
states >>= 1; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// RELAY
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
@ -654,6 +682,19 @@ void relaySetupAPI() { |
|
|
|
} |
|
|
|
); |
|
|
|
|
|
|
|
#if defined(ITEAD_SONOFF_IFAN02)
|
|
|
|
|
|
|
|
apiRegister(MQTT_TOPIC_SPEED, |
|
|
|
[relayID](char * buffer, size_t len) { |
|
|
|
snprintf(buffer, len, "%u", getSpeed()); |
|
|
|
}, |
|
|
|
[relayID](const char * payload) { |
|
|
|
setSpeed(atoi(payload)); |
|
|
|
} |
|
|
|
); |
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
@ -686,6 +727,14 @@ void relayMQTT(unsigned char id) { |
|
|
|
mqttSendRaw(t.c_str(), status ? "1" : "0"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Send speed for IFAN02
|
|
|
|
#if defined (ITEAD_SONOFF_IFAN02)
|
|
|
|
char buffer[5]; |
|
|
|
snprintf(buffer, sizeof(buffer), "%u", getSpeed()); |
|
|
|
mqttSend(MQTT_TOPIC_SPEED, buffer); |
|
|
|
#endif
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
void relayMQTT() { |
|
|
@ -731,6 +780,10 @@ void relayMQTTCallback(unsigned int type, const char * topic, const char * paylo |
|
|
|
snprintf_P(pulse_topic, sizeof(pulse_topic), PSTR("%s/+"), MQTT_TOPIC_PULSE); |
|
|
|
mqttSubscribe(pulse_topic); |
|
|
|
|
|
|
|
#if defined(ITEAD_SONOFF_IFAN02)
|
|
|
|
mqttSubscribe(MQTT_TOPIC_SPEED); |
|
|
|
#endif
|
|
|
|
|
|
|
|
// Subscribe to group topics
|
|
|
|
for (unsigned int i=0; i < _relays.size(); i++) { |
|
|
|
String t = getSetting("mqttGroup", i, ""); |
|
|
@ -810,6 +863,13 @@ void relayMQTTCallback(unsigned int type, const char * topic, const char * paylo |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Itead Sonoff IFAN02
|
|
|
|
#if defined (ITEAD_SONOFF_IFAN02)
|
|
|
|
if (t.startsWith(MQTT_TOPIC_SPEED)) { |
|
|
|
setSpeed(atoi(payload)); |
|
|
|
} |
|
|
|
#endif
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (type == MQTT_DISCONNECT_EVENT) { |
|
|
|