Gamepad API button numbers are inconsistent with the documentation
Clinery1 opened this issue · 5 comments
Problem
In the wiki, the Gamepad
press
and release
functions say buttons 0..31
, but the actual API accepts 1..32
.
Solution 1
Change the documentation to say [1 .. 32]
instead of [0 .. 31]
.
Solution 2
Change the Gamepad
API to support the buttons starting from 0 instead of 1.
How to recreate
This snippet of code will (according to gamepad-tester.com) report button0
when either button0
or button1
are pressed.
Tested on an Arduino Leonardo and Linux 5.17.
#include "HID-Project.h"
void setup() {
Serial.begin(115200);
pinMode(2,INPUT);
pinMode(3,INPUT);
Gamepad.begin();
}
void loop() {
Gamepad.releaseAll();
if (digitalRead(2)==HIGH) {
Serial.println("Button 0 is pressed");
Gamepad.press(0);
}
if (digitalRead(3)==HIGH) {
Serial.println("Button 1 is pressed");
Gamepad.press(1);
}
Gamepad.write();
delay(20);
}
If the press(0)
is changed to a press(1)
and the press(1)
to a press(2)
, then gamepad-tester will report button 0 and 1 being pressed.
What solution would you prefer?
I think that just the documentation update is the better option.
This page, 2 occurences, right?
https://github.com/NicoHood/HID/wiki/Gamepad-API
That is correct.
Done. Close if it is okay for you. Thanks for reporting