Seite 1 von 1

InitJoystick() - Zahl der Joysticks falsch?

Verfasst: 05.12.2020 20:17
von 4Planes
Hallo, kann es sein, dass InitJoystick() nicht für jedes Gerät zuverlässig funktioniert?
Mein generischer No-Name-Controller wird einwandfrei erkannt. Mein XBOX-360-Controller aber wird doppelt erkannt. Obwohl nur ein Gerät angeschlossen ist und auch nur ein Gerät in der Systemsteuerung auftaucht, gibt InitJoystick() den Wert 2 aus. JoystickName() nennt den als zwei Geräte erkannten Controller einmal »Controller (XBOX 360 for Windows)« und einmal »XBOX 360 controller 1«

Ich wollte eigentlich die Anzahl der Controller wissen, um die Controller den Spielern im Menü als Eingabemethode zur Wahl zu stellen. Aber jetzt hänge ich fest, weil ich das nicht zuverlässig ermitteln kann.

Für Hilfe jeder Art bin ich dankbar.

Re: InitJoystick() - Zahl der Joysticks falsch?

Verfasst: 07.12.2020 16:27
von 4Planes
Ich habe mir einen zweiten XBOX-360-Controller besorgt, um sicherzustellen, dass es nicht am Controller lag. Auch er wird doppelt erkannt. Schließe ich beide Controller an, habe ich laut InitJoystick() also vier Joysticks, die ich nutzen kann.

Ich kann auch tatsächlich mit Hilfe der Joystickbefehle (ExamineJoystick, JoystickAxisX, JoystickAxisY, usw.) auf zwei Joysticks zugreifen, selbst wenn nur ein XBOX-360-Controller angeschlossen ist.
Interessant ist, dass die "beiden" Controller nicht nur unterschiedliche Namen haben, sondern auch ein unterschiedliches Layout, was die Tasten angeht. Hier eine Übersicht. Was nach dem "=" steht, ist der Wert den Purebasic ausgibt, wenn man den Stick bewegt bzw. den Button drückt.
Ein Tastendruck auf dem Controller, wird in Purebasic als Tastendruck auf XBOX 360 For Windows (Gamepad 0) und auf XBox 360 controller 1 (Gamepad 1) registriert

Linker Stick:
Controller (XBOX 360 For Windows) (Gamepad 0): Pad 0, X-Axis = -1
XBox 360 controller 1 (Gamepad 1): Pad 0, X-Axis = -1
Controller (XBOX 360 For Windows) (Gamepad 0): Pad 0, X-Axis = 1
XBox 360 controller 1 (Gamepad 1): Pad 0, X-Axis = 1
Controller (XBOX 360 For Windows) (Gamepad 0): Pad 0, Y-Axis = -1
XBox 360 controller 1 (Gamepad 1): Pad 0, Y-Axis = -1
Controller (XBOX 360 For Windows) (Gamepad 0): Pad 0, Y-Axis = 1
XBox 360 controller 1 (Gamepad 1): Pad 0, Y-Axis = 1
D-Pad:
Controller (XBOX 360 For Windows) (Gamepad 0): Pad 2, X-Axis = -1
XBox 360 controller 1 (Gamepad 1): Button 7 = 1
Controller (XBOX 360 For Windows) (Gamepad 0): Pad 2, X-Axis = 1
XBox 360 controller 1 (Gamepad 1): Button 8 = 1
Controller (XBOX 360 For Windows) (Gamepad 0): Pad 2, Y-Axis = 1
XBox 360 controller 1 (Gamepad 1): Button 5 = 1
Controller (XBOX 360 For Windows) (Gamepad 0): Pad 2, Y-Axis = -1
XBox 360 controller 1 (Gamepad 1): Button 6 = 1
Rechter Stick:
Controller (XBOX 360 For Windows) (Gamepad 0): Pad 1, X-Axis = 1
XBox 360 controller 1 (Gamepad 1): Pad 1, X-Axis = 1
Controller (XBOX 360 For Windows) (Gamepad 0): Pad 1, X-Axis = -1
XBox 360 controller 1 (Gamepad 1): Pad 1, X-Axis = -1
Controller (XBOX 360 For Windows) (Gamepad 0): Pad 1, Y-Axis = -1
XBox 360 controller 1 (Gamepad 1): Pad 1, Y-Axis = -1
Controller (XBOX 360 For Windows) (Gamepad 0): Pad 1, Y-Axis = 1
XBox 360 controller 1 (Gamepad 1): Pad 1, Y-Axis = 1
Button X
Controller (XBOX 360 For Windows) (Gamepad 0): Button 3 = 1
XBox 360 controller 1 (Gamepad 1): Button 3 = 1
Button Y
Controller (XBOX 360 For Windows) (Gamepad 0): Button 4 = 1
XBox 360 controller 1 (Gamepad 1): Button 4 = 1
Button A
Controller (XBOX 360 For Windows) (Gamepad 0): Button 1 = 1
XBox 360 controller 1 (Gamepad 1): Button 1 = 1
Button B
Controller (XBOX 360 For Windows) (Gamepad 0): Button 2 = 1
XBox 360 controller 1 (Gamepad 1): Button 2 = 1
Button Start
Controller (XBOX 360 For Windows) (Gamepad 0): Button 8 = 1
XBox 360 controller 1 (Gamepad 1): Button 9 = 1
Button Back
Controller (XBOX 360 For Windows) (Gamepad 0): Button 7 = 1
XBox 360 controller 1 (Gamepad 1): Button 10 = 1
LB
Controller (XBOX 360 For Windows) (Gamepad 0): Button 5 = 1
XBox 360 controller 1 (Gamepad 1): Button 13 = 1
RB
Controller (XBOX 360 For Windows) (Gamepad 0): Button 6 = 1
XBox 360 controller 1 (Gamepad 1): Button 14 = 1
LT
Controller (XBOX 360 For Windows) (Gamepad 0): Pad 0, Z-Axis = 1
XBox 360 controller 1 (Gamepad 1): Pad 0, Z-Axis = 1
RT
Controller (XBOX 360 For Windows) (Gamepad 0): Pad 0, Z-Axis = -1
XBox 360 controller 1 (Gamepad 1): Pad 1, Z-Axis = 1
Linker Stick gedrückt
Controller (XBOX 360 For Windows) (Gamepad 0): Button 9 = 1
XBox 360 controller 1 (Gamepad 1): Button 11 = 1
Rechter tick gedrückt
Controller (XBOX 360 For Windows) (Gamepad 0): Button 10 = 1
XBox 360 controller 1 (Gamepad 1): Button 12 = 1
Das D-Pad wird einmal als Pad, einmal als vier Buttons erkannt. Auch die Schultertasten werden einmal als AxisZ und einmal als Buttons erkannt.

