Documented GVF_SAVE_VAR alongside other flags, and removed a query/doubt
[AROS.git] / rom / usb / classes / egalaxtouch / egalaxtouch.class.c
blob6f0a9c647bb25d11f716b183e93261a5856df426
1 /*
2 *----------------------------------------------------------------------------
3 * egalaxtouch class for poseidon
4 *----------------------------------------------------------------------------
5 * By Chris Hodges <chrisly@platon42.de>
6 */
8 #include "debug.h"
10 #include "egalaxtouch.class.h"
11 #include <proto/timer.h>
13 /* /// "Lib Stuff" */
14 static const STRPTR libname = MOD_NAME_STRING;
16 static int libInit(LIBBASETYPEPTR nh)
18 struct NepClassHid *nch;
19 struct NepHidBase *ret = NULL;
21 KPRINTF(10, ("libInit nh: 0x%08lx SysBase: 0x%08lx\n", nh, SysBase));
23 nh->nh_UtilityBase = OpenLibrary("utility.library", 39);
25 #define UtilityBase nh->nh_UtilityBase
27 if(UtilityBase)
29 NewList(&nh->nh_Bindings);
30 nch = &nh->nh_DummyNCH;
31 nch->nch_ClsBase = nh;
32 nch->nch_Interface = NULL;
33 nch->nch_CDC = AllocVec(sizeof(struct ClsDevCfg), MEMF_PUBLIC|MEMF_CLEAR);
34 if(nch->nch_CDC)
36 ret = nh;
38 if(!ret)
40 CloseLibrary(UtilityBase);
42 } else {
43 KPRINTF(20, ("libInit: OpenLibrary(\"utility.library\", 39) failed!\n"));
46 KPRINTF(10, ("libInit: Ok\n"));
47 return(ret ? TRUE : FALSE);
50 static int libOpen(LIBBASETYPEPTR nh)
52 KPRINTF(10, ("libOpen nh: 0x%08lx\n", nh));
53 nLoadClassConfig(nh);
54 return(TRUE);
57 static int libExpunge(LIBBASETYPEPTR nh)
59 KPRINTF(10, ("libExpunge nh: 0x%08lx\n", nh));
60 CloseLibrary((struct Library *) UtilityBase);
61 FreeVec(nh->nh_DummyNCH.nch_CDC);
62 return(TRUE);
65 ADD2INITLIB(libInit, 0)
66 ADD2OPENLIB(libOpen, 0)
67 ADD2EXPUNGELIB(libExpunge, 0)
68 /* \\\ */
72 * ***********************************************************************
73 * * Library functions *
74 * ***********************************************************************
77 struct AutoBindData
79 UWORD abd_VendID;
80 UWORD abd_ProdID;
83 struct AutoBindData ClassBinds[] =
85 { 0x0123, 0x0001 },
86 { 0x0123, 0x0002 },
87 { 0x1234, 0x0001 },
88 { 0x1234, 0x0002 },
89 { 0x0EEF, 0x0001 },
90 { 0x0EEF, 0x0002 },
91 { 0x3823, 0x0001 },
92 { 0x3823, 0x0002 },
93 { 0, 0 }
96 /* /// "usbAttemptDeviceBinding()" */
97 struct NepClassHid * usbAttemptDeviceBinding(struct NepHidBase *nh, struct PsdDevice *pd)
99 struct Library *ps;
100 struct AutoBindData *abd = ClassBinds;
101 IPTR prodid;
102 IPTR vendid;
104 KPRINTF(1, ("nepHidAttemptDeviceBinding(%08lx)\n", pd));
105 if((ps = OpenLibrary("poseidon.library", 4)))
107 psdGetAttrs(PGA_DEVICE, pd,
108 DA_VendorID, &vendid,
109 DA_ProductID, &prodid,
110 TAG_END);
111 CloseLibrary(ps);
112 while(abd->abd_VendID)
114 if((vendid == abd->abd_VendID) && (prodid == abd->abd_ProdID))
116 return(usbForceDeviceBinding(nh, pd));
118 abd++;
121 return(NULL);
123 /* \\\ */
125 /* /// "usbForceDeviceBinding()" */
126 struct NepClassHid * usbForceDeviceBinding(struct NepHidBase *nh, struct PsdDevice *pd)
128 struct Library *ps;
129 struct NepClassHid *nch;
130 struct ClsDevCfg *cdc;
131 STRPTR devname;
132 STRPTR devidstr;
133 UBYTE buf[64];
134 struct Task *tmptask;
136 KPRINTF(1, ("nepHidForceDeviceBinding(%08lx)\n", pd));
137 if((ps = OpenLibrary("poseidon.library", 4)))
139 psdGetAttrs(PGA_DEVICE, pd,
140 DA_ProductName, &devname,
141 DA_IDString, &devidstr,
142 TAG_END);
143 if((nch = psdAllocVec(sizeof(struct NepClassHid))))
145 nch->nch_ClsBase = nh;
146 nch->nch_CDC = cdc = psdAllocVec(sizeof(struct ClsDevCfg));
147 if(!cdc)
149 psdFreeVec(cdc);
150 psdFreeVec(nch);
151 CloseLibrary(ps);
152 return(NULL);
155 nch->nch_Device = pd;
156 nch->nch_DevIDString = devidstr;
158 nLoadBindingConfig(nch);
160 psdSafeRawDoFmt(buf, 64, "egalaxtouch.class<%08lx>", nch);
161 nch->nch_ReadySignal = SIGB_SINGLE;
162 nch->nch_ReadySigTask = FindTask(NULL);
163 SetSignal(0, SIGF_SINGLE);
164 if((tmptask = psdSpawnSubTask(buf, nHidTask, nch)))
166 psdBorrowLocksWait(tmptask, 1UL<<nch->nch_ReadySignal);
167 if(nch->nch_Task)
169 nch->nch_ReadySigTask = NULL;
170 //FreeSignal(nch->nch_ReadySignal);
171 psdAddErrorMsg(RETURN_OK, (STRPTR) libname,
172 "Touching the sky with '%s'!",
173 devname);
175 Forbid();
176 AddTail(&nh->nh_Bindings, &nch->nch_Node);
177 Permit();
178 CloseLibrary(ps);
179 return(nch);
182 nch->nch_ReadySigTask = NULL;
183 //FreeSignal(nch->nch_ReadySignal);
184 psdFreeVec(nch->nch_CDC);
185 psdFreeVec(nch);
187 CloseLibrary(ps);
189 return(NULL);
191 /* \\\ */
193 /* /// "usbReleaseDeviceBinding()" */
194 void usbReleaseDeviceBinding(struct NepHidBase *nh, struct NepClassHid *nch)
196 struct Library *ps;
197 STRPTR devname;
199 KPRINTF(1, ("nepHidReleaseDeviceBinding(%08lx)\n", nch));
200 if((ps = OpenLibrary("poseidon.library", 4)))
202 Forbid();
203 nch->nch_ReadySignal = SIGB_SINGLE;
204 nch->nch_ReadySigTask = FindTask(NULL);
205 if(nch->nch_GUITask)
207 Signal(nch->nch_GUITask, SIGBREAKF_CTRL_C);
209 Permit();
210 while(nch->nch_GUITask)
212 Wait(1L<<nch->nch_ReadySignal);
215 Forbid();
216 if(nch->nch_Task)
218 Signal(nch->nch_Task, SIGBREAKF_CTRL_C);
220 Permit();
221 while(nch->nch_Task)
223 Wait(1L<<nch->nch_ReadySignal);
225 //FreeSignal(nch->nch_ReadySignal);
226 psdGetAttrs(PGA_DEVICE, nch->nch_Device, DA_ProductName, &devname, TAG_END);
227 psdAddErrorMsg(RETURN_OK, (STRPTR) libname,
228 "Couldn't keep in touch with '%s'!",
229 devname);
230 Forbid();
231 Remove(&nch->nch_Node);
232 Permit();
233 psdFreeVec(nch->nch_CDC);
234 psdFreeVec(nch);
235 CloseLibrary(ps);
238 /* \\\ */
240 /* /// "usbGetAttrsA()" */
241 AROS_LH3(LONG, usbGetAttrsA,
242 AROS_LHA(ULONG, type, D0),
243 AROS_LHA(APTR, usbstruct, A0),
244 AROS_LHA(struct TagItem *, tags, A1),
245 LIBBASETYPEPTR, nh, 5, nep)
247 AROS_LIBFUNC_INIT
249 struct TagItem *ti;
250 LONG count = 0;
252 KPRINTF(1, ("nepHidGetAttrsA(%ld, %08lx, %08lx)\n", type, usbstruct, tags));
253 switch(type)
255 case UGA_CLASS:
256 if((ti = FindTagItem(UCCA_Priority, tags)))
258 *((SIPTR *) ti->ti_Data) = 0;
259 count++;
261 if((ti = FindTagItem(UCCA_Description, tags)))
263 *((STRPTR *) ti->ti_Data) = "Support for eGalax Touchscreens";
264 count++;
266 if((ti = FindTagItem(UCCA_HasClassCfgGUI, tags)))
268 *((IPTR *) ti->ti_Data) = TRUE;
269 count++;
271 if((ti = FindTagItem(UCCA_HasBindingCfgGUI, tags)))
273 *((IPTR *) ti->ti_Data) = TRUE;
274 count++;
276 if((ti = FindTagItem(UCCA_AfterDOSRestart, tags)))
278 *((IPTR *) ti->ti_Data) = FALSE;
279 count++;
281 if((ti = FindTagItem(UCCA_UsingDefaultCfg, tags)))
283 *((IPTR *) ti->ti_Data) = nh->nh_DummyNCH.nch_UsingDefaultCfg;
284 count++;
286 break;
288 case UGA_BINDING:
289 if((ti = FindTagItem(UCBA_UsingDefaultCfg, tags)))
291 *((IPTR *) ti->ti_Data) = ((struct NepClassHid *) usbstruct)->nch_UsingDefaultCfg;
292 count++;
294 break;
296 return(count);
297 AROS_LIBFUNC_EXIT
299 /* \\\ */
301 /* /// "usbSetAttrsA()" */
302 AROS_LH3(LONG, usbSetAttrsA,
303 AROS_LHA(ULONG, type, D0),
304 AROS_LHA(APTR, usbstruct, A0),
305 AROS_LHA(struct TagItem *, tags, A1),
306 LIBBASETYPEPTR, nh, 6, nep)
308 AROS_LIBFUNC_INIT
309 return(0);
310 AROS_LIBFUNC_EXIT
312 /* \\\ */
314 /* /// "usbDoMethodA()" */
315 AROS_LH2(IPTR, usbDoMethodA,
316 AROS_LHA(ULONG, methodid, D0),
317 AROS_LHA(IPTR *, methoddata, A1),
318 LIBBASETYPEPTR, nh, 7, nep)
320 AROS_LIBFUNC_INIT
322 struct NepClassHid *nch;
324 KPRINTF(10, ("Do Method %ld\n", methodid));
325 switch(methodid)
327 case UCM_AttemptDeviceBinding:
328 return((IPTR) usbAttemptDeviceBinding(nh, (struct PsdDevice *) methoddata[0]));
330 case UCM_ForceDeviceBinding:
331 return((IPTR) usbForceDeviceBinding(nh, (struct PsdDevice *) methoddata[0]));
333 case UCM_ReleaseDeviceBinding:
334 usbReleaseDeviceBinding(nh, (struct NepClassHid *) methoddata[0]);
335 return(TRUE);
337 case UCM_OpenCfgWindow:
338 return(nOpenBindingCfgWindow(nh, &nh->nh_DummyNCH));
340 case UCM_OpenBindingCfgWindow:
341 return(nOpenBindingCfgWindow(nh, (struct NepClassHid *) methoddata[0]));
343 case UCM_ConfigChangedEvent:
344 nLoadClassConfig(nh);
345 Forbid();
346 nch = (struct NepClassHid *) nh->nh_Bindings.lh_Head;
347 while(nch->nch_Node.ln_Succ)
349 nLoadBindingConfig(nch);
350 nch = (struct NepClassHid *) nch->nch_Node.ln_Succ;
352 Permit();
353 return(TRUE);
355 default:
356 break;
358 return(0);
359 AROS_LIBFUNC_EXIT
361 /* \\\ */
363 /* /// "nLoadClassConfig()" */
364 BOOL nLoadClassConfig(struct NepHidBase *nh)
366 struct NepClassHid *nch = &nh->nh_DummyNCH;
367 struct Library *ps;
368 struct ClsDevCfg *cdc;
369 struct PsdIFFContext *pic;
371 KPRINTF(10, ("Loading Class Config...\n"));
372 if(!(ps = OpenLibrary("poseidon.library", 4)))
374 return(FALSE);
377 Forbid();
378 /* Create default config */
379 nch->nch_CDC->cdc_ChunkID = AROS_LONG2BE(MAKE_ID('E','G','T','S'));
380 nch->nch_CDC->cdc_Length = AROS_LONG2BE(sizeof(struct ClsDevCfg)-8);
381 nch->nch_CDC->cdc_MinX = 0;
382 nch->nch_CDC->cdc_MinY = 0;
383 nch->nch_CDC->cdc_MaxX = 2047;
384 nch->nch_CDC->cdc_MaxY = 2047;
385 nch->nch_CDC->cdc_RMBDelay = 20;
386 nch->nch_CDC->cdc_RMBTolerance = 20;
387 nch->nch_CDC->cdc_RMBMode = 1;
388 nch->nch_UsingDefaultCfg = TRUE;
389 /* try to load default config */
390 pic = psdGetClsCfg(libname);
391 if(pic)
393 cdc = psdGetCfgChunk(pic, AROS_LONG2BE(nch->nch_CDC->cdc_ChunkID));
394 if(cdc)
396 CopyMem(((UBYTE *) cdc) + 8, ((UBYTE *) nch->nch_CDC) + 8, min(AROS_LONG2BE(cdc->cdc_Length), AROS_LONG2BE(nch->nch_CDC->cdc_Length)));
397 psdFreeVec(cdc);
398 nch->nch_UsingDefaultCfg = FALSE;
401 Permit();
402 CloseLibrary(ps);
403 return(FALSE);
405 /* \\\ */
407 /* /// "nLoadBindingConfig()" */
408 BOOL nLoadBindingConfig(struct NepClassHid *nch)
410 struct NepHidBase *nh = nch->nch_ClsBase;
411 struct Library *ps;
412 struct ClsDevCfg *cdc;
413 struct PsdIFFContext *pic;
415 KPRINTF(10, ("Loading Binding Config...\n"));
416 if(nch->nch_GUITask)
418 return(FALSE);
420 //nLoadClassConfig(nh);
421 *nch->nch_CDC = *nh->nh_DummyNCH.nch_CDC;
422 nch->nch_UsingDefaultCfg = TRUE;
424 if(!(ps = OpenLibrary("poseidon.library", 4)))
426 return(FALSE);
429 Forbid();
430 /* Load config */
431 pic = psdGetUsbDevCfg(libname, nch->nch_DevIDString, NULL);
432 if(pic)
434 cdc = psdGetCfgChunk(pic, AROS_LONG2BE(nch->nch_CDC->cdc_ChunkID));
435 if(cdc)
437 CopyMem(((UBYTE *) cdc) + 8, ((UBYTE *) nch->nch_CDC) + 8, min(AROS_LONG2BE(cdc->cdc_Length), AROS_LONG2BE(nch->nch_CDC->cdc_Length)));
438 psdFreeVec(cdc);
439 nch->nch_UsingDefaultCfg = FALSE;
442 Permit();
443 CloseLibrary(ps);
444 return(FALSE);
446 /* \\\ */
448 /* /// "nOpenBindingCfgWindow()" */
449 LONG nOpenBindingCfgWindow(struct NepHidBase *nh, struct NepClassHid *nch)
451 struct Library *ps;
452 KPRINTF(10, ("Opening GUI...\n"));
453 if(!(ps = OpenLibrary("poseidon.library", 4)))
455 return(FALSE);
457 Forbid();
458 if(!nch->nch_GUITask)
460 if((nch->nch_GUITask = psdSpawnSubTask(MOD_NAME_STRING " GUI", nGUITask, nch)))
462 Permit();
463 CloseLibrary(ps);
464 return(TRUE);
467 Permit();
468 CloseLibrary(ps);
469 return(FALSE);
471 /* \\\ */
473 /**************************************************************************/
475 #undef ps
476 #define ps nch->nch_Base
477 #undef TimerBase
478 #define TimerBase nch->nch_TimerBase
479 #undef IntuitionBase
480 #define IntuitionBase nch->nch_HIntBase
482 /* /// "nHidTask()" */
483 AROS_UFH0(void, nHidTask)
485 AROS_USERFUNC_INIT
487 struct NepClassHid *nch;
488 struct PsdPipe *pp;
489 ULONG sigmask;
490 ULONG sigs;
491 UWORD iecode;
492 UWORD qualifier;
493 UWORD buts;
494 UWORD oldbuts = 0;
495 UBYTE *buf;
496 UBYTE *bufptr;
497 LONG ioerr;
498 ULONG *tagptr;
499 ULONG xpos,ypos;
500 ULONG xrange, yrange;
501 ULONG tmp;
502 ULONG packetpos = 0;
503 UBYTE packet[5] = { 0, 0, 0, 0, 0 };
504 ULONG len;
505 LONG distx;
506 LONG disty;
507 BOOL changed;
508 struct timeval tmptime;
510 if((nch = nAllocHid()))
512 Forbid();
513 if(nch->nch_ReadySigTask)
515 Signal(nch->nch_ReadySigTask, 1L<<nch->nch_ReadySignal);
517 Permit();
518 sigmask = (1L<<nch->nch_TaskMsgPort->mp_SigBit)|SIGBREAKF_CTRL_C;
519 buf = nch->nch_EP1Buf;
520 psdSendPipe(nch->nch_EP1Pipe, buf, nch->nch_EP1PktSize);
523 sigs = Wait(sigmask);
524 while((pp = (struct PsdPipe *) GetMsg(nch->nch_TaskMsgPort)))
526 if(pp == nch->nch_EP1Pipe)
528 ioerr = psdGetPipeError(pp);
529 if(ioerr == UHIOERR_RUNTPACKET)
531 KPRINTF(1, ("This should never happen. Something is wrong with the lowlevel driver!"));
532 ioerr = 0;
534 if(!ioerr)
536 KPRINTF(1, ("Data: %08lx %08lx\n", (*(ULONG *) buf), ((ULONG *) buf)[1]));
537 len = psdGetPipeActual(pp);
538 bufptr = buf;
539 if(len)
543 if(*bufptr & 0x80)
545 packet[0] = *bufptr;
546 packetpos = 1;
547 } else {
548 if(packetpos)
550 packet[packetpos] = *bufptr;
551 packetpos++;
554 if(packetpos == 5)
556 packetpos = 0;
557 qualifier = 0;
558 buts = packet[0] & 1;
560 xpos = (packet[1]<<7)|packet[2];
561 ypos = 2047 - ((packet[3]<<7)|packet[4]);
562 KPRINTF(2, ("Raw Coords %ld, %ld, %02lx, %ld\n", xpos, ypos, packet[0], nch->nch_RMBState));
563 switch(nch->nch_CDC->cdc_Rotate)
565 case 1: // 90°
566 tmp = ypos;
567 ypos = xpos;
568 xpos = 2047 - tmp;
569 break;
571 case 2: // 180°
572 ypos = 2047 - ypos;
573 xpos = 2047 - xpos;
574 break;
576 case 3: // 270°
577 tmp = xpos;
578 xpos = ypos;
579 ypos = 2047 - tmp;
580 break;
582 if(nch->nch_CDC->cdc_Mirror & 1)
584 xpos = 2047 - xpos;
586 if(nch->nch_CDC->cdc_Mirror & 2)
588 ypos = 2047 - ypos;
591 if(nch->nch_TrackDims)
593 buts = 0;
594 changed = FALSE;
595 if(xpos < nch->nch_CDC->cdc_MinX)
597 nch->nch_CDC->cdc_MinX = xpos;
598 changed = TRUE;
600 if(xpos > nch->nch_CDC->cdc_MaxX)
602 nch->nch_CDC->cdc_MaxX = xpos;
603 changed = TRUE;
605 if(ypos < nch->nch_CDC->cdc_MinY)
607 nch->nch_CDC->cdc_MinY = ypos;
608 changed = TRUE;
610 if(ypos > nch->nch_CDC->cdc_MaxY)
612 nch->nch_CDC->cdc_MaxY = ypos;
613 changed = TRUE;
615 Forbid();
616 if(changed && nch->nch_GUITask)
618 Signal(nch->nch_GUITask, 1UL<<nch->nch_TrackingSignal);
620 Permit();
621 } else {
622 if(xpos < nch->nch_CDC->cdc_MinX) xpos = nch->nch_CDC->cdc_MinX;
623 if(xpos > nch->nch_CDC->cdc_MaxX) xpos = nch->nch_CDC->cdc_MaxX;
624 if(ypos < nch->nch_CDC->cdc_MinY) ypos = nch->nch_CDC->cdc_MinY;
625 if(ypos > nch->nch_CDC->cdc_MaxY) ypos = nch->nch_CDC->cdc_MaxY;
627 xrange = nch->nch_CDC->cdc_MaxX - nch->nch_CDC->cdc_MinX + 1;
628 yrange = nch->nch_CDC->cdc_MaxY - nch->nch_CDC->cdc_MinY + 1;
630 xpos -= nch->nch_CDC->cdc_MinX;
631 ypos -= nch->nch_CDC->cdc_MinY;
633 if((buts & 1) && (nch->nch_CDC->cdc_RMBMode > 0))
635 if(nch->nch_RMBState == RMB_IDLE)
637 nch->nch_TouchSpotX = xpos;
638 nch->nch_TouchSpotY = ypos;
639 GetSysTime(&nch->nch_TouchTime);
640 tmptime.tv_secs = nch->nch_CDC->cdc_RMBDelay / 10;
641 tmptime.tv_micro = (nch->nch_CDC->cdc_RMBDelay % 10) * 100000;
642 AddTime(&nch->nch_TouchTime, &tmptime);
643 nch->nch_RMBState = RMB_LMBDOWN;
645 distx = xpos - nch->nch_TouchSpotX;
646 distx *= distx;
647 disty = ypos - nch->nch_TouchSpotY;
648 disty *= disty;
649 if(nch->nch_RMBState == RMB_LMBDOWN)
651 if((distx + disty > (nch->nch_CDC->cdc_RMBTolerance * nch->nch_CDC->cdc_RMBTolerance)))
653 // moved out of tolerance
654 nch->nch_RMBState = RMB_MOVEDTOOFAR;
655 } else {
656 GetSysTime(&tmptime);
657 if(CmpTime(&nch->nch_TouchTime, &tmptime) >= 0)
659 // activate RMB, but release LMB first
660 nch->nch_RMBState = RMB_RMBDOWN;
661 buts = 0;
665 else if(nch->nch_RMBState == RMB_RMBDOWN_LMBUP)
667 if(nch->nch_CDC->cdc_RMBMode == 2)
669 nch->nch_RMBState = RMB_RMBDOWN_LAST;
671 else if(nch->nch_CDC->cdc_RMBMode == 3)
673 GetSysTime(&tmptime);
674 if(DoubleClick(nch->nch_TouchTime.tv_secs, nch->nch_TouchTime.tv_micro, tmptime.tv_secs, tmptime.tv_micro))
676 nch->nch_RMBState = RMB_RMBDOWN_LAST;
677 } else {
678 nch->nch_RMBState = RMB_RMBDOWN;
679 GetSysTime(&nch->nch_TouchTime);
682 buts = 2;
684 else if(nch->nch_RMBState >= RMB_RMBDOWN)
686 buts = 2;
688 } else {
689 switch(nch->nch_CDC->cdc_RMBMode)
691 case 2: // 1-click sticky
692 case 3: // double click sticky
693 if(nch->nch_RMBState == RMB_RMBDOWN)
695 nch->nch_RMBState = RMB_RMBDOWN_LMBUP;
697 else if((nch->nch_RMBState == RMB_RMBDOWN_LAST) || (nch->nch_RMBState < RMB_RMBDOWN))
699 nch->nch_RMBState = RMB_IDLE;
700 break;
702 buts = 2;
703 break;
705 default:
706 nch->nch_RMBState = RMB_IDLE;
710 iecode = IECODE_NOBUTTON;
711 if(buts & 1)
713 qualifier |= IEQUALIFIER_LEFTBUTTON;
715 if(buts & 2)
717 qualifier |= IEQUALIFIER_RBUTTON;
719 if((buts^oldbuts) & 1)
721 iecode = (buts & 1) ? IECODE_LBUTTON : IECODE_LBUTTON|IECODE_UP_PREFIX;
723 else if((buts^oldbuts) & 2)
725 iecode = (buts & 2) ? IECODE_RBUTTON : IECODE_RBUTTON|IECODE_UP_PREFIX;
727 KPRINTF(1, ("Translated Coords %ld, %ld\n", xpos, ypos));
729 tagptr = nch->nch_TabTags;
730 nch->nch_FakeEvent.ie_EventAddress = &nch->nch_TabletEvent;
731 nch->nch_TabletEvent.ient_RangeX = xrange;
732 nch->nch_TabletEvent.ient_RangeY = yrange;
733 nch->nch_TabletEvent.ient_TabletX = xpos;
734 nch->nch_TabletEvent.ient_TabletY = ypos;
735 nch->nch_TabletEvent.ient_TagList = (struct TagItem *) tagptr;
736 *tagptr++ = TABLETA_ButtonBits;
737 *tagptr++ = buts;
738 *tagptr = TAG_END;
739 nch->nch_FakeEvent.ie_Class = IECLASS_NEWPOINTERPOS;
740 nch->nch_FakeEvent.ie_SubClass = IESUBCLASS_NEWTABLET;
741 nch->nch_FakeEvent.ie_Code = IECODE_NOBUTTON;
742 nch->nch_FakeEvent.ie_NextEvent = NULL;
743 nch->nch_FakeEvent.ie_Qualifier = qualifier;
744 nch->nch_InpIOReq->io_Data = &nch->nch_FakeEvent;
745 nch->nch_InpIOReq->io_Length = sizeof(struct InputEvent);
746 nch->nch_InpIOReq->io_Command = IND_WRITEEVENT;
747 DoIO((struct IORequest *) nch->nch_InpIOReq);
749 if(oldbuts != buts)
751 nch->nch_FakeEvent.ie_X = 0;
752 nch->nch_FakeEvent.ie_Y = 0;
753 nch->nch_FakeEvent.ie_Class = IECLASS_RAWMOUSE;
754 nch->nch_FakeEvent.ie_SubClass = 0;
755 nch->nch_FakeEvent.ie_Code = iecode;
756 nch->nch_FakeEvent.ie_NextEvent = NULL;
757 nch->nch_FakeEvent.ie_Qualifier = qualifier|IEQUALIFIER_RELATIVEMOUSE;
758 nch->nch_InpIOReq->io_Data = &nch->nch_FakeEvent;
759 nch->nch_InpIOReq->io_Length = sizeof(struct InputEvent);
760 nch->nch_InpIOReq->io_Command = IND_WRITEEVENT;
761 DoIO((struct IORequest *) nch->nch_InpIOReq);
762 oldbuts = buts;
765 bufptr++;
766 } while(--len);
768 } else {
769 KPRINTF(1, ("Int Pipe failed %ld\n", ioerr));
770 psdDelayMS(20);
772 psdSendPipe(nch->nch_EP1Pipe, buf, nch->nch_EP1PktSize);
773 break;
776 } while(!(sigs & SIGBREAKF_CTRL_C));
777 KPRINTF(20, ("Going down the river!\n"));
778 psdAbortPipe(nch->nch_EP1Pipe);
779 psdWaitPipe(nch->nch_EP1Pipe);
780 nFreeHid(nch);
783 AROS_USERFUNC_EXIT
785 /* \\\ */
787 /* /// "nAllocHid()" */
788 struct NepClassHid * nAllocHid(void)
790 struct Task *thistask;
791 struct NepClassHid *nch;
793 thistask = FindTask(NULL);
794 nch = thistask->tc_UserData;
797 if(!(nch->nch_Base = OpenLibrary("poseidon.library", 4)))
799 Alert(AG_OpenLib);
800 break;
802 if(!(nch->nch_HIntBase = OpenLibrary("intuition.library", 39)))
804 Alert(AG_OpenLib|AO_Intuition);
805 break;
807 nch->nch_Interface = psdFindInterface(nch->nch_Device, NULL, TAG_END);
808 if(!nch->nch_Interface)
810 KPRINTF(1, ("Ooops!?! No interfaces defined?\n"));
811 break;
814 psdGetAttrs(PGA_INTERFACE, nch->nch_Interface,
815 IFA_InterfaceNum, &nch->nch_IfNum,
816 TAG_END);
818 nch->nch_EP1 = psdFindEndpoint(nch->nch_Interface, NULL,
819 EA_IsIn, TRUE,
820 EA_TransferType, USEAF_INTERRUPT,
821 TAG_END);
822 if(!nch->nch_EP1)
824 KPRINTF(1, ("Ooops!?! No Endpoints defined?\n"));
825 break;
827 psdGetAttrs(PGA_ENDPOINT, nch->nch_EP1,
828 EA_MaxPktSize, &nch->nch_EP1PktSize,
829 TAG_END);
831 nch->nch_TimerIOReq.tr_node.io_Message.mn_Node.ln_Type = NT_REPLYMSG;
832 nch->nch_TimerIOReq.tr_node.io_Message.mn_ReplyPort = NULL;
833 nch->nch_TimerIOReq.tr_node.io_Message.mn_Length = sizeof(struct timerequest);
834 if(OpenDevice("timer.device", UNIT_MICROHZ, (struct IORequest *) &nch->nch_TimerIOReq, 0))
836 Alert(AG_OpenDev|AO_TimerDev);
837 break;
839 nch->nch_TimerBase = (struct Library *) nch->nch_TimerIOReq.tr_node.io_Device;
841 if((nch->nch_InpMsgPort = CreateMsgPort()))
843 if((nch->nch_InpIOReq = (struct IOStdReq *) CreateIORequest(nch->nch_InpMsgPort, sizeof(struct IOStdReq))))
845 if(!OpenDevice("input.device", 0, (struct IORequest *) nch->nch_InpIOReq, 0))
847 if((nch->nch_TaskMsgPort = CreateMsgPort()))
849 if((nch->nch_EP0Pipe = psdAllocPipe(nch->nch_Device, nch->nch_TaskMsgPort, NULL)))
851 if((nch->nch_EP1Pipe = psdAllocPipe(nch->nch_Device, nch->nch_TaskMsgPort, nch->nch_EP1)))
853 if((nch->nch_EP1Buf = psdAllocVec(nch->nch_EP1PktSize)))
855 psdSetAttrs(PGA_PIPE, nch->nch_EP1Pipe,
856 PPA_AllowRuntPackets, TRUE,
857 TAG_END);
858 nch->nch_Task = thistask;
859 return(nch);
861 psdFreePipe(nch->nch_EP1Pipe);
863 psdFreePipe(nch->nch_EP0Pipe);
865 DeleteMsgPort(nch->nch_TaskMsgPort);
867 CloseDevice((struct IORequest *) nch->nch_InpIOReq);
869 DeleteIORequest((struct IORequest *) nch->nch_InpIOReq);
871 DeleteMsgPort(nch->nch_InpMsgPort);
873 } while(FALSE);
874 CloseLibrary(nch->nch_HIntBase);
875 CloseLibrary(nch->nch_Base);
876 Forbid();
877 nch->nch_Task = NULL;
878 if(nch->nch_ReadySigTask)
880 Signal(nch->nch_ReadySigTask, 1L<<nch->nch_ReadySignal);
882 return(NULL);
884 /* \\\ */
886 /* /// "nFreeHid()" */
887 void nFreeHid(struct NepClassHid *nch)
889 psdFreeVec(nch->nch_EP1Buf);
890 psdFreePipe(nch->nch_EP1Pipe);
891 psdFreePipe(nch->nch_EP0Pipe);
892 DeleteMsgPort(nch->nch_TaskMsgPort);
893 CloseDevice((struct IORequest *) nch->nch_InpIOReq);
894 DeleteIORequest((struct IORequest *) nch->nch_InpIOReq);
895 DeleteMsgPort(nch->nch_InpMsgPort);
896 CloseDevice((struct IORequest *) &nch->nch_TimerIOReq);
897 CloseLibrary(nch->nch_HIntBase);
898 CloseLibrary(nch->nch_Base);
899 Forbid();
900 nch->nch_Task = NULL;
901 if(nch->nch_ReadySigTask)
903 Signal(nch->nch_ReadySigTask, 1L<<nch->nch_ReadySignal);
906 /* \\\ */
908 /**************************************************************************/
910 static const char *MirrorStrings[] =
912 "Off",
913 "Horizontal",
914 "Vertical",
915 "Both",
916 NULL
919 static const char *RotateStrings[] =
921 "Off",
922 "90°",
923 "180°",
924 "270°",
925 NULL
928 static const char *RMBModeStrings[] =
930 "Off",
931 "RMB until released",
932 "Next click releases RMB",
933 "Double click releases RMB",
934 NULL
937 /* /// "nGUITask()" */
938 AROS_UFH0(void, nGUITask)
940 AROS_USERFUNC_INIT
942 struct Task *thistask;
943 struct NepHidBase *nh;
944 struct NepClassHid *nch;
945 APTR pic;
947 thistask = FindTask(NULL);
948 #undef ps
949 #define ps nch->nch_PsdBase
950 #undef IntuitionBase
951 #define IntuitionBase nch->nch_IntBase
952 #undef MUIMasterBase
953 #define MUIMasterBase nch->nch_MUIBase
955 nch = thistask->tc_UserData;
956 nh = nch->nch_ClsBase;
958 ++nh->nh_Library.lib_OpenCnt;
959 if(!(MUIMasterBase = OpenLibrary(MUIMASTER_NAME, MUIMASTER_VMIN)))
961 KPRINTF(10, ("Couldn't open muimaster.library.\n"));
962 nGUITaskCleanup(nch);
963 return;
966 if(!(IntuitionBase = OpenLibrary("intuition.library", 39)))
968 KPRINTF(10, ("Couldn't open intuition.library.\n"));
969 nGUITaskCleanup(nch);
970 return;
972 if(!(ps = OpenLibrary("poseidon.library", 4)))
974 KPRINTF(10, ("Couldn't open poseidon.library.\n"));
975 nGUITaskCleanup(nch);
976 return;
979 nch->nch_App = ApplicationObject,
980 MUIA_Application_Title , (IPTR)libname,
981 MUIA_Application_Version , (IPTR)VERSION_STRING,
982 MUIA_Application_Copyright , (IPTR)"©2004-2009 Chris Hodges",
983 MUIA_Application_Author , (IPTR)"Chris Hodges <chrisly@platon42.de>",
984 MUIA_Application_Description, (IPTR)"Settings for the egalaxtouch.class",
985 MUIA_Application_Base , (IPTR)"EGALAXTOUCH",
986 MUIA_Application_HelpFile , (IPTR)"HELP:Poseidon.guide",
987 MUIA_Application_Menustrip , (IPTR)MenustripObject,
988 Child, (IPTR)MenuObjectT((IPTR)"Project"),
989 Child, (IPTR)(nch->nch_AboutMI = MenuitemObject,
990 MUIA_Menuitem_Title, (IPTR)"About...",
991 MUIA_Menuitem_Shortcut, (IPTR)"?",
992 End),
993 End,
994 Child, (IPTR)MenuObjectT((IPTR)"Settings"),
995 Child, (IPTR)(nch->nch_UseMI = MenuitemObject,
996 MUIA_Menuitem_Title, (IPTR)"Save",
997 MUIA_Menuitem_Shortcut, (IPTR)"S",
998 End),
999 Child, (IPTR)(nch->nch_SetDefaultMI = MenuitemObject,
1000 MUIA_Menuitem_Title, (IPTR)"Save as Default",
1001 MUIA_Menuitem_Shortcut, (IPTR)"D",
1002 End),
1003 Child, (IPTR)MenuitemObject,
1004 MUIA_Menuitem_Title, (IPTR)NM_BARLABEL,
1005 End,
1006 Child, (IPTR)(nch->nch_MUIPrefsMI = MenuitemObject,
1007 MUIA_Menuitem_Title, (IPTR)"MUI Settings",
1008 MUIA_Menuitem_Shortcut, (IPTR)"M",
1009 End),
1010 End,
1011 End,
1013 SubWindow, (IPTR)(nch->nch_MainWindow = WindowObject,
1014 MUIA_Window_ID , MAKE_ID('M','A','I','N'),
1015 MUIA_Window_Title, (IPTR)libname,
1016 MUIA_HelpNode, (IPTR)libname,
1018 WindowContents, (IPTR)VGroup,
1019 Child, (IPTR)VGroup, GroupFrameT((IPTR)(nch->nch_Interface ? "Device Settings" : "Default Device Settings")),
1020 Child, (IPTR)VGroup, GroupFrameT((IPTR)"Touchscreen Calibration"),
1021 Child, (IPTR)ColGroup(4),
1022 Child, (IPTR)Label((IPTR) "MinX:"),
1023 Child, (IPTR)(nch->nch_MinXObj = SliderObject, SliderFrame,
1024 MUIA_CycleChain, 1,
1025 MUIA_Numeric_Min, 0,
1026 MUIA_Numeric_Max, 1919,
1027 MUIA_Numeric_Value, nch->nch_CDC->cdc_MinX,
1028 End),
1029 Child, (IPTR)Label((IPTR) "MaxX:"),
1030 Child, (IPTR)(nch->nch_MaxXObj = SliderObject, SliderFrame,
1031 MUIA_CycleChain, 1,
1032 MUIA_Numeric_Min, 128,
1033 MUIA_Numeric_Max, 2047,
1034 MUIA_Numeric_Value, nch->nch_CDC->cdc_MaxX,
1035 End),
1036 Child, (IPTR)Label((IPTR) "MinY:"),
1037 Child, (IPTR)(nch->nch_MinYObj = SliderObject, SliderFrame,
1038 MUIA_CycleChain, 1,
1039 MUIA_Numeric_Min, 0,
1040 MUIA_Numeric_Max, 1919,
1041 MUIA_Numeric_Value, nch->nch_CDC->cdc_MinY,
1042 End),
1043 Child, (IPTR)Label((IPTR) "MaxY:"),
1044 Child, (IPTR)(nch->nch_MaxYObj = SliderObject, SliderFrame,
1045 MUIA_CycleChain, 1,
1046 MUIA_Numeric_Min, 128,
1047 MUIA_Numeric_Max, 2047,
1048 MUIA_Numeric_Value, nch->nch_CDC->cdc_MaxY,
1049 End),
1050 Child, (IPTR)Label((IPTR) "Mirror:"),
1051 Child, (IPTR)(nch->nch_MirrorObj = CycleObject,
1052 MUIA_Cycle_Entries, (IPTR)MirrorStrings,
1053 MUIA_Cycle_Active, nch->nch_CDC->cdc_Mirror,
1054 End),
1055 Child, (IPTR)Label((IPTR) "Rotate:"),
1056 Child, (IPTR)(nch->nch_RotateObj = CycleObject,
1057 MUIA_Cycle_Entries, (IPTR)RotateStrings,
1058 MUIA_Cycle_Active, nch->nch_CDC->cdc_Rotate,
1059 End),
1060 End,
1061 Child, (IPTR)HGroup,
1062 Child, (IPTR)(nch->nch_TrackDimsObj = ImageObject, ImageButtonFrame,
1063 MUIA_Background, MUII_ButtonBack,
1064 MUIA_CycleChain, 1,
1065 MUIA_InputMode, MUIV_InputMode_Toggle,
1066 MUIA_Image_Spec, MUII_CheckMark,
1067 MUIA_Image_FreeVert, TRUE,
1068 MUIA_Selected, FALSE,
1069 MUIA_ShowSelState, FALSE,
1070 End),
1071 Child, (IPTR)Label((IPTR) "Track Dimensions by input (disables LMB/RMB)"),
1072 Child, (IPTR)HSpace(0),
1073 End,
1074 End,
1075 Child, (IPTR)ColGroup(2), GroupFrameT("Right Mouse Button Emulation"),
1076 Child, (IPTR)Label((IPTR) "Mode:"),
1077 Child, (IPTR)(nch->nch_RMBModeObj = CycleObject,
1078 MUIA_Cycle_Entries, (IPTR)RMBModeStrings,
1079 MUIA_Cycle_Active, nch->nch_CDC->cdc_RMBMode,
1080 End),
1081 Child, (IPTR)Label((IPTR) "Activation Delay:"),
1082 Child, (IPTR)(nch->nch_RMBDelayObj = SliderObject, SliderFrame,
1083 MUIA_CycleChain, 1,
1084 MUIA_Numeric_Min, 5,
1085 MUIA_Numeric_Max, 50,
1086 MUIA_Numeric_Value, nch->nch_CDC->cdc_RMBDelay,
1087 MUIA_Numeric_Format, (IPTR)"%ld00ms",
1088 End),
1089 Child, (IPTR)Label((IPTR) "Allowed Jitter:"),
1090 Child, (IPTR)(nch->nch_RMBToleranceObj = SliderObject, SliderFrame,
1091 MUIA_CycleChain, 1,
1092 MUIA_Numeric_Min, 0,
1093 MUIA_Numeric_Max, 100,
1094 MUIA_Numeric_Value, nch->nch_CDC->cdc_RMBTolerance,
1095 MUIA_Numeric_Format, (IPTR)"%ld units",
1096 End),
1097 End,
1098 End,
1099 Child, (IPTR)VSpace(0),
1100 Child, (IPTR)HGroup,
1101 MUIA_Group_SameWidth, TRUE,
1102 Child, (IPTR)(nch->nch_UseObj = TextObject, ButtonFrame,
1103 MUIA_ShowMe, (IPTR)nch->nch_Interface,
1104 MUIA_Background, MUII_ButtonBack,
1105 MUIA_CycleChain, 1,
1106 MUIA_InputMode, MUIV_InputMode_RelVerify,
1107 MUIA_Text_Contents, (IPTR)"\33c Save ",
1108 End),
1109 Child, (IPTR)(nch->nch_SetDefaultObj = TextObject, ButtonFrame,
1110 MUIA_Background, MUII_ButtonBack,
1111 MUIA_CycleChain, 1,
1112 MUIA_InputMode, MUIV_InputMode_RelVerify,
1113 MUIA_Text_Contents, (IPTR)(nch->nch_Interface ? "\33c Save as Default " : "\33c Save Defaults "),
1114 End),
1115 Child, (IPTR)(nch->nch_CloseObj = TextObject, ButtonFrame,
1116 MUIA_Background, MUII_ButtonBack,
1117 MUIA_CycleChain, 1,
1118 MUIA_InputMode, MUIV_InputMode_RelVerify,
1119 MUIA_Text_Contents, (IPTR)"\33c Use ",
1120 End),
1121 End,
1122 End,
1123 End),
1124 End;
1126 if(!nch->nch_App)
1128 KPRINTF(10, ("Couldn't create application\n"));
1129 nGUITaskCleanup(nch);
1130 return;
1133 DoMethod(nch->nch_MainWindow, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
1134 nch->nch_App, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
1135 DoMethod(nch->nch_UseObj, MUIM_Notify, MUIA_Pressed, FALSE,
1136 nch->nch_App, 2, MUIM_Application_ReturnID, ID_STORE_CONFIG);
1137 DoMethod(nch->nch_SetDefaultObj, MUIM_Notify, MUIA_Pressed, FALSE,
1138 nch->nch_App, 2, MUIM_Application_ReturnID, ID_DEF_CONFIG);
1139 DoMethod(nch->nch_CloseObj, MUIM_Notify, MUIA_Pressed, FALSE,
1140 nch->nch_App, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
1142 DoMethod(nch->nch_MinXObj, MUIM_Notify, MUIA_Numeric_Value, MUIV_EveryTime,
1143 nch->nch_App, 2, MUIM_Application_ReturnID, ID_UPDATE_LIMITSMIN);
1144 DoMethod(nch->nch_MaxXObj, MUIM_Notify, MUIA_Numeric_Value, MUIV_EveryTime,
1145 nch->nch_App, 2, MUIM_Application_ReturnID, ID_UPDATE_LIMITSMAX);
1146 DoMethod(nch->nch_MinYObj, MUIM_Notify, MUIA_Numeric_Value, MUIV_EveryTime,
1147 nch->nch_App, 2, MUIM_Application_ReturnID, ID_UPDATE_LIMITSMIN);
1148 DoMethod(nch->nch_MaxYObj, MUIM_Notify, MUIA_Numeric_Value, MUIV_EveryTime,
1149 nch->nch_App, 2, MUIM_Application_ReturnID, ID_UPDATE_LIMITSMAX);
1151 DoMethod(nch->nch_MirrorObj, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime,
1152 nch->nch_App, 2, MUIM_Application_ReturnID, ID_UPDATE_MIRRORROT);
1153 DoMethod(nch->nch_RotateObj, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime,
1154 nch->nch_App, 2, MUIM_Application_ReturnID, ID_UPDATE_MIRRORROT);
1155 DoMethod(nch->nch_TrackDimsObj, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
1156 nch->nch_App, 2, MUIM_Application_ReturnID, ID_UPDATE_MIRRORROT);
1158 DoMethod(nch->nch_RMBModeObj, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime,
1159 nch->nch_App, 2, MUIM_Application_ReturnID, ID_UPDATE_MIRRORROT);
1160 DoMethod(nch->nch_RMBDelayObj, MUIM_Notify, MUIA_Numeric_Value, MUIV_EveryTime,
1161 nch->nch_App, 2, MUIM_Application_ReturnID, ID_UPDATE_MIRRORROT);
1162 DoMethod(nch->nch_RMBToleranceObj, MUIM_Notify, MUIA_Numeric_Value, MUIV_EveryTime,
1163 nch->nch_App, 2, MUIM_Application_ReturnID, ID_UPDATE_MIRRORROT);
1165 DoMethod(nch->nch_AboutMI, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
1166 nch->nch_App, 2, MUIM_Application_ReturnID, ID_ABOUT);
1167 DoMethod(nch->nch_UseMI, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
1168 nch->nch_App, 2, MUIM_Application_ReturnID, ID_STORE_CONFIG);
1169 DoMethod(nch->nch_SetDefaultMI, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
1170 nch->nch_App, 2, MUIM_Application_ReturnID, ID_DEF_CONFIG);
1171 DoMethod(nch->nch_MUIPrefsMI, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
1172 nch->nch_App, 2, MUIM_Application_OpenConfigWindow, 0);
1174 IPTR isopen = 0;
1175 IPTR iconify = 0;
1176 ULONG sigs;
1177 ULONG sigmask;
1178 LONG retid;
1180 get(nch->nch_App, MUIA_Application_Iconified, &iconify);
1181 set(nch->nch_MainWindow, MUIA_Window_Open, TRUE);
1182 get(nch->nch_MainWindow, MUIA_Window_Open, &isopen);
1183 if(!(isopen || iconify))
1185 nGUITaskCleanup(nch);
1186 return;
1188 nch->nch_TrackingSignal = AllocSignal(-1);
1189 sigmask = (1<<nch->nch_TrackingSignal);
1192 retid = DoMethod(nch->nch_App, MUIM_Application_NewInput, &sigs);
1193 switch(retid)
1195 case ID_UPDATE_LIMITSMIN:
1196 get(nch->nch_MinXObj, MUIA_Numeric_Value, &nch->nch_CDC->cdc_MinX);
1197 if(nch->nch_CDC->cdc_MinX + 128 >= nch->nch_CDC->cdc_MaxX)
1199 set(nch->nch_MaxXObj, MUIA_Numeric_Value, nch->nch_CDC->cdc_MinX + 128);
1201 get(nch->nch_MinYObj, MUIA_Numeric_Value, &nch->nch_CDC->cdc_MinY);
1202 if(nch->nch_CDC->cdc_MinY + 128 >= nch->nch_CDC->cdc_MaxY)
1204 set(nch->nch_MaxYObj, MUIA_Numeric_Value, nch->nch_CDC->cdc_MinY + 128);
1206 break;
1208 case ID_UPDATE_LIMITSMAX:
1209 get(nch->nch_MaxXObj, MUIA_Numeric_Value, &nch->nch_CDC->cdc_MaxX);
1210 if(nch->nch_CDC->cdc_MinX + 128 >= nch->nch_CDC->cdc_MaxX)
1212 set(nch->nch_MinXObj, MUIA_Numeric_Value, nch->nch_CDC->cdc_MaxX - 128);
1214 get(nch->nch_MaxYObj, MUIA_Numeric_Value, &nch->nch_CDC->cdc_MaxY);
1215 if(nch->nch_CDC->cdc_MinY + 128 >= nch->nch_CDC->cdc_MaxY)
1217 set(nch->nch_MinYObj, MUIA_Numeric_Value, nch->nch_CDC->cdc_MaxY - 128);
1219 break;
1221 case ID_UPDATE_MIRRORROT:
1223 ULONG trackdims = 0;
1224 get(nch->nch_MirrorObj, MUIA_Cycle_Active, &nch->nch_CDC->cdc_Mirror);
1225 get(nch->nch_RotateObj, MUIA_Cycle_Active, &nch->nch_CDC->cdc_Rotate);
1226 get(nch->nch_RMBModeObj, MUIA_Cycle_Active, &nch->nch_CDC->cdc_RMBMode);
1227 get(nch->nch_RMBDelayObj, MUIA_Numeric_Value, &nch->nch_CDC->cdc_RMBDelay);
1228 get(nch->nch_RMBToleranceObj, MUIA_Numeric_Value, &nch->nch_CDC->cdc_RMBTolerance);
1229 get(nch->nch_TrackDimsObj, MUIA_Selected, &trackdims);
1230 if(trackdims)
1232 if(!nch->nch_TrackDims)
1234 nch->nch_CDC->cdc_MinX = 1024-64;
1235 nch->nch_CDC->cdc_MinY = 1024-64;
1236 nch->nch_CDC->cdc_MaxX = 1024+64;
1237 nch->nch_CDC->cdc_MaxY = 1024+64;
1238 set(nch->nch_MinXObj, MUIA_Disabled, TRUE);
1239 set(nch->nch_MaxXObj, MUIA_Disabled, TRUE);
1240 set(nch->nch_MinYObj, MUIA_Disabled, TRUE);
1241 set(nch->nch_MaxYObj, MUIA_Disabled, TRUE);
1243 nch->nch_TrackDims = TRUE;
1244 } else {
1245 if(nch->nch_TrackDims)
1247 set(nch->nch_MinXObj, MUIA_Disabled, FALSE);
1248 set(nch->nch_MaxXObj, MUIA_Disabled, FALSE);
1249 set(nch->nch_MinYObj, MUIA_Disabled, FALSE);
1250 set(nch->nch_MaxYObj, MUIA_Disabled, FALSE);
1252 nch->nch_TrackDims = FALSE;
1254 break;
1257 case ID_DEF_CONFIG:
1258 case ID_STORE_CONFIG:
1259 case MUIV_Application_ReturnID_Quit:
1260 if(retid == ID_DEF_CONFIG)
1262 pic = psdGetClsCfg(libname);
1263 if(!pic)
1265 psdSetClsCfg(libname, NULL);
1266 pic = psdGetClsCfg(libname);
1268 if(pic)
1270 if(psdAddCfgEntry(pic, nch->nch_CDC))
1272 psdSaveCfgToDisk(NULL, FALSE);
1276 if(nch->nch_Device)
1278 pic = psdGetUsbDevCfg(libname, nch->nch_DevIDString, NULL);
1279 if(!pic)
1281 psdSetUsbDevCfg(libname, nch->nch_DevIDString, NULL, NULL);
1282 pic = psdGetUsbDevCfg(libname, nch->nch_DevIDString, NULL);
1284 if(pic)
1286 if(psdAddCfgEntry(pic, nch->nch_CDC))
1288 if(retid != MUIV_Application_ReturnID_Quit)
1290 psdSaveCfgToDisk(NULL, FALSE);
1292 retid = MUIV_Application_ReturnID_Quit;
1295 } else {
1296 retid = MUIV_Application_ReturnID_Quit;
1298 break;
1300 case ID_ABOUT:
1301 MUI_RequestA(nch->nch_App, nch->nch_MainWindow, 0, NULL, "Blimey!", VERSION_STRING, NULL);
1302 break;
1304 if(nch->nch_TrackDims)
1306 nnset(nch->nch_MinXObj, MUIA_Numeric_Value, nch->nch_CDC->cdc_MinX);
1307 nnset(nch->nch_MaxXObj, MUIA_Numeric_Value, nch->nch_CDC->cdc_MaxX);
1308 nnset(nch->nch_MinYObj, MUIA_Numeric_Value, nch->nch_CDC->cdc_MinY);
1309 nnset(nch->nch_MaxYObj, MUIA_Numeric_Value, nch->nch_CDC->cdc_MaxY);
1311 if(retid == MUIV_Application_ReturnID_Quit)
1313 break;
1315 if(sigs)
1317 sigs = Wait(sigs | sigmask | SIGBREAKF_CTRL_C);
1318 if(sigs & SIGBREAKF_CTRL_C)
1320 break;
1323 } while(TRUE);
1324 FreeSignal(nch->nch_TrackingSignal);
1325 nch->nch_TrackingSignal = -1;
1326 nch->nch_TrackDims = FALSE;
1327 set(nch->nch_MainWindow, MUIA_Window_Open, FALSE);
1329 nGUITaskCleanup(nch);
1331 AROS_USERFUNC_EXIT
1333 /* \\\ */
1335 /* /// "nGUITaskCleanup()" */
1336 void nGUITaskCleanup(struct NepClassHid *nch)
1338 if(nch->nch_App)
1340 MUI_DisposeObject(nch->nch_App);
1341 nch->nch_App = NULL;
1343 if(MUIMasterBase)
1345 CloseLibrary(MUIMasterBase);
1346 MUIMasterBase = NULL;
1348 if(IntuitionBase)
1350 CloseLibrary(IntuitionBase);
1351 IntuitionBase = NULL;
1353 if(ps)
1355 CloseLibrary(ps);
1356 ps = NULL;
1358 Forbid();
1359 nch->nch_GUIBinding = NULL;
1360 nch->nch_GUITask = NULL;
1361 if(nch->nch_ReadySigTask)
1363 Signal(nch->nch_ReadySigTask, 1L<<nch->nch_ReadySignal);
1365 --nch->nch_ClsBase->nh_Library.lib_OpenCnt;
1367 /* \\\ */