2
* fsm-events.h: Event-handling functions for SpaghettiMonster.
4
* Copyright (C) 2017 Selene Scriven
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.
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.
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/>.
1
// fsm-events.h: Event-handling functions for SpaghettiMonster.
2
// Copyright (C) 2017-2023 Selene ToyKeeper
3
// SPDX-License-Identifier: GPL-3.0-or-later
23
7
#include <avr/pgmspace.h>
10
// timeout durations in ticks (each tick 1/62th s)
12
#define HOLD_TIMEOUT 24
14
#ifndef RELEASE_TIMEOUT
15
#define RELEASE_TIMEOUT 18
18
// return codes for Event handlers
19
// Indicates whether this handler consumed (handled) the Event, or
20
// if the Event should be sent to the next handler in the stack.
21
#define EVENT_HANDLED 0
22
#define EVENT_NOT_HANDLED 1
23
#define MISCHIEF_MANAGED EVENT_HANDLED
24
#define MISCHIEF_NOT_MANAGED EVENT_NOT_HANDLED
26
27
typedef uint8_t Event;
27
28
typedef struct Emission {
32
#define EVENT_HANDLED 0
33
#define EVENT_NOT_HANDLED 1
34
#define MISCHIEF_MANAGED EVENT_HANDLED
35
#define MISCHIEF_NOT_MANAGED EVENT_NOT_HANDLED
37
33
Event current_event;
38
34
// at 0.016 ms per tick, 255 ticks = 4.08 s
39
35
static volatile uint16_t ticks_since_last_event = 0;
41
// timeout durations in ticks (each tick 1/62th s)
43
#define HOLD_TIMEOUT 24
45
#ifndef RELEASE_TIMEOUT
46
#define RELEASE_TIMEOUT 18
37
// maximum number of events which can be waiting at one time
38
// (would probably be okay to reduce this to 4, but it's higher to be safe)
39
#define EMISSION_QUEUE_LEN 16
40
// was "volatile" before, changed to regular var since IRQ rewrites seem
41
// to have removed the need for it to be volatile
42
// no comment about "volatile emissions"
43
Emission emissions[EMISSION_QUEUE_LEN];
45
void append_emission(Event event, uint16_t arg);
46
void delete_first_emission();
47
void process_emissions();
48
uint8_t emit_now(Event event, uint16_t arg);
49
void emit(Event event, uint16_t arg);
50
void emit_current_event(uint16_t arg);
51
void empty_event_sequence();
52
uint8_t push_event(uint8_t ev_type); // only for use by PCINT_inner()
55
// TODO: Maybe move these to their own file...
56
// ... this probably isn't the right place for delays.
58
// adjust the timing of delays, lower = shorter delays
59
// 90 = 90% delay, 10% for other things
60
#define DELAY_FACTOR 92
62
inline void interrupt_nice_delays();
63
uint8_t nice_delay_ms(uint16_t ms);
64
//uint8_t nice_delay_s();
65
void delay_4ms(uint8_t ms);
50
69
* Bit 7: 1 for a button input event, 0 for all others.
200
219
#define EV_click15_hold (B_CLICK|B_HOLD|B_PRESS|15)
201
220
#define EV_click15_hold_release (B_CLICK|B_HOLD|B_RELEASE|B_TIMEOUT|15)
204
void empty_event_sequence();
205
uint8_t push_event(uint8_t ev_type);
208
#define EMISSION_QUEUE_LEN 16
209
// no comment about "volatile emissions"
210
volatile Emission emissions[EMISSION_QUEUE_LEN];
212
void append_emission(Event event, uint16_t arg);
213
void delete_first_emission();
214
void process_emissions();
215
//#define emit_now emit
216
uint8_t emit_now(Event event, uint16_t arg);
217
void emit(Event event, uint16_t arg);
218
void emit_current_event(uint16_t arg);
220
uint8_t nice_delay_ms(uint16_t ms);
221
//uint8_t nice_delay_s();
222
inline void interrupt_nice_delays();
223
void delay_4ms(uint8_t ms);