~toykeeper/flashlight-firmware/fsm

« back to all changes in this revision

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

  • Committer: Selene ToyKeeper
  • Date: 2023-11-04 15:09:10 UTC
  • mfrom: (483.1.175 anduril2)
  • Revision ID: bzr@toykeeper.net-20231104150910-ddd3afw4nhfvof2l
merged anduril2 branch -> fsm, with *years* of changes
(this also means this code is now Anduril 2 instead of Anduril 1)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// sos-mode.c: SOS mode for Anduril.
 
2
// Copyright (C) 2017-2023 Selene ToyKeeper
 
3
// SPDX-License-Identifier: GPL-3.0-or-later
 
4
 
 
5
#pragma once
 
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);
 
14
        return EVENT_HANDLED;
 
15
    }
 
16
    // 2 clicks: next blinky mode
 
17
    else if (event == EV_2clicks) {
 
18
        #if defined(USE_BATTCHECK_MODE)
 
19
        set_state(battcheck_state, 0);
 
20
        #elif defined(USE_THERMAL_REGULATION)
 
21
        set_state(tempcheck_state, 0);
 
22
        #elif defined(USE_BEACON_MODE)
 
23
        set_state(beacon_state, 0);
 
24
        #endif
 
25
        return EVENT_HANDLED;
 
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