~toykeeper/flashlight-firmware/trunk

188.33.14 by Selene ToyKeeper
switched the rest of FSM + Anduril to use SPDX license headers
1
// fsm-standby.h: standby mode functions for SpaghettiMonster.
2
// Copyright (C) 2017-2023 Selene ToyKeeper
3
// SPDX-License-Identifier: GPL-3.0-or-later
188.1.11 by Selene Scriven
Completely reorganized SpaghettiMonster code into smaller logical pieces: fsm-*.c and fsm-*.h.
4
188.33.14 by Selene ToyKeeper
switched the rest of FSM + Anduril to use SPDX license headers
5
#pragma once
188.1.11 by Selene Scriven
Completely reorganized SpaghettiMonster code into smaller logical pieces: fsm-*.c and fsm-*.h.
6
188.1.69 by Selene Scriven
Got the 4th PWM channel to work, ish. (channel 4 is inverted though)
7
// deferred "off" so we won't suspend in a weird state
8
// (like...  during the middle of a strobe pulse)
9
// set this to nonzero to enter standby mode next time the system is idle
10
volatile uint8_t go_to_standby = 0;
11
188.1.147 by Selene Scriven
Changed halfsleep mode to TICK_DURING_STANDBY. Added blinking indicator LED support to Anduril.
12
#ifdef TICK_DURING_STANDBY
13
#ifndef STANDBY_TICK_SPEED
188.22.33 by Selene Scriven
added auto-lock function, mostly contributed by SammysHP
14
#define STANDBY_TICK_SPEED 3  // every 0.128 s
188.1.147 by Selene Scriven
Changed halfsleep mode to TICK_DURING_STANDBY. Added blinking indicator LED support to Anduril.
15
/*
16
 * From the Attiny85 manual:
17
 * 0: 16 ms
18
 * 1: 32 ms
19
 * 2: 64 ms
188.22.33 by Selene Scriven
added auto-lock function, mostly contributed by SammysHP
20
 * 3: 0.128 s
21
 * 4: 0.256 s
22
 * 5: 0.512 s
188.1.147 by Selene Scriven
Changed halfsleep mode to TICK_DURING_STANDBY. Added blinking indicator LED support to Anduril.
23
 * 6: 1.0 s
24
 * 7: 2.0 s
25
 * 32: 4.0 s
26
 * 33: 8.0 s
27
 * (other values may have unexpected effects; not sure why the final bit is
28
 *  separated from the others, in the "32" position instead of "8", but that's
29
 *  how it is)
30
 */
31
#endif
188.22.57 by Selene Scriven
fixed timing of auto-lock function, added SLEEP_TICKS_PER_MINUTE constants
32
188.22.33 by Selene Scriven
added auto-lock function, mostly contributed by SammysHP
33
#if (STANDBY_TICK_SPEED == 1)
34
#define SLEEP_TICKS_PER_SECOND 31
188.22.59 by Selene Scriven
fixed auto-lock timings again, based on measurement averages of several lights
35
#define SLEEP_TICKS_PER_MINUTE 1800
188.22.57 by Selene Scriven
fixed timing of auto-lock function, added SLEEP_TICKS_PER_MINUTE constants
36
188.22.33 by Selene Scriven
added auto-lock function, mostly contributed by SammysHP
37
#elif (STANDBY_TICK_SPEED == 2)
38
#define SLEEP_TICKS_PER_SECOND 16
188.22.59 by Selene Scriven
fixed auto-lock timings again, based on measurement averages of several lights
39
#define SLEEP_TICKS_PER_MINUTE 900
188.22.57 by Selene Scriven
fixed timing of auto-lock function, added SLEEP_TICKS_PER_MINUTE constants
40
188.22.33 by Selene Scriven
added auto-lock function, mostly contributed by SammysHP
41
#elif (STANDBY_TICK_SPEED == 3)
42
#define SLEEP_TICKS_PER_SECOND 8
188.22.59 by Selene Scriven
fixed auto-lock timings again, based on measurement averages of several lights
43
#define SLEEP_TICKS_PER_MINUTE 450
188.22.57 by Selene Scriven
fixed timing of auto-lock function, added SLEEP_TICKS_PER_MINUTE constants
44
188.22.33 by Selene Scriven
added auto-lock function, mostly contributed by SammysHP
45
#elif (STANDBY_TICK_SPEED == 4)
46
#define SLEEP_TICKS_PER_SECOND 4
188.22.59 by Selene Scriven
fixed auto-lock timings again, based on measurement averages of several lights
47
#define SLEEP_TICKS_PER_MINUTE 225
188.22.57 by Selene Scriven
fixed timing of auto-lock function, added SLEEP_TICKS_PER_MINUTE constants
48
188.22.33 by Selene Scriven
added auto-lock function, mostly contributed by SammysHP
49
#elif (STANDBY_TICK_SPEED == 5)
50
#define SLEEP_TICKS_PER_SECOND 2
188.22.59 by Selene Scriven
fixed auto-lock timings again, based on measurement averages of several lights
51
#define SLEEP_TICKS_PER_MINUTE 113
188.22.57 by Selene Scriven
fixed timing of auto-lock function, added SLEEP_TICKS_PER_MINUTE constants
52
188.22.33 by Selene Scriven
added auto-lock function, mostly contributed by SammysHP
53
#elif (STANDBY_TICK_SPEED == 6)
54
#define SLEEP_TICKS_PER_SECOND 1
188.22.59 by Selene Scriven
fixed auto-lock timings again, based on measurement averages of several lights
55
#define SLEEP_TICKS_PER_MINUTE 57
188.22.57 by Selene Scriven
fixed timing of auto-lock function, added SLEEP_TICKS_PER_MINUTE constants
56
188.22.33 by Selene Scriven
added auto-lock function, mostly contributed by SammysHP
57
#endif
188.1.146 by Selene Scriven
Implemented halfsleep mode.
58
#endif
59
188.1.11 by Selene Scriven
Completely reorganized SpaghettiMonster code into smaller logical pieces: fsm-*.c and fsm-*.h.
60
#define standby_mode sleep_until_eswitch_pressed
61
void sleep_until_eswitch_pressed();
62
188.1.88 by Selene Scriven
Added idle_mode() for slightly lower power use without turning off any regular functions.
63
#ifdef USE_IDLE_MODE
64
// stops processing until next click or timer tick
188.1.89 by Selene Scriven
Removed unused code from first idle_mode(); experiment.
65
// (I think)
188.1.88 by Selene Scriven
Added idle_mode() for slightly lower power use without turning off any regular functions.
66
void idle_mode();
67
#endif
68