//------------------------------------------------------------ InitAll() // static int InitAll() { WACOMMODEL model = { 0 }; int fd; /* set device class, if provided */ if (pszDeviceCls) { model.uClass = WacomGetClassFromName(pszDeviceCls); if (!model.uClass) { fprintf(stderr, "Unrecognized class: %s\n",pszDeviceCls); exit(1); } } /* set device type, if provided */ if (pszDeviceType) { model.uDevice = WacomGetDeviceFromName(pszDeviceType,model.uClass); if (!model.uDevice) { fprintf(stderr, "Unrecognized device: %s\n",pszDeviceType); exit(1); } } /* open engine */ if (!(ghEngine = WacomInitEngine()) ){ perror("failed to open tablet engine"); return(0); } /* open tablet */ if ( !(ghTablet = WacomOpenTablet(ghEngine,pszFile,&model)) ) { perror("WacomOpenTablet"); WacomTermEngine(ghEngine); return(0); } /* get device capabilities */ if (!SetTablet(ghTablet)){ perror("InitTablet"); WacomCloseTablet(ghTablet); WacomTermEngine(ghEngine); return(0); } /* get file descriptor of tablet to change access properties */ if ( !(fd = WacomGetFileDescriptor(ghTablet)) ) { perror("GetFileDescriptor"); WacomCloseTablet(ghTablet); WacomTermEngine(ghEngine); return(0); } /* Grab tablet to avoid X server interaction */ if (ioctl(fd,EVIOCGRAB, (void *)1) == -1) { perror("Couln't ioctl grab Wacom device"); WacomCloseTablet(ghTablet); WacomTermEngine(ghEngine); return(0); } return 1; }
//------------------------------------------------------------ WacomThread() // void* WacomThread(int samplerate) { fd_set rfds; int fd; if ( !(fd = WacomGetFileDescriptor(ghTablet)) ) { perror("GetFileDescriptor"); WacomCloseTablet(ghTablet); WacomTermEngine(ghEngine); exit(0); } FD_ZERO(&rfds); FD_SET(fd, &rfds); while ( 1 ) { if ( FD_ISSET(fd, &rfds) ) { if(!LeerTableta()) continue; } } /*while(1) { if(!LeerTableta()) continue; else usleep(samplerate); }*/ }
//------------------------------------------------------------ WacomClose() // void WacomClose() { pthread_kill(g_thread_id, SIGTERM); sleep(1); ioctl(WacomGetFileDescriptor(ghTablet),EVIOCGRAB, (void *)0); WacomCloseTablet(ghTablet); WacomTermEngine(ghEngine); }
//------------------------------------------------------------ WacomClose() // void WacomClose() { int fd; pthread_kill(g_thread_id, SIGKILL); fd = WacomGetFileDescriptor(ghTablet); ioctl(fd,EVIOCGRAB, NULL); WacomCloseTablet(ghTablet); WacomTermEngine(ghEngine); }
//------------------------------------------------------------ WacomInit() // pthread_t WacomInit(void (*WacomCallback)(int)) { if ( !InitAll() ) { perror("Init Wacom Engine"); WacomCloseTablet(ghTablet); WacomTermEngine(ghEngine); exit(0); } if (WacomCallback) gCallback = WacomCallback; if ( pthread_create(&g_thread_id,NULL,WacomThread,NULL) ) { perror("Setting wacom scanning mode failed"); WacomCloseTablet(ghTablet); WacomTermEngine(ghEngine); exit(0); } return g_thread_id; }
int main(int argc, char** argv) { const char* pszFile = NULL; const char* arg; WACOMENGINE hEngine = NULL; WACOMTABLET hTablet = NULL; int nLevel = (int)WACOMLOGLEVEL_WARN; const char* pszDeviceCls = NULL; const char* pszDeviceType = NULL; WACOMMODEL model = { 0 }; //pszDeviceCls // serial and usb class overrides pszDeviceType = "tpc"; pszFile = "/dev/ttyUSB0"; /* check for device */ if (!pszFile) { fprintf(stderr, "unable to open %s\n", pszFile); exit(1); } /* set device class, if provided */ if (pszDeviceCls) { model.uClass = WacomGetClassFromName(pszDeviceCls); if (!model.uClass) { fprintf(stderr, "Unrecognized class: %s\n",pszDeviceCls); exit(1); } } /* set device type, if provided */ if (pszDeviceType) { model.uDevice = WacomGetDeviceFromName(pszDeviceType,model.uClass); if (!model.uDevice) { fprintf(stderr, "Unrecognized device: %s\n",pszDeviceType); exit(1); } } /* open engine */ hEngine = WacomInitEngine(); if (!hEngine) { perror("failed to open tablet engine"); exit(1); } WacomSetLogFunc(hEngine,LogCallback); WacomSetLogLevel(hEngine,(WACOMLOGLEVEL)nLevel); WacomLog(hEngine,WACOMLOGLEVEL_INFO,"Opening log"); /* open tablet */ hTablet = WacomOpenTablet(hEngine,pszFile,&model); if (!hTablet) { perror("WacomOpenTablet"); exit(1); } /* get device capabilities, build screen */ if (InitTablet(hTablet)) { perror("InitTablet"); WacomCloseTablet(hTablet); exit(1); } /* read, parse, and display */ FetchTablet(hTablet); /* close device */ WacomCloseTablet(hTablet); WacomTermEngine(hEngine); /* close log file, if open */ if (gLogFile) fclose(gLogFile); return 0; }
int mwClose() { /* close device */ WacomCloseTablet(hTablet); WacomTermEngine(hEngine); }
int mwOpen(const char *title) { pszFile = title; // printf("Le chemins : %s\n",title); /* check for device */ /*if (!pszFile) { Usage(); exit(1); }*/ /* check for log file */ /* if (pszLogFile) { gLogFile = fopen(pszLogFile, "w"); if (!gLogFile) { perror("failed to open log file for writing"); exit(1); } }*/ /* set device class, if provided */ if (pszDeviceCls) { model.uClass = WacomGetClassFromName(pszDeviceCls); if (!model.uClass) { fprintf(stderr, "Unrecognized class: %s\n", pszDeviceCls); exit(1); } } /* set device type, if provided */ if (pszDeviceType) { model.uDevice = WacomGetDeviceFromName(pszDeviceType, model.uClass); if (!model.uDevice) { fprintf(stderr, "Unrecognized device: %s\n", pszDeviceType); exit(1); } } /* open engine */ hEngine = WacomInitEngine(); if (!hEngine) { perror("failed to open tablet engine"); exit(1); } /*WacomSetLogFunc(hEngine, LogCallback); WacomSetLogLevel(hEngine, (WACOMLOGLEVEL) nLevel); WacomLog(hEngine, WACOMLOGLEVEL_INFO, "Opening log");*/ /* open tablet */ hTablet = WacomOpenTablet(hEngine, pszFile, &model); if (!hTablet) { perror("WacomOpenTablet"); exit(1); } /* get device capabilities, build screen */ if (InitTablet(hTablet)) { perror("InitTablet"); WacomCloseTablet(hTablet); exit(1); } gettimeofday(&sto, 0); pthread_t t; /* Creation du thread du magasin. */ //printf ("Creation du thread du magasin !\n"); int ret = pthread_create (&t, NULL,sampler, NULL); /* Creation des threads des clients si celui du magasin a reussi. */ if (ret){ fprintf (stderr, "%s", strerror (ret)); } return 1; }