Skip to content

Commit

Permalink
Handle vpad input when processing mode is tight.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel K. O. (dkosmari) committed Aug 29, 2024
1 parent 4ca687b commit ef96036
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions src/pad_mon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,35 +88,39 @@ namespace pad_mon {
return result;
#endif

// We only care from HOME to R stick (skip sync and emulated) buttons.
const std::uint32_t buttons_begin = 0x000002;
const std::uint32_t buttons_end = 0x080000;

unsigned counter = 0;
if (cfg::button_rate) {
// TODO: handle Twilight Princess input
if (buf[0].trigger) {
for (auto button = buttons_begin; button < buttons_end; button <<= 1)
if (buf[0].trigger & button)
++counter;
}
// only touch the atomic counter if there's someting to count
if (counter)
button_presses += counter;
}

// Note: when proc mode is loose, all samples ar identical, so we just check one
const std::int32_t num_samples = VPADGetButtonProcMode(channel) ? result : 1;

// Check if shortcut was pressed
if (holds_alternative<wups::config::vpad_combo>(cfg::toggle_shortcut)) {
auto& shortcut = get<wups::config::vpad_combo>(cfg::toggle_shortcut);
// TODO: handle Twilight Princess input
if (buf[0].trigger & shortcut.buttons) {
if ((buf[0].hold & shortcut.buttons) == shortcut.buttons) {
// user activated the shortcut
overlay::toggle();
for (std::int32_t idx = 0; idx < num_samples; ++idx) {
if (buf[idx].trigger & shortcut.buttons) {
if ((buf[idx].hold & shortcut.buttons) == shortcut.buttons) {
overlay::toggle(); // user activated the shortcut
break;
}
}
}
}

if (cfg::button_rate) {
// We only care from HOME to R stick (skip sync and emulated) buttons.
const std::uint32_t buttons_begin = 0x000002;
const std::uint32_t buttons_end = 0x080000;

unsigned counter = 0;
for (std::int32_t idx = 0; idx < num_samples; ++idx)
if (buf[idx].trigger)
for (auto button = buttons_begin; button < buttons_end; button <<= 1)
if (buf[idx].trigger & button)
++counter;

// only touch the atomic counter if there's someting to count
if (counter)
button_presses += counter;
}

return result;
}

Expand Down

0 comments on commit ef96036

Please sign in to comment.