diff --git a/lib/default/jsmn-shadinger-1.0/src/jsmn.cpp b/lib/default/jsmn-shadinger-1.0/src/jsmn.cpp index 905d102f4..bfd0e11bb 100644 --- a/lib/default/jsmn-shadinger-1.0/src/jsmn.cpp +++ b/lib/default/jsmn-shadinger-1.0/src/jsmn.cpp @@ -399,6 +399,7 @@ void json_unescape(char* string) { c = string[++i]; switch (c) { case 0: + string[outlength++] = 0; return; // end of stream case '\"': case '/': @@ -427,7 +428,10 @@ void json_unescape(char* string) { uint32_t hexval = 0; for (uint32_t j = 0; j < 4; ++j) { char val = string[++i]; - if (0 == val) { return; } // we reached end of string + if (0 == val) { + string[outlength++] = 0; + return; // we reached end of string + } uint32_t uival = 0; if ((val >= 'a') && (val <= 'f')) uival = 10 + (val - 'a'); @@ -450,4 +454,5 @@ void json_unescape(char* string) { string[outlength++] = c; } } + string[outlength++] = 0; } \ No newline at end of file diff --git a/tasmota/tasmota_template.h b/tasmota/tasmota_template.h index dcd3bfb48..51063fb28 100644 --- a/tasmota/tasmota_template.h +++ b/tasmota/tasmota_template.h @@ -247,6 +247,7 @@ const char kSensorNamesFixed[] PROGMEM = #define MAX_A4988_MSS 3 #define MAX_WEBCAM_DATA 8 #define MAX_WEBCAM_HSD 3 +#define MAX_SM2135_DAT 4 const uint16_t kGpioNiceList[] PROGMEM = { GPIO_NONE, // Not used @@ -352,8 +353,8 @@ const uint16_t kGpioNiceList[] PROGMEM = { AGPIO(GPIO_SM16716_SEL), // SM16716 SELECT #endif // USE_SM16716 #ifdef USE_SM2135 - AGPIO(GPIO_SM2135_CLK), // SM2135 CLOCK - AGPIO(GPIO_SM2135_DAT), // SM2135 DATA + AGPIO(GPIO_SM2135_CLK), // SM2135 CLOCK + AGPIO(GPIO_SM2135_DAT) + MAX_SM2135_DAT, // SM2135 DATA #endif // USE_SM2135 #ifdef USE_TUYA_MCU AGPIO(GPIO_TUYA_TX), // Tuya Serial interface diff --git a/tasmota/xlgt_04_sm2135.ino b/tasmota/xlgt_04_sm2135.ino index 17cbc48ec..dd766ab33 100644 --- a/tasmota/xlgt_04_sm2135.ino +++ b/tasmota/xlgt_04_sm2135.ino @@ -24,8 +24,13 @@ * * Action LSC SmartLed (GreenRedBlue) * {"NAME":"LSC RGBCW LED","GPIO":[0,0,0,0,0,0,0,0,181,0,180,0,0],"FLAG":0,"BASE":18} + * {"NAME":"LSC RGBCW LED","GPIO":[0,0,0,0,0,0,0,0,4064,0,4032,0,0,0],"FLAG":0,"BASE":18} * Polux E14 (BlueGreenRed) - Notice GPIO00 = 9 (Switch1) * {"NAME":"Polux RGBCW E14","GPIO":[9,0,0,0,0,0,0,0,181,0,180,0,0],"FLAG":0,"BASE":18} + * Polux E14 (BlueGreenRed) + * {"NAME":"Polux RGBCW E14","GPIO":[0,0,0,0,0,0,0,0,4065,0,4032,0,0,0],"FLAG":0,"BASE":18} + * LE LampUX 907001-US + * {"NAME":"LE LampUX 907001-US","GPIO":[0,0,0,0,0,0,0,0,4066,0,4032,0,0,0],"FLAG":0,"BASE":18} \*********************************************************************************************/ #define XLGT_04 4 @@ -53,14 +58,12 @@ #define SM2135_55MA 0x09 #define SM2135_60MA 0x0A -enum Sm2135Color { SM2135_WCGRB, SM2135_WCBGR }; - -// RGB current CW current -const uint8_t SM2135_CURRENT = (SM2135_20MA << 4) | SM2135_15MA; // See https://github.com/arendst/Tasmota/issues/6495#issuecomment-549121683 +enum Sm2135Color { SM2135_WCGRB, SM2135_WCBGR, SM2135_WCGRBHI, SM2135_WCBGRHI }; struct SM2135 { uint8_t clk = 0; uint8_t data = 0; + uint8_t current; uint8_t model = SM2135_WCGRB; } Sm2135; @@ -135,37 +138,49 @@ bool Sm2135SetChannels(void) { uint8_t *cur_col = (uint8_t*)XdrvMailbox.data; uint8_t data[6]; - Sm2135Start(SM2135_ADDR_MC); - Sm2135Write(SM2135_CURRENT); - if ((0 == cur_col[0]) && (0 == cur_col[1]) && (0 == cur_col[2])) { - Sm2135Write(SM2135_CW); - Sm2135Stop(); - delay(1); - Sm2135Start(SM2135_ADDR_C); - Sm2135Write(cur_col[4]); // Warm - Sm2135Write(cur_col[3]); // Cold - } else { + uint32_t light_type = 3; // RGB and CW + if (Sm2135.model < 2) { + if ((0 == cur_col[0]) && (0 == cur_col[1]) && (0 == cur_col[2])) { + light_type = 1; // CW only + } else { + light_type = 2; // RGB only + } + } + if (light_type &2) { // Set RGB + Sm2135Start(SM2135_ADDR_MC); + Sm2135Write(Sm2135.current); Sm2135Write(SM2135_RGB); - if (SM2135_WCBGR == Sm2135.model) { + if (Sm2135.model &1) { // SM2135_WCBGR Sm2135Write(cur_col[2]); // Blue Sm2135Write(cur_col[1]); // Green Sm2135Write(cur_col[0]); // Red - } else { + } else { // SM2135_WCGRB Sm2135Write(cur_col[1]); // Green Sm2135Write(cur_col[0]); // Red Sm2135Write(cur_col[2]); // Blue } + 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(); } - Sm2135Stop(); return true; } void Sm2135ModuleSelected(void) { - if (PinUsed(GPIO_SM2135_CLK) && PinUsed(GPIO_SM2135_DAT)) { + if (PinUsed(GPIO_SM2135_CLK) && PinUsed(GPIO_SM2135_DAT, GPIO_ANY)) { Sm2135.clk = Pin(GPIO_SM2135_CLK); - Sm2135.data = Pin(GPIO_SM2135_DAT); + Sm2135.data = Pin(GPIO_SM2135_DAT, GPIO_ANY); Sm2135.model = SM2135_WCGRB; if (PinUsed(GPIO_SWT1)) { @@ -173,12 +188,28 @@ void Sm2135ModuleSelected(void) pinMode(Pin(GPIO_SWT1), INPUT); // Discard GPIO_SWT functionality SetPin(Pin(GPIO_SWT1), AGPIO(GPIO_NONE)); } + if (PinUsed(GPIO_SM2135_DAT, 1)) { + Sm2135.model = SM2135_WCBGR; + } + if (PinUsed(GPIO_SM2135_DAT, 2)) { + Sm2135.model = SM2135_WCGRBHI; + } + if (PinUsed(GPIO_SM2135_DAT, 3)) { + Sm2135.model = SM2135_WCBGRHI; + } + +// RGB current CW current + Sm2135.current = (SM2135_20MA << 4) | SM2135_15MA; // See https://github.com/arendst/Tasmota/issues/6495#issuecomment-549121683 + if (Sm2135.model > SM2135_WCBGR) { + Sm2135.current = (SM2135_20MA << 4) | SM2135_30MA; + } Sm2135Init(); TasmotaGlobal.light_type = LT_RGBWC; TasmotaGlobal.light_driver = XLGT_04; - AddLog_P(LOG_LEVEL_DEBUG, PSTR("DBG: SM2135 (%s) Found"), (SM2135_WCBGR == Sm2135.model) ? PSTR("BGR") : PSTR("GRB")); + AddLog_P(LOG_LEVEL_DEBUG, PSTR("LGT: SM2135 (%s-%s current) Found"), + (SM2135_WCBGR == (Sm2135.model &1)) ? PSTR("BGR") : PSTR("GRB"), (Sm2135.model > SM2135_WCBGR) ? PSTR("High") : PSTR("Low")); } }