~toykeeper/flashlight-firmware/fsm

« back to all changes in this revision

Viewing changes to ToyKeeper/spaghetti-monster/fsm-states.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
 
/*
2
 
 * fsm-states.c: State-handling functions for SpaghettiMonster.
3
 
 *
4
 
 * Copyright (C) 2017 Selene Scriven
5
 
 *
6
 
 * This program is free software: you can redistribute it and/or modify
7
 
 * it under the terms of the GNU General Public License as published by
8
 
 * the Free Software Foundation, either version 3 of the License, or
9
 
 * (at your option) any later version.
10
 
 *
11
 
 * This program is distributed in the hope that it will be useful,
12
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 * GNU General Public License for more details.
15
 
 *
16
 
 * You should have received a copy of the GNU General Public License
17
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 
 */
19
 
 
20
 
#ifndef FSM_STATES_C
21
 
#define FSM_STATES_C
 
1
// fsm-states.c: State-handling functions for SpaghettiMonster.
 
2
// Copyright (C) 2017-2023 Selene ToyKeeper
 
3
// SPDX-License-Identifier: GPL-3.0-or-later
 
4
 
 
5
#pragma once
22
6
 
23
7
#include "fsm-states.h"
24
8
#include "fsm-adc.h"
39
23
    current_state = new_state;
40
24
    // call new state-enter hook (don't use stack)
41
25
    if (new_state != NULL) current_state(enter_event, arg);
 
26
 
 
27
    // since state changed, stop any animation in progress
 
28
    interrupt_nice_delays();
42
29
}
43
30
 
44
31
int8_t push_state(StatePtr new_state, uint16_t arg) {
79
66
    return push_state(new_state, arg);
80
67
}
81
68
 
 
69
void set_state_deferred(StatePtr new_state, uint16_t arg) {
 
70
    deferred_state = new_state;
 
71
    deferred_state_arg = arg;
 
72
}
 
73
 
82
74
#ifndef DONT_USE_DEFAULT_STATE
83
75
// bottom state on stack
84
76
// handles default actions for LVP, thermal regulation, etc
111
103
}
112
104
#endif
113
105
 
114
 
#endif