~toykeeper/flashlight-firmware/fsm

« back to all changes in this revision

Viewing changes to ToyKeeper/spaghetti-monster/anduril/ff-strobe-modes.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
// ff-strobe-modes.c: Fireflies Flashlights strobe modes 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 "ff-strobe-modes.h"
 
8
 
 
9
uint8_t boring_strobe_state(Event event, uint16_t arg) {
 
10
    // police strobe and SOS, meh
 
11
    // 'st' reduces ROM size slightly
 
12
    uint8_t st = boring_strobe_type;
 
13
 
 
14
    if (event == EV_enter_state) {
 
15
        return EVENT_HANDLED;
 
16
    }
 
17
    // 1 click: off
 
18
    else if (event == EV_1click) {
 
19
        // reset to police strobe for next time
 
20
        boring_strobe_type = 0;
 
21
        set_state(off_state, 0);
 
22
        return EVENT_HANDLED;
 
23
    }
 
24
    // 2 clicks: rotate through strobe/flasher modes
 
25
    else if (event == EV_2clicks) {
 
26
        boring_strobe_type = (st + 1) % NUM_BORING_STROBES;
 
27
        return EVENT_HANDLED;
 
28
    }
 
29
    return EVENT_NOT_HANDLED;
 
30
}
 
31
 
 
32
inline void boring_strobe_state_iter() {
 
33
    switch(boring_strobe_type) {
 
34
        #ifdef USE_POLICE_STROBE_MODE
 
35
        case 0: // police strobe
 
36
            police_strobe_iter();
 
37
            break;
 
38
        #endif
 
39
 
 
40
        #ifdef USE_SOS_MODE_IN_FF_GROUP
 
41
        default: // SOS
 
42
            sos_mode_iter();
 
43
            break;
 
44
        #endif
 
45
    }
 
46
}
 
47
 
 
48
#ifdef USE_POLICE_STROBE_MODE
 
49
inline void police_strobe_iter() {
 
50
    // one iteration of main loop()
 
51
    // flash at 16 Hz then 8 Hz, 8 times each
 
52
    for (uint8_t del=41; del<100; del+=41) {
 
53
        for (uint8_t f=0; f<8; f++) {
 
54
            set_level(STROBE_BRIGHTNESS);
 
55
            nice_delay_ms(del >> 1);
 
56
            set_level(0);
 
57
            nice_delay_ms(del);
 
58
        }
 
59
    }
 
60
}
 
61
#endif
 
62