home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 4 / FreshFish_May-June1994.bin / bbs / may94 / os20 / cdity / wacom.lha / Wacom / Develop / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-15  |  9.7 KB  |  255 lines

  1. /***********************************************************************/
  2. /* WACOM-Digitizer Driver            (C) 1993-1994 by ROLAND SCHWINGEL */
  3. /***********************************************************************/
  4. /* Demoprogram for obtaining Pressure Data from the Driver             */
  5. /*                                                                     */
  6. /* Prints all Data which is provided by the Driver in a Window         */
  7. /* (only if Window is activated)                                       */
  8. /***********************************************************************/
  9.  
  10. /* INCLUDES ************/
  11. #include <stdio.h>
  12.  
  13. #include <exec/exec.h>
  14. #include <proto/exec.h>
  15. #include <clib/exec_protos.h>
  16.  
  17. #include <intuition/intuition.h>
  18. #include <proto/intuition.h>
  19. #include <clib/intuition_protos.h>
  20.  
  21. #include "Wacom.h"             /* here is all the Wacomdata defined */
  22.  
  23. /* global Variables ****/
  24. /* external */
  25. extern struct ExecBase           *SysBase;
  26.  
  27. /* local */
  28. struct IntuitionBase             *IntuitionBase;
  29.  
  30. char *ITexts[]=
  31. {
  32.  "Sync           = %d",
  33.  "Driver_running = %d",
  34.  "Wacom_Series   = %d",
  35.  "Beeper         = %d",
  36.  "Mode           = %d",
  37.  "MB_Emu         = %d",
  38.  "Pressure_Limit = %03d",
  39.  "Pressure       = %03d",
  40.  "input_device   = %d",
  41.  "Buttons        = %02d",
  42.  "Tablett_Max_X  = %06ld",
  43.  "Tablett_Max_Y  = %06ld",
  44.  "Tablett_X      = %06ld",
  45.  "Tablett_Y      = %06ld",
  46.  "Set_Mouse      = %d",
  47.  "Commandset     = %d",
  48.  "Multi_Mode     = %d",
  49.  "Multi_Mouse    = %d",
  50.  "Macrokey       = %02d",
  51.  "MM_Dig_Buttons = %02d",
  52.  "MM_Dig_X       = %06ld",
  53.  "MM_Dig_Y       = %06ld"
  54. };
  55.  
  56. struct TextAttr DefFont={(STRPTR)"topaz.font",TOPAZ_EIGHTY,FS_NORMAL     ,FPF_ROMFONT};
  57. struct IntuiText IText={1,0,JAM2,0,0,&DefFont, NULL,NULL};
  58.  
  59. /* Version-Tag ***************************/
  60. UBYTE *vers="$VER: Get_Pressure V1.2 ("__TIME__" "__DATE__") by Roland Schwingel.";
  61.  
  62. /* Prototypes **********/
  63.  
  64. #ifdef __SASC
  65. void __regargs      __chkabort(void);  /* Disable SAS/C CTRL-C Check */
  66. #endif
  67. int                   main(void);
  68.  
  69. /***********************************************************************/
  70. /* main()                                                              */
  71. /***********************************************************************/
  72. int main (void)
  73. {
  74. int                         retval=21;
  75. struct MsgPort             *Wacom_data_Port;         /* This is the way where we get the Data */
  76. struct MsgPort             *Our_Port;
  77. struct WacomMSG             WMess;
  78. struct Window              *Win;
  79. struct RastPort            *WinRP;
  80. struct IntuiMessage        *IMess;
  81. BOOL                        cont=TRUE;
  82. ULONG                       class,Sigrcvd;
  83. char                        buffer[80];
  84.  
  85.  /* First check if our MsgPort is here - means if Wacom Driver program is running */
  86.  if(FindPort(WACOM_PORT_NAME))
  87.  {
  88.   /* Now open intution.library */
  89.   if(IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",37L))
  90.   {
  91.    /* open the Window */
  92.    if(Win=OpenWindowTags(NULL,WA_Left,0,WA_Top,12,WA_Width,220,WA_Height,215,
  93.                               WA_IDCMP,  IDCMP_CLOSEWINDOW|IDCMP_INTUITICKS,
  94.                               WA_Flags,  WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE,
  95.                               WA_Title,  "How to get the Data", TAG_DONE))
  96.    {
  97.     /* Get the Rastport */
  98.     WinRP=Win->RPort;
  99.  
  100.     /* Install our MessagePort */
  101.     if(Our_Port=CreateMsgPort())
  102.     {
  103.      /* Set up the Message */
  104.      WMess.Mess.mn_Node.ln_Type=NT_MESSAGE;
  105.      WMess.Mess.mn_Length=sizeof(struct WacomMSG);
  106.      WMess.Mess.mn_ReplyPort=Our_Port;
  107.  
  108.      IText.IText=buffer;         /* Pointer to Text */
  109.      while(cont)
  110.      {
  111.       /* Wait for Window or CTRL-C Event */
  112.       Sigrcvd=Wait(1L << Win->UserPort->mp_SigBit|SIGBREAKF_CTRL_C);
  113.       {
  114.        /* Check CTRL-C */
  115.        if(Sigrcvd & SIGBREAKF_CTRL_C)
  116.         cont=FALSE;
  117.  
  118.        /* Check Event from Window */
  119.        if(Sigrcvd & 1L << Win->UserPort->mp_SigBit)
  120.        {
  121.         while(IMess=(struct IntuiMessage *)GetMsg(Win->UserPort))
  122.         {
  123.          class=IMess->Class;
  124.          ReplyMsg((struct Message *)IMess);     /* Send Msg back to Intuition */
  125.  
  126.          switch(class)
  127.          {
  128.           case IDCMP_CLOSEWINDOW:     cont=FALSE;      /* Somebody pushed the Closebutton */
  129.                                       break;
  130.  
  131.           case IDCMP_INTUITICKS:      /* This is only a Demo Programm in YOUR Porgramm you shouldn't use
  132.                                          INTUITICKS to read the Wacom Infos. */
  133.  
  134.                                       /* Send Request for Data */
  135.                                       Wacom_data_Port=FindPort(WACOM_PORT_NAME);
  136.                                       if(Wacom_data_Port)
  137.                                       {
  138.                                        PutMsg(Wacom_data_Port,(struct Message *)&WMess);
  139.  
  140.                                        /* Wait for Reply */
  141.                                        WaitPort(Our_Port);
  142.  
  143.                                        /* Print all inquired Data */
  144.                                        if(GetMsg(Our_Port))
  145.                                        {
  146.                                         /* Wacom_Driver writes its response directly into WMess */
  147.                                         sprintf(buffer,ITexts[0],WMess.WacomInfo.Sync);
  148.                                         PrintIText(WinRP,&IText,10,12);
  149.  
  150.                                         sprintf(buffer,ITexts[1],WMess.WacomInfo.Driver_running);
  151.                                         PrintIText(WinRP,&IText,10,21);
  152.  
  153.                                         sprintf(buffer,ITexts[2],WMess.WacomInfo.Wacom_Series);
  154.                                         PrintIText(WinRP,&IText,10,30);
  155.  
  156.                                         sprintf(buffer,ITexts[3],WMess.WacomInfo.Beeper);
  157.                                         PrintIText(WinRP,&IText,10,39);
  158.  
  159.                                         sprintf(buffer,ITexts[4],WMess.WacomInfo.Mode);
  160.                                         PrintIText(WinRP,&IText,10,48);
  161.  
  162.                                         sprintf(buffer,ITexts[5],WMess.WacomInfo.MB_Emu);
  163.                                         PrintIText(WinRP,&IText,10,57);
  164.  
  165.                                         sprintf(buffer,ITexts[6],WMess.WacomInfo.Pressure_Limit);
  166.                                         PrintIText(WinRP,&IText,10,66);
  167.  
  168.                                         sprintf(buffer,ITexts[7],WMess.WacomInfo.Pressure);
  169.                                         PrintIText(WinRP,&IText,10,75);
  170.  
  171.                                         sprintf(buffer,ITexts[8],WMess.WacomInfo.input_device);
  172.                                         PrintIText(WinRP,&IText,10,84);
  173.  
  174.                                         sprintf(buffer,ITexts[9],WMess.WacomInfo.Buttons);
  175.                                         PrintIText(WinRP,&IText,10,93);
  176.  
  177.                                         sprintf(buffer,ITexts[10],WMess.WacomInfo.Tablett_Max_X);
  178.                                         PrintIText(WinRP,&IText,10,102);
  179.  
  180.                                         sprintf(buffer,ITexts[11],WMess.WacomInfo.Tablett_Max_Y);
  181.                                         PrintIText(WinRP,&IText,10,111);
  182.  
  183.                                         sprintf(buffer,ITexts[12],WMess.WacomInfo.Tablett_X);
  184.                                         PrintIText(WinRP,&IText,10,120);
  185.  
  186.                                         sprintf(buffer,ITexts[13],WMess.WacomInfo.Tablett_Y);
  187.                                         PrintIText(WinRP,&IText,10,129);
  188.  
  189.                                         sprintf(buffer,ITexts[14],WMess.WacomInfo.Set_Mouse);
  190.                                         PrintIText(WinRP,&IText,10,138);
  191.  
  192.                                         sprintf(buffer,ITexts[15],WMess.WacomInfo.Commandset);
  193.                                         PrintIText(WinRP,&IText,10,147);
  194.  
  195.                                         sprintf(buffer,ITexts[16],WMess.WacomInfo.Multi_Mode);
  196.                                         PrintIText(WinRP,&IText,10,156);
  197.  
  198.                                         sprintf(buffer,ITexts[17],WMess.WacomInfo.Multi_Mouse);
  199.                                         PrintIText(WinRP,&IText,10,165);
  200.  
  201.                                         sprintf(buffer,ITexts[18],WMess.WacomInfo.Macrokey);
  202.                                         PrintIText(WinRP,&IText,10,174);
  203.  
  204.                                         sprintf(buffer,ITexts[19],WMess.WacomInfo.MM_Dig_Buttons);
  205.                                         PrintIText(WinRP,&IText,10,183);
  206.  
  207.                                         sprintf(buffer,ITexts[20],WMess.WacomInfo.MM_Dig_X);
  208.                                         PrintIText(WinRP,&IText,10,192);
  209.  
  210.                                         sprintf(buffer,ITexts[21],WMess.WacomInfo.MM_Dig_Y);
  211.                                         PrintIText(WinRP,&IText,10,201);
  212.                                        }
  213.                                       }
  214.                                       break;
  215.  
  216.          }
  217.  
  218.         }
  219.        }
  220.       }
  221.      }
  222.  
  223.      /* get rid of our port */
  224.      DeleteMsgPort(Our_Port);
  225.     }
  226.     else
  227.      printf("Unable to install a Message Port !!\n");
  228.  
  229.     /* Close Window */
  230.     CloseWindow(Win);
  231.    }
  232.    else
  233.     printf("Can't open Window !!\n");
  234.  
  235.    /* Close Intution */
  236.    CloseLibrary((struct Library *)IntuitionBase);
  237.   }
  238.   else
  239.    printf("Unable to open intuition.library V37+!!!\n");
  240.  }
  241.  else
  242.   printf("Sorry... Can't find " WACOM_PORT_NAME "\n" );
  243.  
  244.  /* exit to Shell/WB */
  245.  return(retval);
  246. }
  247.  
  248. /***********************************************************************/
  249. /* __chkabort(): Disable CTRL-C Handling (SAS/C 6.x)                   */
  250. /***********************************************************************/
  251. #ifdef __SASC
  252. void __chkabort(void){}
  253. #endif
  254.  
  255.