home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 499.lha / InputDeviceToolKit / input.lzh / src / DeviceToolKits / Input / test_shared / test6.c < prev    next >
C/C++ Source or Header  |  1991-01-05  |  3KB  |  139 lines

  1. #include <stdio.h>
  2.  
  3. #include "DeviceToolKits/Input.h"
  4. #ifndef  TESTPROTO
  5. #define  NO_PRAGMAS  1
  6. #endif
  7. #include "DeviceToolKits/proto/Input.h"
  8. #include "DeviceToolKits/InputBase.h"
  9.  
  10. DTInput_t                  Unit0;
  11. BYTE                       port;
  12. BYTE                       type;
  13. struct   GamePortTrigger   trigger;
  14.  
  15. main(argc,argv)
  16. int   argc;
  17. char  *argv[];
  18. {
  19.    int   timeout;
  20.    int   xdelta;
  21.    int   ydelta;
  22.    long  status;
  23.  
  24.    if (argc != 4) {
  25.       fprintf(stderr,"Usage: %s timeout x-delta y-delta\n",argv[0]);
  26.       fflush(stderr);
  27.       exit(1);
  28.    }
  29.  
  30.    timeout = atoi(argv[1]);
  31.    xdelta = atoi(argv[2]);
  32.    ydelta = atoi(argv[3]);
  33.  
  34. #ifdef   TESTSHARED
  35. /*  Open the Input library  */
  36.  
  37.    DTInputOpen(DTINPUTREV);
  38. #endif
  39.  
  40. /*  Try to initialize unit 0 of the Input  */
  41.  
  42.    printf("Make sure a joystick is connected to the right port\n");
  43.    printf("for this test.\n");
  44.    fflush(stdout);
  45.  
  46.    if ((Unit0 = DTInputCreate(&status)) == NULL) {
  47.       fprintf(stderr,"Error initializing unit 0 = %ld.\n",status);
  48.       fflush(stderr);
  49.       goto cleanup;
  50.    }
  51.  
  52.    fprintf(stderr,"Unit0 = %lX\n",(long) Unit0);
  53.    fflush(stderr);
  54.  
  55. /*  Set the input port to the right port  */
  56.  
  57.    port = 1;
  58.    if ((status = DTInputSetMPort(Unit0,&port)) != 0) {
  59.       fprintf(stderr,"Error setting unit 0 port = %ld,%ld.\n",
  60.                status,Unit0->in_error);
  61.       fflush(stderr);
  62.       goto cleanup;
  63.    }
  64.  
  65. /*  Set the input controller to an absolute joystick  */
  66.  
  67.    type = GPCT_ABSJOYSTICK;
  68.    if ((status = DTInputSetMType(Unit0,&type)) != 0) {
  69.       fprintf(stderr,"Error setting unit 0 type = %ld,%ld.\n",
  70.                status,Unit0->in_error);
  71.       fflush(stderr);
  72.       goto cleanup;
  73.    }
  74.  
  75. /*  Set the input trigger for an absolute joystick  */
  76.  
  77.    trigger.gpt_Keys = GPTF_UPKEYS | GPTF_DOWNKEYS;
  78.    trigger.gpt_Timeout = timeout;
  79.    trigger.gpt_XDelta = xdelta;
  80.    trigger.gpt_YDelta = ydelta;
  81.  
  82.    if ((status = DTInputSetMTrigger(Unit0,&trigger)) != 0) {
  83.       fprintf(stderr,"Error setting unit 0 trigger = %ld,%ld.\n",
  84.                status,Unit0->in_error);
  85.       fflush(stderr);
  86.       goto cleanup;
  87.    }
  88.  
  89. /*  Wait while the user plays  */
  90.  
  91.    printf("In 30 seconds, the pointer control will revert to the mouse.\n");
  92.    printf("Try moving the pointer with the joystick.\n");
  93.    fflush(stdout);
  94.    Delay(30L*60L);
  95.  
  96. /*  Set the input port back to the left port  */
  97.  
  98.    port = 0;
  99.    if ((status = DTInputSetMPort(Unit0,&port)) != 0) {
  100.       fprintf(stderr,"Error setting unit 0 port = %ld,%ld.\n",
  101.                status,Unit0->in_error);
  102.       fflush(stderr);
  103.       goto cleanup;
  104.    }
  105.  
  106. /*  Set the input controller to a mouse  */
  107.  
  108.    type = GPCT_MOUSE;
  109.    if ((status = DTInputSetMType(Unit0,&type)) != 0) {
  110.       fprintf(stderr,"Error setting unit 0 type = %ld,%ld.\n",
  111.                status,Unit0->in_error);
  112.       fflush(stderr);
  113.       goto cleanup;
  114.    }
  115.  
  116. /*  Set the input trigger for a mouse  */
  117.  
  118.    trigger.gpt_Keys = GPTF_UPKEYS | GPTF_DOWNKEYS;
  119.    trigger.gpt_Timeout = 0;
  120.    trigger.gpt_XDelta = 1;
  121.    trigger.gpt_YDelta = 1;
  122.  
  123.    if ((status = DTInputSetMTrigger(Unit0,&trigger)) != 0) {
  124.       fprintf(stderr,"Error setting unit 0 trigger = %ld,%ld.\n",
  125.                status,Unit0->in_error);
  126.       fflush(stderr);
  127.       goto cleanup;
  128.    }
  129.  
  130. /*  Free the stuff  */
  131.  
  132. cleanup:
  133.    DTInputFree(Unit0);
  134. #ifdef   TESTSHARED
  135.    DTInputClose();
  136. #endif
  137. }
  138.  
  139.