Schließlich habe ich dasselbe moch einmal mit einem XBOX-One-Controller versucht. Auch er wird doppelt erkannt. Er trägt einmal den klangvollen Namen "Bluetooth XINPUT-kompatibles Eingabegerät" und einmal heißt er "XBox 360 controller 1". Diesmal reagiert aber nur "XBox 360 controller 1" auf Befehle wie ExamineJoystick, JoystickAxisX, JoystickAxisY, usw.

Mein Lernertrag: Wenn es einen Controller mit dem Namen "XBox 360 controller 1", muss einer, der sonst noch vorhandenen Controller ignoriert werden. Wie ich zuverlässig herausfinde, welcher das ist, weiß ich noch nicht.

Re: InitJoystick() - Zahl der Joysticks falsch?

Verfasst: 08.12.2020 00:48
von STARGÅTE
Ich kann das bestätigen:

Code: Alles auswählen

Define N = InitJoystick()
Define I

Debug "Joysticks: "+N
For I = 0 To N-1
	Debug JoystickName(I)
Next
Joysticks: 2
Controller (XBOX 360 For Windows)
XBox 360 controller 1
Leider ist die Joystick Lib ziemlich unvollständig, weil Sachen wie PointOfView und weitere Achsen fehlen.

Re: InitJoystick() - Zahl der Joysticks falsch?

Verfasst: 08.12.2020 20:14
von ccode_new
Hallo!

Ich habe zur Zeit keine Möglichkeit es zu testen, aber es würde mich interessieren was dieses SDL2-Beispiel liefert?

https://workupload.com/file/7aQ7ArRYvcA

Re: InitJoystick() - Zahl der Joysticks falsch?

Verfasst: 08.12.2020 20:53
von #NULL
Ich hatte gestern mal gegoogled nach 'xbox controller showing twice' oder so. Das Problem hatten andere scheinbar auch schon, unabhängig von PB. Ich habe keine direkte Erklärung oder Lösung gesehen, aber es hing wohl mit neueren Windows 10 Treibern zusammen.

Re: InitJoystick() - Zahl der Joysticks falsch?

Verfasst: 09.12.2020 18:47
von 4Planes
Ich habe zur Zeit keine Möglichkeit es zu testen, aber es würde mich interessieren was dieses SDL2-Beispiel liefert?

https://workupload.com/file/7aQ7ArRYvcA
Ich bekomme dieses Ergebnis:
Name: Xbox 360 Controller
Number of Axes: 6
Number of Buttons: 11
Number of Balls: 0
SDL::NumJoysticks() gibt außerdem die richtige Zahl an angeschlossen Gamepads an. Wenn ich zwei XBOX-360-Controller und einen XBOX-One-Controller anschließe, wird korrekterweise drei ausgegeben.

Ich vermute, dass in diesem Code die Lösung für mein Problem steckt, aber der Code übersteigt mein Verständnis in einer Größenordnung, die ich gar nicht beschreiben kann.

Re: InitJoystick() - Zahl der Joysticks falsch?

Verfasst: 09.12.2020 20:44
von ccode_new
#NULL hat geschrieben:SDL::NumJoysticks() gibt außerdem die richtige Zahl an angeschlossen Gamepads an. Wenn ich zwei XBOX-360-Controller und einen XBOX-One-Controller anschließe, wird korrekterweise drei ausgegeben.
Das ist ja cool.
#NULL hat geschrieben:Ich vermute, dass in diesem Code die Lösung für mein Problem steckt, aber der Code übersteigt mein Verständnis in einer Größenordnung, die ich gar nicht beschreiben kann.
Die SDL(2) Bibliothek ist gar nicht so kompliziert und vereinfacht vieles.
Natürlich ist die Verwendung der reinen PureBasic-Funktionsbibliothek einfacher und man benötigt auch nicht die externen Abhängigkeiten, aber man muss dann auch mit gewissen Einschränkungen klarkommen.
Eine Verwendung von direkter OpenGL oder Direct2D - Api finde ich da wesentlich komplizierter.

Dank GPI kann man die SDL2-Bibliothek jetzt ziemlich gut mit PureBasic nutzen.
GPI arbeitet möglicherweise auch an einer tollen GUI-Bibliothek für SDL2.
Ansonsten ist die "SGX" von #NULL meine erste Wahl in diesem Bereich.