Exemple #1
0
QT_BEGIN_NAMESPACE

QTsLibMouseHandler::QTsLibMouseHandler(const QString &key,
                                                 const QString &specification)
    : m_notify(0), m_x(0), m_y(0), m_pressed(0), m_rawMode(false)
{
    qDebug() << "QTsLibMouseHandler" << key << specification;
    setObjectName(QLatin1String("TSLib Mouse Handler"));

    QByteArray device = "/dev/input/event1";
    if (specification.startsWith("/dev/"))
        device = specification.toLocal8Bit();

    m_dev = ts_open(device.constData(), 1);
    if (!m_dev) {
        qErrnoWarning(errno, "ts_open() failed");
        return;
    }

    if (ts_config(m_dev)) {
        perror("Error configuring\n");
    }

    m_rawMode =  !key.compare(QLatin1String("TslibRaw"), Qt::CaseInsensitive);

    int fd = ts_fd(m_dev);
    if (fd >= 0) {
        m_notify = new QSocketNotifier(fd, QSocketNotifier::Read, this);
        connect(m_notify, SIGNAL(activated(int)), this, SLOT(readMouseData()));
    } else {
Exemple #2
0
/* 注意: 由于要用到LCD的分辨率, 此函数要在SelectAndInitDisplay之后调用 */
static int TouchScreenDevInit(void)
{
	char *pcTSName = NULL;

	if ((pcTSName = getenv("TSLIB_TSDEVICE")) != NULL ) 
	{
		g_tTSDev = ts_open(pcTSName, 0);  /* 以阻塞方式打开 */
	}
	else
	{
		g_tTSDev = ts_open("/dev/event0", 1);
	}

	if (!g_tTSDev) {
		DBG_PRINTF(APP_ERR"ts_open error!\n");
		return -1;
	}

	if (ts_config(g_tTSDev)) {
		DBG_PRINTF("ts_config error!\n");
		return -1;
	}

	if (GetDispResolution(&giXres, &giYres))
	{
		return -1;
	}

	return 0;
}
Exemple #3
0
static int PD_Open(MOUSEDEVICE *pmd)
{
	char *tsdevice = NULL;

	if ((tsdevice = getenv("TSLIB_TSDEVICE")) != NULL) {
		ts = ts_open(tsdevice, 1);
	} else {
		ts = ts_open("/dev/input/event0", 1);
	}

	if (!ts) {
		EPRINTF("Error opening touchscreen device [%s]: %s\n",
			tsdevice, strerror(errno));
		return -1;
	}

	if (ts_config(ts)) {
		EPRINTF("Error configuring touchscreen device: %s\n",
			strerror(errno));
		ts_close(ts);
		return -1;
	}

	GdHideCursor(&scrdev);
	return ts_fd(ts);
}
Exemple #4
0
void initialize_panel (int sig) {
	(void) sig;
	bindToGalax();

	if (!ts) {
		fprintf(stderr, "error: ts_open\n");
		remove_pid_file();

		if (ioctl (fd_uinput, UI_DEV_DESTROY) < 0)
			die ("error: ioctl");

		close (fd_uinput);
		exit(-1);
	}

	if (ts_config(ts)) {
		fprintf(stderr, "error: ts_config\n");
		remove_pid_file();

		if (ioctl (fd_uinput, UI_DEV_DESTROY) < 0)
			die ("error: ioctl");

		close (fd_uinput);
		exit(-1);
	}
}
static int TSInputDeviceInit(void)
{
	char *pcTSName = NULL;
	int iError = 0;

	if((pcTSName = getenv("TSLIB_TSDEVICE"))){
		g_ptTouchScreenFd = ts_open(pcTSName, 0);	
	}else{
		g_ptTouchScreenFd = ts_open("/dev/event0", 0);
	}

	if(NULL == g_ptTouchScreenFd){
		DebugPrint(DEBUG_NOTICE"Open ts device error\n");
		return -1;
	}
	
	iError = ts_config(g_ptTouchScreenFd);
	if(iError){
		DebugPrint(DEBUG_NOTICE"Config ts device error\n");
		return -1;
	}
	
	g_tTSInputOpr.iInputDeviceFd = ts_fd(g_ptTouchScreenFd);

	/* g_iBpp 在这里并没有用到 */
	return GetDisDeviceSize(&g_iTSXres, &g_iTSYres, &g_iBpp);
}
Exemple #6
0
struct tsdev *ts_init(void)
{
	struct tsdev *t = ts_open("/dev/ts0", 0);
	if (!t) {
		perror("ts_open");
		exit(1);
	}
	if (ts_config(t)) {
		perror("ts_config");
		exit(1);
	}

	return t;
}
EAPI int
ecore_fb_ts_init(void)
{
#ifdef HAVE_TSLIB
   char *tslib_tsdevice = NULL;
   if ( (tslib_tsdevice = getenv("TSLIB_TSDEVICE")) )
     {
        printf( "ECORE_FB: TSLIB_TSDEVICE = '%s'\n", tslib_tsdevice );
        _ecore_fb_tslib_tsdev = ts_open( tslib_tsdevice, 1 ); /* 1 = nonblocking, 0 = blocking */

        if ( !_ecore_fb_tslib_tsdev )
          {
             printf( "ECORE_FB: Can't ts_open (%s)\n", strerror( errno ) );
             return 0;
          }

        if ( ts_config( _ecore_fb_tslib_tsdev ) )
          {
             printf( "ECORE_FB: Can't ts_config (%s)\n", strerror( errno ) );
             return 0;
          }
        _ecore_fb_ts_fd = ts_fd( _ecore_fb_tslib_tsdev );
        if ( _ecore_fb_ts_fd < 0 )
          {
             printf( "ECORE_FB: Can't open touchscreen (%s)\n", strerror( errno ) );
             return 0;
          }
     }
#else
   _ecore_fb_ts_fd = open("/dev/touchscreen/0", O_RDONLY);
#endif
   if (_ecore_fb_ts_fd >= 0)
     {
        _ecore_fb_ts_fd_handler_handle = ecore_main_fd_handler_add(_ecore_fb_ts_fd,
                                                                   ECORE_FD_READ,
                                                                   _ecore_fb_ts_fd_handler, NULL,
                                                                   NULL, NULL);
        if (!_ecore_fb_ts_fd_handler_handle)
          {
             close(_ecore_fb_ts_fd);
             return 0;
          }
        // FIXME _ecore_fb_kbd_fd = open("/dev/touchscreen/key", O_RDONLY);
        return 1;
     }
   return 0;
}
int main(int argc, char *argv[]) {
    char fb_node[16] = "/dev/fb0";
    char *tsdevice = NULL;
    struct tsdev *ts;
    struct sigaction action;
    cairo_linuxfb_device_t *device;
    cairo_surface_t *fbsurface;
    cairo_t *fbcr;

    if (argc > 1) {
        strcpy(fb_node, argv[1]);
    }

    printf("Frame buffer node is: %s\n", fb_node);

    if( (tsdevice = getenv("TSLIB_TSDEVICE")) != NULL )
        ts = ts_open(tsdevice, 1);
    else
        ts = ts_open("/dev/input/event0", 1);

    if (ts_config(ts)) {
        perror("ts_config");
        exit(1);
    }

    device = malloc(sizeof(*device));
    if (!device) {
        perror("Error: cannot allocate memory\n");
        exit(1);
    }

    memset(&action, 0, sizeof(struct sigaction));
    action.sa_handler = signal_handler;
    sigaction(SIGTERM, &action, NULL);
    sigaction(SIGINT, &action, NULL);

    fbsurface = cairo_linuxfb_surface_create(device, fb_node);
    fbcr = cairo_create(fbsurface);

    draw_rectangles(fbcr, ts, device);

    cairo_destroy(fbcr);
    cairo_surface_destroy(fbsurface);

    return 0;
}
Exemple #9
0
int
TslibInit (void)
{
    int		i;
    KdMouseInfo	*mi, *next;
    int		fd= 0;
    int		n = 0;

    if (!TsInputType)
	TsInputType = KdAllocInputType ();
    
    for (mi = kdMouseInfo; mi; mi = next)
    {
	next = mi->next;
	if (mi->inputType)
	    continue;

	if (!mi->name)
	{
	    for (i = 0; i < NUM_TS_NAMES; i++)    
	    {
		if(!(tsDev = ts_open(TsNames[i],0))) continue;
	        ts_config(tsDev); 
	        fd=ts_fd(tsDev);
		if (fd >= 0) 
		{
		    mi->name = KdSaveString (TsNames[i]);
		    break;
		}
	    }
	}

	if (fd > 0 && tsDev != 0) 
	  {
	    mi->driver = (void *) fd;
	    mi->inputType = TsInputType;
	    	if (KdRegisterFd (TsInputType, fd, TsRead, (void *) mi))
		    n++;
	  } 
	else 
	  if (fd > 0) close(fd);
	}
}
Exemple #10
0
int main()
{
	struct tsdev *ts;
	char *tsdevice=NULL;

	if( (tsdevice = getenv("TSLIB_TSDEVICE")) != NULL ) {
		ts = ts_open(tsdevice,0);
	} else {
		if (!(ts = ts_open("/dev/input/event0", 0)))
			ts = ts_open("/dev/touchscreen/ucb1x00", 0);
	}

	if (!ts) {
		perror("ts_open");
		exit(1);
	}

	if (ts_config(ts)) {
		perror("ts_config");
		exit(1);
	}

	while (1) {
		struct ts_sample samp;
		int ret;

		ret = ts_read(ts, &samp, 1);

		if (ret < 0) {
			perror("ts_read");
			exit(1);
		}

		if (ret != 1)
			continue;

		printf("%ld.%06ld: %6d %6d %6d\n", samp.tv.tv_sec, samp.tv.tv_usec, samp.x, samp.y, samp.pressure);

	}
}
Exemple #11
0
int EventHub::open_device(const char *deviceName)
{
    int version;
    int fd;
    struct pollfd *new_mFDs;
    device_t **new_devices;
    char **new_device_names;
    char name[80];
    char location[80];
    char idstr[80];
    struct input_id id;

    LOGV("Opening device: %s", deviceName);

    AutoMutex _l(mLock);

    fd = open(deviceName, O_RDWR);
    if(fd < 0) {
        LOGE("could not open %s, %s\n", deviceName, strerror(errno));
        return -1;
    }

    if(ioctl(fd, EVIOCGVERSION, &version)) {
        LOGE("could not get driver version for %s, %s\n", deviceName, strerror(errno));
        return -1;
    }
    if(ioctl(fd, EVIOCGID, &id)) {
        LOGE("could not get driver id for %s, %s\n", deviceName, strerror(errno));
        return -1;
    }
    name[sizeof(name) - 1] = '\0';
    location[sizeof(location) - 1] = '\0';
    idstr[sizeof(idstr) - 1] = '\0';
    if(ioctl(fd, EVIOCGNAME(sizeof(name) - 1), &name) < 1) {
        //fprintf(stderr, "could not get device name for %s, %s\n", deviceName, strerror(errno));
        name[0] = '\0';
    }

    // check to see if the device is on our excluded list
    List<String8>::iterator iter = mExcludedDevices.begin();
    List<String8>::iterator end = mExcludedDevices.end();
    for ( ; iter != end; iter++) {
        const char* test = *iter;
        if (strcmp(name, test) == 0) {
            LOGI("ignoring event id %s driver %s\n", deviceName, test);
            close(fd);
            return -1;
        }
    }

    if(ioctl(fd, EVIOCGPHYS(sizeof(location) - 1), &location) < 1) {
        //fprintf(stderr, "could not get location for %s, %s\n", deviceName, strerror(errno));
        location[0] = '\0';
    }
    if(ioctl(fd, EVIOCGUNIQ(sizeof(idstr) - 1), &idstr) < 1) {
        //fprintf(stderr, "could not get idstring for %s, %s\n", deviceName, strerror(errno));
        idstr[0] = '\0';
    }

    int devid = 0;
    while (devid < mNumDevicesById) {
        if (mDevicesById[devid].device == NULL) {
            break;
        }
        devid++;
    }
    if (devid >= mNumDevicesById) {
        device_ent* new_devids = (device_ent*)realloc(mDevicesById,
                sizeof(mDevicesById[0]) * (devid + 1));
        if (new_devids == NULL) {
            LOGE("out of memory");
            return -1;
        }
        mDevicesById = new_devids;
        mNumDevicesById = devid+1;
        mDevicesById[devid].device = NULL;
        mDevicesById[devid].seq = 0;
    }

    mDevicesById[devid].seq = (mDevicesById[devid].seq+(1<<SEQ_SHIFT))&SEQ_MASK;
    if (mDevicesById[devid].seq == 0) {
        mDevicesById[devid].seq = 1<<SEQ_SHIFT;
    }

    new_mFDs = (pollfd*)realloc(mFDs, sizeof(mFDs[0]) * (mFDCount + 1));
    new_devices = (device_t**)realloc(mDevices, sizeof(mDevices[0]) * (mFDCount + 1));
    if (new_mFDs == NULL || new_devices == NULL) {
        LOGE("out of memory");
        return -1;
    }
    mFDs = new_mFDs;
    mDevices = new_devices;

#if 0
    LOGI("add device %d: %s\n", mFDCount, deviceName);
    LOGI("  bus:      %04x\n"
         "  vendor    %04x\n"
         "  product   %04x\n"
         "  version   %04x\n",
        id.bustype, id.vendor, id.product, id.version);
    LOGI("  name:     \"%s\"\n", name);
    LOGI("  location: \"%s\"\n"
         "  id:       \"%s\"\n", location, idstr);
    LOGI("  version:  %d.%d.%d\n",
        version >> 16, (version >> 8) & 0xff, version & 0xff);
#endif

    device_t* device = new device_t(devid|mDevicesById[devid].seq, deviceName, name);
    if (device == NULL) {
        LOGE("out of memory");
        return -1;
    }

    mFDs[mFDCount].fd = fd;
    mFDs[mFDCount].events = POLLIN;

    // figure out the kinds of events the device reports
    
    // See if this is a keyboard, and classify it.  Note that we only
    // consider up through the function keys; we don't want to include
    // ones after that (play cd etc) so we don't mistakenly consider a
    // controller to be a keyboard.
    uint8_t key_bitmask[(KEY_MAX+7)/8];
    memset(key_bitmask, 0, sizeof(key_bitmask));
    LOGV("Getting keys...");
    if (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(key_bitmask)), key_bitmask) >= 0) {
        //LOGI("MAP\n");
        //for (int i=0; i<((KEY_MAX+7)/8); i++) {
        //    LOGI("%d: 0x%02x\n", i, key_bitmask[i]);
        //}
        for (int i=0; i<((BTN_MISC+7)/8); i++) {
            if (key_bitmask[i] != 0) {
                device->classes |= CLASS_KEYBOARD;
                break;
            }
        }
        if ((device->classes & CLASS_KEYBOARD) != 0) {
            device->keyBitmask = new uint8_t[sizeof(key_bitmask)];
            if (device->keyBitmask != NULL) {
                memcpy(device->keyBitmask, key_bitmask, sizeof(key_bitmask));
            } else {
                delete device;
                LOGE("out of memory allocating key bitmask");
                return -1;
            }
        }
    }
    
    // See if this is a trackball.
    if (test_bit(BTN_MOUSE, key_bitmask)) {
        uint8_t rel_bitmask[(REL_MAX+7)/8];
        memset(rel_bitmask, 0, sizeof(rel_bitmask));
        LOGV("Getting relative controllers...");
        if (ioctl(fd, EVIOCGBIT(EV_REL, sizeof(rel_bitmask)), rel_bitmask) >= 0)
        {
            if (test_bit(REL_X, rel_bitmask) && test_bit(REL_Y, rel_bitmask)) {
                if (test_bit(BTN_LEFT, key_bitmask) && test_bit(BTN_RIGHT, key_bitmask))
                    device->classes |= CLASS_MOUSE;
                else
                    device->classes |= CLASS_TRACKBALL;
            }
        }
    }
    
    uint8_t abs_bitmask[(ABS_MAX+7)/8];
    memset(abs_bitmask, 0, sizeof(abs_bitmask));
    LOGV("Getting absolute controllers...");
    ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(abs_bitmask)), abs_bitmask);
    
    // Is this a new modern multi-touch driver?
    if (test_bit(ABS_MT_TOUCH_MAJOR, abs_bitmask)
            && test_bit(ABS_MT_POSITION_X, abs_bitmask)
            && test_bit(ABS_MT_POSITION_Y, abs_bitmask)) {
        device->classes |= CLASS_TOUCHSCREEN | CLASS_TOUCHSCREEN_MT;
        
    // Is this an old style single-touch driver?
    } else if (test_bit(BTN_TOUCH, key_bitmask)
            && test_bit(ABS_X, abs_bitmask) && test_bit(ABS_Y, abs_bitmask)) {
        device->classes |= CLASS_TOUCHSCREEN;
#ifdef HAVE_TSLIB
                mTS->fd = fd;

                //Configure here
                LOGV("Device name = %s, fd = %d", deviceName,fd);
                LOGV("tslib: calling ts_config from eventhub\n");
                if(ts_config(mTS)) {
                    LOGE("Error in Configuring tslib. Device Name = %s \n", deviceName);
                }
#endif
    }

