Пример #1
0
//------------------------------------------------------------  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;
}
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;
}
Пример #3
0
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;
}