pokemon/input.hpp
2023-07-25 05:35:33 +00:00

58 lines
1.1 KiB
C++

#pragma once
#include <stdint.h>
struct count_flop_t {
int8_t count;
uint8_t flop;
uint8_t das;
uint8_t repeat;
};
struct input_t {
count_flop_t right;
count_flop_t left;
count_flop_t down;
count_flop_t up;
count_flop_t start;
count_flop_t a;
count_flop_t b;
count_flop_t c;
count_flop_t r;
count_flop_t x;
count_flop_t y;
count_flop_t z;
count_flop_t l;
};
void digital_callback(uint8_t fsm_state, uint8_t data);
extern input_t input;
constexpr int input_arr = 10;
constexpr int input_das = 20;
constexpr int input_debounce = 2;
static constexpr inline int32_t
input_flopped(count_flop_t& button)
{
if (button.count == input_debounce && button.flop == 0) {
button.flop = 1;
return 1;
} else if (button.flop == 1 && button.das == input_das && button.repeat == 0) {
button.repeat = 1;
button.das = 0;
return 2;
} else if (button.repeat == 1 && (button.das == input_arr)) {
button.das = 0;
return 2;
} else {
return 0;
}
}
struct event {
static inline bool cursor_left() { return input_flopped(input.a) == 1; }
static inline bool cursor_right() { return input_flopped(input.b) == 1; }
};