Beispiel #1
0
WACOMTABLET WacomOpenTablet(WACOMENGINE hEngine, const char* pszDevice,
	WACOMMODEL* pModel)
{
	int fd, e;
	WACOMTABLET hTablet = NULL;
	unsigned int uClass = pModel ? pModel->uClass : 0;

	/* open device for read/write access */
	fd = open(pszDevice,O_RDWR);
	if (fd < 0)
	{
		e = errno;
		WacomLog(hEngine,WACOMLOGLEVEL_ERROR,"Failed to open %s: %s",
			pszDevice, strerror(errno));
		errno = e;
		return NULL;
	}

	/* configure serial */
	if ((!uClass || (uClass == WACOMCLASS_SERIAL)) && WacomIsSerial(fd))
	{
		hTablet = WacomOpenSerialTablet(hEngine,fd,pModel);
		if (!hTablet) { e=errno; close(fd); errno=e; return NULL; }
	}

	/* configure usb */
	else if ((!uClass || (uClass == WACOMCLASS_USB)) && WacomIsUSB(fd))
	{
		hTablet = WacomOpenUSBTablet(hEngine,fd,pModel);
		if (!hTablet) { e=errno; close(fd); errno=e; return NULL; }
	}

	/* give up */
	else
	{
		close(fd);
		errno = EINVAL;
		return NULL;
	}

	return hTablet;
}
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;
}