2 Copyright © 2018-2019, The AROS Development Team. All rights reserved.
5 Desc: Gamepad (XInput) USB class driver
10 #include "arosx.class.h"
12 #include "arosx.class.config.gui.h"
14 #include "include/arosx.h"
15 #include <proto/arosx.h>
20 #define MUIMasterBase MUIBase
22 /* /// "nGUITask()" */
23 AROS_UFH0(void, nGUITask
)
27 struct Task
*thistask
;
28 struct AROSXClassBase
*arosxb
;
29 struct AROSXClassController
*arosxc
;
31 struct Library
*MUIBase
;
32 struct Library
*PsdBase
;
33 struct Library
*AROSXBase
;
35 struct AROSXClassConfigGUI
*gui
;
37 thistask
= FindTask(NULL
);
38 arosxc
= thistask
->tc_UserData
;
39 arosxb
= arosxc
->arosxb
;
41 struct AROSX_GAMEPAD
*arosx_gamepad
;
42 arosx_gamepad
= &arosxc
->arosx_gamepad
;
45 TODO: Make use of OpenLibrary/CloseLibrary to keep track of lib open count...
47 ++arosxb
->Library
.lib_OpenCnt
;
49 struct AROSX_EventHook
*arosx_eventhook
;
50 struct MsgPort
*arosx_eventport
;
52 if(gui
= AllocVec(sizeof(struct AROSXClassConfigGUI
), MEMF_CLEAR
|MEMF_ANY
)) {
54 if(AROSXBase
= OpenLibrary("arosx.library", 0)) {
55 mybug(-1,("[AROSXClass GUI] arosx.library openened\n"));
57 arosx_eventport
= CreateMsgPort();
58 arosx_eventhook
= AROSX_AddEventHandler(arosx_eventport
, (((1<<arosxc
->id
))<<28));
60 Set to listen every controller
62 //arosx_eventhook = AROSX_AddEventHandler(arosx_eventport, (0xf<<28));
64 if((MUIMasterBase
= OpenLibrary(MUIMASTER_NAME
, MUIMASTER_VMIN
)))
66 if((ps
= OpenLibrary("poseidon.library", 4)))
69 gui
->App
= ApplicationObject
,
70 MUIA_Application_Title
, (IPTR
)libname
,
71 MUIA_Application_Version
, (IPTR
)VERSION_STRING
,
72 MUIA_Application_Copyright
, (IPTR
)"©2018-2019 The AROS Development Team",
73 MUIA_Application_Author
, (IPTR
)"The AROS Development Team",
74 MUIA_Application_Description
, (IPTR
)"Settings for the arosx.class",
75 MUIA_Application_Base
, (IPTR
)"AROSX",
76 MUIA_Application_HelpFile
, (IPTR
)"HELP:Poseidon.guide",
77 MUIA_Application_Menustrip
, (IPTR
)MenustripObject
,
78 Child
, (IPTR
)MenuObjectT((IPTR
)"Project"),
79 Child
, (IPTR
)(gui
->AboutMI
= MenuitemObject
,
80 MUIA_Menuitem_Title
, (IPTR
)"About...",
81 MUIA_Menuitem_Shortcut
, (IPTR
)"?",
84 Child
, (IPTR
)MenuObjectT((IPTR
)"Settings"),
85 Child
, (IPTR
)(gui
->UseMI
= MenuitemObject
,
86 MUIA_Menuitem_Title
, (IPTR
)"Save",
87 MUIA_Menuitem_Shortcut
, (IPTR
)"S",
89 Child
, (IPTR
)MenuitemObject
,
90 MUIA_Menuitem_Title
, (IPTR
)NM_BARLABEL
,
92 Child
, (IPTR
)(gui
->MUIPrefsMI
= MenuitemObject
,
93 MUIA_Menuitem_Title
, (IPTR
)"MUI Settings",
94 MUIA_Menuitem_Shortcut
, (IPTR
)"M",
99 SubWindow
, (IPTR
)(gui
->MainWindow
= WindowObject
,
100 MUIA_Window_ID
, MAKE_ID('M','A','I','N'),
101 MUIA_Window_Title
, (IPTR
)arosxc
->name
,
102 MUIA_HelpNode
, (IPTR
)libname
,
104 WindowContents
, (IPTR
)VGroup
,
105 Child
, (IPTR
)(gui
->GamepadGroupObject
= ColGroup(2),
106 GroupFrameT("Gamepad"),
110 Child
, (IPTR
)(gui
->GamepadObject_button_a
= ImageObject
,
111 MUIA_Image_FontMatch
, TRUE
,
112 MUIA_Selected
, FALSE
,
113 MUIA_ShowSelState
, FALSE
,
114 MUIA_Image_Spec
, MUII_RadioButton
,
115 MUIA_Frame
, MUIV_Frame_None
,
118 Child
, (IPTR
)(gui
->GamepadObject_button_b
= ImageObject
,
119 MUIA_Image_FontMatch
, TRUE
,
120 MUIA_Selected
, FALSE
,
121 MUIA_ShowSelState
, FALSE
,
122 MUIA_Image_Spec
, MUII_RadioButton
,
123 MUIA_Frame
, MUIV_Frame_None
,
126 Child
, (IPTR
)(gui
->GamepadObject_button_x
= ImageObject
,
127 MUIA_Image_FontMatch
, TRUE
,
128 MUIA_Selected
, FALSE
,
129 MUIA_ShowSelState
, FALSE
,
130 MUIA_Image_Spec
, MUII_RadioButton
,
131 MUIA_Frame
, MUIV_Frame_None
,
134 Child
, (IPTR
)(gui
->GamepadObject_button_y
= ImageObject
,
135 MUIA_Image_FontMatch
, TRUE
,
136 MUIA_Selected
, FALSE
,
137 MUIA_ShowSelState
, FALSE
,
138 MUIA_Image_Spec
, MUII_RadioButton
,
139 MUIA_Frame
, MUIV_Frame_None
,
142 Child
, (IPTR
)(gui
->GamepadObject_button_ls
= ImageObject
,
143 MUIA_Image_FontMatch
, TRUE
,
144 MUIA_Selected
, FALSE
,
145 MUIA_ShowSelState
, FALSE
,
146 MUIA_Image_Spec
, MUII_RadioButton
,
147 MUIA_Frame
, MUIV_Frame_None
,
150 Child
, (IPTR
)(gui
->GamepadObject_button_rs
= ImageObject
,
151 MUIA_Image_FontMatch
, TRUE
,
152 MUIA_Selected
, FALSE
,
153 MUIA_ShowSelState
, FALSE
,
154 MUIA_Image_Spec
, MUII_RadioButton
,
155 MUIA_Frame
, MUIV_Frame_None
,
158 Child
, (IPTR
)(gui
->GamepadObject_left_thumb
= ImageObject
,
159 MUIA_Image_FontMatch
, TRUE
,
160 MUIA_Selected
, FALSE
,
161 MUIA_ShowSelState
, FALSE
,
162 MUIA_Image_Spec
, MUII_RadioButton
,
163 MUIA_Frame
, MUIV_Frame_None
,
166 Child
, (IPTR
)(gui
->GamepadObject_right_thumb
= ImageObject
,
167 MUIA_Image_FontMatch
, TRUE
,
168 MUIA_Selected
, FALSE
,
169 MUIA_ShowSelState
, FALSE
,
170 MUIA_Image_Spec
, MUII_RadioButton
,
171 MUIA_Frame
, MUIV_Frame_None
,
174 Child
, (IPTR
)(gui
->GamepadObject_dpad_left
= ImageObject
,
175 MUIA_Image_FontMatch
, TRUE
,
176 MUIA_Selected
, FALSE
,
177 MUIA_ShowSelState
, FALSE
,
178 MUIA_Image_Spec
, MUII_RadioButton
,
179 MUIA_Frame
, MUIV_Frame_None
,
182 Child
, (IPTR
)(gui
->GamepadObject_dpad_right
= ImageObject
,
183 MUIA_Image_FontMatch
, TRUE
,
184 MUIA_Selected
, FALSE
,
185 MUIA_ShowSelState
, FALSE
,
186 MUIA_Image_Spec
, MUII_RadioButton
,
187 MUIA_Frame
, MUIV_Frame_None
,
190 Child
, (IPTR
)(gui
->GamepadObject_dpad_up
= ImageObject
,
191 MUIA_Image_FontMatch
, TRUE
,
192 MUIA_Selected
, FALSE
,
193 MUIA_ShowSelState
, FALSE
,
194 MUIA_Image_Spec
, MUII_RadioButton
,
195 MUIA_Frame
, MUIV_Frame_None
,
198 Child
, (IPTR
)(gui
->GamepadObject_dpad_down
= ImageObject
,
199 MUIA_Image_FontMatch
, TRUE
,
200 MUIA_Selected
, FALSE
,
201 MUIA_ShowSelState
, FALSE
,
202 MUIA_Image_Spec
, MUII_RadioButton
,
203 MUIA_Frame
, MUIV_Frame_None
,
206 Child
, (IPTR
)(gui
->GamepadObject_button_back
= ImageObject
,
207 MUIA_Image_FontMatch
, TRUE
,
208 MUIA_Selected
, FALSE
,
209 MUIA_ShowSelState
, FALSE
,
210 MUIA_Image_Spec
, MUII_RadioButton
,
211 MUIA_Frame
, MUIV_Frame_None
,
214 Child
, (IPTR
)(gui
->GamepadObject_button_start
= ImageObject
,
215 MUIA_Image_FontMatch
, TRUE
,
216 MUIA_Selected
, FALSE
,
217 MUIA_ShowSelState
, FALSE
,
218 MUIA_Image_Spec
, MUII_RadioButton
,
219 MUIA_Frame
, MUIV_Frame_None
,
223 Child
, (IPTR
)(gui
->GamepadObject_left_trigger
= GaugeObject
,
225 MUIA_Gauge_Max
, 0xff,
226 MUIA_Gauge_InfoText
, (IPTR
)"%lx",
227 MUIA_Gauge_Horiz
, TRUE
,
228 MUIA_Gauge_Current
, 0,
231 Child
, (IPTR
)(gui
->GamepadObject_right_trigger
= GaugeObject
,
233 MUIA_Gauge_Max
, 0xff,
234 MUIA_Gauge_InfoText
, (IPTR
)"%lx",
235 MUIA_Gauge_Horiz
, TRUE
,
236 MUIA_Gauge_Current
, 0,
239 Child
, (IPTR
)(gui
->GamepadObject_left_stick_x
= GaugeObject
,
241 MUIA_Gauge_Max
, 0xffff,
242 MUIA_Gauge_InfoText
, (IPTR
)"%lx",
243 MUIA_Gauge_Horiz
, TRUE
,
244 MUIA_Gauge_Current
, 0,
247 Child
, (IPTR
)(gui
->GamepadObject_left_stick_y
= GaugeObject
,
249 MUIA_Gauge_Max
, 0xffff,
250 MUIA_Gauge_InfoText
, (IPTR
)"%lx",
251 MUIA_Gauge_Horiz
, TRUE
,
252 MUIA_Gauge_Current
, 0,
255 Child
, (IPTR
)(gui
->GamepadObject_right_stick_x
= GaugeObject
,
257 MUIA_Gauge_Max
, 0xffff,
258 MUIA_Gauge_InfoText
, (IPTR
)"%lx",
259 MUIA_Gauge_Horiz
, TRUE
,
260 MUIA_Gauge_Current
, 0,
263 Child
, (IPTR
)(gui
->GamepadObject_right_stick_y
= GaugeObject
,
265 MUIA_Gauge_Max
, 0xffff,
266 MUIA_Gauge_InfoText
, (IPTR
)"%lx",
267 MUIA_Gauge_Horiz
, TRUE
,
268 MUIA_Gauge_Current
, 0,
273 Child
, (IPTR
)VSpace(0),
275 MUIA_Group_SameWidth
, TRUE
,
276 Child
, (IPTR
)(gui
->UseObj
= TextObject
, ButtonFrame
,
277 MUIA_Background
, MUII_ButtonBack
,
279 MUIA_InputMode
, MUIV_InputMode_RelVerify
,
280 MUIA_Text_Contents
, (IPTR
)"\33c Save ",
282 Child
, (IPTR
)(gui
->CloseObj
= TextObject
, ButtonFrame
,
283 MUIA_Background
, MUII_ButtonBack
,
285 MUIA_InputMode
, MUIV_InputMode_RelVerify
,
286 MUIA_Text_Contents
, (IPTR
)"\33c Use ",
295 DoMethod(gui
->MainWindow
, MUIM_Notify
, MUIA_Window_CloseRequest
, TRUE
,
296 gui
->App
, 2, MUIM_Application_ReturnID
, MUIV_Application_ReturnID_Quit
);
297 DoMethod(gui
->UseObj
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
298 gui
->App
, 2, MUIM_Application_ReturnID
, ID_STORE_CONFIG
);
299 DoMethod(gui
->CloseObj
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
300 gui
->App
, 2, MUIM_Application_ReturnID
, MUIV_Application_ReturnID_Quit
);
302 DoMethod(gui
->AboutMI
, MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
,
303 gui
->App
, 2, MUIM_Application_ReturnID
, ID_ABOUT
);
304 DoMethod(gui
->UseMI
, MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
,
305 gui
->App
, 2, MUIM_Application_ReturnID
, ID_STORE_CONFIG
);
306 DoMethod(gui
->MUIPrefsMI
, MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
,
307 gui
->App
, 2, MUIM_Application_OpenConfigWindow
, 0);
315 get(gui
->App
, MUIA_Application_Iconified
, &iconify
);
316 set(gui
->MainWindow
, MUIA_Window_Open
, TRUE
);
317 get(gui
->MainWindow
, MUIA_Window_Open
, &isopen
);
319 if((isopen
|| (!iconify
)))
321 sigmask
= (1UL<<arosx_eventport
->mp_SigBit
);
324 retid
= DoMethod(gui
->App
, MUIM_Application_NewInput
, &sigs
);
328 MUI_RequestA(gui
->App
, gui
->MainWindow
, 0, NULL
, "Fabulous!", VERSION_STRING
, NULL
);
331 if(retid
== MUIV_Application_ReturnID_Quit
)
337 sigs
= Wait(sigs
| sigmask
| SIGBREAKF_CTRL_C
);
338 if(sigs
& SIGBREAKF_CTRL_C
)
343 if(sigs
& (1UL<<arosx_eventport
->mp_SigBit
)) {
344 mybug(-1,("(%d) I may have received an event...\n", arosxc
->id
));
345 struct AROSX_EventNote
*en
;
346 while((en
= (struct AROSX_EventNote
*)GetMsg(arosx_eventport
))) {
348 mybug(-1,(" event %08lx\n", en
->en_Event
));
350 /* TODO: GUI is disabled until we get the first message even on wired controllers... */
351 if((arosxc
->status
.wireless
)&&(arosxc
->status
.signallost
)) {
352 set(gui
->GamepadGroupObject
, MUIA_Disabled
, TRUE
);
354 set(gui
->GamepadGroupObject
, MUIA_Disabled
, FALSE
);
356 set(gui
->GamepadObject_button_a
, MUIA_Selected
, (arosx_gamepad
->Buttons
& AROSX_GAMEPAD_A
));
357 set(gui
->GamepadObject_button_b
, MUIA_Selected
, (arosx_gamepad
->Buttons
& AROSX_GAMEPAD_B
));
358 set(gui
->GamepadObject_button_x
, MUIA_Selected
, (arosx_gamepad
->Buttons
& AROSX_GAMEPAD_X
));
359 set(gui
->GamepadObject_button_y
, MUIA_Selected
, (arosx_gamepad
->Buttons
& AROSX_GAMEPAD_Y
));
360 set(gui
->GamepadObject_button_ls
, MUIA_Selected
, (arosx_gamepad
->Buttons
& AROSX_GAMEPAD_LEFT_SHOULDER
));
361 set(gui
->GamepadObject_button_rs
, MUIA_Selected
, (arosx_gamepad
->Buttons
& AROSX_GAMEPAD_RIGHT_SHOULDER
));
362 set(gui
->GamepadObject_left_thumb
, MUIA_Selected
, (arosx_gamepad
->Buttons
& AROSX_GAMEPAD_LEFT_THUMB
));
363 set(gui
->GamepadObject_right_thumb
, MUIA_Selected
, (arosx_gamepad
->Buttons
& AROSX_GAMEPAD_RIGHT_THUMB
));
364 set(gui
->GamepadObject_dpad_left
, MUIA_Selected
, (arosx_gamepad
->Buttons
& AROSX_GAMEPAD_DPAD_LEFT
));
365 set(gui
->GamepadObject_dpad_right
, MUIA_Selected
, (arosx_gamepad
->Buttons
& AROSX_GAMEPAD_DPAD_RIGHT
));
366 set(gui
->GamepadObject_dpad_up
, MUIA_Selected
, (arosx_gamepad
->Buttons
& AROSX_GAMEPAD_DPAD_UP
));
367 set(gui
->GamepadObject_dpad_down
, MUIA_Selected
, (arosx_gamepad
->Buttons
& AROSX_GAMEPAD_DPAD_DOWN
));
368 set(gui
->GamepadObject_button_back
, MUIA_Selected
, (arosx_gamepad
->Buttons
& AROSX_GAMEPAD_BACK
));
369 set(gui
->GamepadObject_button_start
, MUIA_Selected
, (arosx_gamepad
->Buttons
& AROSX_GAMEPAD_START
));
371 set(gui
->GamepadObject_left_trigger
, MUIA_Gauge_Current
, (arosx_gamepad
->LeftTrigger
));
372 set(gui
->GamepadObject_right_trigger
, MUIA_Gauge_Current
, (arosx_gamepad
->RightTrigger
));
374 if(arosx_gamepad
->ThumbLX
>=0x8000) {
375 set(gui
->GamepadObject_left_stick_x
, MUIA_Gauge_Current
, (arosx_gamepad
->ThumbLX
-0x8000));
377 set(gui
->GamepadObject_left_stick_x
, MUIA_Gauge_Current
, (0x8000+arosx_gamepad
->ThumbLX
));
380 if(arosx_gamepad
->ThumbLY
>=0x8000) {
381 set(gui
->GamepadObject_left_stick_y
, MUIA_Gauge_Current
, (arosx_gamepad
->ThumbLY
-0x8000));
383 set(gui
->GamepadObject_left_stick_y
, MUIA_Gauge_Current
, (0x8000+arosx_gamepad
->ThumbLY
));
386 if(arosx_gamepad
->ThumbRX
>=0x8000) {
387 set(gui
->GamepadObject_right_stick_x
, MUIA_Gauge_Current
, (arosx_gamepad
->ThumbRX
-0x8000));
389 set(gui
->GamepadObject_right_stick_x
, MUIA_Gauge_Current
, (0x8000+arosx_gamepad
->ThumbRX
));
392 if(arosx_gamepad
->ThumbRY
>=0x8000) {
393 set(gui
->GamepadObject_right_stick_y
, MUIA_Gauge_Current
, (arosx_gamepad
->ThumbRY
-0x8000));
395 set(gui
->GamepadObject_right_stick_y
, MUIA_Gauge_Current
, (0x8000+arosx_gamepad
->ThumbRY
));
399 ReplyMsg((struct Message
*)en
);
404 set(gui
->MainWindow
, MUIA_Window_Open
, FALSE
);
409 MUI_DisposeObject(gui
->App
);
415 CloseLibrary(MUIMasterBase
);
416 MUIMasterBase
= NULL
;
429 AROSX_RemEventHandler(arosx_eventhook
);
430 CloseLibrary(AROSXBase
);
436 arosxc
->GUITask
= NULL
;
437 --arosxb
->Library
.lib_OpenCnt
;