1
0
mirror of https://github.com/djhackersdev/bemanitools.git synced 2025-01-19 15:18:38 +01:00

vigem-iidxio: Fix cab light sequencer blink on TT spin

Similar to the TT analog to button code in main
This commit is contained in:
icex2 2020-12-31 15:57:39 +01:00
parent 2b52fbe211
commit 279d4de4b3

View File

@ -2,13 +2,15 @@
#include <stdbool.h>
#include <stdint.h>
#include <math.h>
#include "vigem-iidxio/cab-light-sequencer.h"
#include "util/log.h"
#include "util/math.h"
#include "util/time.h"
static const uint32_t _SEQ_CYCLE_TIME_MS = 2000;
static const uint32_t _SEQ_CYCLE_TIME_MS = 2000;
static enum vigem_iidxio_cab_light_sequencer_mode _light_seq_mode;
@ -16,6 +18,7 @@ static bool _first_update;
static uint64_t _time_counter;
static uint8_t _tt_prev[2];
static int32_t _tt_neon_on_state;
void _update_neons_seq_flash(bool* out_neon)
{
@ -41,11 +44,36 @@ void _update_neons_flash_tt_input(uint8_t tt_p1, uint8_t tt_p2, bool* out_neon)
return;
}
if (_tt_prev[0] != tt_p1 || _tt_prev[1] != tt_p2) {
int8_t delta[2];
delta[0] = tt_p1 - _tt_prev[0];
delta[1] = tt_p2 - _tt_prev[1];
// Debounce to avoid too much flickering
if (abs(_tt_neon_on_state) < 20) {
if (delta[0] != 0) {
_tt_neon_on_state += delta[0] * 2;
}
if (delta[1] != 0) {
_tt_neon_on_state += delta[1] * 2;
}
}
if (_tt_neon_on_state != 0) {
*out_neon = true;
} else {
*out_neon = false;
}
if (_tt_neon_on_state > 0) {
_tt_neon_on_state--;
} else if (_tt_neon_on_state < 0) {
_tt_neon_on_state++;
}
_tt_prev[0] = tt_p1;
_tt_prev[1] = tt_p2;
}
void vigem_iidxio_cab_light_sequencer_init(