Skip to content

Commit ae75cab

Browse files
authored
fix(hid-rp): Fix switch pro resetting counter (#385)
* Fix issue with switch pro hid report `reset()` resetting the counter value, which prevented `increment_counter()` from working * Update switch pro to clear all the report bytes to 0 ensuring subcommand / reply data is zeroed out * remove additional sets in the reset command so app can do it as necessary Fixes an issue specifically with switch compatibility (ios/android didnt seem to care) if you wanted to simplify application code by calling `increment_counter`. * Building and running https://github.com:/finger563/esp-usb-ble-hid with this code and doing longer play session with the switch
1 parent 6c906a7 commit ae75cab

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

components/hid-rp/include/hid-rp-switch-pro.hpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,14 @@ class SwitchProGamepadInputReport : public hid::report::base<hid::report::type::
188188

189189
/// Reset the gamepad inputs
190190
constexpr void reset() {
191-
std::fill(raw_input_report, raw_input_report + sizeof(raw_input_report), 0);
191+
uint8_t prev_counter = counter;
192+
// fill all 0s
193+
std::fill(raw_report, raw_report + sizeof(raw_report), 0);
194+
// now set the counter to the previous value
195+
counter = prev_counter;
196+
// set the joysticks to 0 since their config may not put them at 0
192197
set_left_joystick(0, 0);
193198
set_right_joystick(0, 0);
194-
set_battery_level(75);
195-
set_battery_charging(false);
196-
set_usb_powered(false);
197199
}
198200

199201
/// Set the counter
@@ -202,7 +204,7 @@ class SwitchProGamepadInputReport : public hid::report::base<hid::report::type::
202204

203205
/// Increment the counter
204206
constexpr void increment_counter() {
205-
counter = (counter + 1) & 0x0F;
207+
counter = (counter + 1);
206208
}
207209

208210
/// Get the counter value

0 commit comments

Comments
 (0)