Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/cmnds/cmd_newLEDDriver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ctype.h>
Expand Down Expand Up @@ -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;
Expand All @@ -904,6 +917,7 @@ void LED_SetEnableAll(int bEnable) {
}
g_lightEnableAll = bEnable;

LED_SetStripStateOutputs();
apply_smart_light();
#if ENABLE_TASMOTADEVICEGROUPS
DRV_DGR_OnLedEnableAllChange(bEnable);
Expand Down
1 change: 1 addition & 0 deletions src/cmnds/cmd_public.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/httpserver/new_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,8 @@ const char* htmlPinRoleNames[] = {
"Counter_f",
"Counter_r",
"IRRecv_nPup",
"StripState",
"StripState_n",
"error",
"error",
"error",
Expand Down
17 changes: 17 additions & 0 deletions src/new_pins.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down Expand Up @@ -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:
{
Expand Down
14 changes: 14 additions & 0 deletions src/new_pins.h
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
35 changes: 34 additions & 1 deletion src/selftest/selftest_led.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
Loading