1 #ifdef WXWIDGETS_JOYSTICK_SUPPORT
2 #include "core/command.hpp"
3 #include "core/framerate.hpp"
4 #include "core/keymapper.hpp"
5 #include "core/joystickapi.hpp"
6 #include "core/window.hpp"
7 #include "library/minmax.hpp"
8 #include "library/string.hpp"
10 #include <wx/joystick.h>
13 #define POLL_WAIT 20000
26 std::map
<unsigned, wxJoystick
*> objs
;
28 const char* buttonnames
[] = {"Button1", "Button2", "Button3", "Button4", "Button5", "Button6", "Button7",
29 "Button8", "Button9", "Button10", "Button11", "Button12", "Button13", "Button14", "Button15",
30 "Button16", "Button17", "Button18", "Button19", "Button20", "Button21", "Button22", "Button23",
31 "Button24", "Button25", "Button26", "Button27", "Button28", "Button29", "Button30", "Button31",
34 struct joystick_timer
: public wxTimer
36 joystick_timer() { start(); }
37 void start() { Start(POLL_WAIT
/ 1000); }
38 void stop() { Stop(); }
44 wxJoystick
& j
= *i
.second
;
45 lsnes_gamepads
[i
.first
].report_hat(0, j
.GetPOVCTSPosition());
46 uint32_t bmask
= j
.GetButtonState();
47 for(unsigned j
= 0; j
< 32; j
++)
48 lsnes_gamepads
[i
.first
].report_button(j
, (bmask
>> j
) & 1);
49 wxPoint xy
= j
.GetPosition();
50 lsnes_gamepads
[i
.first
].report_axis(0, xy
.x
);
51 lsnes_gamepads
[i
.first
].report_axis(1, xy
.y
);
52 lsnes_gamepads
[i
.first
].report_axis(2, j
.GetZPosition());
53 lsnes_gamepads
[i
.first
].report_axis(3, j
.GetRudderPosition());
54 lsnes_gamepads
[i
.first
].report_axis(4, j
.GetUPosition());
55 lsnes_gamepads
[i
.first
].report_axis(5, j
.GetVPosition());
60 struct _joystick_driver drv
= {
61 .init
= []() -> void {
62 unsigned max_joysticks
= wxJoystick::GetNumberJoysticks();
64 return; //No joystick support.
65 for(unsigned i
= 0; i
< max_joysticks
; i
++) {
66 wxJoystick
* joy
= new wxJoystick(i
);
72 unsigned jid
= lsnes_gamepads
.add(joy
->GetProductName());
73 hw_gamepad
& ngp
= lsnes_gamepads
[jid
];
77 ngp
.add_hat(0, "POV");
78 for(unsigned j
= 0; j
< joy
->GetNumberButtons() && j
< 32; j
++)
79 ngp
.add_button(j
, buttonnames
[j
]);
80 const char* R
= "Rudder";
81 ngp
.add_axis(0, joy
->GetXMin(), joy
->GetXMax(), false, "X");
82 ngp
.add_axis(1, joy
->GetYMin(), joy
->GetYMax(), false, "Y");
83 if(joy
->HasZ()) ngp
.add_axis(2, joy
->GetZMin(), joy
->GetZMax(), false, "Z");
84 if(joy
->HasRudder()) ngp
.add_axis(3, joy
->GetRudderMin(), joy
->GetRudderMax(),
86 if(joy
->HasU()) ngp
.add_axis(4, joy
->GetUMin(), joy
->GetUMax(), false, "U");
87 if(joy
->HasV()) ngp
.add_axis(5, joy
->GetVMin(), joy
->GetVMax(), false, "V");
88 messages
<< "Joystick #" << jid
<< " online: " << joy
->GetProductName() << std::endl
;
91 jtimer
= new joystick_timer();
93 .quit
= []() -> void {
103 //We don't poll in this thread, so just quit instantly.
104 .thread_fn
= []() -> void {},
105 .signal
= []() -> void {},
106 .name
= []() -> const char* { return "Wxwidgets joystick plugin"; }
108 struct joystick_driver
_drv(drv
);