10 extern const STRPTR
GM_UNIQUENAME(libname
);
12 /* /// "nHIDCtrlGUITask()" */
13 AROS_UFH0(void, GM_UNIQUENAME(nHIDCtrlGUITask
))
17 struct Task
*thistask
;
18 struct NepHidBase
*nh
;
19 struct NepClassHid
*nch
;
21 thistask
= FindTask(NULL
);
24 #define ps nch->nch_HCPsdBase
26 #define IntuitionBase nch->nch_HCIntBase
28 #define MUIMasterBase nch->nch_HCMUIBase
30 nch
= thistask
->tc_UserData
;
31 nch
->nch_HCGUITask
= thistask
;
32 nh
= nch
->nch_ClsBase
;
34 ++nh
->nh_Library
.lib_OpenCnt
;
35 NewList(&nch
->nch_HCGUIItems
);
36 if(!(MUIMasterBase
= OpenLibrary(MUIMASTER_NAME
, MUIMASTER_VMIN
)))
38 KPRINTF(10, ("Couldn't open muimaster.library.\n"));
39 GM_UNIQUENAME(nHIDCtrlGUITaskCleanup
)(nch
);
43 if(!(IntuitionBase
= OpenLibrary("intuition.library", 39)))
45 KPRINTF(10, ("Couldn't open intuition.library.\n"));
46 GM_UNIQUENAME(nHIDCtrlGUITaskCleanup
)(nch
);
50 if(!(ps
= OpenLibrary("poseidon.library", 4)))
52 KPRINTF(10, ("Couldn't open poseidon.library.\n"));
53 GM_UNIQUENAME(nHIDCtrlGUITaskCleanup
)(nch
);
57 nch
->nch_HCActionClass
= MUI_CreateCustomClass(NULL
, MUIC_Area
, NULL
, sizeof(struct ActionData
), GM_UNIQUENAME(HCActionDispatcher
));
59 if(!nch
->nch_HCActionClass
)
61 KPRINTF(10, ("Couldn't create ActionClass.\n"));
62 GM_UNIQUENAME(nHIDCtrlGUITaskCleanup
)(nch
);
65 nch
->nch_HCApp
= ApplicationObject
,
66 MUIA_Application_Title
, (IPTR
)nch
->nch_CDC
->cdc_HIDCtrlTitle
,
67 MUIA_Application_Version
, (IPTR
)VERSION_STRING
,
68 MUIA_Application_Copyright
, (IPTR
)"©2002-2009 Chris Hodges",
69 MUIA_Application_Author
, (IPTR
)"Chris Hodges <chrisly@platon42.de>",
70 MUIA_Application_Description
, (IPTR
)"HID Device Output Control",
71 MUIA_Application_Base
, (IPTR
)nch
->nch_CDC
->cdc_HIDCtrlRexx
,
72 MUIA_Application_HelpFile
, (IPTR
)"HELP:Poseidon.guide",
73 MUIA_Application_Menustrip
, (IPTR
)MenustripObject
,
74 Child
, (IPTR
)MenuObjectT((IPTR
)"Project"),
75 Child
, (IPTR
)(nch
->nch_HCAboutMI
= MenuitemObject
,
76 MUIA_Menuitem_Title
, (IPTR
)"About...",
77 MUIA_Menuitem_Shortcut
, (IPTR
)"?",
79 Child
, (IPTR
)MenuitemObject
,
80 MUIA_Menuitem_Title
, (IPTR
)NM_BARLABEL
,
82 Child
, (IPTR
)(nch
->nch_HCCloseMI
= MenuitemObject
,
83 MUIA_Menuitem_Title
, (IPTR
)"Hide",
84 MUIA_Menuitem_Shortcut
, (IPTR
)"H",
87 Child
, (IPTR
)MenuObjectT((IPTR
)"Settings"),
88 Child
, (IPTR
)(nch
->nch_HCMUIPrefsMI
= MenuitemObject
,
89 MUIA_Menuitem_Title
, (IPTR
)"MUI Settings",
90 MUIA_Menuitem_Shortcut
, (IPTR
)"M",
95 SubWindow
, (IPTR
)(nch
->nch_HCMainWindow
= WindowObject
,
96 MUIA_Window_ID
, MAKE_ID('H','C','T','L'),
97 MUIA_Window_Title
, (IPTR
)nch
->nch_CDC
->cdc_HIDCtrlTitle
,
98 MUIA_HelpNode
, (IPTR
)GM_UNIQUENAME(libname
),
100 WindowContents
, (IPTR
)VGroup
,
101 Child
, (IPTR
)(nch
->nch_HCActionObj
= NewObject(nch
->nch_HCActionClass
->mcc_Class
, 0, MUIA_ShowMe
, FALSE
, TAG_END
)),
102 Child
, (IPTR
)(nch
->nch_HCGroupObj
= ColGroup(4),
104 Child
, (IPTR
)(nch
->nch_HCCloseObj
= TextObject
, ButtonFrame
,
105 MUIA_Background
, MUII_ButtonBack
,
107 MUIA_InputMode
, MUIV_InputMode_RelVerify
,
108 MUIA_Text_Contents
, (IPTR
)"\33c Hide ",
116 KPRINTF(10, ("Couldn't create application\n"));
117 GM_UNIQUENAME(nHIDCtrlGUITaskCleanup
)(nch
);
122 struct ActionData
*ad
= INST_DATA(nch
->nch_HCActionClass
->mcc_Class
, nch
->nch_HCActionObj
);
127 struct NepHidReport
*nhr
;
128 struct NepHidItem
**nhiptr
;
129 struct NepHidItem
*nhi
;
130 struct NepHidGItem
*nhgi
;
135 nhr
= (struct NepHidReport
*) nch
->nch_HidReports
.lh_Head
;
136 while(nhr
->nhr_Node
.ln_Succ
)
138 if((count
= nhr
->nhr_OutItemCount
))
140 nhiptr
= nhr
->nhr_OutItemMap
;
148 if(nhi
->nhi_Flags
& RPF_MAIN_VARIABLE
)
150 if(nhi
->nhi_Flags
& RPF_MAIN_RELATIVE
)
152 if((nhi
->nhi_LogicalMin
== 0) && (nhi
->nhi_LogicalMax
== 1))
154 if((nhgi
= nAllocGHCItem(nch
, nhi
, NULL
, nhi
->nhi_Usage
)))
158 Child
, (IPTR
)VSpace(0),
159 Child
, (IPTR
)(nhgi
->nhgi_GUIObj
= TextObject
, ButtonFrame
,
160 MUIA_Background
, MUII_ButtonBack
,
162 MUIA_InputMode
, MUIV_InputMode_RelVerify
,
163 MUIA_Text_PreParse
, (IPTR
)"\33c",
164 MUIA_Text_Contents
, (IPTR
)nhgi
->nhgi_Name
,
166 Child
, (IPTR
)VSpace(0),
168 nhgi
->nhgi_ObjType
= NHGIOT_SHOTBUTTON
;
171 else if(nhi
->nhi_LogicalMin
< 0)
173 if((nhgi
= nAllocGHCItem(nch
, nhi
, NULL
, nhi
->nhi_Usage
)))
175 /* Horizontal slider */
177 Child
, (IPTR
)VSpace(0),
179 Child
, (IPTR
)Label((IPTR
)nhgi
->nhgi_Name
),
180 Child
, (IPTR
)(nhgi
->nhgi_GUIObj
= SliderObject
, SliderFrame
,
181 MUIA_Slider_Horiz
, TRUE
,
183 MUIA_InputMode
, MUIV_InputMode_Immediate
,
184 MUIA_Numeric_Min
, nhi
->nhi_LogicalMin
,
185 MUIA_Numeric_Max
, nhi
->nhi_LogicalMax
,
186 MUIA_Numeric_Value
, nhi
->nhi_OldValue
,
189 Child
, (IPTR
)VSpace(0),
191 nhgi
->nhgi_ObjType
= NHGIOT_SLIDERIMM
;
194 if((nhgi
= nAllocGHCItem(nch
, nhi
, NULL
, nhi
->nhi_Usage
)))
196 /* Vertical slider */
198 Child
, (IPTR
)HSpace(0),
200 Child
, (IPTR
)(nhgi
->nhgi_GUIObj
= SliderObject
, SliderFrame
,
201 MUIA_Slider_Horiz
, FALSE
,
203 MUIA_InputMode
, MUIV_InputMode_Immediate
,
204 MUIA_Numeric_Min
, nhi
->nhi_LogicalMin
,
205 MUIA_Numeric_Max
, nhi
->nhi_LogicalMax
,
206 MUIA_Numeric_Value
, nhi
->nhi_OldValue
,
208 Child
, (IPTR
)Label((IPTR
)nhgi
->nhgi_Name
),
210 Child
, (IPTR
)HSpace(0),
212 nhgi
->nhgi_ObjType
= NHGIOT_SLIDERIMM
;
216 if((nhi
->nhi_LogicalMin
== 0) && (nhi
->nhi_LogicalMax
== 1))
218 if((nhgi
= nAllocGHCItem(nch
, nhi
, NULL
, nhi
->nhi_Usage
)))
222 Child
, (IPTR
)VSpace(0),
223 Child
, (IPTR
)(nhgi
->nhgi_GUIObj
= TextObject
, ButtonFrame
,
224 MUIA_Background
, MUII_ButtonBack
,
226 MUIA_InputMode
, MUIV_InputMode_Toggle
,
227 MUIA_Text_PreParse
, (IPTR
)"\33c",
228 MUIA_Text_Contents
, (IPTR
)nhgi
->nhgi_Name
,
230 Child
, (IPTR
)VSpace(0),
232 nhgi
->nhgi_ObjType
= NHGIOT_TOGGLEBUTTON
;
235 else if(nhi
->nhi_LogicalMin
< 0)
237 if((nhgi
= nAllocGHCItem(nch
, nhi
, NULL
, nhi
->nhi_Usage
)))
239 /* Horizontal slider */
241 Child
, (IPTR
)VSpace(0),
243 Child
, (IPTR
)Label((IPTR
)nhgi
->nhgi_Name
),
244 Child
, (IPTR
)(nhgi
->nhgi_GUIObj
= SliderObject
, SliderFrame
,
245 MUIA_Slider_Horiz
, TRUE
,
247 MUIA_Numeric_Min
, nhi
->nhi_LogicalMin
,
248 MUIA_Numeric_Max
, nhi
->nhi_LogicalMax
,
249 MUIA_Numeric_Value
, nhi
->nhi_OldValue
,
252 Child
, (IPTR
)VSpace(0),
254 nhgi
->nhgi_ObjType
= NHGIOT_SLIDER
;
257 if((nhgi
= nAllocGHCItem(nch
, nhi
, NULL
, nhi
->nhi_Usage
)))
259 /* Vertical slider */
261 Child
, (IPTR
)HSpace(0),
263 Child
, (IPTR
)(nhgi
->nhgi_GUIObj
= SliderObject
, SliderFrame
,
264 MUIA_Slider_Horiz
, FALSE
,
266 MUIA_Numeric_Min
, nhi
->nhi_LogicalMin
,
267 MUIA_Numeric_Max
, nhi
->nhi_LogicalMax
,
268 MUIA_Numeric_Value
, nhi
->nhi_OldValue
,
270 Child
, (IPTR
)Label(nhgi
->nhgi_Name
),
272 Child
, (IPTR
)HSpace(0),
274 nhgi
->nhgi_ObjType
= NHGIOT_SLIDER
;
281 DoMethod(nch
->nch_HCGroupObj
, OM_ADDMEMBER
, obj
);
282 switch(nhgi
->nhgi_ObjType
)
284 case NHGIOT_SHOTBUTTON
:
285 DoMethod(nhgi
->nhgi_GUIObj
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
286 nch
->nch_HCActionObj
, 2, MUIM_Action_UpdateHIDCtrl
, nhgi
);
289 case NHGIOT_TOGGLEBUTTON
:
290 DoMethod(nhgi
->nhgi_GUIObj
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
,
291 nch
->nch_HCActionObj
, 2, MUIM_Action_UpdateHIDCtrl
, nhgi
);
294 case NHGIOT_SLIDERIMM
:
295 DoMethod(nhgi
->nhgi_GUIObj
, MUIM_Notify
, MUIA_Numeric_Value
, MUIV_EveryTime
,
296 nch
->nch_HCActionObj
, 2, MUIM_Action_UpdateHIDCtrl
, nhgi
);
300 DoMethod(nhgi
->nhgi_GUIObj
, MUIM_Notify
, MUIA_Numeric_Value
, MUIV_EveryTime
,
301 nch
->nch_HCActionObj
, 2, MUIM_Action_UpdateHIDCtrl
, nhgi
);
309 nhr
= (struct NepHidReport
*) nhr
->nhr_Node
.ln_Succ
;
313 DoMethod(nch
->nch_HCGroupObj
, OM_ADDMEMBER
, Label("No output items in this interface!"));
317 DoMethod(nch
->nch_HCMainWindow
, MUIM_Notify
, MUIA_Window_CloseRequest
, TRUE
,
318 nch
->nch_HCActionObj
, 1, MUIM_Action_HideHIDControl
);
319 DoMethod(nch
->nch_HCCloseObj
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
320 nch
->nch_HCActionObj
, 1, MUIM_Action_HideHIDControl
);
322 DoMethod(nch
->nch_HCAboutMI
, MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
,
323 nch
->nch_HCActionObj
, 1, MUIM_Action_About
);
324 DoMethod(nch
->nch_HCCloseMI
, MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
,
325 nch
->nch_HCActionObj
, 1, MUIM_Action_HideHIDControl
);
326 DoMethod(nch
->nch_HCMUIPrefsMI
, MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
,
327 nch
->nch_HCApp
, 2, MUIM_Application_OpenConfigWindow
, 0);
336 if(nch
->nch_CDC
->cdc_HIDCtrlOpen
)
338 get(nch
->nch_HCApp
, MUIA_Application_Iconified
, &iconify
);
339 set(nch
->nch_HCMainWindow
, MUIA_Window_Open
, TRUE
);
340 get(nch
->nch_HCMainWindow
, MUIA_Window_Open
, &isopen
);
341 if(!(isopen
|| iconify
))
343 GM_UNIQUENAME(nHIDCtrlGUITaskCleanup
)(nch
);
350 retid
= DoMethod(nch
->nch_HCApp
, MUIM_Application_NewInput
, &sigs
);
353 sigs
= Wait(sigs
| sigmask
| SIGBREAKF_CTRL_C
);
354 if(sigs
& SIGBREAKF_CTRL_C
)
359 } while(retid
!= MUIV_Application_ReturnID_Quit
);
360 set(nch
->nch_HCMainWindow
, MUIA_Window_Open
, FALSE
);
362 GM_UNIQUENAME(nHIDCtrlGUITaskCleanup
)(nch
);
368 /* /// "nHIDCtrlGUITaskCleanup()" */
369 void GM_UNIQUENAME(nHIDCtrlGUITaskCleanup
)(struct NepClassHid
*nch
)
371 struct NepHidGItem
*nhgi
;
374 MUI_DisposeObject(nch
->nch_HCApp
);
375 nch
->nch_HCApp
= NULL
;
376 nch
->nch_HCActionObj
= NULL
;
379 nhgi
= (struct NepHidGItem
*) nch
->nch_HCGUIItems
.lh_Head
;
380 while(nhgi
->nhgi_Node
.ln_Succ
)
382 Remove(&nhgi
->nhgi_Node
);
383 psdFreeVec(nhgi
->nhgi_Name
);
385 nhgi
= (struct NepHidGItem
*) nch
->nch_HCGUIItems
.lh_Head
;
387 if(nch
->nch_HCActionClass
)
389 MUI_DeleteCustomClass(nch
->nch_HCActionClass
);
390 nch
->nch_HCActionClass
= NULL
;
395 CloseLibrary(MUIMasterBase
);
396 MUIMasterBase
= NULL
;
400 CloseLibrary(IntuitionBase
);
401 IntuitionBase
= NULL
;
409 nch
->nch_HCGUITask
= NULL
;
410 if(nch
->nch_ReadySigTask
)
412 Signal(nch
->nch_ReadySigTask
, 1L<<nch
->nch_ReadySignal
);
414 --nch
->nch_ClsBase
->nh_Library
.lib_OpenCnt
;
418 /* /// "nGetGHCUsageName()" */
419 STRPTR
nGetGHCUsageName(struct NepClassHid
*nch
, ULONG uid
)
423 uname
= nNumToStr(nch
, NTS_USAGEID
, uid
, NULL
);
426 return(psdCopyStr(uname
));
428 uname
= nNumToStr(nch
, NTS_USAGEPAGE
, uid
>>16, "unknown");
429 return(psdCopyStrFmt("%s (0x%lx)", uname
, uid
));
433 /* /// "nAllocGHCItem()" */
434 struct NepHidGItem
* nAllocGHCItem(struct NepClassHid
*nch
, struct NepHidItem
*nhi
, struct List
*actionlist
, ULONG usageid
)
436 struct NepHidGItem
*nhgi
;
438 if(!(nhgi
= psdAllocVec(sizeof(struct NepHidGItem
))))
442 nhgi
->nhgi_Item
= nhi
;
443 nhgi
->nhgi_ActionList
= actionlist
;
446 nhgi
->nhgi_Name
= nGetGHCUsageName(nch
, usageid
);
448 AddTail(&nch
->nch_HCGUIItems
, &nhgi
->nhgi_Node
);
453 /* /// "HCActionDispatcher()" */
454 AROS_UFH3(IPTR
, GM_UNIQUENAME(HCActionDispatcher
),
455 AROS_UFHA(struct IClass
*, cl
, A0
),
456 AROS_UFHA(Object
*, obj
, A2
),
457 AROS_UFHA(Msg
, msg
, A1
))
461 struct ActionData
*ad
= (struct ActionData
*) 0xABADCAFE;
462 struct NepClassHid
*nch
= NULL
;
463 if(msg
->MethodID
!= OM_NEW
)
465 ad
= INST_DATA(cl
, obj
);
468 switch(msg
->MethodID
)
471 if(!(obj
= (Object
*) DoSuperMethodA(cl
,obj
,msg
)))
477 case MUIM_Action_UpdateHIDCtrl
:
479 struct NepHidGItem
*nhgi
= (struct NepHidGItem
*) ((struct opSet
*) msg
)->ops_AttrList
;
480 switch(nhgi
->nhgi_ObjType
)
482 case NHGIOT_SHOTBUTTON
:
483 nhgi
->nhgi_Item
->nhi_OldValue
= 1;
484 nhgi
->nhgi_Item
->nhi_Collection
->nhc_Report
->nhr_OutTouched
= TRUE
;
485 Signal(nch
->nch_Task
, (1L<<nch
->nch_TaskMsgPort
->mp_SigBit
));
486 while(nhgi
->nhgi_Item
->nhi_Collection
->nhc_Report
->nhr_OutTouched
)
490 nhgi
->nhgi_Item
->nhi_OldValue
= 0;
491 nhgi
->nhgi_Item
->nhi_Collection
->nhc_Report
->nhr_OutTouched
= TRUE
;
492 nch
->nch_OutFeatTouched
= TRUE
;
493 Signal(nch
->nch_Task
, (1L<<nch
->nch_TaskMsgPort
->mp_SigBit
));
496 case NHGIOT_TOGGLEBUTTON
:
497 get(nhgi
->nhgi_GUIObj
, MUIA_Selected
, &nhgi
->nhgi_Item
->nhi_OldValue
);
498 nhgi
->nhgi_Item
->nhi_Collection
->nhc_Report
->nhr_OutTouched
= TRUE
;
499 nch
->nch_OutFeatTouched
= TRUE
;
500 Signal(nch
->nch_Task
, (1L<<nch
->nch_TaskMsgPort
->mp_SigBit
));
504 case NHGIOT_SLIDERIMM
:
505 get(nhgi
->nhgi_GUIObj
, MUIA_Numeric_Value
, &nhgi
->nhgi_Item
->nhi_OldValue
);
506 nhgi
->nhgi_Item
->nhi_Collection
->nhc_Report
->nhr_OutTouched
= TRUE
;
507 nch
->nch_OutFeatTouched
= TRUE
;
508 Signal(nch
->nch_Task
, (1L<<nch
->nch_TaskMsgPort
->mp_SigBit
));
514 case MUIM_Action_About
:
515 MUI_RequestA(nch
->nch_HCApp
, nch
->nch_HCMainWindow
, 0, NULL
, "Blimey!", "HID Output Control Window", NULL
);
518 case MUIM_Action_ShowHIDControl
:
519 set(nch
->nch_HCMainWindow
, MUIA_Window_Open
, TRUE
);
522 case MUIM_Action_HideHIDControl
:
523 set(nch
->nch_HCMainWindow
, MUIA_Window_Open
, FALSE
);
526 return(DoSuperMethodA(cl
,obj
,msg
));