~toykeeper/flashlight-firmware/fsm

« back to all changes in this revision

Viewing changes to ToyKeeper/spaghetti-monster/anduril/tactical-mode.c

  • Committer: Selene ToyKeeper
  • Date: 2023-11-02 17:05:02 UTC
  • mfrom: (483.12.159 multi-channel)
  • mto: This revision was merged to the branch mainline in revision 491.
  • Revision ID: bzr@toykeeper.net-20231102170502-sinkm18qjxlorsxa
merged multi-channel branch with a major refactor and half a year of updates

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * tactical-mode.c: Tactical (ish) mode for Anduril.
3
 
 *
4
 
 * Copyright (C) 2023 Selene Scriven
5
 
 *
6
 
 * This program is free software: you can redistribute it and/or modify
7
 
 * it under the terms of the GNU General Public License as published by
8
 
 * the Free Software Foundation, either version 3 of the License, or
9
 
 * (at your option) any later version.
10
 
 *
11
 
 * This program is distributed in the hope that it will be useful,
12
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 * GNU General Public License for more details.
15
 
 *
16
 
 * You should have received a copy of the GNU General Public License
17
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 
 */
 
1
// tactical-mode.c: Tactical (ish) mode for Anduril.
 
2
// Copyright (C) 2023 Selene ToyKeeper
 
3
// SPDX-License-Identifier: GPL-3.0-or-later
19
4
 
20
 
#ifndef TACTICAL_MODE_C
21
 
#define TACTICAL_MODE_C
 
5
#pragma once
22
6
 
23
7
#include "tactical-mode.h"
24
8
 
25
 
// TODO: save these in eeprom
26
 
uint8_t tactical_levels[] = { TACTICAL_LEVELS };  // high, low, strobe
27
9
 
28
10
uint8_t tactical_state(Event event, uint16_t arg) {
29
11
    // momentary(ish) tactical mode
42
24
        if (click <= 3) {
43
25
            momentary_active = 1;
44
26
            uint8_t lvl;
45
 
            lvl = tactical_levels[click-1];
 
27
            lvl = cfg.tactical_levels[click-1];
46
28
            if ((1 <= lvl) && (lvl <= RAMP_SIZE)) {  // steady output
47
29
                memorized_level = lvl;
48
30
                momentary_mode = 0;
 
31
                #if NUM_CHANNEL_MODES > 1
 
32
                    // use ramp mode's channel
 
33
                    channel_mode = cfg.channel_mode;
 
34
                #endif
49
35
            } else {  // momentary strobe mode
50
36
                momentary_mode = 1;
51
37
                if (lvl > RAMP_SIZE) {
52
 
                    strobe_type = (lvl - RAMP_SIZE - 1) % strobe_mode_END;
 
38
                    current_strobe_type = (lvl - RAMP_SIZE - 1) % strobe_mode_END;
53
39
                }
54
40
            }
55
41
        }
58
44
    else if ((event & (B_CLICK | B_PRESS)) == (B_CLICK)) {
59
45
        momentary_active = 0;
60
46
        set_level(0);
 
47
        interrupt_nice_delays();  // stop animations in progress
61
48
    }
62
49
 
63
50
    // delegate to momentary mode while button is pressed
92
79
    // (unnecessary since this entire mode is blocked in simple UI)
93
80
    /*
94
81
    #ifdef USE_SIMPLE_UI
95
 
    if (simple_ui_active) {
 
82
    if (cfg.simple_ui_active) {
96
83
        return EVENT_NOT_HANDLED;
97
84
    }
98
85
    #endif
101
88
    // 7H: configure tactical mode
102
89
    else if (event == EV_click7_hold) {
103
90
        push_state(tactical_config_state, 0);
104
 
        return MISCHIEF_MANAGED;
 
91
        return EVENT_HANDLED;
105
92
    }
106
93
 
107
94
    return ret;
113
100
    // each value is 1 to 150, or other:
114
101
    // - 1..150 is a ramp level
115
102
    // - other means "strobe mode"
116
 
    tactical_levels[step - 1] = value;
 
103
    cfg.tactical_levels[step - 1] = value;
117
104
}
118
105
 
119
106
uint8_t tactical_config_state(Event event, uint16_t arg) {
120
107
    return config_state_base(event, arg, 3, tactical_config_save);
121
108
}
122
109
 
123
 
 
124
 
#endif
125