Exemple #1
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;
}
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 #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
static int bbb_relation_load(cst_relation *r,const char *filename)
{
    const char *token;
    cst_item *item;
    cst_tokenstream *fd;

    fd = ts_open(filename);
    if (fd == 0)
	return 0;

    while (!ts_eof(fd))
    {
	token = ts_get(fd);
	if (cst_streq(token,""))
	    continue;
	item = relation_append(r,NULL);
	item_set_string(item,"name",token);
	item_set_string(item,"whitespace",fd->whitespace);
	item_set_string(item,"prepunctuation",fd->prepunctuation);
	item_set_string(item,"punc",fd->postpunctuation);
	item_set_int(item,"file_pos",fd->file_pos);
	item_set_int(item,"line_number",fd->line_number);
    }
    
    ts_close(fd);

    return 1;
}
Exemple #5
0
cst_val *get_wavelist(const char *wavelistfile)
{
    cst_val *l = 0;
    cst_tokenstream *ts;
    const char *token;
    int i=0;

    ts = ts_open(wavelistfile);
    if (!ts)
    {
	fprintf(stderr,"combine_waves: can't open \"%s\"\n",wavelistfile);
	return 0;
    }

    while ((token=ts_get(ts)) != 0)
    {
	l = cons_val(string_val(token),l);
	i++;
    }

    if (i%2 != 0)
    {
	fprintf(stderr,"combine_waves: doesn't have matched pairs \"%s\"\n",wavelistfile);
	delete_val(l);
	l = 0;
    }

    ts_close(ts);

    return val_reverse(l);
}
Exemple #6
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 {
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 #8
0
int relation_load(cst_relation *r, const char *filename)
{
    cst_tokenstream *fd;
    cst_item *item;
    const char *token=0;

    if ((fd = ts_open(filename,NULL,";","","")) == 0)
    {
	cst_errmsg("relation_load: can't open file \"%s\" for reading\n",
		   filename);
	return CST_ERROR_FORMAT;
    }

    for ( ; !ts_eof(fd); )
    {
	token = ts_get(fd);
	if (cst_streq("#",token))
	    break;
    }
#import "OpenEarsStaticAnalysisToggle.h"
#ifdef STATICANALYZEDEPENDENCIES
#define __clang_analyzer__ 1
#endif
#if !defined(__clang_analyzer__) || defined(STATICANALYZEDEPENDENCIES)
#undef __clang_analyzer__
    if (!cst_streq("#",token))
#endif        
    {
	cst_errmsg("relation_load: no end of header marker in \"%s\"\n",
		   filename);
	ts_close(fd);
	return CST_ERROR_FORMAT;
    }

    while (!ts_eof(fd))
    {
	token = ts_get(fd);
	if (cst_streq(token,""))
	    continue;
	item = relation_append(r,NULL);
	item_set_float(item,"end",(float)cst_atof(token));
#import "OpenEarsStaticAnalysisToggle.h"
#ifdef STATICANALYZEDEPENDENCIES
#define __clang_analyzer__ 1
#endif
#if !defined(__clang_analyzer__) || defined(STATICANALYZEDEPENDENCIES)
#undef __clang_analyzer__
        
	token = ts_get(fd);
#endif        
	token = ts_get(fd);
	item_set_string(item,"name",token);
    }

    ts_close(fd);
    return CST_OK_FORMAT;
}
Exemple #9
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 #10
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;
}
Exemple #11
0
int relation_load(cst_relation *r, const char *filename)
{
    cst_tokenstream *fd;
    cst_item *item;
    const char *token=0;

    if ((fd = ts_open(filename,NULL,";","","")) == 0)
    {
	cst_errmsg("relation_load: can't open file \"%s\" for reading\n",
		   filename);
	return CST_ERROR_FORMAT;
    }

    for ( ; !ts_eof(fd); )
    {
	token = ts_get(fd);
	if (cst_streq("#",token))
	    break;
    }
 

    if (!cst_streq("#",token))
        
    {
	cst_errmsg("relation_load: no end of header marker in \"%s\"\n",
		   filename);
	ts_close(fd);
	return CST_ERROR_FORMAT;
    }

    while (!ts_eof(fd))
    {
	token = ts_get(fd);
	if (cst_streq(token,""))
	    continue;
	item = relation_append(r,NULL);
	item_set_float(item,"end",(float)cst_atof(token));
 

        
	token = ts_get(fd);
       
	token = ts_get(fd);
	item_set_string(item,"name",token);
    }

    ts_close(fd);
    return CST_OK_FORMAT;
}
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;
}
Exemple #13
0
float flite_ssml_to_speech(const char *filename,
                           cst_voice *voice,
                           const char *outtype)
{
    cst_tokenstream *ts;
    int fp;
    cst_wave *w;
    float d;

    if ((ts = ts_open(filename,
	      get_param_string(voice->features,"text_whitespace",NULL),
	      get_param_string(voice->features,"text_singlecharsymbols",NULL),
	      get_param_string(voice->features,"text_prepunctuation",NULL),
	      get_param_string(voice->features,"text_postpunctuation",NULL)))
	== NULL)
    {
	cst_errmsg("failed to open file \"%s\" for ssml reading\n",
		   filename);
	return 1;
    }
    fp = get_param_int(voice->features,"file_start_position",0);
    if (fp > 0)
        ts_set_stream_pos(ts,fp);

    /* If its a file to write to, create and save an empty wave file */
    /* as we are going to incrementally append to it                 */
    if (!cst_streq(outtype,"play") && 
        !cst_streq(outtype,"none") &&
        !cst_streq(outtype,"stream"))
    {
	w = new_wave();
	cst_wave_resize(w,0,1);
	cst_wave_set_sample_rate(w,16000);
	cst_wave_save_riff(w,outtype);  /* an empty wave */
	delete_wave(w);
    }

    d = flite_ssml_to_speech_ts(ts,voice,outtype);

    ts_close(ts);
    
    return d;

}
Exemple #14
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 #15
0
cst_val *cst_lex_load_addenda(const cst_lexicon *lex, const char *lexfile)
{   /* Load an addend from given file, check its phones wrt lex */
    cst_tokenstream *lf;
    const cst_string *line;
    cst_val *e = NULL;
    cst_val *na = NULL;
    int i;

    lf = ts_open(lexfile,"\n","","","");
    if (lf == NULL)
    {
        cst_errmsg("lex_add_addenda: cannot open lexicon file\n");
        return NULL;;
    }

    while (!ts_eof(lf))
    {
        line = ts_get(lf);
        if (line[0] == '#')
            continue;  /* a comment */
        for (i=0; line[i]; i++)
        {
            if (line[i] != ' ')
                break;
        }
        if (line[i])
        {
            e = cst_lex_make_entry(lex,line);
            if (e)
                na = cons_val(e,na);
        }
        else
            continue;  /* a blank line */
    }

    ts_close(lf);
    return val_reverse(na);
}
Exemple #16
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 #17
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 #18
0
int cst_track_load_est(cst_track *t, const char *filename)
{
    cst_tokenstream *ts;
    const char *tok;
    int num_frames, num_channels;
    int i, ascii = 1, swap = 0, rv;

    num_frames = 0;
    num_channels = 0;
    ts = ts_open(filename, NULL, NULL, NULL, NULL);
    if (ts == NULL)
    {
        cst_errmsg("cst_track_load: can't open file \"%s\"\n", filename);
        return -1;
    }

    if (!cst_streq(ts_get(ts), "EST_File"))
    {
        cst_errmsg("cst_track_load: not an EST file \"%s\"\n", filename);
        ts_close(ts);
        return -1;
    }
    if (!cst_streq(ts_get(ts), "Track"))
    {
        cst_errmsg("cst_track_load: not an track file \"%s\"\n", filename);
        ts_close(ts);
        return -1;
    }

    while (!cst_streq("EST_Header_End", (tok = ts_get(ts))))
    {
        if (cst_streq("DataType", tok))
        {
            tok = ts_get(ts);
            if (cst_streq("ascii", tok))
            {
                ascii = 1;
            }
            else if (cst_streq("binary", tok))
            {
                ascii = 0;
            }
            else
            {
                cst_errmsg("cst_track_load: don't know how to deal "
                           "with type \"%s\"\n", tok);
                ts_close(ts);
                return -1;
            }
        }
        else if (cst_streq("ByteOrder", tok))
        {
            tok = ts_get(ts);
            swap = (cst_streq(tok, BYTE_ORDER_BIG) && CST_LITTLE_ENDIAN)
                || (cst_streq(tok, BYTE_ORDER_LITTLE) && CST_BIG_ENDIAN);
        }
        else if (cst_streq("NumFrames", tok))
            num_frames = atoi(ts_get(ts));
        else if (cst_streq("NumChannels", tok))
            num_channels = atoi(ts_get(ts));
        else
            ts_get(ts);
        if (ts_eof(ts))
        {
            cst_errmsg("cst_track_load: EOF in header \"%s\"\n", filename);
            ts_close(ts);
            return -1;
        }
    }

    cst_track_resize(t, num_frames, num_channels);

    for (i = 0; i < t->num_frames; i++)
    {
        if (ascii)
            rv = load_frame_ascii(t, i, ts);
        else
            rv = load_frame_binary(t, i, ts, swap);
        if (rv < 0)
        {
            ts_close(ts);
            cst_errmsg("cst_track_load: EOF in data \"%s\"\n", filename);
            return rv;
        }
    }

    ts_get(ts);
    if (!ts_eof(ts))
    {
        cst_errmsg("cst_track_load: not EOF when expected \"%s\"\n",
                   filename);
        ts_close(ts);
        return -1;
    }

    ts_close(ts);

    return 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";
	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 #20
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;
}
float flite_file_to_speech(const char *filename, 
			   cst_voice *voice,
			   const char *outtype)
{
    cst_utterance *utt;
    cst_tokenstream *ts;
    const char *token;
    cst_item *t;
    cst_relation *tokrel;
    float d, durs = 0;
    int num_tokens;
    cst_breakfunc breakfunc = default_utt_break;

    if ((ts = ts_open(filename,
	      get_param_string(voice->features,"text_whitespace",NULL),
	      get_param_string(voice->features,"text_singlecharsymbols",NULL),
	      get_param_string(voice->features,"text_prepunctuation",NULL),
	      get_param_string(voice->features,"text_postpunctuation",NULL)))
	== NULL)
    {
	cst_errmsg("failed to open file \"%s\" for reading\n",
		   filename);
	return 1;
    }

    if (feat_present(voice->features,"utt_break"))
	breakfunc = val_breakfunc(feat_val(voice->features,"utt_break"));

    /* If its a file to write to delete it as we're going to */
    /* incrementally append to it                            */
    if (!cst_streq(outtype,"play") && !cst_streq(outtype,"none"))
    {
	cst_wave *w;
	w = new_wave();
	cst_wave_resize(w,0,1);
	cst_wave_set_sample_rate(w,16000);
	cst_wave_save_riff(w,outtype);  /* an empty wave */
	delete_wave(w);
    }

    num_tokens = 0;
    utt = new_utterance();
    tokrel = utt_relation_create(utt, "Token");
    while (!ts_eof(ts) || num_tokens > 0)
    {
	token = ts_get(ts);
	if ((strlen(token) == 0) ||
	    (num_tokens > 500) ||  /* need an upper bound */
	    (relation_head(tokrel) && 
	     breakfunc(ts,token,tokrel)))
	{
	    /* An end of utt */
	    d = flite_tokens_to_speech(utt,voice,outtype);
	    utt = NULL;
	    if (d < 0)
		goto out;
	    durs += d;

	    if (ts_eof(ts))
		goto out;

	    utt = new_utterance();
	    tokrel = utt_relation_create(utt, "Token");
	    num_tokens = 0;
	}
	num_tokens++;

	t = relation_append(tokrel, NULL);
	item_set_string(t,"name",token);
	item_set_string(t,"whitespace",ts->whitespace);
	item_set_string(t,"prepunctuation",ts->prepunctuation);
	item_set_string(t,"punc",ts->postpunctuation);
	item_set_int(t,"file_pos",ts->file_pos);
	item_set_int(t,"line_number",ts->line_number);
    }

out:
    delete_utterance(utt);
    ts_close(ts);
    return durs;
}
Exemple #22
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();
}
Exemple #23
0
static int waveshare_read(struct tslib_module_info *inf, struct ts_sample *samp,
			  int nr)
{
	static short reopen = 1;
	struct stat devstat;
	struct hidraw_devinfo info;
	char name_buf[512];
	int cnt;
	short found = 0;
	struct tslib_input *i = (struct tslib_input *) inf;
	struct tsdev *ts = inf->dev;
	struct tsdev *ts_tmp;
	char *buf;
	int ret;

	if (reopen == 1) {
		reopen = 0;

		if (i->vendor > 0 && i->product > 0) {
#ifdef DEBUG
			fprintf(stderr,
				"waveshare: searching for device using hidraw...\n");
#endif
			for (cnt = 0; cnt < HIDRAW_MAX_DEVICES; cnt++) {
				snprintf(name_buf, sizeof(name_buf),
					 "/dev/hidraw%d", cnt);
#ifdef DEBUG
				fprintf(stderr,
					"waveshare: device: %s\n", name_buf);
#endif
				ret = stat(name_buf, &devstat);
				if (ret < 0)
					continue;

				ts_tmp = ts_open(name_buf, 0);
				if (!ts_tmp)
					continue;

#ifdef DEBUG
				fprintf(stderr, "  opened\n");
#endif
				ret = ioctl(ts_tmp->fd, HIDIOCGRAWINFO, &info);
				if (ret < 0) {
					ts_close(ts_tmp);
					continue;
				}

				info.vendor &= 0xFFFF;
				info.product &= 0xFFFF;
#ifdef DEBUG
				fprintf(stderr,
					"  vid=%04X, pid=%04X\n",
					info.vendor, info.product);
#endif

				if (i->vendor == info.vendor &&
				    i->product == info.product) {
					close(ts->fd);

					ts->fd = ts_tmp->fd;
					found = 1;
#ifdef DEBUG
					fprintf(stderr, "  correct device\n");
#endif
					ts_close(ts_tmp);
					break;
				}

				ts_close(ts_tmp);
			} /* for HIDRAW_MAX_DEVICES */

			if (found == 0)
				return -1;
		} /* vid/pid set */
	} /* reopen */

	buf = alloca(i->len * nr);

	ret = read(ts->fd, buf, i->len * nr);
	if (ret > 0) {
		while (ret >= (int) i->len) {
	/*
	  0000271: aa01 00e4 0139 bb01 01e0 0320 01e0 0320 01e0 0320 01e0 0320 cc  .....9..... ... ... ... .

	  "aa" is start of the command,
	  "01" means clicked, while
	  "00" means unclicked.
	  "00e4" and "0139" is the X,Y position (HEX).
	  "bb" is start of multi-touch,
	  and the following bytes are the position of each point.
	 */
			samp->pressure = buf[1] & 0xff;
			samp->x = ((buf[2] & 0xff) << 8) | (buf[3] & 0xff);
			samp->y = ((buf[4] & 0xff) << 8) | (buf[5] & 0xff);
			gettimeofday(&samp->tv, NULL);
		#ifdef DEBUG
			fprintf(stderr, "waveshare raw: %d %d %d\n",
				samp->x, samp->y, samp->pressure);
			fprintf(stderr, "%x %x %x %x %x %x\n",
				buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
		#endif
			samp++;
			buf += i->len;
			ret -= i->len;
		}
	} else {
		return -1;
	}

	return nr;
}
Exemple #24
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;

}
/*!***********************************************************************
 @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 #26
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);
}
Exemple #27
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 #28
0
float flite_file_to_speech(const char *filename, 
			   cst_voice *voice,
			   const char *outtype)
{
    cst_utterance *utt;
    cst_tokenstream *ts;
    const char *token;
    cst_item *t;
    cst_relation *tokrel;
    float durs = 0;
    int num_tokens;
    cst_wave *w;
    cst_breakfunc breakfunc = default_utt_break;
    cst_uttfunc utt_user_callback = 0;
    int fp;

    if ((ts = ts_open(filename,
	      get_param_string(voice->features,"text_whitespace",NULL),
	      get_param_string(voice->features,"text_singlecharsymbols",NULL),
	      get_param_string(voice->features,"text_prepunctuation",NULL),
	      get_param_string(voice->features,"text_postpunctuation",NULL)))
	== NULL)
    {
	cst_errmsg("failed to open file \"%s\" for reading\n",
		   filename);
	return 1;
    }
    fp = get_param_int(voice->features,"file_start_position",0);
    if (fp > 0)
        ts_set_stream_pos(ts,fp);

    if (feat_present(voice->features,"utt_break"))
	breakfunc = val_breakfunc(feat_val(voice->features,"utt_break"));

    if (feat_present(voice->features,"utt_user_callback"))
	utt_user_callback = val_uttfunc(feat_val(voice->features,"utt_user_callback"));

    /* If its a file to write to, create and save an empty wave file */
    /* as we are going to incrementally append to it                 */
    if (!cst_streq(outtype,"play") && 
        !cst_streq(outtype,"none") &&
        !cst_streq(outtype,"stream"))
    {
	w = new_wave();
	cst_wave_resize(w,0,1);
	cst_wave_set_sample_rate(w,16000);
	cst_wave_save_riff(w,outtype);  /* an empty wave */
	delete_wave(w);
    }

    num_tokens = 0;
    utt = new_utterance();
    tokrel = utt_relation_create(utt, "Token");
    while (!ts_eof(ts) || num_tokens > 0)
    {
	token = ts_get(ts);
	if ((cst_strlen(token) == 0) ||
	    (num_tokens > 500) ||  /* need an upper bound */
	    (relation_head(tokrel) && 
	     breakfunc(ts,token,tokrel)))
	{
	    /* An end of utt, so synthesize it */
            if (utt_user_callback)
                utt = (utt_user_callback)(utt);

            if (utt)
            {
                utt = flite_do_synth(utt,voice,utt_synth_tokens);
                durs += flite_process_output(utt,outtype,TRUE);
                delete_utterance(utt); utt = NULL;
            }
            else 
                break;

	    if (ts_eof(ts)) break;

	    utt = new_utterance();
	    tokrel = utt_relation_create(utt, "Token");
	    num_tokens = 0;
	}
	num_tokens++;

	t = relation_append(tokrel, NULL);
	item_set_string(t,"name",token);
	item_set_string(t,"whitespace",ts->whitespace);
	item_set_string(t,"prepunctuation",ts->prepunctuation);
	item_set_string(t,"punc",ts->postpunctuation);
        /* Mark it at the beginning of the token */
	item_set_int(t,"file_pos",
                     ts->file_pos-(1+ /* as we are already on the next char */
                                   cst_strlen(token)+
                                   cst_strlen(ts->prepunctuation)+
                                   cst_strlen(ts->postpunctuation)));
	item_set_int(t,"line_number",ts->line_number);
    }

    delete_utterance(utt);
    ts_close(ts);
    return durs;
}
Exemple #29
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);
}
Exemple #30
0
void bindToGalax (void) {
	FILE *fp = NULL;
	char keyword[MAX_KEYWORD_LEN];
	char param[MAX_PARAM_LEN];
	unsigned char thisDev = 0;
	int ch, devFound = 0;
	unsigned int i = 0;

	//if ( ts )
	//	return;

	fp = fopen("/proc/bus/input/devices", "r");
    
	if (!fp) {
		int err = errno;
		fprintf(stderr, "error: Unable to open file /proc/bus/input/devices.\r\nError: %s\n", strerror(err));
		exit(-1);
	}

	while ( !feof(fp) ) {

		ch = fgetc(fp);
		if ( ch == 'N' ) {
			memset(keyword, 0, sizeof(keyword));
			i = 0;
			while (( !feof(fp)) && ( ch != '\n' )) {
				if ( i < sizeof(keyword) - 2 )
					keyword[i++] = ch;
				ch = fgetc(fp);
			}
                
			if ( strcmp(keyword, GALAX_DEVICE_NAME) == 0 ) {
				devFound = 1;
				thisDev = 1;
			} else thisDev = 0;
		}

		if (( ch == 'H' ) && ( thisDev )) {
			memset(keyword, 0, sizeof(keyword));
			i = 0;
			while (( !feof(fp)) && ( ch != '\n')) {
				if ( i < sizeof(keyword) - 2 )
					keyword[i++] = ch;
				ch = fgetc(fp);
			}

			if ( strncmp(keyword, "H: Handlers=", 12) == 0 ) {
				int lastParam = 0;
				int paramEnd, paramBegin = 12;

				while ( !lastParam ) {
					memset(param, 0, sizeof(param));
					paramEnd = 0;

					while (( keyword[paramBegin + paramEnd] != ' ') && ( keyword[paramBegin + paramEnd] != 0 ))
						paramEnd++;

					if (( keyword[paramBegin + paramEnd] == 0 ) || ( keyword[paramBegin + paramEnd + 1] == 0 ))
						lastParam = 1;

					strncpy(param, keyword+paramBegin, paramEnd);
					if ( strncmp(param, "event", 5) == 0 ) {
						fclose(fp);
						char eventPath[16 + paramEnd];
						sprintf(eventPath, "/dev/input/%s", param);
						ts = ts_open(eventPath, 0);

						printf("Binding tslib to %s\n", eventPath);
						return;
					}
					paramBegin += paramEnd + 1;
				}
			}
		}
		while (( !feof(fp)) && ( ch != '\n' ))
			ch = fgetc(fp);
	}

	fclose(fp);

	if ( devFound )
		fprintf(stderr, "error: Unable to parse event handler for eGalax Touchscreen from /proc/bus/input/devices.\nEvent handler missing, or file format cannot be parsed.\n");
	else
		fprintf(stderr, "error: Unable find eGalax Touchscreen from /proc/bus/input/devices.\nMissing %s\n", GALAX_DEVICE_NAME);
	exit(-1);
}