#ifdef EV_SW
    // figure out the switches this device reports
    uint8_t sw_bitmask[(SW_MAX+7)/8];
    memset(sw_bitmask, 0, sizeof(sw_bitmask));
    if (ioctl(fd, EVIOCGBIT(EV_SW, sizeof(sw_bitmask)), sw_bitmask) >= 0) {
        for (int i=0; i<EV_SW; i++) {
            //LOGI("Device 0x%x sw %d: has=%d", device->id, i, test_bit(i, sw_bitmask));
            if (test_bit(i, sw_bitmask)) {
                if (mSwitches[i] == 0) {
                    mSwitches[i] = device->id;
                }
            }
        }
    }
#endif

    if ((device->classes&CLASS_KEYBOARD) != 0) {
        char tmpfn[sizeof(name)];
        char keylayoutFilename[300];

        // a more descriptive name
        device->name = name;

        // replace all the spaces with underscores
        strcpy(tmpfn, name);
        for (char *p = strchr(tmpfn, ' '); p && *p; p = strchr(tmpfn, ' '))
            *p = '_';

        // find the .kl file we need for this device
        const char* root = getenv("ANDROID_ROOT");
        snprintf(keylayoutFilename, sizeof(keylayoutFilename),
                 "%s/usr/keylayout/%s.kl", root, tmpfn);
        bool defaultKeymap = false;
        if (access(keylayoutFilename, R_OK)) {
            snprintf(keylayoutFilename, sizeof(keylayoutFilename),
                     "%s/usr/keylayout/%s", root, "qwerty.kl");
            defaultKeymap = true;
        }
        device->layoutMap->load(keylayoutFilename);

        // tell the world about the devname (the descriptive name)
        if (!mHaveFirstKeyboard && !defaultKeymap && strstr(name, "-keypad")) {
            // the built-in keyboard has a well-known device ID of 0,
            // this device better not go away.
            mHaveFirstKeyboard = true;
            mFirstKeyboardId = device->id;
            property_set("hw.keyboards.0.devname", name);
        } else {
            // ensure mFirstKeyboardId is set to -something-.
            if (mFirstKeyboardId == 0) {
                mFirstKeyboardId = device->id;
            }
        }
        char propName[100];
        sprintf(propName, "hw.keyboards.%u.devname", device->id);
        property_set(propName, name);

        // 'Q' key support = cheap test of whether this is an alpha-capable kbd
        if (hasKeycode(device, kKeyCodeQ)) {
            device->classes |= CLASS_ALPHAKEY;
        }
        
        // See if this has a DPAD.
        if (hasKeycode(device, kKeyCodeDpadUp) &&
                hasKeycode(device, kKeyCodeDpadDown) &&
                hasKeycode(device, kKeyCodeDpadLeft) &&
                hasKeycode(device, kKeyCodeDpadRight) &&
                hasKeycode(device, kKeyCodeDpadCenter)) {
            device->classes |= CLASS_DPAD;
        }
        
        LOGI("New keyboard: device->id=0x%x devname='%s' propName='%s' keylayout='%s'\n",
                device->id, name, propName, keylayoutFilename);
    }

    // If the device isn't recognized as something we handle, don't monitor it.
    if (device->classes == 0) {
        LOGV("Dropping device %s %p, id = %d\n", deviceName, device, devid);
        close(fd);
        delete device;
        return -1;
    }

    LOGI("New device: path=%s name=%s id=0x%x (of 0x%x) index=%d fd=%d classes=0x%x\n",
         deviceName, name, device->id, mNumDevicesById, mFDCount, fd, device->classes);
         
    LOGV("Adding device %s %p at %d, id = %d, classes = 0x%x\n",
         deviceName, device, mFDCount, devid, device->classes);

    mDevicesById[devid].device = device;
    device->next = mOpeningDevices;
    mOpeningDevices = device;
    mDevices[mFDCount] = device;

    mFDCount++;
    return 0;
}
Exemple #12
0
int main(int argc, char **argv)
{
	struct tsdev *ts;
	char *tsdevice = NULL;
	struct ts_sample_mt **samp_mt = NULL;
	struct input_absinfo slot;
	unsigned short max_slots = 1;
	int fd_input = 0;
	int ret, i;

	while (1) {
		const struct option long_options[] = {
			{ "help",         no_argument,       0, 'h' },
			{ "idev",         required_argument, 0, 'i' },
		};

		int option_index = 0;
		int c = getopt_long(argc, argv, "hi:", long_options, &option_index);

		errno = 0;
		if (c == -1)
			break;

		switch (c) {
		case 'h':
			printf("Usage: %s [-i <device>]\n", argv[0]);
			return 0;

		case 'i':
			tsdevice = optarg;
			break;

		default:
			printf("Usage: %s [-i <device>]\n", argv[0]);
			break;
		}

		if (errno) {
			char *str = "option ?";
			str[7] = c & 0xff;
			perror(str);
		}
	}

	if (!tsdevice) {
		if (getenv("TSLIB_TSDEVICE")) {
			tsdevice = getenv("TSLIB_TSDEVICE");
		} else {
			fprintf(stderr, RED "ts_print_raw_mt: no input device specified\n" RESET);
			return -EINVAL;
		}
	}

	fd_input = open(tsdevice, O_RDWR);
	if (fd_input == -1) {
		perror("open");
		return errno;
	}

	ts = ts_open(tsdevice, 0);
	if (!ts) {
		close(fd_input);
		perror("ts_open");
		return errno;
	}

	if (ts_config(ts)) {
		close(fd_input);
		ts_close(ts);
		perror("ts_config");
		return errno;
	}

	if (ioctl(fd_input, EVIOCGABS(ABS_MT_SLOT), &slot) < 0) {
		perror("ioctl EVIOGABS");
		close(fd_input);
		ts_close(ts);
		return errno;
	}
	close(fd_input);
	max_slots = slot.maximum + 1 - slot.minimum;

	samp_mt = malloc(sizeof(struct ts_sample_mt *));
	if (!samp_mt) {
		ts_close(ts);
		return -ENOMEM;
	}
	samp_mt[0] = calloc(max_slots, sizeof(struct ts_sample_mt));
	if (!samp_mt[0]) {
		free(samp_mt);
		ts_close(ts);
		return -ENOMEM;
	}

	while (1) {
		ret = ts_read_raw_mt(ts, samp_mt, max_slots, 1);
		if (ret < 0) {
			perror("ts_read_raw_mt");
			exit(1);
		}

		if (ret != 1)
			continue;

		for (i = 0; i < max_slots; i++) {
			if (samp_mt[0][i].valid != 1)
				continue;

			printf(YELLOW "%ld.%06ld:" RESET " (slot %d) %6d %6d %6d\n",
			       samp_mt[0][i].tv.tv_sec,
			       samp_mt[0][i].tv.tv_usec,
			       samp_mt[0][i].slot,
			       samp_mt[0][i].x,
			       samp_mt[0][i].y,
			       samp_mt[0][i].pressure);
		}
	}
}
Exemple #13
0
int main()
{
	struct tsdev *ts;
	unsigned int i;
	int ret,count;
	int connect = 0;
	char buff[10]="";
	char myaddr[16] = "";
	char *fbuff;
	pthread_t ts_thread;
	char *tsdevice = "/dev/ts0";
	int read_flag;

	signal(SIGSEGV, sig);
	signal(SIGINT, sig);
	signal(SIGTERM, sig);

	//open touchscreen device
	ts = ts_open(tsdevice,0);

	if(!ts)
	{
		perror(tsdevice);
		exit(1);
	}

	if(ts_config(ts))
	{
		perror("ts_config");
		exit(1);
	}
	if(open_framebuffer()){
		close_framebuffer();
		exit(1);
	}

	for(i=0;i<NR_COLORS;i++)
		setcolor(i,palette[i]);

	/* button settings for server program 
	 * server program only have clear and exit button.
	 */
	memset(&buttons,0,sizeof(buttons));
	buttons[0].w  = 70;
	buttons[0].h  = 20;
	buttons[0].x = 40; buttons[0].y = 200;
	buttons[0].text = "Clear";
	buttons[1].w = 20;
	buttons[1].h = 20;
	buttons[1].x = 280; buttons[1].y = 20;
	buttons[1].text = "Exit";

	refresh_screen();
	//sleep(30);
	reset_ipaddr();
	//strcpy(myaddr,ipaddr[mylocation]);
	strcpy(myaddr,my_ipaddr);
#ifdef DEBUG
	printf("ipaddr[mylocation] : %s\n",ipaddr[mylocation]);
	printf("my_ipaddr : %s\n",my_ipaddr);
	printf("myaddr : %s\n",myaddr);
#endif

	serv_sock = tcp_server_listen(ip2port(myaddr,7777),2);
	if(serv_sock < 0)
	{
		perror("tcp_server_listen");
		close_framebuffer();
		exit(1);
	}
	else
	{
		printf("server started!!! Ip: %s Port : %d\n",myaddr,ip2port(myaddr,7777));
	}

	pthread_create(&ts_thread, NULL, read_ts,ts);
	while(1)
	{

		clnt_sock = tcp_server_accept(serv_sock);
		if(clnt_sock <0)
		{
			perror("tcp_server_accept");
			exit(1);
		}
		else{
			//connect = 1;
#ifdef DEBUG
			printf("accept successful!!\n");
#endif
		}

		while(1)
		{
			ret = read(clnt_sock,buff,10);
#ifdef DEBUG
			printf("buff = %s\n",buff);
#endif

			if(!strcmp(buff,"Merge"))
			{
				//merge mode
				buff[0] = '\0';
#ifdef DEBUG
				printf("Merge mode on\n");
				printf("is buff cleared ? : %s\n",buff);
#endif
				ret = write(clnt_sock,fbuffer,fix.smem_len);

				if(ret<=0)
				{
					perror("write");
					exit(1);
				}
#ifdef DEBUG
				else
				{
					printf("server sent : %d\n",ret);
				}
				sleep(1);
#endif
			}
			/*
			   else if(!strcmp(buff,"Send"))
			   {
			   buff[0] = '\0';
			   count=0;
			   read_flag=0;
			   while(!read_flag)
			   {
			   ret = read(clnt_sock,fbuff+count,fix.smem_len);
			   if(ret<=0)				
			   {
			   perror("read");
			   exit(1);
			   }
			   count+=ret;
			   printf(" read : %d\n",count);
			   if(count>=fix.smem_len)
			   {
			   read_flag = 1;
			   }
			   }
			   for(i=0;i<fix.smem_len;i++)
			   {
			   fbuffer[i]|=fbuff[i];
			   }

			   }
			   */
			   else if(!strcmp(buff,"Split"))
			   {
				   //split mode
				   buff[0] = '\0';
				   sleep(1);
#ifdef DEBUG
				   printf("Split mode on\n");
				   printf("is buff cleared ? : %s\n",buff);
#endif
			   }
			   else if(!strcmp(buff,"Exit"))
			   {
				   buff[0] = '\0';
				   sleep(1);
#ifdef DEBUG
				   printf("Exit\n");
				   printf("is buff cleared ? : %s\n",buff);
#endif
				   break;
			   }
			   else
			   {
				   buff[0] = '\0';
				   sleep(1);
				   //	continue;
				   break;
			   }

		}
		close(clnt_sock);
		pthread_cancel(ts_thread);
	}
	pthread_join(ts_thread, NULL);
	close(serv_sock);
}
Exemple #14
0
int main()
{
	struct tsdev *ts;
	int x, y;
	unsigned int i;
	unsigned int mode = 0;

	char *tsdevice=NULL;

	signal(SIGSEGV, sig);
	signal(SIGINT, sig);
	signal(SIGTERM, sig);

	if ((tsdevice = getenv("TSLIB_TSDEVICE")) == NULL) {
#ifdef USE_INPUT_API
		tsdevice = strdup ("/dev/input/event0");
#else
		tsdevice = strdup ("/dev/touchscreen/ucb1x00");
#endif /* USE_INPUT_API */
        }

	ts = ts_open (tsdevice, 0);

	if (!ts) {
		perror (tsdevice);
		exit(1);
	}

	if (ts_config(ts)) {
		perror("ts_config");
		exit(1);
	}

	if (open_framebuffer()) {
		close_framebuffer();
		exit(1);
	}

	x = xres/2;
	y = yres/2;

	for (i = 0; i < NR_COLORS; i++)
		setcolor (i, palette [i]);

	/* Initialize buttons */
	memset (&buttons, 0, sizeof (buttons));
	buttons [0].w = buttons [1].w = xres / 4;
	buttons [0].h = buttons [1].h = 20;
	buttons [0].x = xres / 4 - buttons [0].w / 2;
	buttons [1].x = (3 * xres) / 4 - buttons [0].w / 2;
	buttons [0].y = buttons [1].y = 10;
	buttons [0].text = "Drag";
	buttons [1].text = "Draw";

	refresh_screen ();

	while (1) {
		struct ts_sample samp;
		int ret;

		/* Show the cross */
		if ((mode & 15) != 1)
			put_cross(x, y, 2 | XORMODE);

		ret = ts_read(ts, &samp, 1);

		/* Hide it */
		if ((mode & 15) != 1)
			put_cross(x, y, 2 | XORMODE);

		if (ret < 0) {
			perror("ts_read");
			close_framebuffer();
			exit(1);
		}

		if (ret != 1)
			continue;

		for (i = 0; i < NR_BUTTONS; i++)
			if (button_handle (&buttons [i], &samp))
				switch (i) {
				case 0:
					mode = 0;
					refresh_screen ();
					break;
				case 1:
					mode = 1;
					refresh_screen ();
					break;
				}

		printf("%ld.%06ld: %6d %6d %6d\n", samp.tv.tv_sec, samp.tv.tv_usec,
			samp.x, samp.y, samp.pressure);

		if (samp.pressure > 0) {
			if (mode == 0x80000001)
				line (x, y, samp.x, samp.y, 2);
			x = samp.x;
			y = samp.y;
			mode |= 0x80000000;
		} else
			mode &= ~0x80000000;
	}
	close_framebuffer();
}
int main()
{
	struct tsdev *ts;
	int x, y;
	unsigned int i;
	unsigned int mode = 0;

	char *tsdevice=NULL;

	signal(SIGSEGV, sig);
	signal(SIGINT, sig);
	signal(SIGTERM, sig);

	if ((tsdevice = getenv("TSLIB_TSDEVICE")) == NULL) {
#ifdef USE_INPUT_API
		tsdevice = strdup ("/dev/input/event0");
#else
		tsdevice = strdup ("/dev/touchscreen/ucb1x00");
#endif /* USE_INPUT_API */
        }

	ts = ts_open (tsdevice, 0);

	if (!ts) {
		perror (tsdevice);
		exit(1);
	}

	if (ts_config(ts)) {
		perror("ts_config");
		exit(1);
	}

	if (open_framebuffer()) {
		close_framebuffer();
		exit(1);
	}

	x = xres/2;
	y = yres/2;

	for (i = 0; i < NR_COLORS; i++)
		setcolor (i, palette [i]);

	/* Initialize buttons */
	memset (&buttons, 0, sizeof (buttons));
	/*buttons [0].w = buttons [1].w = xres / 4;
	buttons [0].h = buttons [1].h = 20;
	buttons [0].x = xres / 4 - buttons [0].w / 2;
	buttons [1].x = (3 * xres) / 4 - buttons [0].w / 2;
	buttons [0].y = buttons [1].y = 10;
	buttons [0].text = "Drag";
	buttons [1].text = "Draw";
	buttons [0].*/

	/*weight height*/
	for(i=1; i<17; i++){
		buttons [i].w = xres / 7;
		buttons [i].h = yres / 5;
	}	

	buttons [0].w = (2*xres/7) + (xres/49);
	buttons [0].h = yres / 5;

	/*result a half of xres and position is center*/
	buttons [17].w = xres / 2;
	buttons [17].h = yres / 5;
	buttons [17].text = "";

	/*value*/
	buttons [0].text = "0";
	buttons [1].text = "1";
	buttons [2].text = "2";
	buttons [3].text = "3";
	buttons [4].text = "4";
	buttons [5].text = "5";
	buttons [6].text = "6";
	buttons [7].text = "7";
	buttons [8].text = "8";
	buttons [9].text = "9";
	buttons [10].text = "+";
	buttons [11].text = "-";
	buttons [12].text = "*";
	buttons [13].text = "/";
	buttons [14].text = "=";
	buttons [15].text = "C";
	buttons [16].text = "D";

	/*
	 *800 * 480 
	 *
	 *such design: the y-blank is yres/25 = 96px, x-blank is xres/49 = 114px; 
	 * */
	
	/*
	 *
	 *	   	17
	 *15 16 10 11 12 13 
	 *1  2  3  4  5  14
	 *6  7  8  9	0  
	 *
	 * */

	/*the x position of buttons*/
	buttons [15].x = buttons [1].x = buttons [6].x = xres / 49;
	buttons [16].x = buttons [2].x = buttons [7].x = (xres/7) + (2*xres/49);
	buttons [10].x = buttons [3].x = buttons [8].x = (2*xres/7) + (3*xres/49);
	buttons [11].x = buttons [4].x = buttons [9].x = (3*xres/7) + (4*xres/49);
	buttons [12].x = buttons [5].x = buttons [0].x = (4*xres/7) + (5*xres/49);
	buttons [13].x = buttons [14].x = (5*xres/7) + (6*xres/49);

	/*the y position of buttons*/
	buttons [15].y =buttons [16].y =buttons [10].y =buttons [11].y =buttons [12].y = buttons [13].y = (yres/5) + (2*yres/25);
	buttons [1].y =buttons [2].y =buttons [3].y =buttons [4].y =buttons [5].y = buttons [14].y = (2*yres/5) + (3*yres/25);
	buttons [6].y =buttons [7].y =buttons [8].y =buttons [9].y =buttons [0].y = (3*yres/5) + (4*yres/25);

	/*result center*/
	buttons [17].x = xres / 4;
	buttons [17].y = yres / 25;

	/*refresh*/
	refresh_screen ();

	while (1) {
		struct ts_sample samp;
		int ret;

		// Show the cross 
		if ((mode & 15) != 1)
			put_cross(x, y, 2 | XORMODE);

		ret = ts_read(ts, &samp, 1);

		// Hide it 
		if ((mode & 15) != 1)
			put_cross(x, y, 2 | XORMODE);

		if (ret < 0) {
			perror("ts_read");
			close_framebuffer();
			exit(1);
		}

		if (ret != 1)
			continue;

		for (i = 0; i < NR_BUTTONS; i++)
			if (button_handle (&buttons [i], &samp))
				switch (i) {
				case 0:
					mode = 0;
					refresh_screen ();
					break;
				case 1:
					mode = 1;
					refresh_screen ();
					break;
				}

		printf("%ld.%06ld: %6d %6d %6d\n", samp.tv.tv_sec, samp.tv.tv_usec,
			samp.x, samp.y, samp.pressure);

		if (samp.pressure > 0) {
			if (mode == 0x80000001)
				line (x, y, samp.x, samp.y, 2);
			x = samp.x;
			y = samp.y;
			mode |= 0x80000000;
		} else
			mode &= ~0x80000000;
	}
	close_framebuffer();
}
Exemple #16
0
int main(int argc, char *argv[])
{
	int ret;
	int serv_sock, clnt_sock;
	char *myip;
	char *tsdevice = "/dev/ts0";
	struct tsdev *ts;

	if (argc < 2) {
		printf("USAGE : %s myip\n", argv[0]);
		exit(1);
	}
	myip = argv[1];

	signal(SIGSEGV, sig);
	signal(SIGINT, sig);
	signal(SIGTERM, sig);

#ifdef DEBUG
	fprintf(stderr, " *** server for theMeal ***\n\n");
#endif
	printf("theMeal: oo_ts_server started!\n");
	
/* initialize */
	ts = ts_open(tsdevice, 0);
	if (!ts) {
		perror("ts_open");
		exit(1);
	}

	if (ts_config(ts)) {
		perror("ts_config");
		exit(1);
	}

	serv_sock = tcp_server_listen(ip2port(myip, 7000), 2);
	if (serv_sock < 0)
		exit(1);

/* main process */
	while (1) {
		int pid, status;
		char ts_ack[1];
		struct ts_sample samp, v_samp;
		clnt_sock = tcp_server_accept(serv_sock);
		if (clnt_sock < 0)
			exit(1);

		pid = fork();
		// Parent Process
		if (pid > 0) {
#ifdef DEBUG
			fprintf(stderr, "clnt_sock #%d pid #%d\n", clnt_sock, pid);
#endif
			close(clnt_sock);
			wait(&status);
			continue;
		} 
		/* Child Process
		 * send ts_sample structure and recv ack character
		 * unless ack is not 1, it will send ts_sample structure
		 */
		else { 		
			do {
				ret = ts_read(ts, &samp, 1);
				if (ret < 0) {
					perror("ts_read");
					continue;
				}

				if (ret != 1)
					continue;

//				v_samp = phy2vir_pos(samp, mylocation);
//				ret = write(clnt_sock, &v_samp, sizeof(struct ts_sample));
				ret = write(clnt_sock, &samp, sizeof(struct ts_sample));
#ifdef DEBUG
				fprintf(stderr, "%ld.%06ld: %6d %6d %6d\n", samp.tv.tv_sec, samp.tv.tv_usec, samp.x, samp.y, samp.pressure);
				fprintf(stderr, "To #%d write: %d\n", clnt_sock, ret);
#endif
				if (samp.x > 300 && samp.y < 20)
					break;
			} while (1);
			shutdown(clnt_sock, SHUT_WR);
			close(clnt_sock);
#ifdef DEBUG
			fprintf(stderr, "\n *** child process is done\n");
#endif
			exit(0);
		} // end child process
	} // end while(1)
	
	close(serv_sock);
#ifdef DEBUG
	fprintf(stderr, "\n *** All done completely. ***\n");
#endif
	exit(0);
	return 0;
}
Exemple #17
0
void *  ts_click(void* arg)
{
    int i , ret ,t;
    int chat = 0 ;

    ts = ts_open(tsdevice, 0);
    if (!ts)
    {
        perror("ts_open");
        exit(1);
    }


    if (ts_config(ts))
    {
        perror("ts_config");
        exit(1);
    }
#if DEBUG
    printf(" thread func start \n");
#endif
    while(1)
    {
        ret = ts_read(ts, &samp, 1);
        chat ++;

        if (ret < 0) {
            perror("ts_read");
            exit(1);
        }

        if (chat < 15)
            continue;
        else
        {
            chat = 0;
            for (i=0; i < myicon_count; i++)
            {
                if ( (t = myicon_handle(&icon[myicon_count -1], &samp)))
                {
                    put_string_center(140, 100, " exit cam app ", white);
                    event = 9 ;
                    sleep(1);
                    pthread_exit(NULL);
                }

                else if( (t = myicon_handle(&icon[i], &samp)))
                {
                    func = i+1;
                    event =1;
#if DEBUG
                    printf(" event is %d \n", event);
#endif
                }


            }
        }
    }
    pthread_exit(NULL);
}
/*!***********************************************************************
 @Function		OsInit
 @description	Initialisation for OS-specific code.
*************************************************************************/
void PVRShellInit::OsInit()
{
	bcm_host_init();

	// In case we're in the background ignore SIGTTIN and SIGTTOU
	signal( SIGTTIN, SIG_IGN );
	signal( SIGTTOU, SIG_IGN );

	remote_fd = 0;

	m_pShell->m_pShellData->bFullScreen= true;	// linux overrides default to use fullscreen

	m_ui32NativeDisplay = 0;

	// Keyboard handling
	if((devfd=open(CONNAME, O_RDWR|O_NDELAY)) <= 0)
	{
		m_pShell->PVRShellOutputDebug("Can't open tty (%s)\n",CONNAME);
	}
	else
	{
		tcgetattr(devfd,&termio_orig);
		tcgetattr(devfd,&termio);
		cfmakeraw(&termio);
		termio.c_oflag |= OPOST | ONLCR; // Turn back on cr-lf expansion on output
		termio.c_cc[VMIN]=1;
		termio.c_cc[VTIME]=0;

		if(tcsetattr(devfd,TCSANOW,&termio) == -1)
		{
			m_pShell->PVRShellOutputDebug("Can't set tty attributes for %s\n",CONNAME);
		}
	}

	// Keypad handling.
	if ((keypad_fd = open(KEYPAD_INPUT, O_RDONLY | O_NDELAY)) <= 0)
	{
		m_pShell->PVRShellOutputDebug("Can't open keypad input device (%s)\n",KEYPAD_INPUT);
	}

#if defined(PVRSHELL_OMAP3_TS_SUPPORT)
	/*************************************************
	 * Touchscreen code
	 * NOTE: For the init code to work, these variables have to be set prior to the app launch.
	 *
	 * export TSLIB_TSDEVICE=/dev/input/event1
	 * export TSLIB_CONFFILE=/etc/ts.conf
	 * export TSLIB_CALIBFILE=/etc/pointercal
	 * export TSLIB_CONSOLEDEVICE=/dev/tty
	 * export TSLIB_FBDEVICE=/dev/fb0
	 *************************************************/

	ts = ts_open(TOUCHSCREEN_INPUT, 1);

	if (!ts)
	{
		m_pShell->PVRShellOutputDebug("Can't open the touchscreen input device\n");
	}
	else if (ts_config(ts))
	{
		m_pShell->PVRShellOutputDebug("Can't open the touchscreen input device\n");
	}
#endif

   // Remote Control handling
#if defined(PVRSHELL_INTEL_CE_PIC24_REMOTE)
	g_usRemoteLastKey = 0x0;
	pic_if.Init(REMOTE);
#else
    if((remote_fd = open(REMOTE, O_RDONLY|O_NDELAY)) <= 0)
	{
		m_pShell->PVRShellOutputDebug("Can't open remote control input device (%s)\n",REMOTE);
	}
    else
    {
		tcgetattr(remote_fd, &remios_orig);
		remios.c_cflag = B9600 | CRTSCTS | CS8 | CLOCAL | CREAD;
		remios.c_iflag = IGNPAR | ICRNL;
		remios.c_oflag = 0;
		remios.c_lflag = 0;
		remios.c_cc[VMIN] = 1;
		remios.c_cc[VTIME]= 0;

		tcflush(remote_fd, TCIFLUSH);
		tcsetattr(remote_fd, TCSANOW, &remios);
    }
#endif

	// Construct the binary path for GetReadPath() and GetWritePath()

	// Get PID (Process ID)
	pid_t ourPid = getpid();
	char *pszExePath, pszSrcLink[64];
	int len = 64;
	int res;

	sprintf(pszSrcLink, "/proc/%d/exe", ourPid);
	pszExePath = 0;

	do
	{
		len *= 2;
		delete[] pszExePath;
		pszExePath = new char[len];
		res = readlink(pszSrcLink, pszExePath, len);

		if(res < 0)
		{
			m_pShell->PVRShellOutputDebug("Warning Readlink %s failed. The application name, read path and write path have not been set.\n", pszExePath);
			break;
		}
	} while(res >= len);

	if(res >= 0)
	{
		pszExePath[res] = '\0'; // Null-terminate readlink's result
		SetReadPath(pszExePath);
		SetWritePath(pszExePath);
		SetAppName(pszExePath);
	}

	delete[] pszExePath;

	/*
	 Get rid of the blinking cursor on a screen.

	 It's an equivalent of:
	 <CODE> echo -n -e "\033[?25l" > /dev/tty0 </CODE>
	 if you do the above command then you can undo it with:
	 <CODE> echo -n -e "\033[?25h" > /dev/tty0 </CODE>
	*/
	FILE *tty = 0;
	tty = fopen("/dev/tty0", "w");
	if (tty != 0)
	{
		const char txt[] = { 27 /* the ESCAPE ASCII character */
						   , '['
						   , '?'
						   , '2'
						   , '5'
						   , 'l'
						   , 0
						   };

		fprintf(tty, "%s", txt);
		fclose(tty);
	}

	gettimeofday(&m_StartTime,NULL);

#if defined(USE_GDL_PLANE)
	gdl_init(0);

	// Set the width and height to fill the screen
	gdl_display_info_t di;
	gdl_get_display_info(GDL_DISPLAY_ID_0, &di);
	m_pShell->m_pShellData->nShellDimX = di.tvmode.width;
	m_pShell->m_pShellData->nShellDimY = di.tvmode.height;
#endif
}
Exemple #19
0
/*******************************************************************************
*	Description		:
*	Argurments		:
*	Return value	:
*	Modify			:
*	warning			:
*******************************************************************************/
static int nca_touch_device_open(void *ctx_t)
{
	struct NCA_TOUCH_CTX *ctx;

	if( ctx_t == NULL )
		return -1;
	else
		ctx = ctx_t;

	char *tsdevice;

	if( (tsdevice = getenv("TSLIB_TSDEVICE")) )
	{
		if( (ctx->dev=ts_open(tsdevice, 0)))
		{
			if (ts_config(ctx->dev) == 0 )
			{
				/*
				* serch Calibration Info
				*/
				if( touch_check_calibration_file() == FALSE )
				{
					/*
					* serch default Calibration file
					*/
					if( touch_check_default_calibration_file() == TRUE )
					{
						char *def_calibfile = "pointercal";
						char command[128];
						sprintf( command, "cp /etc/%s %s", def_calibfile, getenv("TSLIB_CALIBFILE") );
						system( command );
						system( "sync" );
					}
					else
					{
						printf("NO!! default calibration data!!! \n");
						running_touch_calibrarion(ctx);// add draw graphic
					}
					
				}
			}
			else
			{
				printf("[ERROR] ts_config error \n");
				return -1;
			}
		}
		else
		{
			printf("[ERROR] ts_open error \n");
			return -1;
		}
	}
	else
	{
		printf("[ERROR] getenv error  TSLIB_TSDEVICE \n");
		return -1;
	}

	return 0;

}
Exemple #20
0
int main()
{
	struct tsdev *ts;
	int fd;
	calibration cal;
	int cal_fd;
	char cal_buffer[256];
	char *tsdevice = NULL;
	char *calfile = NULL;
	int i;

	signal(SIGSEGV, sig);
	signal(SIGINT, sig);
	signal(SIGTERM, sig);

	if( (tsdevice = getenv("TSLIB_TSDEVICE")) != NULL ) {
		ts = ts_open(tsdevice,0);
	} else {
#if 0
#ifdef USE_INPUT_API
		ts = ts_open("/dev/input/event0", 0);
#else
		ts = ts_open("/dev/touchscreen/ucb1x00", 0);
#endif /* USE_INPUT_API */
#else
	ts = ts_open("/dev/input/event2", 0);
#endif
	}

	if (!ts) {
		perror("ts_open");
		exit(1);
	}
#if 0
	if (ts_config(ts)) {
		perror("ts_config");
		exit(1);
	}
#endif

	if (open_framebuffer()) {
		close_framebuffer();
		exit(1);
	}
	close_framebuffer();
	if (open_framebuffer()) {
		close_framebuffer();
		exit(1);
	}

	setcolors(0x48ff48,0x880000);

	put_string(xres/2,yres/4,"TSLIB calibration utility",1);
	put_string(xres/2,yres/4 + 20,"Touch crosshair to calibrate",1);

	printf("xres = %d, yres = %d\n",xres,yres);

// Read a touchscreen event to clear the buffer
	//getxy(ts, 0, 0);

// Now paint a crosshair on the upper left and start taking calibration
// data
	put_cross(50,50,1);
	getxy(ts, &cal.x[0], &cal.y[0]);
	put_cross(50,50,0);

	cal.xfb[0] = 50;
	cal.yfb[0] = 50;

	printf("Top left : X = %4d Y = %4d\n", cal.x[0], cal.y[0]);

	put_cross(xres - 50, 50, 1);
	getxy(ts, &cal.x[1], &cal.y[1]);
	put_cross(xres - 50, 50, 0);

	cal.xfb[1] = xres-50;
	cal.yfb[1] = 50;

	printf("Top right: X = %4d Y = %4d\n", cal.x[1], cal.y[1]);

	put_cross(xres - 50, yres - 50, 1);
	getxy(ts, &cal.x[2], &cal.y[2]);
	put_cross(xres - 50, yres - 50, 0);

	cal.xfb[2] = xres-50;
	cal.yfb[2] = yres-50;

	printf("Bot right: X = %4d Y = %4d\n", cal.x[2], cal.y[2]);

	put_cross(50, yres - 50, 1);
	getxy(ts, &cal.x[3], &cal.y[3]);
	put_cross(50, yres - 50, 0);

	cal.xfb[3] = 50;
	cal.yfb[3] = yres-50;

	printf("Bot left : X = %4d Y = %4d\n", cal.x[3], cal.y[3]);

	put_cross(xres/2, yres/2, 1);
	getxy(ts, &cal.x[4], &cal.y[4]);
	put_cross(xres/2, yres/2, 0);

	cal.xfb[4] = xres/2;
	cal.yfb[4] = yres/2;

	printf("Middle: X = %4d Y = %4d\n", cal.x[4], cal.y[4]);

	if(perform_calibration(&cal)) {
		printf("Calibration constants: ");
		for(i=0;i<7;i++) printf("%d ",cal.a[i]);
		printf("\n");
		if( (calfile = getenv("TSLIB_CALIBFILE")) != NULL) {
			cal_fd = open(calfile,O_CREAT|O_RDWR);
		} else {
			cal_fd = open("/etc/pointercal",O_CREAT|O_RDWR);
		}
		sprintf(cal_buffer,"%d %d %d %d %d %d %d\n",cal.a[1],cal.a[2],cal.a[0],cal.a[4],cal.a[5],cal.a[3],cal.a[6]);
		write(cal_fd,cal_buffer,strlen(cal_buffer)+1);
		close(cal_fd);	
	} else {
		printf("Calibration failed.\n");
	}

//	while (1) {
//		struct ts_sample samp;
//
//		if (ts_read_raw(ts, &samp, 1) < 0) {
//			perror("ts_read");
//			exit(1);
//		}
//
//		printf("%ld.%06ld: %6d %6d %6d\n", samp.tv.tv_sec, samp.tv.tv_usec,
//			samp.x, samp.y, samp.pressure);
//	}
	close_framebuffer();
}
Exemple #21
0
static void * Handle_TouchScreen_Input ()
/* 功能:处理触屏输入 */
{
	char *tsdevice;
	struct ts_sample samp;
	int button, x, y, ret;
	LCUI_MouseEvent event;
	
	char str[100];
	while (LCUI_Active()) {
		if (LCUI_Sys.ts.status != INSIDE) {
			tsdevice = getenv("TSLIB_TSDEVICE");
			if( tsdevice != NULL ) {
				LCUI_Sys.ts.td = ts_open(tsdevice, 0);
			} else {
				tsdevice = TS_DEV;
			}
			LCUI_Sys.ts.td = ts_open (tsdevice, 0);
			if (!LCUI_Sys.ts.td) { 
				sprintf (str, "ts_open: %s", tsdevice);
				perror (str);
				LCUI_Sys.ts.status = REMOVE;
				break;
			}

			if (ts_config (LCUI_Sys.ts.td)) {
				perror ("ts_config");
				LCUI_Sys.ts.status = REMOVE;
				break;
			}
			LCUI_Sys.ts.status = INSIDE;
		}

		/* 开始获取触屏点击处的坐标 */ 
		ret = ts_read (LCUI_Sys.ts.td, &samp, 1); 
		if (ret < 0) {
			perror ("ts_read");
			continue;
		}

		if (ret != 1) {
			continue;
		}
		x = samp.x;
		y = samp.y;
		
		if (x > Get_Screen_Width ()) {
			x = Get_Screen_Width ();
		}
		if (y > Get_Screen_Height ()) {
			y = Get_Screen_Height ();
		}
		if (x < 0) {
			x = 0;
		}
		if (y < 0) {
			y = 0;
		}
		/* 设定游标位置 */ 
		Set_Cursor_Pos (Pos(x, y));
		
		event.global_pos.x = x;
		event.global_pos.y = y;
		/* 获取当前鼠标指针覆盖到的部件的指针 */
		event.widget = Get_Cursor_Overlay_Widget();
		/* 如果有覆盖到的部件,就需要计算鼠标指针与部件的相对坐标 */
		if(event.widget != NULL) {
			event.pos.x = x - Get_Widget_Global_Pos(event.widget).x;
			event.pos.y = y - Get_Widget_Global_Pos(event.widget).y;
		} else {/* 否则,和全局坐标一样 */
			event.pos.x = x;
			event.pos.y = y;
		}
		if (samp.pressure > 0) {
			button = 1; 
		} else {
			button = 0; 
		}
			/* 处理鼠标事件 */
		Handle_Mouse_Event(button, &event); 
		//printf("%ld.%06ld: %6d %6d %6d\n", samp.tv.tv_sec, samp.tv.tv_usec, samp.x, samp.y, samp.pressure);
	}
	if(LCUI_Sys.ts.status == INSIDE) {
		ts_close(LCUI_Sys.ts.td); 
	}
	LCUI_Sys.ts.status = REMOVE;
	thread_exit (NULL);
}