mirror of
https://github.com/ravinrabbid/DonCon2040.git
synced 2024-11-20 11:47:07 +01:00
Allow left+right double hits
The largest reading for each side is taken into account.
This commit is contained in:
parent
0f9d433253
commit
1644e1e611
@ -45,7 +45,7 @@ const Peripherals::Drum::Config drum_config = {
|
|||||||
50, // Ka Right
|
50, // Ka Right
|
||||||
},
|
},
|
||||||
|
|
||||||
10, // ADC sample count
|
16, // ADC sample count
|
||||||
25, // Debounce delay in milliseconds
|
25, // Debounce delay in milliseconds
|
||||||
500, // Roll Counter Timeout in Milliseconds
|
500, // Roll Counter Timeout in Milliseconds
|
||||||
|
|
||||||
|
@ -158,21 +158,27 @@ void Drum::updateInputState(Utils::InputState &input_state) {
|
|||||||
return (uint16_t)0;
|
return (uint16_t)0;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Consider the hardest hit pad the one that actually was hit,
|
const auto set_max = [&](Id a, Id b) {
|
||||||
const auto max_hit = std::max_element(raw_values.cbegin(), raw_values.cend(),
|
const auto set_with_threshold = [&](Id target) {
|
||||||
[](const auto a, const auto b) { return a.second < b.second; });
|
if (raw_values.at(target) > get_threshold(target)) {
|
||||||
|
m_pads.at(target).setState(true, m_config.debounce_delay_ms);
|
||||||
if (max_hit->second > get_threshold(max_hit->first)) {
|
|
||||||
m_pads.at(max_hit->first).setState(true, m_config.debounce_delay_ms);
|
|
||||||
} else {
|
} else {
|
||||||
m_pads.at(max_hit->first).setState(false, m_config.debounce_delay_ms);
|
m_pads.at(target).setState(false, m_config.debounce_delay_ms);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
for (const auto &input : raw_values) {
|
if (raw_values.at(a) > raw_values.at(b)) {
|
||||||
if (input.first != max_hit->first) {
|
set_with_threshold(a);
|
||||||
m_pads.at(input.first).setState(false, m_config.debounce_delay_ms);
|
m_pads.at(b).setState(false, m_config.debounce_delay_ms);
|
||||||
}
|
} else {
|
||||||
|
set_with_threshold(b);
|
||||||
|
m_pads.at(a).setState(false, m_config.debounce_delay_ms);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Consider the hardest hit for each side
|
||||||
|
set_max(Id::DON_LEFT, Id::KA_LEFT);
|
||||||
|
set_max(Id::DON_RIGHT, Id::KA_RIGHT);
|
||||||
|
|
||||||
input_state.drum.don_left.raw = raw_values.at(Id::DON_LEFT);
|
input_state.drum.don_left.raw = raw_values.at(Id::DON_LEFT);
|
||||||
input_state.drum.ka_left.raw = raw_values.at(Id::KA_LEFT);
|
input_state.drum.ka_left.raw = raw_values.at(Id::KA_LEFT);
|
||||||
|
Loading…
Reference in New Issue
Block a user