Skip to content

Commit

Permalink
New feature: Select previous channel mode
Browse files Browse the repository at this point in the history
Two options. Previous channel is on 4C from ramp mode only and replaces lockout mode. By defining `USE_PREVIOUS_CHANNEL` it is included as a configurable option under the ramp extras menu (0: 4C -> lock. 1: 4C -> previous channel). By defining both `USE_PREVIOUS_CHANNEL` and `PREVIOUS_CHANNEL_REPLACES_LOCKOUT` the lockout shortcut is entirely removed and the config option is not included to save some space.
  • Loading branch information
SiteRelEnby committed Apr 5, 2024
1 parent cc228bd commit 6d90905
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 3 deletions.
8 changes: 7 additions & 1 deletion docs/anduril-manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,9 @@ While the light is on, a few actions are available:
- `3H`: Tint ramping (only when current channel has adjustable tint).
- `4H`: Momentary turbo, when `3H` is mapped to tint.

- `4C`: Go to lockout mode.
- `4C`: Go to lockout mode. On some lights with multiple channel modes, this
can instead be configured to select the previous channel. See 10H for
details.

- `5C`: Go to momentary mode.
- `5H`: Start a sunset timer. Details are below in the Sunset Timer section.
Expand Down Expand Up @@ -274,6 +276,10 @@ While the light is on, a few actions are available:
- Item 5: Configure "smooth steps".
0: Disable smooth steps.
1: Enable smooth steps.
- Item 6: Configure the function of 4C when in ramp mode (only on lights
with more than one defined channel mode)
0: 4C switches off the light and enters lockout mode.
1: 4C selects the previous channel mode.

Memory determines which brightness level the light goes to with 1 click
from off. There are three types of brightness memory to choose from:
Expand Down
1 change: 1 addition & 0 deletions hw/hank/emisar-2ch/anduril.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,4 @@
#undef BLINK_AT_RAMP_MIDDLE
#endif

#define USE_PREVIOUS_CHANNEL
1 change: 1 addition & 0 deletions hw/hank/noctigon-k9.3/anduril.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,4 @@
#undef BLINK_AT_RAMP_MIDDLE
#endif

#define USE_PREVIOUS_CHANNEL
1 change: 1 addition & 0 deletions hw/hank/noctigon-m44/anduril.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,4 @@
// for consistency with KR4 (not otherwise necessary though)
#define USE_SOFT_FACTORY_RESET

#define USE_PREVIOUS_CHANNEL
26 changes: 26 additions & 0 deletions ui/anduril/channel-modes.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,32 @@ uint8_t channel_mode_state(Event event, uint16_t arg) {
}
#endif // if NUM_CHANNEL_MODES > 1

#ifdef USE_PREVIOUS_CHANNEL
if (
(event == EV_4clicks)
#ifndef PREVIOUS_CHANNEL_REPLACES_LOCKOUT
&& (cfg.previous_channel_enabled)
#endif
){
uint8_t next = cfg.channel_mode;
uint8_t count = 0;
do {
count ++;
if (next > 0){ next--; }
else if (next == 0) { next = (NUM_CHANNEL_MODES - 1); }
} while ((! channel_mode_enabled(next)) && count < NUM_CHANNEL_MODES);
// if mode hasn't changed, abort
if (cfg.channel_mode == next)
return EVENT_NOT_HANDLED;

set_channel_mode(next);
// remember after battery changes
cfg.channel_mode = channel_mode;
save_config();
return EVENT_HANDLED;
}
#endif

#ifdef USE_CUSTOM_CHANNEL_3H_MODES
// defer to mode-specific function if defined
else if (channel_3H_modes[channel_mode]) {
Expand Down
4 changes: 4 additions & 0 deletions ui/anduril/load-save-config-fsm.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ typedef struct Config {
#ifdef DEFAULT_BLINK_CHANNEL
uint8_t blink_channel;
#endif

#if (defined(USE_PREVIOUS_CHANNEL) && !defined(PREVIOUS_CHANNEL_REPLACES_LOCKOUT))
uint8_t previous_channel_enabled;
#endif
#endif
#ifdef USE_CHANNEL_MODE_ARGS
// this is an array, needs a few bytes
Expand Down
3 changes: 3 additions & 0 deletions ui/anduril/load-save-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ Config cfg = {
// blink numbers in a specific channel (user configurable)
.blink_channel = DEFAULT_BLINK_CHANNEL,
#endif
#if (defined(USE_PREVIOUS_CHANNEL) && !defined(PREVIOUS_CHANNEL_REPLACES_LOCKOUT))
.previous_channel_enabled = 0,
#endif
#endif
#ifdef USE_CHANNEL_MODE_ARGS
// one byte of extra data per channel mode, like for tint value
Expand Down
18 changes: 16 additions & 2 deletions ui/anduril/ramp-mode.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,20 @@ uint8_t steady_state(Event event, uint16_t arg) {
}

#ifdef USE_LOCKOUT_MODE
#ifdef USE_PREVIOUS_CHANNEL
#ifndef PREVIOUS_CHANNEL_REPLACES_LOCKOUT //don't include this code at all if we're forcing overriding this shortcut
// 4 clicks: shortcut to lockout mode
else if (event == EV_4clicks) {
else if ((event == EV_4clicks) && (!cfg.previous_channel_enabled))
#else
else if (event == EV_4clicks)
#endif //ifndef PREVIOUS_CHANNEL_REPLACES_LOCKOUT
{
set_level(0);
set_state(lockout_state, 0);
return EVENT_HANDLED;
}
#endif
#endif //ifdef USE_PREVIOUS_CHANNEL
#endif //ifdef USE_LOCKOUT_MODE

// hold: change brightness (brighter, dimmer)
// click, hold: change brightness (dimmer)
Expand Down Expand Up @@ -612,6 +619,13 @@ void ramp_extras_config_save(uint8_t step, uint8_t value) {
cfg.smooth_steps_style = value;
}
#endif

#if (defined(USE_PREVIOUS_CHANNEL) && !defined(PREVIOUS_CHANNEL_REPLACES_LOCKOUT))
else if (previous_channel_enabled_config_step == step) {
cfg.previous_channel_enabled = value;
}
#endif

}

uint8_t ramp_extras_config_state(Event event, uint16_t arg) {
Expand Down
3 changes: 3 additions & 0 deletions ui/anduril/ramp-mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ typedef enum {
#ifdef USE_SMOOTH_STEPS
smooth_steps_style_config_step,
#endif
#if (defined(USE_PREVIOUS_CHANNEL) && !defined(PREVIOUS_CHANNEL_REPLACES_LOCKOUT))
previous_channel_enabled_config_step,
#endif
ramp_extras_config_num_steps
} ramp_extras_config_steps_e;
#endif
Expand Down

0 comments on commit 6d90905

Please sign in to comment.