Skip to content

Commit

Permalink
smart ledd button
Browse files Browse the repository at this point in the history
  • Loading branch information
openshwprojects committed Feb 22, 2023
1 parent 8441770 commit d6db57c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 6 deletions.
14 changes: 14 additions & 0 deletions src/cmnds/cmd_newLEDDriver.c
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,20 @@ void LED_AddDimmer(int iVal, int addMode, int minValue) {
void LED_NextTemperatureHold() {
LED_AddTemperature(25, true);
}
void LED_NextTemperature() {
if (g_lightMode != Light_Temperature) {
LED_SetTemperature(HASS_TEMPERATURE_MIN, true);
return;
}
if (led_temperature_current == HASS_TEMPERATURE_MIN) {
LED_SetTemperature(HASS_TEMPERATURE_CENTER, true);
} else if (led_temperature_current == HASS_TEMPERATURE_CENTER) {
LED_SetTemperature(HASS_TEMPERATURE_MAX, true);
}
else {
LED_SetTemperature(HASS_TEMPERATURE_MIN, true);
}
}
void LED_NextDimmerHold() {
// dimmer hold will use some kind of min value,
// because it's easy to get confused if we set accidentally dimmer to 0
Expand Down
2 changes: 2 additions & 0 deletions src/cmnds/cmd_public.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ enum EventCode {

#define HASS_TEMPERATURE_MIN 154
#define HASS_TEMPERATURE_MAX 500
#define HASS_TEMPERATURE_CENTER ((HASS_TEMPERATURE_MAX+HASS_TEMPERATURE_MIN)/2);
#define KELVIN_TEMPERATURE_MIN 2000
#define KELVIN_TEMPERATURE_MAX 6500

Expand Down Expand Up @@ -194,6 +195,7 @@ void LED_GetFinalRGBCW(byte* rgbcw);
// color indices are as in Tasmota
void LED_SetColorByIndex(int index);
void LED_NextColor();
void LED_NextColorTemperature();
void LED_ToggleEnabled();
bool LED_IsLedDriverChipRunning();
bool LED_IsLEDRunning();
Expand Down
4 changes: 3 additions & 1 deletion src/httpserver/new_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,9 @@ const char* htmlPinRoleNames[] = {
"SM2235CLK",
"BridgeFWD",
"BridgeREV",
"error",
"Btn_SmartLED",
"Btn_SmartLED_n",
"error",
"error",
"error",
"error",
Expand Down
25 changes: 20 additions & 5 deletions src/new_pins.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,9 @@ void Button_OnDoubleClick(int index)
// double click toggles SECOND CHANNEL linked to this button
CHANNEL_Toggle(g_cfg.pins.channels2[index]);
}

if (g_cfg.pins.roles[index] == IOR_SmartButtonForLEDs || g_cfg.pins.roles[index] == IOR_SmartButtonForLEDs_n) {
LED_NextColor();
}
if (g_doubleClickCallback != 0) {
g_doubleClickCallback(index);
}
Expand All @@ -367,6 +369,9 @@ void Button_OnTripleClick(int index)
addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, "%i key_triple_press\r\n", index);
// fire event - button on pin <index> was 3clicked
EventHandlers_FireEvent(CMD_EVENT_PIN_ON3CLICK, index);
if (g_cfg.pins.roles[index] == IOR_SmartButtonForLEDs || g_cfg.pins.roles[index] == IOR_SmartButtonForLEDs_n) {
LED_NextTemperature();
}
}
void Button_OnQuadrupleClick(int index)
{
Expand All @@ -385,6 +390,9 @@ void Button_OnLongPressHold(int index) {
if (g_cfg.pins.roles[index] == IOR_Button_NextTemperature || g_cfg.pins.roles[index] == IOR_Button_NextTemperature_n) {
LED_NextTemperatureHold();
}
if (g_cfg.pins.roles[index] == IOR_SmartButtonForLEDs || g_cfg.pins.roles[index] == IOR_SmartButtonForLEDs_n) {
LED_NextDimmerHold();
}
}
void Button_OnLongPressHoldStart(int index) {
addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, "%i Button_OnLongPressHoldStart\r\n", index);
Expand All @@ -400,7 +408,8 @@ bool BTN_ShouldInvert(int index) {
if (g_cfg.pins.roles[index] == IOR_Button_n || g_cfg.pins.roles[index] == IOR_Button_ToggleAll_n ||
g_cfg.pins.roles[index] == IOR_DigitalInput_n || g_cfg.pins.roles[index] == IOR_DigitalInput_NoPup_n
|| g_cfg.pins.roles[index] == IOR_Button_NextColor_n || g_cfg.pins.roles[index] == IOR_Button_NextDimmer_n
|| g_cfg.pins.roles[index] == IOR_Button_NextTemperature_n || g_cfg.pins.roles[index] == IOR_Button_ScriptOnly_n) {
|| g_cfg.pins.roles[index] == IOR_Button_NextTemperature_n || g_cfg.pins.roles[index] == IOR_Button_ScriptOnly_n
|| g_cfg.pins.roles[index] == IOR_SmartButtonForLEDs_n) {
return true;
}
return false;
Expand Down Expand Up @@ -470,10 +479,12 @@ void CHANNEL_SetAll(int iVal, int iFlags) {
case IOR_Button_NextTemperature_n:
case IOR_Button_ScriptOnly:
case IOR_Button_ScriptOnly_n:
case IOR_SmartButtonForLEDs:
case IOR_SmartButtonForLEDs_n:
{

}
break;
break;
case IOR_LED:
case IOR_LED_n:
case IOR_Relay:
Expand Down Expand Up @@ -586,6 +597,8 @@ void PIN_SetPinRoleForPinIndex(int index, int role) {
case IOR_Button_NextTemperature_n:
case IOR_Button_ScriptOnly:
case IOR_Button_ScriptOnly_n:
case IOR_SmartButtonForLEDs:
case IOR_SmartButtonForLEDs_n:
{
//pinButton_s *bt = &g_buttons[index];
// TODO: disable button
Expand Down Expand Up @@ -645,14 +658,15 @@ void PIN_SetPinRoleForPinIndex(int index, int role) {
case IOR_Button_NextDimmer:
case IOR_Button_NextTemperature:
case IOR_Button_ScriptOnly:
case IOR_SmartButtonForLEDs:
falling = 1;

case IOR_Button_n:
case IOR_Button_ToggleAll_n:
case IOR_Button_NextColor_n:
case IOR_Button_NextDimmer_n:
case IOR_Button_NextTemperature_n:
case IOR_Button_ScriptOnly_n:
case IOR_SmartButtonForLEDs_n:
{
pinButton_s* bt = &g_buttons[index];

Expand Down Expand Up @@ -1456,7 +1470,8 @@ void PIN_ticks(void* param)
|| g_cfg.pins.roles[i] == IOR_Button_NextColor || g_cfg.pins.roles[i] == IOR_Button_NextColor_n
|| g_cfg.pins.roles[i] == IOR_Button_NextDimmer || g_cfg.pins.roles[i] == IOR_Button_NextDimmer_n
|| g_cfg.pins.roles[i] == IOR_Button_NextTemperature || g_cfg.pins.roles[i] == IOR_Button_NextTemperature_n
|| g_cfg.pins.roles[i] == IOR_Button_ScriptOnly || g_cfg.pins.roles[i] == IOR_Button_ScriptOnly_n) {
|| g_cfg.pins.roles[i] == IOR_Button_ScriptOnly || g_cfg.pins.roles[i] == IOR_Button_ScriptOnly_n
|| g_cfg.pins.roles[i] == IOR_SmartButtonForLEDs || g_cfg.pins.roles[i] == IOR_SmartButtonForLEDs_n) {
//addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL,"Test hold %i\r\n",i);
PIN_Input_Handler(i, t_diff);
}
Expand Down
7 changes: 7 additions & 0 deletions src/new_pins.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ enum IORole {
IOR_BridgeForward,
IOR_BridgeReverse,

// Smart LED button
// Click = toggle power
// Hold = control temperature
// Double click = next color
IOR_SmartButtonForLEDs,
IOR_SmartButtonForLEDs_n,

IOR_Total_Options,
};

Expand Down

0 comments on commit d6db57c

Please sign in to comment.