diff --git a/src/cmnds/cmd_newLEDDriver.c b/src/cmnds/cmd_newLEDDriver.c index 92d2d5bca..23bc48ecb 100644 --- a/src/cmnds/cmd_newLEDDriver.c +++ b/src/cmnds/cmd_newLEDDriver.c @@ -75,6 +75,27 @@ float led_temperature_max = HASS_TEMPERATURE_MAX; float led_temperature_current = HASS_TEMPERATURE_MIN; +bool LED_IsLedDriverChipRunning() +{ +#ifndef OBK_DISABLE_ALL_DRIVERS + return DRV_IsRunning("SM2135") || DRV_IsRunning("BP5758D") || DRV_IsRunning("TESTLED"); +#else + return false; +#endif +} +bool LED_IsLEDRunning() +{ + int pwmCount; + + if (LED_IsLedDriverChipRunning()) + return true; + + pwmCount = PIN_CountPinsWithRoleOrRole(IOR_PWM, IOR_PWM_n); + if (pwmCount > 0) + return true; + return false; +} + int isCWMode() { int pwmCount; diff --git a/src/cmnds/cmd_public.h b/src/cmnds/cmd_public.h index bec1204c8..1faedeaf2 100644 --- a/src/cmnds/cmd_public.h +++ b/src/cmnds/cmd_public.h @@ -146,6 +146,8 @@ void LED_SetFinalRGB(byte r, byte g, byte b); void LED_SetFinalRGBCW(byte *rgbcw); void LED_NextColor(); void LED_ToggleEnabled(); +bool LED_IsLedDriverChipRunning(); +bool LED_IsLEDRunning(); void LED_SetEnableAll(int bEnable); int LED_GetEnableAll(); void LED_GetBaseColorString(char * s); diff --git a/src/cmnds/cmd_tasmota.c b/src/cmnds/cmd_tasmota.c index 20cfbd6bb..c447b37c5 100644 --- a/src/cmnds/cmd_tasmota.c +++ b/src/cmnds/cmd_tasmota.c @@ -24,18 +24,28 @@ static int power(const void *context, const char *cmd, const char *args, int cmd int channel = 0; int iVal = 0; int i; + bool bRelayIndexingStartsWithZero; + + bRelayIndexingStartsWithZero = CHANNEL_HasChannelPinWithRoleOrRole(0, IOR_Relay, IOR_Relay_n); ADDLOG_INFO(LOG_FEATURE_CMD, "tasCmnd POWER (%s) received with args %s",cmd,args); if (strlen(cmd) > 5) { channel = atoi(cmd+5); - if (PIN_CountPinsWithRoleOrRole(IOR_PWM, IOR_PWM_n) > 0) { + if (LED_IsLEDRunning()) { channel = SPECIAL_CHANNEL_LEDPOWER; } + else { + if (bRelayIndexingStartsWithZero) { + channel--; + if (channel < 0) + channel = 0; + } + } } else { // if new LED driver active - if(PIN_CountPinsWithRoleOrRole(IOR_PWM, IOR_PWM_n) > 0) { + if(LED_IsLEDRunning()) { channel = SPECIAL_CHANNEL_LEDPOWER; } else { // find first active channel, because some people index with 0 and some with 1 diff --git a/src/httpserver/http_fns.c b/src/httpserver/http_fns.c index 471ce0b49..6d90e4f43 100644 --- a/src/httpserver/http_fns.c +++ b/src/httpserver/http_fns.c @@ -196,6 +196,9 @@ int http_fn_index(http_request_t* request) { bRawPWMs = CFG_HasFlag(OBK_FLAG_LED_RAWCHANNELSMODE); forceShowRGBCW = CFG_HasFlag(OBK_FLAG_LED_FORCESHOWRGBCWCONTROLLER); + if (LED_IsLedDriverChipRunning()) { + forceShowRGBCW = true; + } http_setup(request, httpMimeTypeHTML); //Add mimetype regardless of the request // use ?state URL parameter to only request current state @@ -1325,14 +1328,6 @@ void get_Relay_PWM_Count(int* relayCount, int* pwmCount) { } } -bool isLedDriverChipRunning() -{ -#ifndef OBK_DISABLE_ALL_DRIVERS - return DRV_IsRunning("SM2135") || DRV_IsRunning("BP5758D") || DRV_IsRunning("TESTLED"); -#else - return false; -#endif -} /// @brief Sends HomeAssistant discovery MQTT messages. /// @param request @@ -1363,7 +1358,7 @@ int http_fn_ha_discovery(http_request_t* request) { //Note: PublishChannels should be done for the last MQTT publish except for power measurement which always //sends out MQTT updates. - ledDriverChipRunning = isLedDriverChipRunning(); + ledDriverChipRunning = LED_IsLedDriverChipRunning(); if ((relayCount == 0) && (pwmCount == 0) && !measuringPower && !ledDriverChipRunning) { poststr(request, "No relay, PWM or power driver running."); @@ -1513,7 +1508,7 @@ int http_fn_ha_cfg(http_request_t* request) { } } } - if (pwmCount == 5 || isLedDriverChipRunning()) { + if (pwmCount == 5 || LED_IsLedDriverChipRunning()) { // Enable + RGB control + CW control if (mqttAdded == 0) { poststr(request, HASS_MQTT_NODE); @@ -1619,7 +1614,7 @@ int http_tasmota_json_power(http_request_t* request) { numRelays = 0; // LED driver (if has PWMs) - if (numPWMs > 0) { + if (LED_IsLEDRunning()) { int dimmer = LED_GetDimmer(); hprintf255(request, "\"Dimmer\":%i,", dimmer); hprintf255(request, "\"Fade\":\"OFF\","); @@ -1746,7 +1741,7 @@ int http_tasmota_json_status_generic(http_request_t* request) { get_Relay_PWM_Count(&relayCount, &pwmCount); - if (pwmCount > 0) { + if (LED_IsLEDRunning()) { powerCode = LED_GetEnableAll(); } else {