diff --git a/src/cmnds/cmd_newLEDDriver.c b/src/cmnds/cmd_newLEDDriver.c index 7593275331..903123702c 100644 --- a/src/cmnds/cmd_newLEDDriver.c +++ b/src/cmnds/cmd_newLEDDriver.c @@ -10,6 +10,7 @@ #include "../driver/drv_public.h" #include "../driver/drv_local.h" #include "../hal/hal_flashVars.h" +#include "../hal/hal_pins.h" #include "../hal/hal_flashConfig.h" #include "../rgb2hsv.h" #include @@ -876,8 +877,20 @@ void LED_ToggleEnabled() { } bool g_guard_led_enable_event_cast = false; +void LED_SetStripStateOutputs() { + for (int i = 0; i < PLATFORM_GPIO_MAX; i++) { + int state = g_cfg.pins.roles[i]; + if (state == IOR_StripState) { + HAL_PIN_SetOutputValue(i, g_lightEnableAll); + } + else if (state == IOR_StripState_n) { + HAL_PIN_SetOutputValue(i, !g_lightEnableAll); + } + } +} void LED_SetEnableAll(int bEnable) { bool bEnableAllWasSetTo1; + bool bHadChange; if (g_lightEnableAll == 0 && bEnable == 1) { bEnableAllWasSetTo1 = true; @@ -904,6 +917,7 @@ void LED_SetEnableAll(int bEnable) { } g_lightEnableAll = bEnable; + LED_SetStripStateOutputs(); apply_smart_light(); #if ENABLE_TASMOTADEVICEGROUPS DRV_DGR_OnLedEnableAllChange(bEnable); diff --git a/src/cmnds/cmd_public.h b/src/cmnds/cmd_public.h index 6bef6fc42d..9e2b54cd00 100644 --- a/src/cmnds/cmd_public.h +++ b/src/cmnds/cmd_public.h @@ -274,6 +274,7 @@ void LED_ToggleEnabled(); bool LED_IsLedDriverChipRunning(); bool LED_IsLEDRunning(); void LED_SetEnableAll(int bEnable); +void LED_SetStripStateOutputs(); int LED_GetEnableAll(); void LED_SaveStateToFlashVarsNow(); void LED_GetBaseColorString(char* s); diff --git a/src/httpserver/new_http.c b/src/httpserver/new_http.c index a5f5a36109..c04bffa8b2 100644 --- a/src/httpserver/new_http.c +++ b/src/httpserver/new_http.c @@ -555,6 +555,8 @@ const char* htmlPinRoleNames[] = { "Counter_f", "Counter_r", "IRRecv_nPup", + "StripState", + "StripState_n", "error", "error", "error", diff --git a/src/new_pins.c b/src/new_pins.c index c2ce522c38..aeea8922a4 100644 --- a/src/new_pins.c +++ b/src/new_pins.c @@ -408,6 +408,9 @@ void PIN_SetupPins() { #ifdef ENABLE_DRIVER_DHT // TODO: better place to call? DHT_OnPinsConfigChanged(); +#endif +#if ENABLE_LED_BASIC + LED_SetStripStateOutputs(); #endif addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, "PIN_SetupPins pins have been set up.\r\n"); } @@ -1141,6 +1144,20 @@ void PIN_SetPinRoleForPinIndex(int index, int role) { } } break; +#if ENABLE_LED_BASIC + case IOR_StripState: + case IOR_StripState_n: + { + HAL_PIN_Setup_Output(index); + if (role == IOR_StripState) { + HAL_PIN_SetOutputValue(index, LED_GetEnableAll()); + } + else { + HAL_PIN_SetOutputValue(index, !LED_GetEnableAll()); + } + } + break; +#endif case IOR_BridgeForward: case IOR_BridgeReverse: { diff --git a/src/new_pins.h b/src/new_pins.h index a725e3e116..32e4590644 100644 --- a/src/new_pins.h +++ b/src/new_pins.h @@ -595,6 +595,20 @@ typedef enum ioRole_e { //iodetail:"file":"new_pins.h", //iodetail:"driver":""} IOR_IRRecv_nPup, + //iodetail:{"name":"StripState", + //iodetail:"title":"TODO", + //iodetail:"descr":"This is an output pin which has current led_enableAll value", + //iodetail:"enum":"IOR_StripState", + //iodetail:"file":"new_pins.h", + //iodetail:"driver":""} + IOR_StripState, + //iodetail:{"name":"StripState_n", + //iodetail:"title":"TODO", + //iodetail:"descr":"This is an output pin which has negation of current led_enableAll value", + //iodetail:"enum":"IOR_StripState_n", + //iodetail:"file":"new_pins.h", + //iodetail:"driver":""} + IOR_StripState_n, //iodetail:{"name":"Total_Options", //iodetail:"title":"TODO", //iodetail:"descr":"Current total number of available IOR roles", diff --git a/src/selftest/selftest_led.c b/src/selftest/selftest_led.c index f821c1978e..79be23dc2a 100644 --- a/src/selftest/selftest_led.c +++ b/src/selftest/selftest_led.c @@ -556,6 +556,11 @@ void Test_LEDDriver_BP5758_RGBCW() { // reset whole device SIM_ClearOBK(0); + PIN_SetPinRoleForPinIndex(10, IOR_StripState); + PIN_SetPinRoleForPinIndex(11, IOR_StripState_n); + SELFTEST_ASSERT_PIN_BOOLEAN(10, false); // IOR_StripState is false + SELFTEST_ASSERT_PIN_BOOLEAN(11, true); // IOR_StripState_n is true + Test_FakeHTTPClientPacket_GET("index"); SELFTEST_ASSERT_PAGE_NOT_CONTAINS("index","LED RGB Color"); SELFTEST_ASSERT_HTML_REPLY_NOT_CONTAINS("LED Temperature Slider"); @@ -567,22 +572,36 @@ void Test_LEDDriver_BP5758_RGBCW() { CMD_ExecuteCommand("led_basecolor_rgb FF0000", 0); CMD_ExecuteCommand("led_enableAll 1", 0); + SELFTEST_ASSERT_PIN_BOOLEAN(10, true); // IOR_StripState is true + SELFTEST_ASSERT_PIN_BOOLEAN(11, false); // IOR_StripState_n is false // set RED - FF0000 , remap 0 to 0 -> 1023 (10 bit resolution) SELFTEST_ASSERT_SM_CHANNELS(1023, 0, 0, 0, 0); CMD_ExecuteCommand("LED_Map 4 1 2 3 0", 0); CMD_ExecuteCommand("led_enableAll 0", 0); + SELFTEST_ASSERT_PIN_BOOLEAN(10, false); // IOR_StripState is false + SELFTEST_ASSERT_PIN_BOOLEAN(11, true); // IOR_StripState_n is true CMD_ExecuteCommand("led_enableAll 1", 0); + SELFTEST_ASSERT_PIN_BOOLEAN(10, true); // IOR_StripState is true + SELFTEST_ASSERT_PIN_BOOLEAN(11, false); // IOR_StripState_n is false SELFTEST_ASSERT_SM_CHANNELS(0, 0, 0, 0, 1023); CMD_ExecuteCommand("LED_Map 1 4 2 3 0", 0); CMD_ExecuteCommand("led_enableAll 0", 0); + SELFTEST_ASSERT_PIN_BOOLEAN(10, false); // IOR_StripState is false + SELFTEST_ASSERT_PIN_BOOLEAN(11, true); // IOR_StripState_n is true CMD_ExecuteCommand("led_enableAll 1", 0); + SELFTEST_ASSERT_PIN_BOOLEAN(10, true); // IOR_StripState is true + SELFTEST_ASSERT_PIN_BOOLEAN(11, false); // IOR_StripState_n is false SELFTEST_ASSERT_SM_CHANNELS(0, 0, 0, 0, 1023); CMD_ExecuteCommand("LED_Map 1 0 2 3 4", 0); CMD_ExecuteCommand("led_enableAll 0", 0); + SELFTEST_ASSERT_PIN_BOOLEAN(10, false); // IOR_StripState is false + SELFTEST_ASSERT_PIN_BOOLEAN(11, true); // IOR_StripState_n is true CMD_ExecuteCommand("led_enableAll 1", 0); + SELFTEST_ASSERT_PIN_BOOLEAN(10, true); // IOR_StripState is true + SELFTEST_ASSERT_PIN_BOOLEAN(11, false); // IOR_StripState_n is false SELFTEST_ASSERT_SM_CHANNELS(0, 1023, 0, 0, 0); Test_FakeHTTPClientPacket_GET("index"); @@ -629,6 +648,8 @@ void Test_LEDDriver_BP5758_RGBCW() { CMD_ExecuteCommand("led_temperature 500", 0); CMD_ExecuteCommand("led_enableAll 1", 0); CMD_ExecuteCommand("led_enableAll 1", 1); + SELFTEST_ASSERT_PIN_BOOLEAN(10, true); // IOR_StripState is true + SELFTEST_ASSERT_PIN_BOOLEAN(11, false); // IOR_StripState_n is false SELFTEST_ASSERT_SM_CHANNELS(0, 0, 0, 0, 1023); CMD_ExecuteCommand("led_temperature 154", 0); SELFTEST_ASSERT_SM_CHANNELS(0, 0, 0, 1023, 0); @@ -670,9 +691,17 @@ void Test_LEDDriver_RGB(int firstChannel) { PIN_SetPinRoleForPinIndex(9, IOR_PWM); PIN_SetPinChannelForPinIndex(9, firstChannel + 2); + PIN_SetPinRoleForPinIndex(10, IOR_StripState); + PIN_SetPinRoleForPinIndex(11, IOR_StripState_n); + + SELFTEST_ASSERT_PIN_BOOLEAN(10, false); // IOR_StripState is false + SELFTEST_ASSERT_PIN_BOOLEAN(11, true); // IOR_StripState_n is true + CMD_ExecuteCommand("led_enableAll 1", 0); + SELFTEST_ASSERT_PIN_BOOLEAN(10, true); // IOR_StripState is true + SELFTEST_ASSERT_PIN_BOOLEAN(11, false); // IOR_StripState_n is false // check expressions (not really LED related but ok) - SELFTEST_ASSERT_EXPRESSION("$led_enableAll", 1.0f); + SELFTEST_ASSERT_EXPRESSION("$led_enableAll", 1.0f); // Set red CMD_ExecuteCommand("led_baseColor_rgb FF0000", 0); // full brightness @@ -742,11 +771,15 @@ void Test_LEDDriver_RGB(int firstChannel) { SELFTEST_ASSERT_CHANNEL(firstChannel, 0); SELFTEST_ASSERT_CHANNEL(firstChannel+1, 0); SELFTEST_ASSERT_CHANNEL(firstChannel+2, 0); + SELFTEST_ASSERT_PIN_BOOLEAN(10, false); // IOR_StripState is false + SELFTEST_ASSERT_PIN_BOOLEAN(11, true); // IOR_StripState_n is true // Tasmota style command should enable LED Test_FakeHTTPClientPacket_GET("cm?cmnd=POWER%201"); SELFTEST_ASSERT_CHANNEL(firstChannel, 0); SELFTEST_ASSERT_CHANNEL(firstChannel+1, 0); SELFTEST_ASSERT_CHANNEL(firstChannel+2, 79); + SELFTEST_ASSERT_PIN_BOOLEAN(10, true); // IOR_StripState is true + SELFTEST_ASSERT_PIN_BOOLEAN(11, false); // IOR_StripState_n is false // set 100% brightness CMD_ExecuteCommand("led_dimmer 100", 0);