1
// momentary-mode.c: Momentary mode for Anduril.
2
// Copyright (C) 2017-2023 Selene ToyKeeper
3
// SPDX-License-Identifier: GPL-3.0-or-later
7
#include "momentary-mode.h"
9
uint8_t momentary_state(Event event, uint16_t arg) {
10
// init strobe mode, if relevant
11
#ifdef USE_STROBE_STATE
12
if ((event == EV_enter_state) && (momentary_mode != 0)) {
13
strobe_state(event, arg);
17
// light up when the button is pressed; go dark otherwise
18
// button is being held
19
if ((event & (B_CLICK | B_PRESS)) == (B_CLICK | B_PRESS)) {
21
// 0 = ramping, 1 = strobes
22
if (momentary_mode == 0) {
23
set_level(memorized_level);
27
// button was released
28
else if ((event & (B_CLICK | B_PRESS)) == (B_CLICK)) {
31
//go_to_standby = 1; // sleep while light is off
35
// Sleep, dammit! (but wait a few seconds first)
36
// (because standby mode uses such little power that it can interfere
37
// with exiting via tailcap loosen+tighten unless you leave power
38
// disconnected for several seconds, so we want to be awake when that
39
// happens to speed up the process)
40
else if (event == EV_tick) {
41
#ifdef USE_STROBE_STATE
42
if (momentary_active) {
43
// 0 = ramping, non-zero = strobes
44
if (momentary_mode != 0) {
45
return strobe_state(event, arg);
50
if (arg > TICKS_PER_SECOND*5) { // sleep after 5 seconds
51
go_to_standby = 1; // sleep while light is off
52
// turn off lighted button
53
#ifdef USE_INDICATOR_LED
55
#elif defined(USE_AUX_RGB_LEDS)
59
#ifdef USE_STROBE_STATE
65
return EVENT_NOT_HANDLED;