*/}}

la_controllers.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. /*
  2. * LaGUI: A graphical application framework.
  3. * Copyright (C) 2022-2023 Wu Yiming
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include "la_5.h"
  19. #include <math.h>
  20. #ifdef __linux__
  21. #include <fcntl.h>
  22. #include <sys/types.h>
  23. #include <sys/stat.h>
  24. #include <sys/ioctl.h>
  25. #include <sys/inotify.h>
  26. #include <linux/input.h>
  27. #include <linux/joystick.h>
  28. #include <fcntl.h>
  29. #include <unistd.h>
  30. #include <errno.h>
  31. #include <X11/extensions/XInput2.h>
  32. #endif
  33. extern LA MAIN;
  34. #define LA_JS_EVENT_BUTTON 0x01 // button pressed/released
  35. #define LA_JS_EVENT_AXIS 0x02 // joystick moved
  36. #define LA_JS_EVENT_INIT 0x80 // initial state of device
  37. #define LA_JS_TYPE_X56_THROTTLE 1
  38. #define LA_JS_TYPE_X56_STICK 2
  39. char LA_JS_BTN_NAMES[LA_JS_MAX_BUTTONS][10];
  40. char LA_JS_AXIS_NAMES[LA_JS_MAX_AXES][10];
  41. int la_IdentifyControllerInternalType(char* name){
  42. if(strstr(name, "X-56") && strstr(name, "Throttle")){ return LA_JS_TYPE_X56_THROTTLE; }
  43. if(strstr(name, "X-56") && strstr(name, "Stick")){ return LA_JS_TYPE_X56_STICK; }
  44. return 0;
  45. }
  46. laController* la_NewController(char* name, char* path, int device, int NumAxes, int NumButtons){
  47. laController* c=memAcquire(sizeof(laController));
  48. logPrint("Found controller %s\n at %s\n with %d axes, %d buttons\n", name, path, NumAxes, NumButtons);
  49. strSafeSet(&c->Name, name); strSafeSet(&c->Path, path); c->fd=device;
  50. c->NumAxes = NumAxes; c->NumButtons=NumButtons;
  51. c->InternalType = la_IdentifyControllerInternalType(name);
  52. lstAppendItem(&MAIN.Controllers,c);
  53. c->UserAssignedID=MAIN.NextControllerID; MAIN.NextControllerID++;
  54. laPropContainer*pc=la_EnsureSubTarget(LA_PROP_CONTROLLER,c);
  55. if(!pc){ return c; }
  56. for(laProp* p=pc->Props.pFirst;p;p=p->Item.pNext){
  57. if(p->PropertyType & LA_PROP_INT && p->Offset){ int off=p->Offset;
  58. if(off >= offsetof(laController,AxisValues[0]) && off <= offsetof(laController,AxisValues[LA_JS_MAX_AXES-1])){
  59. int index = (off - offsetof(laController,AxisValues[0]))/sizeof(u16bit);
  60. if(p->Len<2){ strSafeSet(&c->AxisNames[index], p->Name); }
  61. else for(int i=0;i<p->Len;i++){ strSafePrint(&c->AxisNames[index+i],"%s.%d", p->Name,i+1); }
  62. }
  63. }elif(p->PropertyType & LA_PROP_ENUM && p->Offset){ int off=p->Offset;
  64. if(off >= offsetof(laController,ButtonValues[0]) && off <= offsetof(laController,ButtonValues[LA_JS_MAX_BUTTONS-1])){
  65. int index = (off - offsetof(laController,ButtonValues[0]));
  66. if(p->Len<2){ strSafeSet(&c->ButtonNames[index], p->Name); }
  67. else for(int i=0;i<p->Len;i++){ strSafePrint(&c->ButtonNames[index+i],"%s.%d", p->Name,i+1); }
  68. }
  69. }
  70. }
  71. return c;
  72. }
  73. void la_DestroyController(laController* c){
  74. strSafeDestroy(&c->Name); strSafeDestroy(&c->Path);
  75. memFree(c); laNotifyUsers("la.controllers");
  76. }
  77. laController* la_FindControllerWithID(int id){
  78. for(laController* c=MAIN.Controllers.pFirst;c;c=c->Item.pNext){ if(c->UserAssignedID==id) return c; } return 0;
  79. }
  80. void la_ReadControllerAxisLimit(laController* c, int i, int Min, int Max){
  81. c->AxisMins[i] = Min;
  82. c->AxisMaxes[i] = Max;
  83. c->AxisLimitMins[i] = -32768*0.95;
  84. c->AxisLimitMaxes[i] = 32767*0.95;
  85. }
  86. int la_ControllerButtonToMap(int btn){
  87. if(btn<BTN_MISC) return -1;
  88. if(btn<=BTN_GEAR_UP) return btn-BTN_MISC;
  89. if(btn<BTN_DPAD_UP) return -1;
  90. if(btn<=BTN_DPAD_RIGHT) return BTN_GEAR_UP-BTN_MISC+1+btn-BTN_DPAD_UP;
  91. if(btn<BTN_TRIGGER_HAPPY) return -1;
  92. if(btn<=BTN_TRIGGER_HAPPY40) return BTN_GEAR_UP-BTN_MISC+1+BTN_DPAD_RIGHT-BTN_DPAD_UP+1+btn-BTN_TRIGGER_HAPPY;
  93. return -1;
  94. }
  95. int la_ControllerButtonToIndex(laController* c,int btn){
  96. int map=la_ControllerButtonToMap(btn); if(map<0) return -1; return c->ButtonsMap[map];
  97. }
  98. int la_ControllerAxisToMap(int abs){
  99. if(abs<ABS_X) return -1; if(abs>ABS_MAX) return -1;
  100. return abs;
  101. }
  102. int la_ControllerAxisToIndex(laController* c,int abs){
  103. int map=la_ControllerAxisToMap(abs); if(map<0) return -1; return c->AxisMap[map];
  104. }
  105. char* laControllerIDGetAxisName(int id, int axis){
  106. laController* c=la_FindControllerWithID(id); if(!c){ return "?"; }
  107. return SSTR(c->AxisNames[axis]);
  108. }
  109. char* laControllerIDGetButtonName(int id, int button){
  110. laController* c=la_FindControllerWithID(id); if(!c){ return "?"; }
  111. return SSTR(c->ButtonNames[button]);
  112. }
  113. int laControllerIDGetAxis(int id, char* name){
  114. laController* c=la_FindControllerWithID(id); if(!c){ return -1; }
  115. for(int i=0;i<LA_JS_MAX_AXES;i++){ if(strSame(SSTR(c->AxisNames[i]),name)) return i; } return -1;
  116. }
  117. int laControllerIDGetButton(int id, char* name){
  118. laController* c=la_FindControllerWithID(id); if(!c){ return -1; }
  119. for(int i=0;i<LA_JS_MAX_AXES;i++){ if(strSame(SSTR(c->ButtonNames[i]),name)) return i; } return -1;
  120. }
  121. void la_InitControllers(){
  122. #ifdef __linux__
  123. char path[32]="/dev/input/js";
  124. char name[128]={0};
  125. int numpos=strlen(path);
  126. char fileName[32];
  127. for (int i=0; i<32; ++i) {
  128. sprintf(fileName, "/dev/input/event%d", i);
  129. int file = open(fileName, O_RDWR | O_NONBLOCK);
  130. if (file != -1){
  131. ioctl(file, EVIOCGNAME(128), name);
  132. barray_t *abs_barray = barray_init(ABS_CNT);
  133. ioctl(file, EVIOCGBIT(EV_ABS, ABS_CNT), barray_data(abs_barray));
  134. size_t abs_count = barray_count_set(abs_barray);
  135. barray_t *key_barray = barray_init(KEY_CNT);
  136. ioctl(file, EVIOCGBIT(EV_KEY, KEY_CNT), barray_data(key_barray));
  137. size_t key_count = barray_count_set(key_barray);
  138. if(!abs_count && !key_count){ close(file); continue; }
  139. laController* c=la_NewController(name, fileName, file, abs_count, key_count);
  140. int nextid=0;
  141. for (unsigned int j=0; j<KEY_CNT; j++){
  142. if(barray_is_set(key_barray,j)){
  143. int mapid=la_ControllerButtonToMap(j); if(mapid<0){ continue; }
  144. c->ButtonsMap[mapid]=nextid; nextid++;
  145. }
  146. }
  147. nextid=0;
  148. for (unsigned int j=0; j<ABS_CNT; j++){ struct input_absinfo axisInfo;
  149. if (barray_is_set(abs_barray,j) && (ioctl(file, EVIOCGABS(j), &axisInfo) != -1)){
  150. int mapid=la_ControllerAxisToMap(j); if(mapid<0){ continue; }
  151. la_ReadControllerAxisLimit(c,nextid,axisInfo.minimum,axisInfo.maximum);
  152. c->AxisMap[mapid]=nextid; nextid++;
  153. }
  154. }
  155. barray_free(abs_barray);
  156. barray_free(key_barray);
  157. }
  158. }
  159. #endif
  160. }
  161. void la_UpdateControllerStatus(){
  162. #ifdef __linux__
  163. struct input_event event; int HasEvent=0;
  164. for(laController* c=MAIN.Controllers.pFirst;c;c=c->Item.pNext){ if(c->Error) continue;
  165. int bytes; while((bytes=read(c->fd, &event, sizeof(struct input_event)))>0){
  166. if(event.type == EV_KEY){
  167. int idx = la_ControllerButtonToIndex(c,event.code); if(idx<0) continue;
  168. c->ButtonValues[idx]=event.value; HasEvent=1;
  169. MAIN.LastControllerKey=idx; MAIN.LastControllerKeyDevice=c->UserAssignedID; MAIN.ControllerHasNewKey = 1; laRetriggerOperators();
  170. }
  171. else if(event.type == EV_ABS){
  172. int idx = la_ControllerAxisToIndex(c,event.code); if(idx<0) continue; HasEvent=1;
  173. c->AxisValues[idx]=rint(tnsLinearItp(-32768.0f,32767.0f,((real)event.value/(c->AxisMaxes[idx]-c->AxisMins[idx]))));
  174. if(abs(c->AxisValues[idx]-c->SaveAxisValues[idx])>10000){ c->SaveAxisValues[idx]=c->AxisValues[idx];
  175. MAIN.LastControllerAxis=idx; MAIN.LastControllerAxisDevice=c->UserAssignedID; MAIN.ControllerHasNewAxis = 1; laRetriggerOperators();
  176. }
  177. }
  178. }
  179. if(bytes<=0){ struct stat buffer; if(stat(c->Path->Ptr,&buffer)<0){ c->Error=1; HasEvent=1; } }
  180. }
  181. if(HasEvent){ laNotifyUsers("la.controllers"); laMappingRequestEval(); }
  182. #endif
  183. }
  184. void la_RefreshControllers(){
  185. laController* c; while(c=lstPopItem(&MAIN.Controllers)){ la_DestroyController(c); } MAIN.NextControllerID=0;
  186. la_InitControllers();
  187. }
  188. int OPINV_RefreshControllers(){
  189. la_RefreshControllers();
  190. #ifdef __linux__
  191. la_ScanWacomDevices(MAIN.dpy,XIAllDevices);
  192. #endif
  193. #ifdef _WIN32
  194. MAIN.WinTabOpened = 0;
  195. if(MAIN.CurrentWindow){ la_OpenWacomWinTab(MAIN.CurrentWindow->win); }
  196. #endif
  197. return LA_FINISHED;
  198. }
  199. void la_AddButtonProp(laPropContainer* pc, char* id, char* name, char* desc, int i, int array_len, char* array_prefix){
  200. laProp* p=laAddEnumProperty(pc, id, name, desc, LA_WIDGET_ENUM_HIGHLIGHT,
  201. array_prefix,0,0,0,offsetof(laController, ButtonValues[i]),0,0,array_len,0,0,0,0,0,0,LA_READ_ONLY);
  202. laAddEnumItemAs(p,"IDLE", "Idle", "Button is not pressed", 0, 0);
  203. laAddEnumItemAs(p,"ACTIVE", "Active", "Button is pressed", 1, 0);
  204. p->ElementBytes=1;
  205. }
  206. void la_AddAxisProp(laPropContainer* pc, char* id, char* name, char* id_min, char* id_max, char* id_cmin, char* id_cmax, char* desc, int i, int array_len, char* array_prefix){
  207. laAddIntProperty(pc,id,name,desc,array_len>1?LA_WIDGET_VALUE_METER_2D:LA_WIDGET_METER_TYPE2,
  208. array_prefix,0,32767,-32768,1,0,0,offsetof(laController, AxisValues[i]),0,0,array_len,0,0,0,0,0,0,0,LA_READ_ONLY)->ElementBytes = 2;
  209. if(id_min) laAddIntProperty(pc,id_min,id_min,desc,0,
  210. array_prefix,0,-25000,-32768,1,0,0,offsetof(laController, AxisLimitMins[i]),0,0,array_len,0,0,0,0,0,0,0,0)->ElementBytes = 2;
  211. if(id_max) laAddIntProperty(pc,id_max,id_max,desc,0,
  212. array_prefix,0,32767,25000,1,0,0,offsetof(laController, AxisLimitMaxes[i]),0,0,array_len,0,0,0,0,0,0,0,0)->ElementBytes = 2;
  213. if(id_cmin) laAddIntProperty(pc,id_cmax,id_cmax,desc,0,
  214. array_prefix,0,-25000,-32768,1,0,0,offsetof(laController, AxisCenterMins[i]),0,0,array_len,0,0,0,0,0,0,0,0)->ElementBytes = 2;
  215. if(id_cmax) laAddIntProperty(pc,id_cmin,id_cmin,desc,0,
  216. array_prefix,0,32767,25000,1,0,0,offsetof(laController, AxisCenterMaxes[i]),0,0,array_len,0,0,0,0,0,0,0,0)->ElementBytes = 2;
  217. }
  218. void la_AddGenericButtonProps(laPropContainer* pc){
  219. for(int i=0;i<LA_JS_MAX_BUTTONS;i++){ char* name=LA_JS_BTN_NAMES[i]; la_AddButtonProp(pc,name,name,name,i,0,0); }
  220. }
  221. void la_AddGenericAxisProps(laPropContainer* pc){
  222. for(int i=0;i<LA_JS_MAX_AXES;i++){ char* name=LA_JS_AXIS_NAMES[i]; la_AddAxisProp(pc,name,name,0,0,0,0,name,i,0,0); }
  223. }
  224. #define ADD_AXIS_PROP(pc,id,name,desc,i,array_len,array_prefix) \
  225. la_AddAxisProp(pc,id,name,id "_min",id "_max",id "_cmin",id "_cmax",desc,i,array_len,array_prefix)
  226. void laui_GenericJoystick(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context);
  227. void laui_X56Throttle(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context);
  228. void laui_X56Stick(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context);
  229. laPropContainer* LA_PC_JS_GENERIC;
  230. laPropContainer* LA_PC_JS_X56_THROTTLE;
  231. laPropContainer* LA_PC_JS_X56_STICK;
  232. laPropContainer* laget_ControllerType(laController* c){
  233. switch(c->InternalType){
  234. default: case 0: return LA_PC_JS_GENERIC;
  235. case LA_JS_TYPE_X56_THROTTLE: return LA_PC_JS_X56_THROTTLE;
  236. case LA_JS_TYPE_X56_STICK: return LA_PC_JS_X56_STICK;
  237. }
  238. }
  239. void la_RegisterControllerProps(){
  240. for(int i=0;i<LA_JS_MAX_AXES;i++){ sprintf(LA_JS_AXIS_NAMES[i],"a%d",i); }
  241. for(int i=0;i<LA_JS_MAX_BUTTONS;i++){ sprintf(LA_JS_BTN_NAMES[i],"b%d",i); }
  242. laCreateOperatorType("LA_refresh_controllers", "Refresh Controllers", "Look for connected controllers",0,0,0,OPINV_RefreshControllers,0,U'🗘',0);
  243. laPropContainer* pc; laProp* p;
  244. pc=laAddPropertyContainer("la_controller", "Controller", "A joystick/gamepad controller", U'🕹', laui_GenericJoystick, sizeof(laController), 0,0,1);
  245. LA_PC_JS_GENERIC = pc;
  246. laAddStringProperty(pc,"name","Name","Name of the controller", LA_WIDGET_STRING_PLAIN,0,0,0,1,offsetof(laController,Name),0,0,0,0,LA_READ_ONLY|LA_AS_IDENTIFIER);
  247. laAddStringProperty(pc,"path","Path","Device path to the controller", LA_WIDGET_STRING_PLAIN,0,0,0,1,offsetof(laController,Path),0,0,0,0,LA_READ_ONLY);
  248. laAddIntProperty(pc,"user_assigned_id", "ID", "User assigned ID", 0,0,0,0,0,0,0,0,offsetof(laController, UserAssignedID),0,0,0,0,0,0,0,0,0,0,0);
  249. laAddIntProperty(pc,"error", "Error", "Device error", 0,0,0,0,0,0,0,0,offsetof(laController, Error),0,0,0,0,0,0,0,0,0,0,0);
  250. la_AddGenericButtonProps(pc);
  251. la_AddGenericAxisProps(pc);
  252. pc=laAddPropertyContainer("la_controller_x56_throttle", "X56 Throttle", "X56 Throttle", 0,laui_X56Throttle,sizeof(laController),0,0,1);
  253. LA_PC_JS_X56_THROTTLE = pc;
  254. laAddStringProperty(pc,"name","Name","Name of the controller", LA_WIDGET_STRING_PLAIN,0,0,0,1,offsetof(laController,Name),0,0,0,0,LA_READ_ONLY|LA_AS_IDENTIFIER);
  255. laAddSubGroup(pc,"base","Base","Generic controller status", "la_controller",0,0,0,0,0,0,0,0,0,0,0,LA_UDF_LOCAL);
  256. ADD_AXIS_PROP(pc,"thr1","THR1","Throttle 1",0,0,0);
  257. ADD_AXIS_PROP(pc,"thr2","THR2","Throttle 1",1,0,0);
  258. ADD_AXIS_PROP(pc,"wf","WF","Wheel F (big wheel)",2,0,0);
  259. ADD_AXIS_PROP(pc,"ball","Ball","Thumb ball",3,2,"Left/Right,Up/Down");
  260. ADD_AXIS_PROP(pc,"wg","WG","Wheel G (smaller wheel)",5,0,0);
  261. ADD_AXIS_PROP(pc,"r4","RTY4","Rotary 4",6,0,0);
  262. ADD_AXIS_PROP(pc,"r3","RTY3","Rotary 3",7,0,0);
  263. la_AddButtonProp(pc,"be","E","Button E (thumb flat switch)", 0,0,0);
  264. la_AddButtonProp(pc,"bf","F","Button F (big push down switch)", 1,0,0);
  265. la_AddButtonProp(pc,"bg","G","Button G (smaller up-side-down switch)", 2,0,0);
  266. la_AddButtonProp(pc,"bi","I","Button I (left reverser)", 3,0,0);
  267. la_AddButtonProp(pc,"bh","H","Button H (right reverser)", 4,0,0);
  268. la_AddButtonProp(pc,"sw1","SW1","Switch 1", 5,0,0);
  269. la_AddButtonProp(pc,"sw2","SW2","Switch 2", 6,0,0);
  270. la_AddButtonProp(pc,"sw3","SW3","Switch 3", 7,0,0);
  271. la_AddButtonProp(pc,"sw4","SW4","Switch 4", 8,0,0);
  272. la_AddButtonProp(pc,"sw5","SW5","Switch 5", 9,0,0);
  273. la_AddButtonProp(pc,"sw6","SW6","Switch 6", 10,0,0);
  274. la_AddButtonProp(pc,"t1_up","T1+","Toggle 1+", 11,0,0);
  275. la_AddButtonProp(pc,"t1_dn","T1-","Toggle 1-", 12,0,0);
  276. la_AddButtonProp(pc,"t2_up","T2+","Toggle 2+", 13,0,0);
  277. la_AddButtonProp(pc,"t2_dn","T2-","Toggle 2-", 14,0,0);
  278. la_AddButtonProp(pc,"t3_up","T3+","Toggle 3+", 15,0,0);
  279. la_AddButtonProp(pc,"t3_dn","T3-","Toggle 3-", 16,0,0);
  280. la_AddButtonProp(pc,"t4_up","T4+","Toggle 4+", 17,0,0);
  281. la_AddButtonProp(pc,"t4_dn","T4-","Toggle 4-", 18,0,0);
  282. la_AddButtonProp(pc,"h3","H3","Hat 3 (Upper round hat)", 19,4,"N,E,S,W");
  283. la_AddButtonProp(pc,"h4","H4","Hat 4 (lower jagged hat)", 23,4,"N,E,S,W");
  284. la_AddButtonProp(pc,"pinky_up","P+","Pinky up", 27,0,0);
  285. la_AddButtonProp(pc,"pinky_dn","P-","Pinky down", 28,0,0);
  286. la_AddButtonProp(pc,"dial_fwd","D+","Dial forward", 29,0,0);
  287. la_AddButtonProp(pc,"dial_back","D-","Dial backward", 30,0,0);
  288. la_AddButtonProp(pc,"bball","BP","Ball push", 31,0,0);
  289. la_AddButtonProp(pc,"slider","SLD","Slider", 32,0,0);
  290. la_AddButtonProp(pc,"mode","Mode","Mode switch", 33,3,"M1,M2,S1");
  291. pc=laAddPropertyContainer("la_controller_x56_stick", "X56 Stick", "X56 Stick", 0,laui_X56Stick,sizeof(laController),0,0,1);
  292. LA_PC_JS_X56_STICK = pc;
  293. laAddStringProperty(pc,"name","Name","Name of the controller", LA_WIDGET_STRING_PLAIN,0,0,0,1,offsetof(laController,Name),0,0,0,0,LA_READ_ONLY|LA_AS_IDENTIFIER);
  294. laAddSubGroup(pc,"base","Base","Generic controller status", "la_controller",0,0,0,0,0,0,0,0,0,0,0,LA_UDF_LOCAL);
  295. ADD_AXIS_PROP(pc,"stick","Stick","Main stick",0,2,"Left/Right,Up/Down");
  296. ADD_AXIS_PROP(pc,"ball","Ball","Ball stick",2,2,"Left/Right,Up/Down");
  297. ADD_AXIS_PROP(pc,"rudder","Rudder","Ruder twist",4,0,0);
  298. ADD_AXIS_PROP(pc,"pov","POV","POV hat",5,2,"Left/Right,Up/Down");
  299. la_AddButtonProp(pc,"trigger","Trigger","Trigger", 0,0,0);
  300. la_AddButtonProp(pc,"ba","A","Button A", 1,0,0);
  301. la_AddButtonProp(pc,"bb","B","Button B (Side of stick)", 2,0,0);
  302. la_AddButtonProp(pc,"bball","BP","Ball push", 3,0,0); la_AddButtonProp(pc,"bc","BC","Button C (ball push)", 3,0,0);
  303. la_AddButtonProp(pc,"pinky","PK","Pinky small button", 4,0,0); la_AddButtonProp(pc,"bd","BD","Button D pinky small button", 4,0,0);
  304. la_AddButtonProp(pc,"pinkyl","PKL","Pinky lever", 5,0,0);
  305. la_AddButtonProp(pc,"h1","H1","Hat 1 (Upper round hat)", 6,4,"N,E,S,W");
  306. la_AddButtonProp(pc,"h2","H2","Hat 2 (lower jagged hat)", 10,4,"N,E,S,W");
  307. //button 14-16 not sure where it is....
  308. }
  309. void laui_GenericJoystick(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
  310. laColumn* c=laFirstColumn(uil); laUiItem* b,*b1;
  311. char buf[32];
  312. laShowItem(uil,c,This,"name")->Flags|=LA_TEXT_ALIGN_CENTER;
  313. b=laBeginRow(uil,c,0,0);
  314. laShowItem(uil,c,This,"user_assigned_id");
  315. b1=laOnConditionThat(uil,c,laPropExpression(This,"error"));{
  316. laShowLabel(uil,c,"Device error.",0,0)->Expand=1;
  317. }laElse(uil,b1);{
  318. laShowItem(uil,c,This,"path")->Expand=1;
  319. }laEndCondition(uil,b1);
  320. laEndRow(uil,b);
  321. laShowSeparator(uil,c);
  322. laShowLabel(uil,c,"Axes",0,0);
  323. for(int i=0;i<8;i++){
  324. if(!(i%2)){ b=laBeginRow(uil,c,0,0); }
  325. sprintf(buf,"a%d",i);
  326. laShowLabel(uil,c,buf,0,0); laShowItem(uil,c,This,buf)->Expand=1;
  327. if(i%2){ laEndRow(uil,b); }
  328. }
  329. b1=laOnConditionToggle(uil,c,0,0,0,0,0); strSafeSet(&b1->ExtraInstructions,"text=More axes..."); b1->Flags|=LA_TEXT_ALIGN_LEFT;
  330. for(int i=8;i<LA_JS_MAX_AXES;i++){
  331. if(!(i%2)){ b=laBeginRow(uil,c,0,0); }
  332. sprintf(buf,"a%d",i);
  333. laShowLabel(uil,c,buf,0,0); laShowItem(uil,c,This,buf)->Expand=1;
  334. if(i%2){ laEndRow(uil,b); }
  335. }
  336. laEndCondition(uil,b1);
  337. laShowSeparator(uil,c);
  338. laShowLabel(uil,c,"Buttons",0,0);
  339. for(int i=0;i<16;i++){
  340. if(!(i%2)){ b=laBeginRow(uil,c,0,0); }
  341. sprintf(buf,"b%d",i);
  342. laShowLabel(uil,c,buf,0,0); laShowItem(uil,c,This,buf)->Expand=1;
  343. if(i%2){ laEndRow(uil,b); }
  344. }
  345. b1=laOnConditionToggle(uil,c,0,0,0,0,0); strSafeSet(&b1->ExtraInstructions,"text=More buttons..."); b1->Flags|=LA_TEXT_ALIGN_LEFT;
  346. for(int i=8;i<LA_JS_MAX_BUTTONS;i++){
  347. if(!(i%2)){ b=laBeginRow(uil,c,0,0); }
  348. sprintf(buf,"b%d",i);
  349. laShowLabel(uil,c,buf,0,0); laShowItem(uil,c,This,buf)->Expand=1;
  350. if(i%2){ laEndRow(uil,b); }
  351. }
  352. laEndCondition(uil,b1);
  353. }
  354. void laui_X56Throttle(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
  355. laColumn* c=laFirstColumn(uil),*cl, *cr, *crl,*crr, *rc, *vc, *rcl,*rcr;
  356. laSplitColumn(uil,c,0.17); cl=laLeftColumn(c,0); cr=laRightColumn(c,0);
  357. laSplitColumn(uil,cr,0.4); crl=laLeftColumn(cr,0); crr=laRightColumn(cr,0);
  358. laSplitColumn(uil,crr,0.6); rc=laLeftColumn(crr,10); vc=laRightColumn(crr,0);
  359. laSplitColumn(uil,rc,0.4); rcl=laLeftColumn(rc,2); rcr=laRightColumn(rc,0);
  360. laUiItem* b,*ui,*g; laUiList*gu;
  361. laShowItem(uil,c,This,"base.name")->Flags|=LA_TEXT_ALIGN_CENTER;
  362. b=laBeginRow(uil,c,0,0);
  363. laShowItem(uil,c,This,"base.user_assigned_id");
  364. laUiItem* b1=laOnConditionThat(uil,c,laPropExpression(This,"base.error"));{
  365. laShowLabel(uil,c,"Device error.",0,0)->Expand=1;
  366. }laElse(uil,b1);{
  367. laShowItem(uil,c,This,"base.path")->Expand=1;
  368. }laEndCondition(uil,b1);
  369. laEndRow(uil,b);
  370. laShowSeparator(uil,c);
  371. laShowItem(uil,cl,This,"pinky_up");
  372. laShowItem(uil,cl,This,"pinky_dn");
  373. laShowSeparator(uil,cl);
  374. laShowItem(uil,cl,This,"dial_fwd");
  375. laShowItem(uil,cl,This,"dial_back");
  376. b=laBeginRow(uil,crl,0,0);
  377. ui=laShowItem(uil,crl,This,"bi");ui->Expand=1;
  378. ui=laShowItem(uil,crl,This,"bh");ui->Expand=1;
  379. laEndRow(uil,b);
  380. b=laBeginRow(uil,crl,0,0);
  381. ui=laShowItem(uil,crl,This,"thr1");ui->Expand=1;ui->Extra->HeightCoeff=10;ui->Flags|=LA_UI_FLAGS_TRANSPOSE;
  382. laShowCompoundValue(ui,LA_SLOT_MARKER_1,This,"thr1_min");
  383. laShowCompoundValue(ui,LA_SLOT_MARKER_2,This,"thr1_max");
  384. ui=laShowItem(uil,crl,This,"thr2");ui->Expand=1;ui->Extra->HeightCoeff=10;ui->Flags|=LA_UI_FLAGS_TRANSPOSE;
  385. laShowCompoundValue(ui,LA_SLOT_MARKER_1,This,"thr2_min");
  386. laShowCompoundValue(ui,LA_SLOT_MARKER_2,This,"thr2_max");
  387. laEndRow(uil,b);
  388. b=laBeginRow(uil,crl,1,1);
  389. laShowItem(uil,crl,This,"thr1_min")->Flags|=LA_UI_FLAGS_KNOB; laShowItem(uil,crl,This,"thr1_max")->Flags|=LA_UI_FLAGS_KNOB;
  390. //laShowSeparator(uil,crl)->Expand=1;
  391. laShowItem(uil,crl,This,"thr2_min")->Flags|=LA_UI_FLAGS_KNOB; laShowItem(uil,crl,This,"thr2_max")->Flags|=LA_UI_FLAGS_KNOB;
  392. laEndRow(uil,b);
  393. laShowItem(uil,rcl,This,"bf");
  394. laShowItem(uil,rcr,This,"wf");
  395. laShowItem(uil,rcl,This,"bg");
  396. laShowItem(uil,rcr,This,"wg");
  397. laShowSeparator(uil,cl);
  398. laShowItem(uil,rcl,This,"slider");
  399. laShowSeparator(uil,rcl);
  400. laShowItem(uil,rcl,This,"be");
  401. laShowItem(uil,rcl,This,"bball");
  402. laShowItem(uil,rcr,This,"ball");
  403. laShowItem(uil,rc,This,"h3")->Flags|=LA_UI_FLAGS_TRANSPOSE;
  404. laShowItem(uil,rc,This,"h4")->Flags|=LA_UI_FLAGS_TRANSPOSE;
  405. laShowItem(uil,vc,This,"t4_up");
  406. laShowItem(uil,vc,This,"t4_dn"); laShowSeparator(uil,vc);
  407. laShowItem(uil,vc,This,"t3_up");
  408. laShowItem(uil,vc,This,"t3_dn"); laShowSeparator(uil,vc);
  409. laShowItem(uil,vc,This,"t2_up");
  410. laShowItem(uil,vc,This,"t2_dn"); laShowSeparator(uil,vc);
  411. laShowItem(uil,vc,This,"t1_up");
  412. laShowItem(uil,vc,This,"t1_dn"); laShowSeparator(uil,vc);
  413. laShowItem(uil,vc,This,"r3");
  414. laShowItem(uil,vc,This,"r4");
  415. laShowSeparator(uil,c);
  416. laShowLabel(uil,cl,"Mode",0,0)->Flags|=LA_TEXT_ALIGN_CENTER;
  417. laShowItem(uil,cl,This,"mode");
  418. laShowLabel(uil,cr,"Switches",0,0)->Flags|=LA_TEXT_ALIGN_CENTER;
  419. b=laBeginRow(uil,cr,0,0);
  420. laShowItem(uil,cr,This,"sw1")->Expand=1;
  421. laShowItem(uil,cr,This,"sw3")->Expand=1;
  422. laShowItem(uil,cr,This,"sw5")->Expand=1;
  423. laEndRow(uil,b);
  424. b=laBeginRow(uil,cr,0,0);
  425. laShowItem(uil,cr,This,"sw2")->Expand=1;
  426. laShowItem(uil,cr,This,"sw4")->Expand=1;
  427. laShowItem(uil,cr,This,"sw6")->Expand=1;
  428. laEndRow(uil,b);
  429. }
  430. void laui_X56Stick(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
  431. laColumn* c=laFirstColumn(uil),*cl, *cc, *cr;
  432. laSplitColumn(uil,c,0.2); cl=laLeftColumn(c,10); cr=laRightColumn(c,0);
  433. laSplitColumn(uil,cr,0.8); cc=laLeftColumn(cr,0); cr=laRightColumn(cr,10);
  434. laUiItem* b;
  435. laShowItem(uil,c,This,"base.name")->Flags|=LA_TEXT_ALIGN_CENTER;
  436. b=laBeginRow(uil,c,0,0);
  437. laShowItem(uil,c,This,"base.user_assigned_id");
  438. laUiItem* b1=laOnConditionThat(uil,c,laPropExpression(This,"base.error"));{
  439. laShowLabel(uil,c,"Device error.",0,0)->Expand=1;
  440. }laElse(uil,b1);{
  441. laShowItem(uil,c,This,"base.path")->Expand=1;
  442. }laEndCondition(uil,b1);
  443. laEndRow(uil,b);
  444. laShowSeparator(uil,c);
  445. laShowItem(uil,cl,This,"ba");
  446. laShowItem(uil,cl,This,"pov");
  447. laShowSeparator(uil,cl);
  448. laShowLabel(uil,cl,"Thumb",0,0)->Flags|=LA_TEXT_ALIGN_CENTER;
  449. laShowItem(uil,cl,This,"bc");
  450. laShowItem(uil,cl,This,"ball");
  451. laShowSeparator(uil,cl);
  452. laShowLabel(uil,cl,"Pinky",0,0)->Flags|=LA_TEXT_ALIGN_CENTER;
  453. laShowItem(uil,cl,This,"pinkyl");
  454. laShowItem(uil,cl,This,"pinky");
  455. laShowItem(uil,cr,This,"bb");
  456. laShowSeparator(uil,cr);
  457. laShowItem(uil,cc,This,"trigger");
  458. laShowItem(uil,cc,This,"stick");
  459. laShowItem(uil,cc,This,"rudder");
  460. laShowLabel(uil,cr,"H1",0,0)->Flags|=LA_TEXT_ALIGN_CENTER;
  461. laShowItem(uil,cr,This,"h1");
  462. laShowSeparator(uil,cr);
  463. laShowLabel(uil,cr,"H2",0,0)->Flags|=LA_TEXT_ALIGN_CENTER;
  464. laShowItem(uil,cr,This,"h2");
  465. }