483.12.14
by Selene ToyKeeper
switched the rest of FSM + Anduril to use SPDX license headers |
1 |
// sos-mode.c: SOS mode for Anduril.
|
2 |
// Copyright (C) 2017-2023 Selene ToyKeeper
|
|
3 |
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
483.1.11
by Selene Scriven
more progress on refactoring Anduril into separate files... nearly done with the initial split |
4 |
|
483.12.14
by Selene ToyKeeper
switched the rest of FSM + Anduril to use SPDX license headers |
5 |
#pragma once
|
483.1.11
by Selene Scriven
more progress on refactoring Anduril into separate files... nearly done with the initial split |
6 |
|
7 |
#include "sos-mode.h" |
|
8 |
||
9 |
#ifdef USE_SOS_MODE_IN_BLINKY_GROUP
|
|
10 |
uint8_t sos_state(Event event, uint16_t arg) { |
|
11 |
// 1 click: off
|
|
12 |
if (event == EV_1click) { |
|
13 |
set_state(off_state, 0); |
|
483.12.66
by Selene ToyKeeper
Removed references to Harry Potter, |
14 |
return EVENT_HANDLED; |
483.1.11
by Selene Scriven
more progress on refactoring Anduril into separate files... nearly done with the initial split |
15 |
}
|
483.1.92
by Selene Scriven
improved docs, changed blinky order: Battcheck, Tempcheck, Beacon, SOS |
16 |
// 2 clicks: next blinky mode
|
483.1.11
by Selene Scriven
more progress on refactoring Anduril into separate files... nearly done with the initial split |
17 |
else if (event == EV_2clicks) { |
483.1.92
by Selene Scriven
improved docs, changed blinky order: Battcheck, Tempcheck, Beacon, SOS |
18 |
#if defined(USE_BATTCHECK_MODE)
|
19 |
set_state(battcheck_state, 0); |
|
20 |
#elif defined(USE_THERMAL_REGULATION)
|
|
483.1.11
by Selene Scriven
more progress on refactoring Anduril into separate files... nearly done with the initial split |
21 |
set_state(tempcheck_state, 0); |
483.1.92
by Selene Scriven
improved docs, changed blinky order: Battcheck, Tempcheck, Beacon, SOS |
22 |
#elif defined(USE_BEACON_MODE)
|
23 |
set_state(beacon_state, 0); |
|
483.1.11
by Selene Scriven
more progress on refactoring Anduril into separate files... nearly done with the initial split |
24 |
#endif
|
483.12.66
by Selene ToyKeeper
Removed references to Harry Potter, |
25 |
return EVENT_HANDLED; |
483.1.11
by Selene Scriven
more progress on refactoring Anduril into separate files... nearly done with the initial split |
26 |
}
|
27 |
return EVENT_NOT_HANDLED; |
|
28 |
}
|
|
29 |
#endif
|
|
30 |
||
31 |
void sos_blink(uint8_t num, uint8_t dah) { |
|
32 |
#define DIT_LENGTH 200
|
|
33 |
for (; num > 0; num--) { |
|
34 |
set_level(memorized_level); |
|
35 |
nice_delay_ms(DIT_LENGTH); |
|
36 |
if (dah) { // dah is 3X as long as a dit |
|
37 |
nice_delay_ms(DIT_LENGTH*2); |
|
38 |
}
|
|
39 |
set_level(0); |
|
40 |
// one "off" dit between blinks
|
|
41 |
nice_delay_ms(DIT_LENGTH); |
|
42 |
}
|
|
43 |
// three "off" dits (or one "dah") between letters
|
|
44 |
// (except for SOS, which is collectively treated as a single "letter")
|
|
45 |
//nice_delay_ms(DIT_LENGTH*2);
|
|
46 |
}
|
|
47 |
||
48 |
inline void sos_mode_iter() { |
|
49 |
// one iteration of main loop()
|
|
50 |
//nice_delay_ms(1000);
|
|
51 |
sos_blink(3, 0); // S |
|
52 |
sos_blink(3, 1); // O |
|
53 |
sos_blink(3, 0); // S |
|
54 |
nice_delay_ms(2000); |
|
55 |
}
|
|
56 |