From f76400ba03d63edc46c2190a0f9367ca967704ee Mon Sep 17 00:00:00 2001 From: Cossid Date: Tue, 21 Jun 2022 00:32:56 -0500 Subject: [PATCH 1/9] Initial implementation of SM2335 LED driver. --- BUILDS.md | 1 + tasmota/include/tasmota_configurations.h | 4 + tasmota/include/tasmota_template.h | 7 + tasmota/language/af_AF.h | 2 + tasmota/language/bg_BG.h | 2 + tasmota/language/cs_CZ.h | 2 + tasmota/language/de_DE.h | 2 + tasmota/language/el_GR.h | 2 + tasmota/language/en_GB.h | 2 + tasmota/language/es_ES.h | 2 + tasmota/language/fr_FR.h | 2 + tasmota/language/fy_NL.h | 2 + tasmota/language/he_HE.h | 2 + tasmota/language/hu_HU.h | 2 + tasmota/language/it_IT.h | 2 + tasmota/language/ko_KO.h | 2 + tasmota/language/nl_NL.h | 2 + tasmota/language/pl_PL.h | 2 + tasmota/language/pt_BR.h | 2 + tasmota/language/pt_PT.h | 2 + tasmota/language/ro_RO.h | 2 + tasmota/language/ru_RU.h | 2 + tasmota/language/sk_SK.h | 2 + tasmota/language/sv_SE.h | 2 + tasmota/language/tr_TR.h | 2 + tasmota/language/uk_UA.h | 2 + tasmota/language/vi_VN.h | 2 + tasmota/language/zh_CN.h | 2 + tasmota/language/zh_TW.h | 2 + tasmota/my_user_config.h | 1 + tasmota/tasmota_support/support_features.ino | 4 +- tasmota/tasmota_xlgt_light/xlgt_09_sm2335.ino | 245 ++++++++++++++++++ tools/decode-status.py | 2 +- 33 files changed, 314 insertions(+), 2 deletions(-) create mode 100644 tasmota/tasmota_xlgt_light/xlgt_09_sm2335.ino diff --git a/BUILDS.md b/BUILDS.md index 89f522bce..576c8be6f 100644 --- a/BUILDS.md +++ b/BUILDS.md @@ -65,6 +65,7 @@ Note: `minimal` variant is not listed as it shouldn't be used outside of the [up | USE_MY92X1 | - | x / - | x | x | - | x | | USE_SM16716 | - | x / - | x | x | - | x | | USE_SM2135 | - | x / - | x | x | - | x | +| USE_SM2335 | - | x / - | x | x | - | x | | USE_BP5758D | - | x / - | x | x | - | x | | USE_SONOFF_L1 | - | x / - | x | x | - | x | | USE_ELECTRIQ_MOODL | - | x / - | x | x | - | x | diff --git a/tasmota/include/tasmota_configurations.h b/tasmota/include/tasmota_configurations.h index e0d00cb59..eb8af48f5 100644 --- a/tasmota/include/tasmota_configurations.h +++ b/tasmota/include/tasmota_configurations.h @@ -69,6 +69,7 @@ #define USE_MY92X1 // Add support for MY92X1 RGBCW led controller as used in Sonoff B1, Ailight and Lohas #define USE_SM16716 // Add support for SM16716 RGB LED controller (+0k7 code) #define USE_SM2135 // Add support for SM2135 RGBCW led control as used in Action LSC (+0k6 code) +#define USE_SM2335 // Add support for SM2335 RGBCW led control as used in Switchbot Bulb (+0k# code) #define USE_BP5758D // Add support for BP5758D RGBCW led control as used in some Tuya lightbulbs (+0k8 code) #define USE_SONOFF_L1 // Add support for Sonoff L1 led control #define USE_ELECTRIQ_MOODL // Add support for ElectriQ iQ-wifiMOODL RGBW LED controller @@ -403,6 +404,7 @@ #undef USE_MY92X1 // Disable support for MY92X1 RGBCW led controller as used in Sonoff B1, Ailight and Lohas #undef USE_SM16716 // Disable support for SM16716 RGB LED controller (+0k7 code) #undef USE_SM2135 // Disable support for SM2135 RGBCW led control as used in Action LSC (+0k6 code) +#undef USE_SM2335 // Disable support for SM2335 RGBCW led control as used in Switchbot Bulb (+0k# code) #undef USE_BP5758D // Disable support for BP5758D RGBCW led control as used in some Tuya lightbulbs (+0k8 code) #undef USE_SONOFF_L1 // Disable support for Sonoff L1 led control #undef USE_ELECTRIQ_MOODL // Disable support for ElectriQ iQ-wifiMOODL RGBW LED controller @@ -552,6 +554,7 @@ #undef USE_MY92X1 // Disable support for MY92X1 RGBCW led controller as used in Sonoff B1, Ailight and Lohas #undef USE_SM16716 // Disable support for SM16716 RGB LED controller (+0k7 code) #undef USE_SM2135 // Disable support for SM2135 RGBCW led control as used in Action LSC (+0k6 code) +#undef USE_SM2335 // Disable support for SM2335 RGBCW led control as used in Switchbot Bulb (+0k# code) #undef USE_BP5758D // Disable support for BP5758D RGBCW led control as used in some Tuya lightbulbs (+0k8 code) #undef USE_SONOFF_L1 // Disable support for Sonoff L1 led control #undef USE_ELECTRIQ_MOODL // Disable support for ElectriQ iQ-wifiMOODL RGBW LED controller @@ -697,6 +700,7 @@ #undef USE_MY92X1 // Disable support for MY92X1 RGBCW led controller as used in Sonoff B1, Ailight and Lohas #undef USE_SM16716 // Disable support for SM16716 RGB LED controller (+0k7 code) #undef USE_SM2135 // Disable support for SM2135 RGBCW led control as used in Action LSC (+0k6 code) +#undef USE_SM2335 // Disable support for SM2335 RGBCW led control as used in Switchbot Bulb (+0k# code) #undef USE_BP5758D // Disable support for BP5758D RGBCW led control as used in some Tuya lightbulbs (+0k8 code) #undef USE_SONOFF_L1 // Disable support for Sonoff L1 led control #undef USE_ELECTRIQ_MOODL // Disable support for ElectriQ iQ-wifiMOODL RGBW LED controller diff --git a/tasmota/include/tasmota_template.h b/tasmota/include/tasmota_template.h index 80cfa3fe8..70021178e 100644 --- a/tasmota/include/tasmota_template.h +++ b/tasmota/include/tasmota_template.h @@ -189,6 +189,7 @@ enum UserSelectablePins { GPIO_SDIO_CMD, GPIO_SDIO_CLK, GPIO_SDIO_D0, GPIO_SDIO_D1, GPIO_SDIO_D2, GPIO_SDIO_D3, // SD Card SDIO interface, including 1-bit and 4-bit modes GPIO_FLOWRATEMETER_IN, // Flowrate Meter GPIO_BP5758D_CLK, GPIO_BP5758D_DAT, // BP5758D PWM controller + GPIO_SM2335_CLK, GPIO_SM2335_DAT, // SM2335 PWM controller GPIO_SENSOR_END }; enum ProgramSelectablePins { @@ -422,6 +423,7 @@ const char kSensorNames[] PROGMEM = D_SENSOR_SDIO_D3 "|" D_SENSOR_FLOWRATEMETER "|" D_SENSOR_BP5758D_CLK "|" D_SENSOR_BP5758D_DAT "|" + D_SENSOR_SM2335_CLK "|" D_SENSOR_SM2335_DAT "|" ; const char kSensorNamesFixed[] PROGMEM = @@ -433,6 +435,7 @@ const char kSensorNamesFixed[] PROGMEM = #define MAX_WEBCAM_DATA 8 #define MAX_WEBCAM_HSD 3 #define MAX_SM2135_DAT 7 +#define MAX_SM2335_DAT 16 const uint16_t kGpioNiceList[] PROGMEM = { GPIO_NONE, // Not used @@ -663,6 +666,10 @@ const uint16_t kGpioNiceList[] PROGMEM = { AGPIO(GPIO_SM2135_CLK), // SM2135 CLOCK AGPIO(GPIO_SM2135_DAT) + MAX_SM2135_DAT, // SM2135 DATA #endif // USE_SM2135 +#ifdef USE_SM2335 + AGPIO(GPIO_SM2335_CLK), // SM2335 CLOCK + AGPIO(GPIO_SM2335_DAT) + MAX_SM2335_DAT, // SM2335 DATA +#endif // USE_SM2335 #ifdef USE_BP5758D AGPIO(GPIO_BP5758D_CLK), // BP5758D CLOCK AGPIO(GPIO_BP5758D_DAT), // BP5758D DATA diff --git a/tasmota/language/af_AF.h b/tasmota/language/af_AF.h index d07ea47f8..a29ad6816 100644 --- a/tasmota/language/af_AF.h +++ b/tasmota/language/af_AF.h @@ -773,6 +773,8 @@ #define D_SENSOR_DDSU666_RX "DDSU666 Rx" #define D_SENSOR_SM2135_CLK "SM2135 Clk" #define D_SENSOR_SM2135_DAT "SM2135 Dat" +#define D_SENSOR_SM2335_CLK "SM2335 Clk" +#define D_SENSOR_SM2335_DAT "SM2335 Dat" #define D_SENSOR_BP5758D_CLK "BP5758D Clk" #define D_SENSOR_BP5758D_DAT "BP5758D Dat" #define D_SENSOR_DEEPSLEEP "Diep slaap" diff --git a/tasmota/language/bg_BG.h b/tasmota/language/bg_BG.h index 155da5507..6498e414e 100644 --- a/tasmota/language/bg_BG.h +++ b/tasmota/language/bg_BG.h @@ -773,6 +773,8 @@ #define D_SENSOR_DDSU666_RX "DDSU666 Rx" #define D_SENSOR_SM2135_CLK "SM2135 Clk" #define D_SENSOR_SM2135_DAT "SM2135 Dat" +#define D_SENSOR_SM2335_CLK "SM2335 Clk" +#define D_SENSOR_SM2335_DAT "SM2335 Dat" #define D_SENSOR_BP5758D_CLK "BP5758D Clk" #define D_SENSOR_BP5758D_DAT "BP5758D Dat" #define D_SENSOR_DEEPSLEEP "DeepSleep" diff --git a/tasmota/language/cs_CZ.h b/tasmota/language/cs_CZ.h index d57e42a24..e03d86fe0 100644 --- a/tasmota/language/cs_CZ.h +++ b/tasmota/language/cs_CZ.h @@ -773,6 +773,8 @@ #define D_SENSOR_DDSU666_RX "DDSU666 Rx" #define D_SENSOR_SM2135_CLK "SM2135 Clk" #define D_SENSOR_SM2135_DAT "SM2135 Dat" +#define D_SENSOR_SM2335_CLK "SM2335 Clk" +#define D_SENSOR_SM2335_DAT "SM2335 Dat" #define D_SENSOR_BP5758D_CLK "BP5758D Clk" #define D_SENSOR_BP5758D_DAT "BP5758D Dat" #define D_SENSOR_DEEPSLEEP "DeepSleep" diff --git a/tasmota/language/de_DE.h b/tasmota/language/de_DE.h index da558a560..4148f0f84 100644 --- a/tasmota/language/de_DE.h +++ b/tasmota/language/de_DE.h @@ -773,6 +773,8 @@ #define D_SENSOR_DDSU666_RX "DDSU666 Rx" #define D_SENSOR_SM2135_CLK "SM2135 Clk" #define D_SENSOR_SM2135_DAT "SM2135 Dat" +#define D_SENSOR_SM2335_CLK "SM2335 Clk" +#define D_SENSOR_SM2335_DAT "SM2335 Dat" #define D_SENSOR_BP5758D_CLK "BP5758D Clk" #define D_SENSOR_BP5758D_DAT "BP5758D Dat" #define D_SENSOR_DEEPSLEEP "DeepSleep" diff --git a/tasmota/language/el_GR.h b/tasmota/language/el_GR.h index bc9cae4d1..5cd5b3344 100644 --- a/tasmota/language/el_GR.h +++ b/tasmota/language/el_GR.h @@ -773,6 +773,8 @@ #define D_SENSOR_DDSU666_RX "DDSU666 Rx" #define D_SENSOR_SM2135_CLK "SM2135 Clk" #define D_SENSOR_SM2135_DAT "SM2135 Dat" +#define D_SENSOR_SM2335_CLK "SM2335 Clk" +#define D_SENSOR_SM2335_DAT "SM2335 Dat" #define D_SENSOR_BP5758D_CLK "BP5758D Clk" #define D_SENSOR_BP5758D_DAT "BP5758D Dat" #define D_SENSOR_DEEPSLEEP "DeepSleep" diff --git a/tasmota/language/en_GB.h b/tasmota/language/en_GB.h index 6f5b040ea..1be50befb 100644 --- a/tasmota/language/en_GB.h +++ b/tasmota/language/en_GB.h @@ -773,6 +773,8 @@ #define D_SENSOR_DDSU666_RX "DDSU666 Rx" #define D_SENSOR_SM2135_CLK "SM2135 Clk" #define D_SENSOR_SM2135_DAT "SM2135 Dat" +#define D_SENSOR_SM2335_CLK "SM2335 Clk" +#define D_SENSOR_SM2335_DAT "SM2335 Dat" #define D_SENSOR_BP5758D_CLK "BP5758D Clk" #define D_SENSOR_BP5758D_DAT "BP5758D Dat" #define D_SENSOR_DEEPSLEEP "DeepSleep" diff --git a/tasmota/language/es_ES.h b/tasmota/language/es_ES.h index c730b9bdf..a517d24cc 100644 --- a/tasmota/language/es_ES.h +++ b/tasmota/language/es_ES.h @@ -773,6 +773,8 @@ #define D_SENSOR_DDSU666_RX "DDSU666 Rx" #define D_SENSOR_SM2135_CLK "SM2135 Clk" #define D_SENSOR_SM2135_DAT "SM2135 Dat" +#define D_SENSOR_SM2335_CLK "SM2335 Clk" +#define D_SENSOR_SM2335_DAT "SM2335 Dat" #define D_SENSOR_BP5758D_CLK "BP5758D Clk" #define D_SENSOR_BP5758D_DAT "BP5758D Dat" #define D_SENSOR_DEEPSLEEP "DeepSleep" diff --git a/tasmota/language/fr_FR.h b/tasmota/language/fr_FR.h index 2718ed619..d48ec0cb4 100644 --- a/tasmota/language/fr_FR.h +++ b/tasmota/language/fr_FR.h @@ -773,6 +773,8 @@ #define D_SENSOR_DDSU666_RX "DDSU666 RX" #define D_SENSOR_SM2135_CLK "SM2135 CLK" #define D_SENSOR_SM2135_DAT "SM2135 DAT" +#define D_SENSOR_SM2335_CLK "SM2335 CLK" +#define D_SENSOR_SM2335_DAT "SM2335 DAT" #define D_SENSOR_BP5758D_CLK "BP5758D Clk" #define D_SENSOR_BP5758D_DAT "BP5758D Dat" #define D_SENSOR_DEEPSLEEP "Hibernation" diff --git a/tasmota/language/fy_NL.h b/tasmota/language/fy_NL.h index 4890eb1fd..202fd7a53 100644 --- a/tasmota/language/fy_NL.h +++ b/tasmota/language/fy_NL.h @@ -773,6 +773,8 @@ #define D_SENSOR_DDSU666_RX "DDSU666 Rx" #define D_SENSOR_SM2135_CLK "SM2135 Clk" #define D_SENSOR_SM2135_DAT "SM2135 Dat" +#define D_SENSOR_SM2335_CLK "SM2335 Clk" +#define D_SENSOR_SM2335_DAT "SM2335 Dat" #define D_SENSOR_BP5758D_CLK "BP5758D Clk" #define D_SENSOR_BP5758D_DAT "BP5758D Dat" #define D_SENSOR_DEEPSLEEP "DeepSleep" diff --git a/tasmota/language/he_HE.h b/tasmota/language/he_HE.h index 7207d6197..0e3cefa3c 100644 --- a/tasmota/language/he_HE.h +++ b/tasmota/language/he_HE.h @@ -773,6 +773,8 @@ #define D_SENSOR_DDSU666_RX "DDSU666 Rx" #define D_SENSOR_SM2135_CLK "SM2135 Clk" #define D_SENSOR_SM2135_DAT "SM2135 Dat" +#define D_SENSOR_SM2335_CLK "SM2335 Clk" +#define D_SENSOR_SM2335_DAT "SM2335 Dat" #define D_SENSOR_BP5758D_CLK "BP5758D Clk" #define D_SENSOR_BP5758D_DAT "BP5758D Dat" #define D_SENSOR_DEEPSLEEP "DeepSleep" diff --git a/tasmota/language/hu_HU.h b/tasmota/language/hu_HU.h index b964ef793..21c1ec2e2 100644 --- a/tasmota/language/hu_HU.h +++ b/tasmota/language/hu_HU.h @@ -773,6 +773,8 @@ #define D_SENSOR_DDSU666_RX "DDSU666 Rx" #define D_SENSOR_SM2135_CLK "SM2135 Clk" #define D_SENSOR_SM2135_DAT "SM2135 Dat" +#define D_SENSOR_SM2335_CLK "SM2335 Clk" +#define D_SENSOR_SM2335_DAT "SM2335 Dat" #define D_SENSOR_BP5758D_CLK "BP5758D Clk" #define D_SENSOR_BP5758D_DAT "BP5758D Dat" #define D_SENSOR_DEEPSLEEP "DeepSleep" diff --git a/tasmota/language/it_IT.h b/tasmota/language/it_IT.h index c8d2085bc..e98b1a790 100644 --- a/tasmota/language/it_IT.h +++ b/tasmota/language/it_IT.h @@ -771,6 +771,8 @@ #define D_SENSOR_DDSU666_RX "DDSU666 - RX" #define D_SENSOR_SM2135_CLK "SM2135 - CLK" #define D_SENSOR_SM2135_DAT "SM2135 - DATI" +#define D_SENSOR_SM2335_CLK "SM2335 CLK" +#define D_SENSOR_SM2335_DAT "SM2335 DATI" #define D_SENSOR_BP5758D_CLK "BP5758D - CLK" #define D_SENSOR_BP5758D_DAT "BP5758D - DATI" #define D_SENSOR_DEEPSLEEP "Sleep profondo" diff --git a/tasmota/language/ko_KO.h b/tasmota/language/ko_KO.h index aa4232772..5f5b167d1 100644 --- a/tasmota/language/ko_KO.h +++ b/tasmota/language/ko_KO.h @@ -773,6 +773,8 @@ #define D_SENSOR_DDSU666_RX "DDSU666 Rx" #define D_SENSOR_SM2135_CLK "SM2135 Clk" #define D_SENSOR_SM2135_DAT "SM2135 Dat" +#define D_SENSOR_SM2335_CLK "SM2335 Clk" +#define D_SENSOR_SM2335_DAT "SM2335 Dat" #define D_SENSOR_BP5758D_CLK "BP5758D Clk" #define D_SENSOR_BP5758D_DAT "BP5758D Dat" #define D_SENSOR_DEEPSLEEP "DeepSleep" diff --git a/tasmota/language/nl_NL.h b/tasmota/language/nl_NL.h index 4060e3cd7..9ca818f66 100644 --- a/tasmota/language/nl_NL.h +++ b/tasmota/language/nl_NL.h @@ -773,6 +773,8 @@ #define D_SENSOR_DDSU666_RX "DDSU666 Rx" #define D_SENSOR_SM2135_CLK "SM2135 Clk" #define D_SENSOR_SM2135_DAT "SM2135 Dat" +#define D_SENSOR_SM2335_CLK "SM2335 Clk" +#define D_SENSOR_SM2335_DAT "SM2335 Dat" #define D_SENSOR_BP5758D_CLK "BP5758D Clk" #define D_SENSOR_BP5758D_DAT "BP5758D Dat" #define D_SENSOR_DEEPSLEEP "DeepSleep" diff --git a/tasmota/language/pl_PL.h b/tasmota/language/pl_PL.h index 6bf3b66d2..0d596765e 100644 --- a/tasmota/language/pl_PL.h +++ b/tasmota/language/pl_PL.h @@ -773,6 +773,8 @@ #define D_SENSOR_DDSU666_RX "DDSU666 Rx" #define D_SENSOR_SM2135_CLK "SM2135 Clk" #define D_SENSOR_SM2135_DAT "SM2135 Dat" +#define D_SENSOR_SM2335_CLK "SM2335 Clk" +#define D_SENSOR_SM2335_DAT "SM2335 Dat" #define D_SENSOR_BP5758D_CLK "BP5758D Clk" #define D_SENSOR_BP5758D_DAT "BP5758D Dat" #define D_SENSOR_DEEPSLEEP "Głęboko uśpiony" diff --git a/tasmota/language/pt_BR.h b/tasmota/language/pt_BR.h index fc8f54ad7..9e3455a3b 100644 --- a/tasmota/language/pt_BR.h +++ b/tasmota/language/pt_BR.h @@ -773,6 +773,8 @@ #define D_SENSOR_DDSU666_RX "DDSU666 Rx" #define D_SENSOR_SM2135_CLK "SM2135 Clk" #define D_SENSOR_SM2135_DAT "SM2135 Dat" +#define D_SENSOR_SM2335_CLK "SM2335 Clk" +#define D_SENSOR_SM2335_DAT "SM2335 Dat" #define D_SENSOR_BP5758D_CLK "BP5758D Clk" #define D_SENSOR_BP5758D_DAT "BP5758D Dat" #define D_SENSOR_DEEPSLEEP "DeepSleep" diff --git a/tasmota/language/pt_PT.h b/tasmota/language/pt_PT.h index d02cfb137..8b1acbe0b 100644 --- a/tasmota/language/pt_PT.h +++ b/tasmota/language/pt_PT.h @@ -773,6 +773,8 @@ #define D_SENSOR_DDSU666_RX "DDSU666 Rx" #define D_SENSOR_SM2135_CLK "SM2135 Clk" #define D_SENSOR_SM2135_DAT "SM2135 Dat" +#define D_SENSOR_SM2335_CLK "SM2335 Clk" +#define D_SENSOR_SM2335_DAT "SM2335 Dat" #define D_SENSOR_BP5758D_CLK "BP5758D Clk" #define D_SENSOR_BP5758D_DAT "BP5758D Dat" #define D_SENSOR_DEEPSLEEP "DeepSleep" diff --git a/tasmota/language/ro_RO.h b/tasmota/language/ro_RO.h index b6fb28845..ef5923f05 100644 --- a/tasmota/language/ro_RO.h +++ b/tasmota/language/ro_RO.h @@ -773,6 +773,8 @@ #define D_SENSOR_DDSU666_RX "DDSU666 Rx" #define D_SENSOR_SM2135_CLK "SM2135 Clk" #define D_SENSOR_SM2135_DAT "SM2135 Dat" +#define D_SENSOR_SM2335_CLK "SM2335 Clk" +#define D_SENSOR_SM2335_DAT "SM2335 Dat" #define D_SENSOR_BP5758D_CLK "BP5758D Clk" #define D_SENSOR_BP5758D_DAT "BP5758D Dat" #define D_SENSOR_DEEPSLEEP "DeepSleep" diff --git a/tasmota/language/ru_RU.h b/tasmota/language/ru_RU.h index d69309c34..735fb4b37 100644 --- a/tasmota/language/ru_RU.h +++ b/tasmota/language/ru_RU.h @@ -773,6 +773,8 @@ #define D_SENSOR_DDSU666_RX "DDSU666 Rx" #define D_SENSOR_SM2135_CLK "SM2135 Clk" #define D_SENSOR_SM2135_DAT "SM2135 Dat" +#define D_SENSOR_SM2335_CLK "SM2335 Clk" +#define D_SENSOR_SM2335_DAT "SM2335 Dat" #define D_SENSOR_BP5758D_CLK "BP5758D Clk" #define D_SENSOR_BP5758D_DAT "BP5758D Dat" #define D_SENSOR_DEEPSLEEP "DeepSleep" diff --git a/tasmota/language/sk_SK.h b/tasmota/language/sk_SK.h index 3820d88e8..41fabdaf3 100644 --- a/tasmota/language/sk_SK.h +++ b/tasmota/language/sk_SK.h @@ -773,6 +773,8 @@ #define D_SENSOR_DDSU666_RX "DDSU666 Rx" #define D_SENSOR_SM2135_CLK "SM2135 Clk" #define D_SENSOR_SM2135_DAT "SM2135 Dat" +#define D_SENSOR_SM2335_CLK "SM2335 Clk" +#define D_SENSOR_SM2335_DAT "SM2335 Dat" #define D_SENSOR_BP5758D_CLK "BP5758D Clk" #define D_SENSOR_BP5758D_DAT "BP5758D Dat" #define D_SENSOR_DEEPSLEEP "DeepSleep" diff --git a/tasmota/language/sv_SE.h b/tasmota/language/sv_SE.h index e5ae351bb..66b34580d 100644 --- a/tasmota/language/sv_SE.h +++ b/tasmota/language/sv_SE.h @@ -773,6 +773,8 @@ #define D_SENSOR_DDSU666_RX "DDSU666 Rx" #define D_SENSOR_SM2135_CLK "SM2135 Clk" #define D_SENSOR_SM2135_DAT "SM2135 Dat" +#define D_SENSOR_SM2335_CLK "SM2335 Clk" +#define D_SENSOR_SM2335_DAT "SM2335 Dat" #define D_SENSOR_BP5758D_CLK "BP5758D Clk" #define D_SENSOR_BP5758D_DAT "BP5758D Dat" #define D_SENSOR_DEEPSLEEP "DeepSleep" diff --git a/tasmota/language/tr_TR.h b/tasmota/language/tr_TR.h index 942936615..150eaff3f 100644 --- a/tasmota/language/tr_TR.h +++ b/tasmota/language/tr_TR.h @@ -773,6 +773,8 @@ #define D_SENSOR_DDSU666_RX "DDSU666 Rx" #define D_SENSOR_SM2135_CLK "SM2135 Clk" #define D_SENSOR_SM2135_DAT "SM2135 Dat" +#define D_SENSOR_SM2335_CLK "SM2335 Clk" +#define D_SENSOR_SM2335_DAT "SM2335 Dat" #define D_SENSOR_BP5758D_CLK "BP5758D Clk" #define D_SENSOR_BP5758D_DAT "BP5758D Dat" #define D_SENSOR_DEEPSLEEP "DeepSleep" diff --git a/tasmota/language/uk_UA.h b/tasmota/language/uk_UA.h index a0e5c5eaf..36f192931 100644 --- a/tasmota/language/uk_UA.h +++ b/tasmota/language/uk_UA.h @@ -773,6 +773,8 @@ #define D_SENSOR_DDSU666_RX "DDSU666 Rx" #define D_SENSOR_SM2135_CLK "SM2135 Clk" #define D_SENSOR_SM2135_DAT "SM2135 Dat" +#define D_SENSOR_SM2335_CLK "SM2335 Clk" +#define D_SENSOR_SM2335_DAT "SM2335 Dat" #define D_SENSOR_BP5758D_CLK "BP5758D Clk" #define D_SENSOR_BP5758D_DAT "BP5758D Dat" #define D_SENSOR_DEEPSLEEP "DeepSleep" diff --git a/tasmota/language/vi_VN.h b/tasmota/language/vi_VN.h index 8833d1046..9ef9fd9f0 100644 --- a/tasmota/language/vi_VN.h +++ b/tasmota/language/vi_VN.h @@ -773,6 +773,8 @@ #define D_SENSOR_DDSU666_RX "DDSU666 Rx" #define D_SENSOR_SM2135_CLK "SM2135 Clk" #define D_SENSOR_SM2135_DAT "SM2135 Dat" +#define D_SENSOR_SM2335_CLK "SM2335 Clk" +#define D_SENSOR_SM2335_DAT "SM2335 Dat" #define D_SENSOR_BP5758D_CLK "BP5758D Clk" #define D_SENSOR_BP5758D_DAT "BP5758D Dat" #define D_SENSOR_DEEPSLEEP "DeepSleep" diff --git a/tasmota/language/zh_CN.h b/tasmota/language/zh_CN.h index 7db58cadb..4ca980d70 100644 --- a/tasmota/language/zh_CN.h +++ b/tasmota/language/zh_CN.h @@ -773,6 +773,8 @@ #define D_SENSOR_DDSU666_RX "DDSU666 Rx" #define D_SENSOR_SM2135_CLK "SM2135 Clk" #define D_SENSOR_SM2135_DAT "SM2135 Dat" +#define D_SENSOR_SM2335_CLK "SM2335 Clk" +#define D_SENSOR_SM2335_DAT "SM2335 Dat" #define D_SENSOR_BP5758D_CLK "BP5758D Clk" #define D_SENSOR_BP5758D_DAT "BP5758D Dat" #define D_SENSOR_DEEPSLEEP "DeepSleep" diff --git a/tasmota/language/zh_TW.h b/tasmota/language/zh_TW.h index 7f067f023..277b3ca1c 100644 --- a/tasmota/language/zh_TW.h +++ b/tasmota/language/zh_TW.h @@ -773,6 +773,8 @@ #define D_SENSOR_DDSU666_RX "DDSU666 Rx" #define D_SENSOR_SM2135_CLK "SM2135 Clk" #define D_SENSOR_SM2135_DAT "SM2135 Dat" +#define D_SENSOR_SM2335_CLK "SM2335 Clk" +#define D_SENSOR_SM2335_DAT "SM2335 Dat" #define D_SENSOR_BP5758D_CLK "BP5758D Clk" #define D_SENSOR_BP5758D_DAT "BP5758D Dat" #define D_SENSOR_DEEPSLEEP "DeepSleep" diff --git a/tasmota/my_user_config.h b/tasmota/my_user_config.h index 1ce6bf230..fcfad2090 100644 --- a/tasmota/my_user_config.h +++ b/tasmota/my_user_config.h @@ -556,6 +556,7 @@ #define USE_MY92X1 // Add support for MY92X1 RGBCW led controller as used in Sonoff B1, Ailight and Lohas #define USE_SM16716 // Add support for SM16716 RGB LED controller (+0k7 code) #define USE_SM2135 // Add support for SM2135 RGBCW led control as used in Action LSC (+0k6 code) +#define USE_SM2335 // Add support for SM2335 RGBCW led control as used in SwitchBot Color Bulb (+0k# code) #define USE_BP5758D // Add support for BP5758D RGBCW led control as used in some Tuya lightbulbs (+0k8 code) #define USE_SONOFF_L1 // Add support for Sonoff L1 led control #define USE_ELECTRIQ_MOODL // Add support for ElectriQ iQ-wifiMOODL RGBW LED controller (+0k3 code) diff --git a/tasmota/tasmota_support/support_features.ino b/tasmota/tasmota_support/support_features.ino index aae6e897c..2e6203aa8 100644 --- a/tasmota/tasmota_support/support_features.ino +++ b/tasmota/tasmota_support/support_features.ino @@ -815,7 +815,9 @@ void ResponseAppendFeatures(void) #if defined(USE_I2C) && defined(USE_HYT) feature8 |= 0x20000000; // xsns_97_hyt.ino #endif -// feature8 |= 0x40000000; +#if defined(USE_LIGHT) && defined(USE_SM2335) + feature8 |= 0x40000000; // xlgt_09_sm2335.ino +#endif // feature8 |= 0x80000000; } diff --git a/tasmota/tasmota_xlgt_light/xlgt_09_sm2335.ino b/tasmota/tasmota_xlgt_light/xlgt_09_sm2335.ino new file mode 100644 index 000000000..f41913245 --- /dev/null +++ b/tasmota/tasmota_xlgt_light/xlgt_09_sm2335.ino @@ -0,0 +1,245 @@ +/* + xlgt_09_sm2335.ino - sm2335 five channel led support for Tasmota + + Copyright (C) 2021 Theo Arends and Cossid + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifdef USE_LIGHT +#ifdef USE_SM2335 +/*********************************************************************************************\ + * SM2335 RGBCW Led bulbs like the SwitchBot Color Bulb + * + * SwitchBot Color Bulb + * {"NAME":"SwitchBot Color Bulb","GPIO":[0,0,0,0,9129,9088,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"FLAG":0,"BASE":1} +\*********************************************************************************************/ + +#define XLGT_09 9 + +// 11 = identification | 0 = reserved | 00 = Standby | 000 = start at OUT1/5 +#define SM2335_ADDR_STANDBY 0xC0 // 11000000 0xC0 +// 11 = identification | 0 = reserved | 01 = 3 channels (RGB) | 000 = start at OUT1/5 +#define SM2335_ADDR_START_3CH 0xC8 // 11001000 0xC8 +// 11 = identification | 0 = reserved | 10 = 2 channels (CW) | 000 = start at OUT1/5 +#define SM2335_ADDR_START_2CH 0xD0 // 11010000 0xD0 +// 11 = identification | 0 = reserved | 11 = 5 channels (RGB+CW) | 000 = start at OUT1/5 +#define SM2335_ADDR_START_5CH 0xD8 // 11011000 0xD8 + +// Current values +#define SM2335_RGB_10MA_CW_5MA 0x0 // 0000 RGB 10mA | CW 5mA +#define SM2335_RGB_20MA_CW_10MA 0x1 // 0001 RGB 20mA | CW 10mA +#define SM2335_RGB_30MA_CW_15MA 0x2 // 0010 RGB 30mA | CW 15mA +#define SM2335_RGB_40MA_CW_20MA 0x3 // 0011 RGB 40mA | CW 20mA +#define SM2335_RGB_50MA_CW_25MA 0x4 // 0100 RGB 50mA | CW 25mA +#define SM2335_RGB_60MA_CW_30MA 0x5 // 0101 RGB 60mA | CW 30mA +#define SM2335_RGB_70MA_CW_35MA 0x6 // 0110 RGB 70mA | CW 35mA +#define SM2335_RGB_80MA_CW_40MA 0x7 // 0111 RGB 80mA | CW 40mA +#define SM2335_RGB_90MA_CW_45MA 0x8 // 1000 RGB 90mA | CW 45mA +#define SM2335_RGB_100MA_CW_50MA 0x9 // 1001 RGB 100mA | CW 50mA +#define SM2335_RGB_110MA_CW_55MA 0xA // 1010 RGB 110mA | CW 55mA +#define SM2335_RGB_120MA_CW_60MA 0xB // 1011 RGB 120mA | CW 60mA +#define SM2335_RGB_130MA_CW_65MA 0xC // 1100 RGB 130mA | CW 65mA +#define SM2335_RGB_140MA_CW_70MA 0xD // 1101 RGB 140mA | CW 70mA +#define SM2335_RGB_150MA_CW_75MA 0xE // 1110 RGB 150mA | CW 75mA +#define SM2335_RGB_160MA_CW_80MA 0xF // 1111 RGB 160mA | CW 80mA + +enum Sm2335Current { SM2335_10_5, SM2335_20_10, SM2335_30_15, SM2335_40_20, SM2335_50_25, + SM2335_60_30, SM2335_70_35, SM2335_80_40, SM2335_90_45, SM2335_100_50, SM2335_110_55, + SM2335_120_60, SM2335_130_65, SM2335_140_70, SM2335_150_75, SM2335_160_80 }; + +struct SM2335 { + uint8_t clk = 0; + uint8_t data = 0; + uint8_t currentValue; + uint8_t currentEnum = SM2335_50_25; +} Sm2335; + +/*********************************************************************************************\ + * SM2335 code - inspired by Bp5758d/SM2135 +\*********************************************************************************************/ +const uint8_t SM2335_DELAY = 2; + +void SM2335Init(void) { + pinMode(Sm2335.data, OUTPUT); + pinMode(Sm2335.clk, OUTPUT); + SM2335Stop(); +} + +void SM2335Write(uint8_t value) { + for (int bit_idx = 7; bit_idx >= 0; bit_idx--) { + bool bit = bitRead(value, bit_idx); + digitalWrite(Sm2335.data, bit); + delayMicroseconds(SM2335_DELAY); + digitalWrite(Sm2335.clk, HIGH); + delayMicroseconds(SM2335_DELAY); + digitalWrite(Sm2335.clk, LOW); + delayMicroseconds(SM2335_DELAY); + } + // Wait for ACK + pinMode(Sm2335.data, INPUT); + digitalWrite(Sm2335.clk, HIGH); + delayMicroseconds(SM2335_DELAY); + digitalWrite(Sm2335.clk, LOW); + delayMicroseconds(SM2335_DELAY); + pinMode(Sm2335.data, OUTPUT); +} + +void SM2335Start(uint16_t addr) { + digitalWrite(Sm2335.data, LOW); + delayMicroseconds(SM2335_DELAY); + digitalWrite(Sm2335.clk, LOW); + delayMicroseconds(SM2335_DELAY); + SM2335Write(addr); +} + +void SM2335Stop(void) { + digitalWrite(Sm2335.clk, HIGH); + delayMicroseconds(SM2335_DELAY); + digitalWrite(Sm2335.data, HIGH); + delayMicroseconds(SM2335_DELAY); +} + +/********************************************************************************************/ + +bool SM2335SetChannels(void) { + uint16_t *cur_col_10 = (uint16_t*)XdrvMailbox.command; + + // If we receive 0 for all channels, we'll assume that the lightbulb is off, and activate SM2335's standby mode. + if (cur_col_10[0] == 0 && cur_col_10[1] == 0 && cur_col_10[2] == 0 && cur_col_10[3] == 0 && cur_col_10[4] == 0) { + SM2335Start(SM2335_ADDR_STANDBY); + SM2335Write(0); // Current + SM2335Write(0); // Red 1/2 + SM2335Write(0); // Red 2/2 + SM2335Write(0); // Green 1/2 + SM2335Write(0); // Green 2/2 + SM2335Write(0); // Blue 1/2 + SM2335Write(0); // Blue 2/2 + SM2335Write(0); // Cold White 1/2 + SM2335Write(0); // Cold White 2/2 + SM2335Write(0); // Warm White 1/2 + SM2335Write(0); // WarmW hite 2/2 + SM2335Stop(); + return true; + } + + // Write the header activating all 5 channels + SM2335Start(SM2335_ADDR_START_5CH); + // Set the current defined in ModuleSelected. + SM2335Write(Sm2335.currentValue); + // Set RGB and CW grayscale. + SM2335Write((uint8_t)(cur_col_10[0] >> 8)); // Red 1/2 + SM2335Write((uint8_t)(cur_col_10[0] & 0xFF)); // Red 2/2 + SM2335Write((uint8_t)(cur_col_10[1] >> 8)); // Green 1/2 + SM2335Write((uint8_t)(cur_col_10[1] & 0xFF)); // Green 2/2 + SM2335Write((uint8_t)(cur_col_10[2] >> 8)); // Blue 1/2 + SM2335Write((uint8_t)(cur_col_10[2] & 0xFF)); // Blue 2/2 + SM2335Write((uint8_t)(cur_col_10[3] >> 8)); // Cold White 1/2 + SM2335Write((uint8_t)(cur_col_10[3] & 0xFF)); // Cold White 2/2 + SM2335Write((uint8_t)(cur_col_10[4] >> 8)); // Warm White 1/2 + SM2335Write((uint8_t)(cur_col_10[4] & 0xFF)); // Warm White 2/2 + + SM2335Stop(); + return true; +} + +void SM2335ModuleSelected(void) +{ + if (PinUsed(GPIO_SM2335_CLK) && PinUsed(GPIO_SM2335_DAT, GPIO_ANY)) { + Sm2335.clk = Pin(GPIO_SM2335_CLK); + Sm2335.data = Pin(GPIO_SM2335_DAT, GPIO_ANY); + + // See #define MAX_SM2335_DAT 16 in tasmota_template.h + Sm2335.currentEnum = GetPin(Sm2335.data) - AGPIO(GPIO_SM2335_DAT); // 0 .. 15 + + switch (Sm2335.currentEnum) { + case SM2335_10_5: + Sm2335.currentValue = (SM2335_RGB_10MA_CW_5MA << 4) | SM2335_RGB_10MA_CW_5MA; + break; + case SM2335_20_10: + Sm2335.currentValue = (SM2335_RGB_20MA_CW_10MA << 4) | SM2335_RGB_20MA_CW_10MA; + break; + case SM2335_30_15: + Sm2335.currentValue = (SM2335_RGB_30MA_CW_15MA << 4) | SM2335_RGB_30MA_CW_15MA; + break; + case SM2335_40_20: + Sm2335.currentValue = (SM2335_RGB_30MA_CW_15MA << 4) | SM2335_RGB_30MA_CW_15MA; + break; + case SM2335_50_25: + Sm2335.currentValue = (SM2335_RGB_50MA_CW_25MA << 4) | SM2335_RGB_50MA_CW_25MA; + break; + case SM2335_60_30: + Sm2335.currentValue = (SM2335_RGB_60MA_CW_30MA << 4) | SM2335_RGB_60MA_CW_30MA; + break; + case SM2335_70_35: + Sm2335.currentValue = (SM2335_RGB_70MA_CW_35MA << 4) | SM2335_RGB_70MA_CW_35MA; + break; + case SM2335_80_40: + Sm2335.currentValue = (SM2335_RGB_80MA_CW_40MA << 4) | SM2335_RGB_80MA_CW_40MA; + break; + case SM2335_90_45: + Sm2335.currentValue = (SM2335_RGB_90MA_CW_45MA << 4) | SM2335_RGB_90MA_CW_45MA; + break; + case SM2335_100_50: + Sm2335.currentValue = (SM2335_RGB_100MA_CW_50MA << 4) | SM2335_RGB_100MA_CW_50MA; + break; + case SM2335_110_55: + Sm2335.currentValue = (SM2335_RGB_110MA_CW_55MA << 4) | SM2335_RGB_110MA_CW_55MA; + break; + case SM2335_120_60: + Sm2335.currentValue = (SM2335_RGB_120MA_CW_60MA << 4) | SM2335_RGB_120MA_CW_60MA; + break; + case SM2335_130_65: + Sm2335.currentValue = (SM2335_RGB_130MA_CW_65MA << 4) | SM2335_RGB_130MA_CW_65MA; + break; + case SM2335_140_70: + Sm2335.currentValue = (SM2335_RGB_140MA_CW_70MA << 4) | SM2335_RGB_140MA_CW_70MA; + break; + case SM2335_150_75: + Sm2335.currentValue = (SM2335_RGB_150MA_CW_75MA << 4) | SM2335_RGB_150MA_CW_75MA; + break; + case SM2335_160_80: + Sm2335.currentValue = (SM2335_RGB_160MA_CW_80MA << 4) | SM2335_RGB_160MA_CW_80MA; + break; + } + + SM2335Init(); + + TasmotaGlobal.light_type = LT_RGBWC; + TasmotaGlobal.light_driver = XLGT_09; + AddLog(LOG_LEVEL_DEBUG, PSTR("LGT: SM2335 Found")); + } +} + +/*********************************************************************************************\ + * Interface +\*********************************************************************************************/ + +bool Xlgt09(uint8_t function) +{ + bool result = false; + + switch (function) { + case FUNC_SET_CHANNELS: + result = SM2335SetChannels(); + break; + case FUNC_MODULE_INIT: + SM2335ModuleSelected(); + break; + } + return result; +} + +#endif // USE_SM2335 +#endif // USE_LIGHT diff --git a/tools/decode-status.py b/tools/decode-status.py index cde2a575e..5a7bba7d6 100755 --- a/tools/decode-status.py +++ b/tools/decode-status.py @@ -280,7 +280,7 @@ a_features = [[ "USE_HDC2010","USE_LSC_MCSL","USE_SONOFF_SPM","USE_SHIFT595", "USE_SDM230","USE_CM110x","USE_BL6523","USE_ADE7880", "USE_PCF85363","USE_DS3502","USE_IMPROV","USE_FLOWRATEMETER", - "USE_BP5758D","USE_HYT","","" + "USE_BP5758D","USE_HYT","USE_SM2335","" ],[ "","","","", "","","","", From 996d614027fff68156303776462b9cd589818902 Mon Sep 17 00:00:00 2001 From: Cossid Date: Tue, 21 Jun 2022 00:50:44 -0500 Subject: [PATCH 2/9] SM2335 - Fix an argument size. --- tasmota/tasmota_xlgt_light/xlgt_09_sm2335.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasmota/tasmota_xlgt_light/xlgt_09_sm2335.ino b/tasmota/tasmota_xlgt_light/xlgt_09_sm2335.ino index f41913245..347067a04 100644 --- a/tasmota/tasmota_xlgt_light/xlgt_09_sm2335.ino +++ b/tasmota/tasmota_xlgt_light/xlgt_09_sm2335.ino @@ -96,7 +96,7 @@ void SM2335Write(uint8_t value) { pinMode(Sm2335.data, OUTPUT); } -void SM2335Start(uint16_t addr) { +void SM2335Start(uint8_t addr) { digitalWrite(Sm2335.data, LOW); delayMicroseconds(SM2335_DELAY); digitalWrite(Sm2335.clk, LOW); From 6f7ff480f889b42768a716d34c2df6552075c042 Mon Sep 17 00:00:00 2001 From: Cossid Date: Tue, 21 Jun 2022 00:51:21 -0500 Subject: [PATCH 3/9] SM2335 - Fix a typo. --- tasmota/tasmota_xlgt_light/xlgt_09_sm2335.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasmota/tasmota_xlgt_light/xlgt_09_sm2335.ino b/tasmota/tasmota_xlgt_light/xlgt_09_sm2335.ino index 347067a04..f8ecd89a0 100644 --- a/tasmota/tasmota_xlgt_light/xlgt_09_sm2335.ino +++ b/tasmota/tasmota_xlgt_light/xlgt_09_sm2335.ino @@ -129,7 +129,7 @@ bool SM2335SetChannels(void) { SM2335Write(0); // Cold White 1/2 SM2335Write(0); // Cold White 2/2 SM2335Write(0); // Warm White 1/2 - SM2335Write(0); // WarmW hite 2/2 + SM2335Write(0); // Warm White 2/2 SM2335Stop(); return true; } From 5ec8aa542079be89b47f9b2bf6e271a0422106bd Mon Sep 17 00:00:00 2001 From: Cossid Date: Tue, 21 Jun 2022 19:01:16 -0500 Subject: [PATCH 4/9] Remove unknown comment of code size added. --- tasmota/my_user_config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasmota/my_user_config.h b/tasmota/my_user_config.h index 397da4737..ea88e9bef 100644 --- a/tasmota/my_user_config.h +++ b/tasmota/my_user_config.h @@ -556,7 +556,7 @@ #define USE_MY92X1 // Add support for MY92X1 RGBCW led controller as used in Sonoff B1, Ailight and Lohas #define USE_SM16716 // Add support for SM16716 RGB LED controller (+0k7 code) #define USE_SM2135 // Add support for SM2135 RGBCW led control as used in Action LSC (+0k6 code) -#define USE_SM2335 // Add support for SM2335 RGBCW led control as used in SwitchBot Color Bulb (+0k# code) +#define USE_SM2335 // Add support for SM2335 RGBCW led control as used in SwitchBot Color Bulb #define USE_BP5758D // Add support for BP5758D RGBCW led control as used in some Tuya lightbulbs (+0k8 code) #define USE_SONOFF_L1 // Add support for Sonoff L1 led control #define USE_ELECTRIQ_MOODL // Add support for ElectriQ iQ-wifiMOODL RGBW LED controller (+0k3 code) From 9774cc84782c07ee471bf8888ea0af0f62c25814 Mon Sep 17 00:00:00 2001 From: Cossid Date: Tue, 21 Jun 2022 19:01:32 -0500 Subject: [PATCH 5/9] Add release note for feature added. --- RELEASENOTES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 1a0505579..92888e5b0 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -109,6 +109,7 @@ The latter links can be used for OTA upgrades too like ``OtaUrl http://ota.tasmo ## Changelog v12.0.2.1 ### Added +- Support for 5-channel light dimmer driver SM2335 used in SwitchBot Color Bulbs ### Breaking Changed From d763bf24ebfa313c359c29253df9d69dee0e4944 Mon Sep 17 00:00:00 2001 From: Cossid Date: Tue, 21 Jun 2022 22:44:50 -0500 Subject: [PATCH 6/9] Remove unknown code size comments. --- tasmota/include/tasmota_configurations.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tasmota/include/tasmota_configurations.h b/tasmota/include/tasmota_configurations.h index eb8af48f5..1eb21552f 100644 --- a/tasmota/include/tasmota_configurations.h +++ b/tasmota/include/tasmota_configurations.h @@ -69,7 +69,7 @@ #define USE_MY92X1 // Add support for MY92X1 RGBCW led controller as used in Sonoff B1, Ailight and Lohas #define USE_SM16716 // Add support for SM16716 RGB LED controller (+0k7 code) #define USE_SM2135 // Add support for SM2135 RGBCW led control as used in Action LSC (+0k6 code) -#define USE_SM2335 // Add support for SM2335 RGBCW led control as used in Switchbot Bulb (+0k# code) +#define USE_SM2335 // Add support for SM2335 RGBCW led control as used in Switchbot Bulb #define USE_BP5758D // Add support for BP5758D RGBCW led control as used in some Tuya lightbulbs (+0k8 code) #define USE_SONOFF_L1 // Add support for Sonoff L1 led control #define USE_ELECTRIQ_MOODL // Add support for ElectriQ iQ-wifiMOODL RGBW LED controller @@ -404,7 +404,7 @@ #undef USE_MY92X1 // Disable support for MY92X1 RGBCW led controller as used in Sonoff B1, Ailight and Lohas #undef USE_SM16716 // Disable support for SM16716 RGB LED controller (+0k7 code) #undef USE_SM2135 // Disable support for SM2135 RGBCW led control as used in Action LSC (+0k6 code) -#undef USE_SM2335 // Disable support for SM2335 RGBCW led control as used in Switchbot Bulb (+0k# code) +#undef USE_SM2335 // Disable support for SM2335 RGBCW led control as used in Switchbot Bulb #undef USE_BP5758D // Disable support for BP5758D RGBCW led control as used in some Tuya lightbulbs (+0k8 code) #undef USE_SONOFF_L1 // Disable support for Sonoff L1 led control #undef USE_ELECTRIQ_MOODL // Disable support for ElectriQ iQ-wifiMOODL RGBW LED controller @@ -554,7 +554,7 @@ #undef USE_MY92X1 // Disable support for MY92X1 RGBCW led controller as used in Sonoff B1, Ailight and Lohas #undef USE_SM16716 // Disable support for SM16716 RGB LED controller (+0k7 code) #undef USE_SM2135 // Disable support for SM2135 RGBCW led control as used in Action LSC (+0k6 code) -#undef USE_SM2335 // Disable support for SM2335 RGBCW led control as used in Switchbot Bulb (+0k# code) +#undef USE_SM2335 // Disable support for SM2335 RGBCW led control as used in Switchbot Bulb #undef USE_BP5758D // Disable support for BP5758D RGBCW led control as used in some Tuya lightbulbs (+0k8 code) #undef USE_SONOFF_L1 // Disable support for Sonoff L1 led control #undef USE_ELECTRIQ_MOODL // Disable support for ElectriQ iQ-wifiMOODL RGBW LED controller @@ -700,7 +700,7 @@ #undef USE_MY92X1 // Disable support for MY92X1 RGBCW led controller as used in Sonoff B1, Ailight and Lohas #undef USE_SM16716 // Disable support for SM16716 RGB LED controller (+0k7 code) #undef USE_SM2135 // Disable support for SM2135 RGBCW led control as used in Action LSC (+0k6 code) -#undef USE_SM2335 // Disable support for SM2335 RGBCW led control as used in Switchbot Bulb (+0k# code) +#undef USE_SM2335 // Disable support for SM2335 RGBCW led control as used in Switchbot Bulb #undef USE_BP5758D // Disable support for BP5758D RGBCW led control as used in some Tuya lightbulbs (+0k8 code) #undef USE_SONOFF_L1 // Disable support for Sonoff L1 led control #undef USE_ELECTRIQ_MOODL // Disable support for ElectriQ iQ-wifiMOODL RGBW LED controller From 8ffc7b9f0260c5d86af663db36116791a172eee6 Mon Sep 17 00:00:00 2001 From: Cossid Date: Wed, 22 Jun 2022 10:00:34 -0500 Subject: [PATCH 7/9] SM2335 - Reduce code size by replacing redundant calls with for loops. Remove defines that are unused or can be replaced with array locations. --- tasmota/tasmota_xlgt_light/xlgt_09_sm2335.ino | 133 +++++------------- 1 file changed, 33 insertions(+), 100 deletions(-) diff --git a/tasmota/tasmota_xlgt_light/xlgt_09_sm2335.ino b/tasmota/tasmota_xlgt_light/xlgt_09_sm2335.ino index f8ecd89a0..e020b0a5e 100644 --- a/tasmota/tasmota_xlgt_light/xlgt_09_sm2335.ino +++ b/tasmota/tasmota_xlgt_light/xlgt_09_sm2335.ino @@ -31,39 +31,34 @@ // 11 = identification | 0 = reserved | 00 = Standby | 000 = start at OUT1/5 #define SM2335_ADDR_STANDBY 0xC0 // 11000000 0xC0 // 11 = identification | 0 = reserved | 01 = 3 channels (RGB) | 000 = start at OUT1/5 -#define SM2335_ADDR_START_3CH 0xC8 // 11001000 0xC8 +//#define SM2335_ADDR_START_3CH 0xC8 // 11001000 0xC8 // 11 = identification | 0 = reserved | 10 = 2 channels (CW) | 000 = start at OUT1/5 -#define SM2335_ADDR_START_2CH 0xD0 // 11010000 0xD0 +//#define SM2335_ADDR_START_2CH 0xD0 // 11010000 0xD0 // 11 = identification | 0 = reserved | 11 = 5 channels (RGB+CW) | 000 = start at OUT1/5 #define SM2335_ADDR_START_5CH 0xD8 // 11011000 0xD8 // Current values -#define SM2335_RGB_10MA_CW_5MA 0x0 // 0000 RGB 10mA | CW 5mA -#define SM2335_RGB_20MA_CW_10MA 0x1 // 0001 RGB 20mA | CW 10mA -#define SM2335_RGB_30MA_CW_15MA 0x2 // 0010 RGB 30mA | CW 15mA -#define SM2335_RGB_40MA_CW_20MA 0x3 // 0011 RGB 40mA | CW 20mA -#define SM2335_RGB_50MA_CW_25MA 0x4 // 0100 RGB 50mA | CW 25mA -#define SM2335_RGB_60MA_CW_30MA 0x5 // 0101 RGB 60mA | CW 30mA -#define SM2335_RGB_70MA_CW_35MA 0x6 // 0110 RGB 70mA | CW 35mA -#define SM2335_RGB_80MA_CW_40MA 0x7 // 0111 RGB 80mA | CW 40mA -#define SM2335_RGB_90MA_CW_45MA 0x8 // 1000 RGB 90mA | CW 45mA -#define SM2335_RGB_100MA_CW_50MA 0x9 // 1001 RGB 100mA | CW 50mA -#define SM2335_RGB_110MA_CW_55MA 0xA // 1010 RGB 110mA | CW 55mA -#define SM2335_RGB_120MA_CW_60MA 0xB // 1011 RGB 120mA | CW 60mA -#define SM2335_RGB_130MA_CW_65MA 0xC // 1100 RGB 130mA | CW 65mA -#define SM2335_RGB_140MA_CW_70MA 0xD // 1101 RGB 140mA | CW 70mA -#define SM2335_RGB_150MA_CW_75MA 0xE // 1110 RGB 150mA | CW 75mA -#define SM2335_RGB_160MA_CW_80MA 0xF // 1111 RGB 160mA | CW 80mA - -enum Sm2335Current { SM2335_10_5, SM2335_20_10, SM2335_30_15, SM2335_40_20, SM2335_50_25, - SM2335_60_30, SM2335_70_35, SM2335_80_40, SM2335_90_45, SM2335_100_50, SM2335_110_55, - SM2335_120_60, SM2335_130_65, SM2335_140_70, SM2335_150_75, SM2335_160_80 }; +// 0x0 // 0000 RGB 10mA | CW 5mA +// 0x1 // 0001 RGB 20mA | CW 10mA +// 0x2 // 0010 RGB 30mA | CW 15mA +// 0x3 // 0011 RGB 40mA | CW 20mA +// 0x4 // 0100 RGB 50mA | CW 25mA +// 0x5 // 0101 RGB 60mA | CW 30mA +// 0x6 // 0110 RGB 70mA | CW 35mA +// 0x7 // 0111 RGB 80mA | CW 40mA +// 0x8 // 1000 RGB 90mA | CW 45mA +// 0x9 // 1001 RGB 100mA | CW 50mA +// 0xA // 1010 RGB 110mA | CW 55mA +// 0xB // 1011 RGB 120mA | CW 60mA +// 0xC // 1100 RGB 130mA | CW 65mA +// 0xD // 1101 RGB 140mA | CW 70mA +// 0xE // 1110 RGB 150mA | CW 75mA +// 0xF // 1111 RGB 160mA | CW 80mA struct SM2335 { uint8_t clk = 0; uint8_t data = 0; - uint8_t currentValue; - uint8_t currentEnum = SM2335_50_25; + uint8_t current; } Sm2335; /*********************************************************************************************\ @@ -119,17 +114,11 @@ bool SM2335SetChannels(void) { // If we receive 0 for all channels, we'll assume that the lightbulb is off, and activate SM2335's standby mode. if (cur_col_10[0] == 0 && cur_col_10[1] == 0 && cur_col_10[2] == 0 && cur_col_10[3] == 0 && cur_col_10[4] == 0) { SM2335Start(SM2335_ADDR_STANDBY); - SM2335Write(0); // Current - SM2335Write(0); // Red 1/2 - SM2335Write(0); // Red 2/2 - SM2335Write(0); // Green 1/2 - SM2335Write(0); // Green 2/2 - SM2335Write(0); // Blue 1/2 - SM2335Write(0); // Blue 2/2 - SM2335Write(0); // Cold White 1/2 - SM2335Write(0); // Cold White 2/2 - SM2335Write(0); // Warm White 1/2 - SM2335Write(0); // Warm White 2/2 + // Clear all remaining data. This clears out Current, Red, Green, Blue, Cold White, Warm White. + for (int i = 0; i < 11; i++) + { + SM2335Write(0); + } SM2335Stop(); return true; } @@ -137,19 +126,13 @@ bool SM2335SetChannels(void) { // Write the header activating all 5 channels SM2335Start(SM2335_ADDR_START_5CH); // Set the current defined in ModuleSelected. - SM2335Write(Sm2335.currentValue); + SM2335Write(Sm2335.current); // Set RGB and CW grayscale. - SM2335Write((uint8_t)(cur_col_10[0] >> 8)); // Red 1/2 - SM2335Write((uint8_t)(cur_col_10[0] & 0xFF)); // Red 2/2 - SM2335Write((uint8_t)(cur_col_10[1] >> 8)); // Green 1/2 - SM2335Write((uint8_t)(cur_col_10[1] & 0xFF)); // Green 2/2 - SM2335Write((uint8_t)(cur_col_10[2] >> 8)); // Blue 1/2 - SM2335Write((uint8_t)(cur_col_10[2] & 0xFF)); // Blue 2/2 - SM2335Write((uint8_t)(cur_col_10[3] >> 8)); // Cold White 1/2 - SM2335Write((uint8_t)(cur_col_10[3] & 0xFF)); // Cold White 2/2 - SM2335Write((uint8_t)(cur_col_10[4] >> 8)); // Warm White 1/2 - SM2335Write((uint8_t)(cur_col_10[4] & 0xFF)); // Warm White 2/2 - + for (int i = 0; i < 5; i++) + { + SM2335Write((uint8_t)(cur_col_10[i] >> 8)); + SM2335Write((uint8_t)(cur_col_10[i] & 0xFF)); + } SM2335Stop(); return true; } @@ -159,60 +142,10 @@ void SM2335ModuleSelected(void) if (PinUsed(GPIO_SM2335_CLK) && PinUsed(GPIO_SM2335_DAT, GPIO_ANY)) { Sm2335.clk = Pin(GPIO_SM2335_CLK); Sm2335.data = Pin(GPIO_SM2335_DAT, GPIO_ANY); - // See #define MAX_SM2335_DAT 16 in tasmota_template.h - Sm2335.currentEnum = GetPin(Sm2335.data) - AGPIO(GPIO_SM2335_DAT); // 0 .. 15 - - switch (Sm2335.currentEnum) { - case SM2335_10_5: - Sm2335.currentValue = (SM2335_RGB_10MA_CW_5MA << 4) | SM2335_RGB_10MA_CW_5MA; - break; - case SM2335_20_10: - Sm2335.currentValue = (SM2335_RGB_20MA_CW_10MA << 4) | SM2335_RGB_20MA_CW_10MA; - break; - case SM2335_30_15: - Sm2335.currentValue = (SM2335_RGB_30MA_CW_15MA << 4) | SM2335_RGB_30MA_CW_15MA; - break; - case SM2335_40_20: - Sm2335.currentValue = (SM2335_RGB_30MA_CW_15MA << 4) | SM2335_RGB_30MA_CW_15MA; - break; - case SM2335_50_25: - Sm2335.currentValue = (SM2335_RGB_50MA_CW_25MA << 4) | SM2335_RGB_50MA_CW_25MA; - break; - case SM2335_60_30: - Sm2335.currentValue = (SM2335_RGB_60MA_CW_30MA << 4) | SM2335_RGB_60MA_CW_30MA; - break; - case SM2335_70_35: - Sm2335.currentValue = (SM2335_RGB_70MA_CW_35MA << 4) | SM2335_RGB_70MA_CW_35MA; - break; - case SM2335_80_40: - Sm2335.currentValue = (SM2335_RGB_80MA_CW_40MA << 4) | SM2335_RGB_80MA_CW_40MA; - break; - case SM2335_90_45: - Sm2335.currentValue = (SM2335_RGB_90MA_CW_45MA << 4) | SM2335_RGB_90MA_CW_45MA; - break; - case SM2335_100_50: - Sm2335.currentValue = (SM2335_RGB_100MA_CW_50MA << 4) | SM2335_RGB_100MA_CW_50MA; - break; - case SM2335_110_55: - Sm2335.currentValue = (SM2335_RGB_110MA_CW_55MA << 4) | SM2335_RGB_110MA_CW_55MA; - break; - case SM2335_120_60: - Sm2335.currentValue = (SM2335_RGB_120MA_CW_60MA << 4) | SM2335_RGB_120MA_CW_60MA; - break; - case SM2335_130_65: - Sm2335.currentValue = (SM2335_RGB_130MA_CW_65MA << 4) | SM2335_RGB_130MA_CW_65MA; - break; - case SM2335_140_70: - Sm2335.currentValue = (SM2335_RGB_140MA_CW_70MA << 4) | SM2335_RGB_140MA_CW_70MA; - break; - case SM2335_150_75: - Sm2335.currentValue = (SM2335_RGB_150MA_CW_75MA << 4) | SM2335_RGB_150MA_CW_75MA; - break; - case SM2335_160_80: - Sm2335.currentValue = (SM2335_RGB_160MA_CW_80MA << 4) | SM2335_RGB_160MA_CW_80MA; - break; - } + int currentDat = GetPin(Sm2335.data) - AGPIO(GPIO_SM2335_DAT); // 0 .. 15 + // Split RGB and CW current. + Sm2335.current = (currentDat << 4) | currentDat; SM2335Init(); From df9c3a733e3e3b7e5520dcdc158671807c5889aa Mon Sep 17 00:00:00 2001 From: Cossid Date: Wed, 22 Jun 2022 10:02:20 -0500 Subject: [PATCH 8/9] SM2335 - Disable by default on ESP8266, enable by default on ESP32. --- BUILDS.md | 2 +- tasmota/include/tasmota_configurations.h | 8 ++++---- tasmota/include/tasmota_configurations_ESP32.h | 2 +- tasmota/my_user_config.h | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/BUILDS.md b/BUILDS.md index 576c8be6f..4d7611a29 100644 --- a/BUILDS.md +++ b/BUILDS.md @@ -65,7 +65,7 @@ Note: `minimal` variant is not listed as it shouldn't be used outside of the [up | USE_MY92X1 | - | x / - | x | x | - | x | | USE_SM16716 | - | x / - | x | x | - | x | | USE_SM2135 | - | x / - | x | x | - | x | -| USE_SM2335 | - | x / - | x | x | - | x | +| USE_SM2335 | - | - / x | - | - | - | - | | USE_BP5758D | - | x / - | x | x | - | x | | USE_SONOFF_L1 | - | x / - | x | x | - | x | | USE_ELECTRIQ_MOODL | - | x / - | x | x | - | x | diff --git a/tasmota/include/tasmota_configurations.h b/tasmota/include/tasmota_configurations.h index 1eb21552f..5fe9514ea 100644 --- a/tasmota/include/tasmota_configurations.h +++ b/tasmota/include/tasmota_configurations.h @@ -69,7 +69,7 @@ #define USE_MY92X1 // Add support for MY92X1 RGBCW led controller as used in Sonoff B1, Ailight and Lohas #define USE_SM16716 // Add support for SM16716 RGB LED controller (+0k7 code) #define USE_SM2135 // Add support for SM2135 RGBCW led control as used in Action LSC (+0k6 code) -#define USE_SM2335 // Add support for SM2335 RGBCW led control as used in Switchbot Bulb +//#define USE_SM2335 // Add support for SM2335 RGBCW led control as used in Switchbot Bulb #define USE_BP5758D // Add support for BP5758D RGBCW led control as used in some Tuya lightbulbs (+0k8 code) #define USE_SONOFF_L1 // Add support for Sonoff L1 led control #define USE_ELECTRIQ_MOODL // Add support for ElectriQ iQ-wifiMOODL RGBW LED controller @@ -404,7 +404,7 @@ #undef USE_MY92X1 // Disable support for MY92X1 RGBCW led controller as used in Sonoff B1, Ailight and Lohas #undef USE_SM16716 // Disable support for SM16716 RGB LED controller (+0k7 code) #undef USE_SM2135 // Disable support for SM2135 RGBCW led control as used in Action LSC (+0k6 code) -#undef USE_SM2335 // Disable support for SM2335 RGBCW led control as used in Switchbot Bulb +//#undef USE_SM2335 // Disable support for SM2335 RGBCW led control as used in Switchbot Bulb #undef USE_BP5758D // Disable support for BP5758D RGBCW led control as used in some Tuya lightbulbs (+0k8 code) #undef USE_SONOFF_L1 // Disable support for Sonoff L1 led control #undef USE_ELECTRIQ_MOODL // Disable support for ElectriQ iQ-wifiMOODL RGBW LED controller @@ -554,7 +554,7 @@ #undef USE_MY92X1 // Disable support for MY92X1 RGBCW led controller as used in Sonoff B1, Ailight and Lohas #undef USE_SM16716 // Disable support for SM16716 RGB LED controller (+0k7 code) #undef USE_SM2135 // Disable support for SM2135 RGBCW led control as used in Action LSC (+0k6 code) -#undef USE_SM2335 // Disable support for SM2335 RGBCW led control as used in Switchbot Bulb +//#undef USE_SM2335 // Disable support for SM2335 RGBCW led control as used in Switchbot Bulb #undef USE_BP5758D // Disable support for BP5758D RGBCW led control as used in some Tuya lightbulbs (+0k8 code) #undef USE_SONOFF_L1 // Disable support for Sonoff L1 led control #undef USE_ELECTRIQ_MOODL // Disable support for ElectriQ iQ-wifiMOODL RGBW LED controller @@ -700,7 +700,7 @@ #undef USE_MY92X1 // Disable support for MY92X1 RGBCW led controller as used in Sonoff B1, Ailight and Lohas #undef USE_SM16716 // Disable support for SM16716 RGB LED controller (+0k7 code) #undef USE_SM2135 // Disable support for SM2135 RGBCW led control as used in Action LSC (+0k6 code) -#undef USE_SM2335 // Disable support for SM2335 RGBCW led control as used in Switchbot Bulb +//#undef USE_SM2335 // Disable support for SM2335 RGBCW led control as used in Switchbot Bulb #undef USE_BP5758D // Disable support for BP5758D RGBCW led control as used in some Tuya lightbulbs (+0k8 code) #undef USE_SONOFF_L1 // Disable support for Sonoff L1 led control #undef USE_ELECTRIQ_MOODL // Disable support for ElectriQ iQ-wifiMOODL RGBW LED controller diff --git a/tasmota/include/tasmota_configurations_ESP32.h b/tasmota/include/tasmota_configurations_ESP32.h index cf2e21cc3..6b0b8c3b0 100644 --- a/tasmota/include/tasmota_configurations_ESP32.h +++ b/tasmota/include/tasmota_configurations_ESP32.h @@ -696,7 +696,7 @@ #define USE_HRE // Add support for Badger HR-E Water Meter (+1k4 code) //#define USE_A4988_STEPPER // Add support for A4988/DRV8825 stepper-motor-driver-circuit (+10k5 code) //#define USE_THERMOSTAT // Add support for Thermostat - +#define USE_SM2335 // Add support for SM2335 RGBCW led control as used in Switchbot Bulb #define USE_ETHERNET // Add support for ethernet (+20k code) #ifndef USE_KNX diff --git a/tasmota/my_user_config.h b/tasmota/my_user_config.h index ea88e9bef..868a16bd0 100644 --- a/tasmota/my_user_config.h +++ b/tasmota/my_user_config.h @@ -556,7 +556,7 @@ #define USE_MY92X1 // Add support for MY92X1 RGBCW led controller as used in Sonoff B1, Ailight and Lohas #define USE_SM16716 // Add support for SM16716 RGB LED controller (+0k7 code) #define USE_SM2135 // Add support for SM2135 RGBCW led control as used in Action LSC (+0k6 code) -#define USE_SM2335 // Add support for SM2335 RGBCW led control as used in SwitchBot Color Bulb +//#define USE_SM2335 // Add support for SM2335 RGBCW led control as used in SwitchBot Color Bulb #define USE_BP5758D // Add support for BP5758D RGBCW led control as used in some Tuya lightbulbs (+0k8 code) #define USE_SONOFF_L1 // Add support for Sonoff L1 led control #define USE_ELECTRIQ_MOODL // Add support for ElectriQ iQ-wifiMOODL RGBW LED controller (+0k3 code) From 5741c06acdd1a99890fdb6662848e9317f9f0d10 Mon Sep 17 00:00:00 2001 From: Cossid Date: Wed, 22 Jun 2022 10:10:58 -0500 Subject: [PATCH 9/9] SM2335 - Be more consistent with code formatting. --- tasmota/tasmota_xlgt_light/xlgt_09_sm2335.ino | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tasmota/tasmota_xlgt_light/xlgt_09_sm2335.ino b/tasmota/tasmota_xlgt_light/xlgt_09_sm2335.ino index e020b0a5e..eb4c8f035 100644 --- a/tasmota/tasmota_xlgt_light/xlgt_09_sm2335.ino +++ b/tasmota/tasmota_xlgt_light/xlgt_09_sm2335.ino @@ -115,8 +115,7 @@ bool SM2335SetChannels(void) { if (cur_col_10[0] == 0 && cur_col_10[1] == 0 && cur_col_10[2] == 0 && cur_col_10[3] == 0 && cur_col_10[4] == 0) { SM2335Start(SM2335_ADDR_STANDBY); // Clear all remaining data. This clears out Current, Red, Green, Blue, Cold White, Warm White. - for (int i = 0; i < 11; i++) - { + for (int i = 0; i < 11; i++) { SM2335Write(0); } SM2335Stop(); @@ -128,8 +127,7 @@ bool SM2335SetChannels(void) { // Set the current defined in ModuleSelected. SM2335Write(Sm2335.current); // Set RGB and CW grayscale. - for (int i = 0; i < 5; i++) - { + for (int i = 0; i < 5; i++) { SM2335Write((uint8_t)(cur_col_10[i] >> 8)); SM2335Write((uint8_t)(cur_col_10[i] & 0xFF)); }