diff --git a/tasmota/tasmota_xlgt_light/xlgt_04_sm2135.ino b/tasmota/tasmota_xlgt_light/xlgt_04_sm2135.ino index 0b72520a8..1b6a00b0f 100644 --- a/tasmota/tasmota_xlgt_light/xlgt_04_sm2135.ino +++ b/tasmota/tasmota_xlgt_light/xlgt_04_sm2135.ino @@ -60,7 +60,14 @@ #define SM2135_55MA 0x09 #define SM2135_60MA 0x0A -enum Sm2135Color { SM2135_WCGRB, SM2135_WCBGR, SM2135_WCGRBHI, SM2135_WCBGRHI, SM2135_WCGRB15W, SM2135_WCBGR15W, SM2135_WCBRG_SETALL }; +enum Sm2135Color { SM2135_WCGRB, // 1 - Action LSC GRB (20mA) and CW (15mA) + SM2135_WCBGR, // 2 - Polux BGR (20mA) and CW (15mA) + SM2135_WCGRBHI, // 3 - GRB (20mA) and CW (30mA) + SM2135_WCBGRHI, // 4 - BGR (20mA) and CW (30mA) + SM2135_WCGRB15W, // 5 - LE LampUX 907001-US GRB (45mA) and CW (60mA) + SM2135_WCBGR15W, // 6 - BGR (45mA) and CW (60mA) + SM2135_WCBRG_SETALL // 7 - Fitop 10W RGBCCT BRG (15mA) and CW (40mA) + }; struct SM2135 { uint8_t clk = 0; @@ -136,9 +143,36 @@ void Sm2135Stop(void) { /********************************************************************************************/ +void Sm2135SetRGB(uint32_t red, uint32_t green, uint32_t blue) { + Sm2135Start(SM2135_ADDR_MC); + Sm2135Write(Sm2135.current); + Sm2135Write(SM2135_RGB); + if (Sm2135.model &1) { // SM2135_WCBGR + Sm2135Write(blue); + Sm2135Write(green); + Sm2135Write(red); + } else { // SM2135_WCGRB + Sm2135Write(green); + Sm2135Write(red); + Sm2135Write(blue); + } + Sm2135Stop(); +} + +void Sm2135SetCW(uint32_t cold, uint32_t warm) { + Sm2135Start(SM2135_ADDR_MC); + Sm2135Write(Sm2135.current); + Sm2135Write(SM2135_CW); + Sm2135Stop(); + delay(1); + Sm2135Start(SM2135_ADDR_C); + Sm2135Write(warm); + Sm2135Write(cold); + Sm2135Stop(); +} + bool Sm2135SetChannels(void) { uint8_t *cur_col = (uint8_t*)XdrvMailbox.data; - uint8_t data[6]; // Fitop bulbs have the behaviour that they store previous states if not explicitly overwritten. // Example: If set to RGB then CCT, this bulb keeps RGB-led's on, even though they should be cleared. @@ -147,50 +181,37 @@ bool Sm2135SetChannels(void) { Sm2135Start(SM2135_ADDR_MC); Sm2135Write(Sm2135.current); Sm2135Write(SM2135_RGB); - Sm2135Write(cur_col[2]); // Blue - Sm2135Write(cur_col[0]); // Red - Sm2135Write(cur_col[1]); // Green - Sm2135Write(cur_col[4]); // Warm - Sm2135Write(cur_col[3]); // Cold + Sm2135Write(cur_col[2]); // Blue + Sm2135Write(cur_col[0]); // Red + Sm2135Write(cur_col[1]); // Green + Sm2135Write(cur_col[4]); // Warm + Sm2135Write(cur_col[3]); // Cold Sm2135Stop(); return true; } uint32_t light_type = 3; // RGB and CW if (Sm2135.model < 2) { // Only allow one of two options due to power supply - if ((0 == cur_col[0]) && (0 == cur_col[1]) && (0 == cur_col[2])) { - light_type = 1; // CW only - } else { + if ((0 == cur_col[3]) && (0 == cur_col[4])) { light_type = 2; // RGB only + } else { + light_type = 1; // CW only } } if (light_type &2) { // Set RGB - Sm2135Start(SM2135_ADDR_MC); - Sm2135Write(Sm2135.current); - Sm2135Write(SM2135_RGB); - if (Sm2135.model &1) { // SM2135_WCBGR - Sm2135Write(cur_col[2]); // Blue - Sm2135Write(cur_col[1]); // Green - Sm2135Write(cur_col[0]); // Red - } else { // SM2135_WCGRB - Sm2135Write(cur_col[1]); // Green - Sm2135Write(cur_col[0]); // Red - Sm2135Write(cur_col[2]); // Blue + Sm2135SetRGB(cur_col[0], cur_col[1], cur_col[2]); + if (!light_type &1) { + delay(1); + Sm2135SetCW(0, 0); // Clear CW } - Sm2135Stop(); } if (light_type &1) { // Set CW - Sm2135Start(SM2135_ADDR_MC); - Sm2135Write(Sm2135.current); - Sm2135Write(SM2135_CW); - Sm2135Stop(); - delay(1); - Sm2135Start(SM2135_ADDR_C); - Sm2135Write(cur_col[4]); // Warm - Sm2135Write(cur_col[3]); // Cold - Sm2135Stop(); + if (!light_type &2) { + Sm2135SetRGB(0, 0, 0); // CLear RGB + delay(1); + } + Sm2135SetCW(cur_col[3], cur_col[4]); } - return true; } @@ -214,17 +235,17 @@ void Sm2135ModuleSelected(void) // RGB current CW current Sm2135.current = (SM2135_20MA << 4) | SM2135_15MA; // See https://github.com/arendst/Tasmota/issues/6495#issuecomment-549121683 switch (Sm2135.model) { - case SM2135_WCBRG_SETALL: // SM2135 Dat 7 - values copied from tuya implementation - Sm2135.current = (SM2135_15MA << 4) | SM2135_40MA; - break; - case SM2135_WCGRBHI: // SM2135 Dat 3 - case SM2135_WCBGRHI: // SM2135 Dat 4 + case SM2135_WCGRBHI: // SM2135 Dat 3 + case SM2135_WCBGRHI: // SM2135 Dat 4 Sm2135.current = (SM2135_20MA << 4) | SM2135_30MA; break; - case SM2135_WCGRB15W: // SM2135 Dat 5 - case SM2135_WCBGR15W: // SM2135 Dat 6 + case SM2135_WCGRB15W: // SM2135 Dat 5 + case SM2135_WCBGR15W: // SM2135 Dat 6 Sm2135.current = (SM2135_45MA << 4) | SM2135_60MA; break; + case SM2135_WCBRG_SETALL: // SM2135 Dat 7 - values copied from tuya implementation + Sm2135.current = (SM2135_15MA << 4) | SM2135_40MA; + break; } Sm2135Init();