1
// tactical-mode.c: Tactical (ish) mode for Anduril.
2
// Copyright (C) 2023 Selene ToyKeeper
3
// SPDX-License-Identifier: GPL-3.0-or-later
7
#include "tactical-mode.h"
10
uint8_t tactical_state(Event event, uint16_t arg) {
11
// momentary(ish) tactical mode
12
uint8_t mem_lvl = memorized_level; // save this to restore it later
13
uint8_t ret = EVENT_NOT_HANDLED;
15
// button is being held
16
if ((event & (B_CLICK | B_PRESS)) == (B_CLICK | B_PRESS)) {
23
uint8_t click = event & 0x0f; // click number
27
lvl = cfg.tactical_levels[click-1];
28
if ((1 <= lvl) && (lvl <= RAMP_SIZE)) { // steady output
29
memorized_level = lvl;
31
#if NUM_CHANNEL_MODES > 1
32
// use ramp mode's channel
33
channel_mode = cfg.channel_mode;
35
} else { // momentary strobe mode
37
if (lvl > RAMP_SIZE) {
38
current_strobe_type = (lvl - RAMP_SIZE - 1) % strobe_mode_END;
43
// button was released
44
else if ((event & (B_CLICK | B_PRESS)) == (B_CLICK)) {
47
interrupt_nice_delays(); // stop animations in progress
50
// delegate to momentary mode while button is pressed
51
if (momentary_active) {
52
momentary_state(event, arg);
55
memorized_level = mem_lvl; // restore temporarily overridden mem level
57
// copy lockout mode's aux LED and sleep behaviors
58
if (event == EV_enter_state) {
59
lockout_state(event, arg);
61
else if (event == EV_tick) {
62
if (! momentary_active) {
63
return lockout_state(event, arg);
67
else if (event == EV_sleep_tick) {
68
return lockout_state(event, arg);
71
// 6 clicks: exit and turn off
72
else if (event == EV_6clicks) {
74
set_state(off_state, 0);
78
////////// Every action below here is blocked in the simple UI //////////
79
// (unnecessary since this entire mode is blocked in simple UI)
82
if (cfg.simple_ui_active) {
83
return EVENT_NOT_HANDLED;
88
// 7H: configure tactical mode
89
else if (event == EV_click7_hold) {
90
push_state(tactical_config_state, 0);
97
void tactical_config_save(uint8_t step, uint8_t value) {
98
// update tac mode values
100
// each value is 1 to 150, or other:
101
// - 1..150 is a ramp level
102
// - other means "strobe mode"
103
cfg.tactical_levels[step - 1] = value;
106
uint8_t tactical_config_state(Event event, uint16_t arg) {
107
return config_state_base(event, arg, 3, tactical_config_save);