From b2005fba405a5b1a13bac698af2ae6033ed3d475 Mon Sep 17 00:00:00 2001 From: Joel Stein Date: Mon, 17 Dec 2018 17:34:55 +0100 Subject: [PATCH] introduce new api-call for dimmer-devices --- sonoff/sonoff.h | 2 +- sonoff/xdrv_04_light.ino | 26 ++++++++------------------ sonoff/xdrv_16_tuyadimmer.ino | 9 +++++++++ sonoff/xdrv_18_armtronix_dimmers.ino | 9 +++++++++ sonoff/xdrv_19_ps16dz_dimmer.ino | 9 +++++++++ 5 files changed, 36 insertions(+), 19 deletions(-) diff --git a/sonoff/sonoff.h b/sonoff/sonoff.h index 71c761b28..7c2de21e6 100644 --- a/sonoff/sonoff.h +++ b/sonoff/sonoff.h @@ -245,7 +245,7 @@ enum XsnsFunctions {FUNC_SETTINGS_OVERRIDE, FUNC_MODULE_INIT, FUNC_PRE_INIT, FUN FUNC_MQTT_SUBSCRIBE, FUNC_MQTT_INIT, FUNC_MQTT_DATA, FUNC_SET_POWER, FUNC_SET_DEVICE_POWER, FUNC_SHOW_SENSOR, FUNC_RULES_PROCESS, FUNC_SERIAL, FUNC_FREE_MEM, FUNC_BUTTON_PRESSED, - FUNC_WEB_ADD_BUTTON, FUNC_WEB_ADD_MAIN_BUTTON, FUNC_WEB_ADD_HANDLER}; + FUNC_WEB_ADD_BUTTON, FUNC_WEB_ADD_MAIN_BUTTON, FUNC_WEB_ADD_HANDLER, FUNC_SET_CHANNELS}; enum CommandSource { SRC_IGNORE, SRC_MQTT, SRC_RESTART, SRC_BUTTON, SRC_SWITCH, SRC_BACKLOG, SRC_SERIAL, SRC_WEBGUI, SRC_WEBCOMMAND, SRC_WEBCONSOLE, SRC_PULSETIMER, SRC_TIMER, SRC_RULE, SRC_MAXPOWER, SRC_MAXENERGY, SRC_LIGHT, SRC_KNX, SRC_DISPLAY, SRC_WEMO, SRC_HUE, SRC_RETRY, SRC_MAX }; diff --git a/sonoff/xdrv_04_light.ino b/sonoff/xdrv_04_light.ino index 52eba7d2d..ae6644dda 100644 --- a/sonoff/xdrv_04_light.ino +++ b/sonoff/xdrv_04_light.ino @@ -828,30 +828,20 @@ void LightAnimate(void) } } } + XdrvMailbox.index = light_device; + XdrvMailbox.data = (char*)cur_col; + XdrvMailbox.data_len = sizeof(cur_col); + if (XdrvCall(FUNC_SET_CHANNELS)) { + // Serviced + } #ifdef USE_WS2812 // ************************************************************************ - if (LT_WS2812 == light_type) { + else if (LT_WS2812 == light_type) { Ws2812SetColor(0, cur_col[0], cur_col[1], cur_col[2], cur_col[3]); } #endif // USE_ES2812 ************************************************************************ - if (light_type > LT_WS2812) { + else if (light_type > LT_WS2812) { LightMy92x1Duty(cur_col[0], cur_col[1], cur_col[2], cur_col[3], cur_col[4]); } -#ifdef USE_TUYA_DIMMER - if (light_type == LT_SERIAL1 && Settings.module == TUYA_DIMMER ) { - LightSerialDuty(cur_col[0]); - } -#endif // USE_TUYA_DIMMER -#ifdef USE_ARMTRONIX_DIMMERS - if (light_type == LT_SERIAL2) { - LightSerial2Duty(cur_col[0],cur_col[1]); - } -#endif // USE_ARMTRONIX_DIMMERS -#ifdef USE_PS_16_DZ - if (light_type == LT_SERIAL1 && Settings.module == PS_16_DZ) { - PS16DZSerialDuty(cur_col[0]); - } -#endif // USE_PS_16_DZ - } } } diff --git a/sonoff/xdrv_16_tuyadimmer.ino b/sonoff/xdrv_16_tuyadimmer.ino index 1312a7199..eb564a8e8 100644 --- a/sonoff/xdrv_16_tuyadimmer.ino +++ b/sonoff/xdrv_16_tuyadimmer.ino @@ -133,6 +133,12 @@ boolean TuyaSetPower(void) return status; } +boolean TuyaSetChannels(void) +{ + LightSerialDuty(((uint8_t*)XdrvMailbox.data)[0]); + return true; +} + void LightSerialDuty(uint8_t duty) { if (duty > 0 && !tuya_ignore_dim && TuyaSerial) { @@ -416,6 +422,9 @@ boolean Xdrv16(byte function) case FUNC_EVERY_SECOND: if(TuyaSerial && tuya_wifi_state!=WifiState()) { TuyaSetWifiLed(); } break; + case FUNC_SET_CHANNELS: + result = TuyaSetChannels(); + break; } } return result; diff --git a/sonoff/xdrv_18_armtronix_dimmers.ino b/sonoff/xdrv_18_armtronix_dimmers.ino index 0cab44e1d..795149bff 100644 --- a/sonoff/xdrv_18_armtronix_dimmers.ino +++ b/sonoff/xdrv_18_armtronix_dimmers.ino @@ -40,6 +40,12 @@ int8_t armtronix_knobState[2]; // Dimmer state values. * Internal Functions \*********************************************************************************************/ +boolean ArmtronixSetChannels(void) +{ + LightSerial2Duty(((uint8_t*)XdrvMailbox.data)[0], ((uint8_t*)XdrvMailbox.data)[1]); + return true; +} + void LightSerial2Duty(uint8_t duty1, uint8_t duty2) { if (ArmtronixSerial && !armtronix_ignore_dim) { @@ -186,6 +192,9 @@ boolean Xdrv18(byte function) } } break; + case FUNC_SET_CHANNELS: + result = ArmtronixSetChannels(); + break; } } return result; diff --git a/sonoff/xdrv_19_ps16dz_dimmer.ino b/sonoff/xdrv_19_ps16dz_dimmer.ino index d8c8138e1..3c895cf98 100644 --- a/sonoff/xdrv_19_ps16dz_dimmer.ino +++ b/sonoff/xdrv_19_ps16dz_dimmer.ino @@ -91,6 +91,12 @@ boolean PS16DZSetPower(void) return status; } +boolean PS16DZSetChannels(void) +{ + PS16DZSerialDuty(((uint8_t*)XdrvMailbox.data)[0]); + return true; +} + void PS16DZSerialDuty(uint8_t duty) { if (duty > 0 && !ps16dz_ignore_dim && PS16DZSerial) { @@ -236,6 +242,9 @@ boolean Xdrv19(byte function) case FUNC_SET_DEVICE_POWER: result = PS16DZSetPower(); break; + case FUNC_SET_CHANNELS: + result = PS16DZSetChannels(); + break; } } return result;