mirror of
https://github.com/ravinrabbid/DonCon2040.git
synced 2024-11-20 03:37:07 +01:00
Add basic roll counters
This commit is contained in:
parent
d81dd41d79
commit
71b17d4daa
@ -94,6 +94,8 @@ const Peripherals::StatusLed::Config led_config = {
|
||||
const Peripherals::Display::Config display_config = {
|
||||
i2c_config.block, // Block
|
||||
0x3C, // Address
|
||||
|
||||
500, // Roll Counter Timeout in Milliseconds
|
||||
};
|
||||
|
||||
} // namespace Default
|
||||
|
@ -19,6 +19,8 @@ class Display {
|
||||
struct Config {
|
||||
i2c_inst_t *i2c_block;
|
||||
uint8_t i2c_address;
|
||||
|
||||
uint32_t roll_counter_timeout_ms;
|
||||
};
|
||||
|
||||
private:
|
||||
|
@ -201,6 +201,41 @@ static std::string modeToString(usb_mode_t mode) {
|
||||
return "?";
|
||||
}
|
||||
|
||||
static std::vector<uint16_t> updateRollCounters(const Utils::InputState::Drum &drum, const uint32_t timeout_ms) {
|
||||
struct CounterState {
|
||||
uint32_t last_triggered_time;
|
||||
bool last_state;
|
||||
uint16_t count;
|
||||
};
|
||||
|
||||
static CounterState ka_left_state = {0, false, 0};
|
||||
static CounterState don_left_state = {0, false, 0};
|
||||
static CounterState don_right_state = {0, false, 0};
|
||||
static CounterState ka_right_state = {0, false, 0};
|
||||
|
||||
uint32_t now = to_ms_since_boot(get_absolute_time());
|
||||
|
||||
auto check_roll = [&](CounterState &target, bool current_state) {
|
||||
if (current_state && (target.last_state != current_state)) {
|
||||
if ((now - target.last_triggered_time) > timeout_ms) {
|
||||
target.count = 0;
|
||||
}
|
||||
|
||||
target.last_triggered_time = now;
|
||||
target.count++;
|
||||
}
|
||||
|
||||
target.last_state = current_state;
|
||||
};
|
||||
|
||||
check_roll(ka_left_state, drum.ka_left.triggered);
|
||||
check_roll(don_left_state, drum.don_left.triggered);
|
||||
check_roll(don_right_state, drum.don_right.triggered);
|
||||
check_roll(ka_right_state, drum.ka_right.triggered);
|
||||
|
||||
return {ka_left_state.count, don_left_state.count, don_right_state.count, ka_right_state.count};
|
||||
}
|
||||
|
||||
void Display::drawIdleScreen() {
|
||||
// Header
|
||||
std::string mode_string = modeToString(m_usb_mode) + " mode";
|
||||
@ -222,6 +257,15 @@ void Display::drawIdleScreen() {
|
||||
if (m_input_state.drum.ka_right.triggered) {
|
||||
ssd1306_bmp_show_image_with_offset(&m_display, ka_r_bmp.data(), ka_r_bmp.size(), 64 - 26, 12);
|
||||
}
|
||||
|
||||
// Roll counters
|
||||
auto roll_counters = updateRollCounters(m_input_state.drum, m_config.roll_counter_timeout_ms);
|
||||
int num = 1;
|
||||
for (const auto &counter : roll_counters) {
|
||||
ssd1306_draw_string(&m_display, 2, 12 * num, 1, std::to_string(counter).c_str());
|
||||
num++;
|
||||
}
|
||||
|
||||
// Player "LEDs"
|
||||
if (m_player_id != 0) {
|
||||
for (uint8_t i = 0; i < 4; ++i) {
|
||||
|
Loading…
Reference in New Issue
Block a user