Skip to content

Commit

Permalink
Button preset call mode
Browse files Browse the repository at this point in the history
(stops main segment values from being applied to all presets)
  • Loading branch information
Aircoookie committed Dec 11, 2021
1 parent 2ce8f1e commit fb338c0
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
10 changes: 5 additions & 5 deletions wled00/button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void shortPressAction(uint8_t b)
default: ++effectCurrent %= strip.getModeCount(); colorUpdated(CALL_MODE_BUTTON); break;
}
} else {
applyPreset(macroButton[b], CALL_MODE_BUTTON);
applyPreset(macroButton[b], CALL_MODE_BUTTON_PRESET);
}

// publish MQTT message
Expand All @@ -39,7 +39,7 @@ void longPressAction(uint8_t b)
default: bri += 8; colorUpdated(CALL_MODE_BUTTON); buttonPressedTime[b] = millis(); break; // repeatable action
}
} else {
applyPreset(macroLongPress[b], CALL_MODE_BUTTON);
applyPreset(macroLongPress[b], CALL_MODE_BUTTON_PRESET);
}

// publish MQTT message
Expand All @@ -58,7 +58,7 @@ void doublePressAction(uint8_t b)
default: ++effectPalette %= strip.getPaletteCount(); colorUpdated(CALL_MODE_BUTTON); break;
}
} else {
applyPreset(macroDoublePress[b], CALL_MODE_BUTTON);
applyPreset(macroDoublePress[b], CALL_MODE_BUTTON_PRESET);
}

// publish MQTT message
Expand Down Expand Up @@ -105,12 +105,12 @@ void handleSwitch(uint8_t b)

if (millis() - buttonPressedTime[b] > WLED_DEBOUNCE_THRESHOLD) { //fire edge event only after 50ms without change (debounce)
if (!buttonPressedBefore[b]) { // on -> off
if (macroButton[b]) applyPreset(macroButton[b], CALL_MODE_BUTTON);
if (macroButton[b]) applyPreset(macroButton[b], CALL_MODE_BUTTON_PRESET);
else { //turn on
if (!bri) {toggleOnOff(); colorUpdated(CALL_MODE_BUTTON);}
}
} else { // off -> on
if (macroLongPress[b]) applyPreset(macroLongPress[b], CALL_MODE_BUTTON);
if (macroLongPress[b]) applyPreset(macroLongPress[b], CALL_MODE_BUTTON_PRESET);
else { //turn off
if (bri) {toggleOnOff(); colorUpdated(CALL_MODE_BUTTON);}
}
Expand Down
3 changes: 2 additions & 1 deletion wled00/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
//Notifier callMode
#define CALL_MODE_INIT 0 //no updates on init, can be used to disable updates
#define CALL_MODE_DIRECT_CHANGE 1
#define CALL_MODE_BUTTON 2
#define CALL_MODE_BUTTON 2 //default button actions applied to selected segments
#define CALL_MODE_NOTIFICATION 3
#define CALL_MODE_NIGHTLIGHT 4
#define CALL_MODE_NO_NOTIFY 5
Expand All @@ -84,6 +84,7 @@
#define CALL_MODE_BLYNK 9
#define CALL_MODE_ALEXA 10
#define CALL_MODE_WS_SEND 11 //special call mode, not for notifier, updates websocket only
#define CALL_MODE_BUTTON_PRESET 12 //button/IR JSON preset/macro

//RGB to RGBW conversion mode
#define RGBW_MODE_MANUAL_ONLY 0 //No automatic white channel calculation. Manual white channel slider
Expand Down
6 changes: 3 additions & 3 deletions wled00/ir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void decBrightness()
void presetFallback(uint8_t presetID, uint8_t effectID, uint8_t paletteID)
{
byte prevError = errorFlag;
if (!applyPreset(presetID, CALL_MODE_BUTTON)) {
if (!applyPreset(presetID, CALL_MODE_BUTTON_PRESET)) {
effectCurrent = effectID;
effectPalette = paletteID;
errorFlag = prevError; //clear error 12 from non-existent preset
Expand All @@ -87,7 +87,7 @@ bool decodeIRCustom(uint32_t code)
{
//just examples, feel free to modify or remove
case IRCUSTOM_ONOFF : toggleOnOff(); break;
case IRCUSTOM_MACRO1 : applyPreset(1, CALL_MODE_BUTTON); break;
case IRCUSTOM_MACRO1 : applyPreset(1, CALL_MODE_BUTTON_PRESET); break;

default: return false;
}
Expand Down Expand Up @@ -631,7 +631,7 @@ void decodeIRJson(uint32_t code)
colorUpdated(CALL_MODE_BUTTON);
} else if (!jsonCmdObj.isNull()) {
// command is JSON object
deserializeState(jsonCmdObj, CALL_MODE_BUTTON);
deserializeState(jsonCmdObj, CALL_MODE_BUTTON_PRESET);
}
releaseJSONBufferLock();
}
Expand Down
5 changes: 3 additions & 2 deletions wled00/led.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,11 @@ bool colorChanged()
void colorUpdated(int callMode)
{
//call for notifier -> 0: init 1: direct change 2: button 3: notification 4: nightlight 5: other (No notification)
// 6: fx changed 7: hue 8: preset cycle 9: blynk 10: alexa
// 6: fx changed 7: hue 8: preset cycle 9: blynk 10: alexa 11: ws send only 12: button preset
if (callMode != CALL_MODE_INIT &&
callMode != CALL_MODE_DIRECT_CHANGE &&
callMode != CALL_MODE_NO_NOTIFY) strip.applyToAllSelected = true; //if not from JSON api, which directly sets segments
callMode != CALL_MODE_NO_NOTIFY &&
callMode != CALL_MODE_BUTTON_PRESET) strip.applyToAllSelected = true; //if not from JSON api, which directly sets segments

bool someSel = false;

Expand Down
1 change: 1 addition & 0 deletions wled00/udp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ void notify(byte callMode, bool followUp)
case CALL_MODE_INIT: return;
case CALL_MODE_DIRECT_CHANGE: if (!notifyDirect) return; break;
case CALL_MODE_BUTTON: if (!notifyButton) return; break;
case CALL_MODE_BUTTON_PRESET: if (!notifyButton) return; break;
case CALL_MODE_NIGHTLIGHT: if (!notifyDirect) return; break;
case CALL_MODE_HUE: if (!notifyHue) return; break;
case CALL_MODE_PRESET_CYCLE: if (!notifyDirect) return; break;
Expand Down

0 comments on commit fb338c0

Please sign in to comment.