Skip to content

Commit

Permalink
ww
Browse files Browse the repository at this point in the history
  • Loading branch information
openshwprojects committed Jan 6, 2025
1 parent 08e9817 commit bd1f743
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/cmnds/cmd_newLEDDriver_colors.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "../littlefs/our_lfs.h"
#endif

#if ENABLE_LED_BASIC

static byte g_curColor = 0;
// TODO: make this list consistent with
// Tasmota colors standard:
Expand Down Expand Up @@ -153,3 +155,7 @@ void LED_NextColor() {
LED_SetColorByIndex(g_curColor);
}


#endif


2 changes: 2 additions & 0 deletions src/httpserver/hass.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ HassDeviceInfo* hass_init_relay_device_info(int index, ENTITY_TYPE type, bool bT
return info;
}

#if ENABLE_LED_BASIC
/// @brief Initializes HomeAssistant light device discovery storage.
/// @param type
/// @return
Expand Down Expand Up @@ -433,6 +434,7 @@ HassDeviceInfo* hass_init_light_device_info(ENTITY_TYPE type) {

return info;
}
#endif

/// @brief Initializes HomeAssistant binary sensor device discovery storage.
/// @param index
Expand Down
2 changes: 2 additions & 0 deletions src/httpserver/http_fns.c
Original file line number Diff line number Diff line change
Expand Up @@ -1742,6 +1742,7 @@ void doHomeAssistantDiscovery(const char* topic, http_request_t* request) {
#endif


#if ENABLE_LED_BASIC
if (pwmCount == 5 || ledDriverChipRunning || (pwmCount == 4 && CFG_HasFlag(OBK_FLAG_LED_EMULATE_COOL_WITH_RGB))) {
if (dev_info == NULL) {
dev_info = hass_init_light_device_info(LIGHT_RGBCW);
Expand Down Expand Up @@ -1775,6 +1776,7 @@ void doHomeAssistantDiscovery(const char* topic, http_request_t* request) {
discoveryQueued = true;
}
}
#endif

#ifdef ENABLE_DRIVER_BL0937
if (measuringPower == true) {
Expand Down
3 changes: 2 additions & 1 deletion src/mqtt/new_mqtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ int channelGet(obk_mqtt_request_t* request) {
}

addLogAdv(LOG_INFO, LOG_FEATURE_MQTT, "channelGet part topic %s", p);

#if ENABLE_LED_BASIC
if (stribegins(p, "led_enableAll")) {
LED_SendEnableAllState();
return 1;
Expand All @@ -581,6 +581,7 @@ int channelGet(obk_mqtt_request_t* request) {
sendColorChange();
return 1;
}
#endif

// atoi won't parse any non-decimal chars, so it should skip over the rest of the topic.
channel = atoi(p);
Expand Down
28 changes: 26 additions & 2 deletions src/new_pins.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,11 +417,13 @@ void Button_OnInitialPressDown(int index)
CHANNEL_DoSpecialToggleAll();
return;
}
#if ENABLE_LED_BASIC
if (g_cfg.pins.roles[index] == IOR_Button_NextColor || g_cfg.pins.roles[index] == IOR_Button_NextColor_n)
{
LED_NextColor();
return;
}
#endif
if (g_cfg.pins.roles[index] == IOR_Button_NextDimmer || g_cfg.pins.roles[index] == IOR_Button_NextDimmer_n)
{

Expand All @@ -437,11 +439,14 @@ void Button_OnInitialPressDown(int index)

return;
}
#if ENABLE_LED_BASIC
// is it a device with RGB/CW/single color/etc LED driver?
if (LED_IsLEDRunning()) {
LED_ToggleEnabled();
}
else {
else
#endif
{
// Relays
CHANNEL_Toggle(g_cfg.pins.channels[index]);
}
Expand All @@ -464,11 +469,13 @@ void Button_OnShortClick(int index)
CHANNEL_DoSpecialToggleAll();
return;
}
#if ENABLE_LED_BASIC
if (g_cfg.pins.roles[index] == IOR_Button_NextColor || g_cfg.pins.roles[index] == IOR_Button_NextColor_n)
{
LED_NextColor();
return;
}
#endif
if (g_cfg.pins.roles[index] == IOR_Button_NextDimmer || g_cfg.pins.roles[index] == IOR_Button_NextDimmer_n)
{
return;
Expand All @@ -481,11 +488,14 @@ void Button_OnShortClick(int index)
{
return;
}
#if ENABLE_LED_BASIC
// is it a device with RGB/CW/single color/etc LED driver?
if (LED_IsLEDRunning()) {
LED_ToggleEnabled();
}
else {
else
#endif
{
// Relays
CHANNEL_Toggle(g_cfg.pins.channels[index]);
}
Expand All @@ -511,11 +521,13 @@ void Button_OnDoubleClick(int index)
// double click toggles SECOND CHANNEL linked to this button
CHANNEL_Toggle(g_cfg.pins.channels2[index]);
}
#if ENABLE_LED_BASIC
if (g_cfg.pins.roles[index] == IOR_SmartButtonForLEDs || g_cfg.pins.roles[index] == IOR_SmartButtonForLEDs_n) {
LED_NextColor();
// make it easier for users, enable LED by default
LED_SetEnableAll(true);
}
#endif
if (g_doubleClickCallback != 0) {
g_doubleClickCallback(index);
}
Expand All @@ -529,11 +541,13 @@ void Button_OnTripleClick(int index)
}
// fire event - button on pin <index> was 3clicked
EventHandlers_FireEvent(CMD_EVENT_PIN_ON3CLICK, index);
#if ENABLE_LED_BASIC
if (g_cfg.pins.roles[index] == IOR_SmartButtonForLEDs || g_cfg.pins.roles[index] == IOR_SmartButtonForLEDs_n) {
LED_NextTemperature();
// make it easier for users, enable LED by default
LED_SetEnableAll(true);
}
#endif
}
void Button_OnQuadrupleClick(int index)
{
Expand Down Expand Up @@ -564,6 +578,7 @@ void Button_OnLongPressHold(int index) {
// fire event - button on pin <index> was held
EventHandlers_FireEvent(CMD_EVENT_PIN_ONHOLD, index);

#if ENABLE_LED_BASIC
if (g_cfg.pins.roles[index] == IOR_Button_NextDimmer || g_cfg.pins.roles[index] == IOR_Button_NextDimmer_n) {
LED_NextDimmerHold();
}
Expand All @@ -575,6 +590,7 @@ void Button_OnLongPressHold(int index) {
// make it easier for users, enable LED by default
LED_SetEnableAll(true);
}
#endif
}
void Button_OnLongPressHoldStart(int index) {
addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, "%i Button_OnLongPressHoldStart\r\n", index);
Expand Down Expand Up @@ -1282,6 +1298,7 @@ float CHANNEL_GetFloat(int ch) {
return g_channelValuesFloats[ch];
}
int CHANNEL_Get(int ch) {
#if ENABLE_LED_BASIC
// special channels
if (ch == SPECIAL_CHANNEL_LEDPOWER) {
return LED_GetEnableAll();
Expand All @@ -1292,6 +1309,7 @@ int CHANNEL_Get(int ch) {
if (ch == SPECIAL_CHANNEL_TEMPERATURE) {
return LED_GetTemperature();
}
#endif
if (ch >= SPECIAL_CHANNEL_BASECOLOR_FIRST && ch <= SPECIAL_CHANNEL_BASECOLOR_LAST) {
return 0; // TODO
}
Expand Down Expand Up @@ -1343,6 +1361,7 @@ void CHANNEL_Set(int ch, int iVal, int iFlags) {
bForce = iFlags & CHANNEL_SET_FLAG_FORCE;
bSilent = iFlags & CHANNEL_SET_FLAG_SILENT;

#if ENABLE_LED_BASIC
// special channels
if (ch == SPECIAL_CHANNEL_LEDPOWER) {
LED_SetEnableAll(iVal);
Expand All @@ -1360,6 +1379,7 @@ void CHANNEL_Set(int ch, int iVal, int iFlags) {
LED_SetBaseColorByIndex(ch - SPECIAL_CHANNEL_BASECOLOR_FIRST, iVal, 1);
return;
}
#endif
if (ch >= SPECIAL_CHANNEL_FLASHVARS_FIRST && ch <= SPECIAL_CHANNEL_FLASHVARS_LAST) {
HAL_FlashVars_SaveChannel(ch - SPECIAL_CHANNEL_FLASHVARS_FIRST, iVal);
return;
Expand Down Expand Up @@ -1484,11 +1504,13 @@ int CHANNEL_FindMaxValueForChannel(int ch) {
void CHANNEL_Toggle(int ch) {
int prev;

#if ENABLE_LED_BASIC
// special channels
if (ch == SPECIAL_CHANNEL_LEDPOWER) {
LED_SetEnableAll(!LED_GetEnableAll());
return;
}
#endif
if (ch < 0 || ch >= CHANNEL_MAX) {
addLogAdv(LOG_ERROR, LOG_FEATURE_GENERAL, "CHANNEL_Toggle: Channel index %i is out of range <0,%i)\n\r", ch, CHANNEL_MAX);
return;
Expand Down Expand Up @@ -1534,9 +1556,11 @@ int CHANNEL_HasChannelPinWithRole(int ch, int iorType) {
return 0;
}
bool CHANNEL_Check(int ch) {
#if ENABLE_LED_BASIC
if (ch == SPECIAL_CHANNEL_LEDPOWER) {
return LED_GetEnableAll();
}
#endif
if (ch < 0 || ch >= CHANNEL_MAX) {
addLogAdv(LOG_ERROR, LOG_FEATURE_GENERAL, "CHANNEL_Check: Channel index %i is out of range <0,%i)\n\r", ch, CHANNEL_MAX);
return 0;
Expand Down

0 comments on commit bd1f743

Please sign in to comment.