@ -21,7 +21,7 @@ bool recursive = false;
# ifdef SONOFF_DUAL
# ifdef SONOFF_DUAL
unsigned char dualRelayStatus = 0 ;
unsigned char dualRelayStatus = 0 ;
# endif
# endif
Ticker inching ;
Ticker pulseTicker ;
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// RELAY
// RELAY
@ -69,69 +69,69 @@ bool relayStatus(unsigned char id) {
# endif
# endif
}
}
void relayInching Back ( unsigned char id ) {
void relayPulse Back ( unsigned char id ) {
relayToggle ( id ) ;
relayToggle ( id ) ;
inching . detach ( ) ;
pulseTicker . detach ( ) ;
}
}
void relayInching Start ( unsigned char id ) {
void relayPulse Start ( unsigned char id ) {
byte relayInch = getSetting ( " relayInch " , RELAY_INCHING ) . toInt ( ) ;
if ( relayInch = = RELAY_INCHING _NONE ) return ;
byte relayPulseMode = getSetting ( " relayPulseMode " , RELAY_PULSE_MODE ) . toInt ( ) ;
if ( relayPulseMode = = RELAY_PULSE _NONE ) return ;
bool status = relayStatus ( id ) ;
bool status = relayStatus ( id ) ;
bool inchingStatus = ( relayInch = = RELAY_INCHING _ON) ;
if ( inching Status = = status ) {
inching . detach ( ) ;
bool pulseStatus = ( relayPulseMode = = RELAY_PULSE _ON) ;
if ( pulse Status = = status ) {
pulseTicker . detach ( ) ;
return ;
return ;
}
}
inching . attach (
getSetting ( " relayInchTime " , RELAY_INCHING _TIME ) . toInt ( ) ,
relayInching Back ,
pulseTicker . attach (
getSetting ( " relayPulseTime " , RELAY_PULSE _TIME ) . toInt ( ) ,
relayPulse Back ,
id
id
) ;
) ;
}
}
unsigned int relayInching ( ) {
unsigned int relayInch = getSetting ( " relayInch " , RELAY_INCHING ) . toInt ( ) ;
return relayInch ;
unsigned int relayPulseMode ( ) {
unsigned int value = getSetting ( " relayPulseMode " , RELAY_PULSE_MODE ) . toInt ( ) ;
return value ;
}
}
void relayInching ( unsigned int relayInch , bool report ) {
void relayPulseMode ( unsigned int value , bool report ) {
setSetting ( " relayInch " , relayInch ) ;
setSetting ( " relayPulseMode " , value ) ;
/*
/*
if ( report ) {
if ( report ) {
String mqttGetter = getSetting ( " mqttGetter " , MQTT_USE_GETTER ) ;
String mqttGetter = getSetting ( " mqttGetter " , MQTT_USE_GETTER ) ;
char topic [ strlen ( MQTT_RELAY_TOPIC ) + mqttGetter . length ( ) + 10 ] ;
char topic [ strlen ( MQTT_RELAY_TOPIC ) + mqttGetter . length ( ) + 10 ] ;
sprintf ( topic , " %s/inching %s " , MQTT_RELAY_TOPIC , mqttGetter . c_str ( ) ) ;
sprintf ( topic , " %s/pulse %s " , MQTT_RELAY_TOPIC , mqttGetter . c_str ( ) ) ;
char value [ 2 ] ;
char value [ 2 ] ;
sprintf ( value , " %d " , relayInch ) ;
sprintf ( value , " %d " , value ) ;
mqttSend ( topic , value ) ;
mqttSend ( topic , value ) ;
}
}
*/
*/
char message [ 20 ] ;
char message [ 20 ] ;
sprintf ( message , " { \" relayInch \" : %d} " , relayInch ) ;
sprintf ( message , " { \" relayPulseMode \" : %d} " , value ) ;
wsSend ( message ) ;
wsSend ( message ) ;
# ifdef LED_INCHING
digitalWrite ( LED_INCHING , relayInch ! = RELAY_INCHING _NONE ) ;
# ifdef LED_PULSE
digitalWrite ( LED_PULSE , relayPulseMode ! = RELAY_PULSE _NONE ) ;
# endif
# endif
}
}
void relayInching ( unsigned int relayInch ) {
relayInching ( relayInch , true ) ;
void relayPulseMode ( unsigned int value ) {
relayPulseMode ( value , true ) ;
}
}
void relayInching Toggle ( ) {
unsigned int relayInch = relayInching ( ) ;
relayInch = ( relayInch = = RELAY_INCHING_NONE ) ? RELAY_INCHING_OFF : RELAY_INCHING _NONE;
relayInching ( relayInch ) ;
void relayPulse Toggle ( ) {
unsigned int value = relayPulseMode ( ) ;
value = ( value = = RELAY_PULSE_NONE ) ? RELAY_PULSE_OFF : RELAY_PULSE _NONE;
relayPulseMode ( value ) ;
}
}
bool relayStatus ( unsigned char id , bool status , bool report ) {
bool relayStatus ( unsigned char id , bool status , bool report ) {
@ -160,7 +160,7 @@ bool relayStatus(unsigned char id, bool status, bool report) {
# endif
# endif
if ( ! recursive ) {
if ( ! recursive ) {
relayInching Start ( id ) ;
relayPulse Start ( id ) ;
relaySync ( id ) ;
relaySync ( id ) ;
relaySave ( ) ;
relaySave ( ) ;
}
}
@ -263,7 +263,7 @@ void relayMQTTCallback(unsigned int type, const char * topic, const char * paylo
sprintf ( buffer , " %s/+%s " , MQTT_RELAY_TOPIC , mqttSetter . c_str ( ) ) ;
sprintf ( buffer , " %s/+%s " , MQTT_RELAY_TOPIC , mqttSetter . c_str ( ) ) ;
mqttSubscribe ( buffer ) ;
mqttSubscribe ( buffer ) ;
sprintf ( buffer , " %s/inching %s " , MQTT_RELAY_TOPIC , mqttSetter . c_str ( ) ) ;
sprintf ( buffer , " %s/pulse %s " , MQTT_RELAY_TOPIC , mqttSetter . c_str ( ) ) ;
mqttSubscribe ( buffer ) ;
mqttSubscribe ( buffer ) ;
}
}
@ -278,9 +278,9 @@ void relayMQTTCallback(unsigned int type, const char * topic, const char * paylo
// Get value
// Get value
unsigned int value = ( char ) payload [ 0 ] - ' 0 ' ;
unsigned int value = ( char ) payload [ 0 ] - ' 0 ' ;
// Inching topic
if ( t . indexOf ( " inching " ) > 0 ) {
relayInching ( value , ! sameSetGet ) ;
// Pulse topic
if ( t . indexOf ( " pulse " ) > 0 ) {
relayPulseMode ( value , ! sameSetGet ) ;
return ;
return ;
}
}