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; }
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; }
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); }
static void parse_description(const char *description, cst_features *f) { /* parse the description into something more usable */ cst_tokenstream *ts; const char *arg; char *op; const char *xop; ts = ts_open_string(description, " \t\r\n", /* whitespace */ "{}[]|", /* singlecharsymbols */ "", /* prepunctuation */ ""); /* postpunctuation */ while (!ts_eof(ts)) { op = cst_strdup(ts_get(ts)); if ((op[0] == '-') && (cst_strchr(ts->whitespace,'\n') != 0)) { /* got an option */ xop = feat_own_string(f,op); arg = ts_get(ts); if (arg[0] == '<') feat_set_string(f,xop,arg); else feat_set_string(f,xop,"<binary>"); } cst_free(op); } ts_close(ts); }
static void parse_description(const char *description, cst_features *f) { /* parse the description into something more usable */ cst_tokenstream *ts; const char *arg; char *op; ts = ts_open_string(description); ts->whitespacesymbols = " \t\r\n"; ts->singlecharsymbols = "{}[]|"; ts->prepunctuationsymbols = ""; ts->postpunctuationsymbols = ""; while (!ts_eof(ts)) { op = cst_strdup(ts_get(ts)); if ((op[0] == '-') && (strchr(ts->whitespace,'\n') != 0)) { /* got an option */ arg = ts_get(ts); if (arg[0] == '<') feat_set_string(f,op,arg); else feat_set_string(f,op,"<binary>"); } } ts_close(ts); }
cst_utterance *default_tokenization(cst_utterance *u) { const char *text,*token; cst_tokenstream *fd; cst_item *t; cst_relation *r; text = utt_input_text(u); r = utt_relation_create(u,"Token"); fd = ts_open_string(text, get_param_string(u->features,"text_whitespace",NULL), get_param_string(u->features,"text_singlecharsymbols",NULL), get_param_string(u->features,"text_prepunctuation",NULL), get_param_string(u->features,"text_postpunctuation",NULL)); while(!ts_eof(fd)) { token = ts_get(fd); if (cst_strlen(token) > 0) { t = relation_append(r,NULL); item_set_string(t,"name",token); item_set_string(t,"whitespace",fd->whitespace); item_set_string(t,"prepunctuation",fd->prepunctuation); item_set_string(t,"punc",fd->postpunctuation); item_set_int(t,"file_pos",fd->file_pos); item_set_int(t,"line_number",fd->line_number); } } ts_close(fd); return u; }
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); }
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; }
static int TSInputDeviceExit(void) { if(NULL != g_ptTouchScreenFd){ ts_close(g_ptTouchScreenFd); } return 0; }
static void PD_Close(void) { /* Close the touch panel device. */ if(pd_fd < 0) return; ts_close(ts); pd_fd = -1; }
void TslibFini (void) { KdMouseInfo *mi; KdUnregisterFds (TsInputType, TRUE); for (mi = kdMouseInfo; mi; mi = mi->next) { if (mi->inputType == TsInputType) { if(mi->driver) ts_close(tsDev); mi->driver = 0; mi->inputType = 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; }
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); }
int main(int argc, char **argv) { int c, r; char *hostname, *service; struct tunsess *tun; struct sigaction sigact; int local_tunid; openlog("tunneldigger-client", 0, 0); while ((c = getopt(argc, argv, "dhfu:l:b:p:i:s:t:L:")) != EOF) { switch (c) { case 'h': /* show help */ print_help(); exit(EXIT_SUCCESS); break; case 'f': /* don't daemonize */ dont_daemonize = 1; break; case 'd': debug_flag = 1; break; case 'u': /* connection UUID */ uuid = strdup(optarg); break; case 'l': /* local IP address */ local_ip = strdup(optarg); break; case 'b': /* broker in <host>:<port> form */ if (parse_broker(optarg, &hostname, &service) != 0) { fprintf(stderr, "invalid broker specification\n"); exit(EXIT_FAILURE); } break; case 'i': /* tunnel interface name */ ifname = strdup(optarg); break; case 's': /* hook script */ script = strdup(optarg); break; case 't': /* tunnel id */ local_tunid = atoi(optarg); break; case 'L': /* limit bandwidth down */ limit_down = atoi(optarg); break; default: fprintf(stderr, "use '-h' for help\n", c); break; } } l2tp_init(); if (!uuid) { printf ("the uuid is required\n"); exit(EXIT_FAILURE); } tun = ts_new(hostname, service); tun->local_tunid = local_tunid; tun->ifname = strdup(ifname); /* create and bind a socket, and connect it */ if ((r=ts_socket_bind_connect(tun)) != 0) { error("unable to obtain bound socket\n"); exit(EXIT_FAILURE); } /* request a cookie */ if ((r=ts_get_cookie(tun)) != 0) { error("unable to get cookie\n"); exit(EXIT_FAILURE); } /* request a tunnel */ if ((r=ts_get_tunnel(tun)) != 0) { error("unable to get tunnel\n"); exit(EXIT_FAILURE); } /* create the tunnel */ if (ts_create_tunnel(tun) != 0) { error("unable to create tunnel (is l2tp_eth loaded?)!\n"); exit(EXIT_FAILURE); } /* handle SIGINT */ sigact.sa_handler = signal_handler; sigemptyset(&sigact.sa_mask); if (sigaction(SIGINT, &sigact, NULL) < 0) { error("couldn't set signal handler\n"); } /* keep the tunnel alive, and respond to PMTU discovery requests */ ts_keepalive(tun); error("closing tunnel\n"); if (ts_delete_tunnel(tun) != 0) { error("unable to delete tunnel!\n"); exit(EXIT_FAILURE); } ts_close(tun); }
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; }
int main(int argc, char *argv[]) { int ret; struct tsdev *ts; lua_State *L; myfb = myfb_open(); set_vfb_buf(1); ts = ts_init(); L = luaL_newstate(); luaL_openlibs(L); lua_register(L, "SET_COUNT", lua_set_icon_count); lua_register(L, "SET_ICON", lua_set_icon_info); lua_register(L, "SET_CMD", lua_set_cmd_list); lua_register(L, "SET_BGCOLOR", lua_set_bgcolor); lua_register(L, "SET_BGIMAGE", lua_set_bgimage); luaL_dofile(L, file_ui); lua_close(L); while (1) { int c, da_count, old_da_count, pid, state = 0; struct ts_sample samp; struct icon *i; struct cmd_list *j; da_count = get_DeviceAttached(); if (!da_count) da_count = 0; if (!old_da_count) old_da_count = da_count; else { if (old_da_count != da_count) { clear_screen(); put_string_center(myfb->fbvar.xres/2, myfb->fbvar.yres/2 - 10, "Attached Info is changed!", white); put_string_center(myfb->fbvar.xres/2, myfb->fbvar.yres/2 + 10, "Touch the screen!", white); old_da_count = da_count; ret = ts_read(ts, &samp, 1); continue; } } set_bgimage(); set_bgcolor(); for (c=0; c<=da_count; c++) draw_block(myfb->fbvar.xres-12*c-12, 3); if (head == NULL) { put_string_center(myfb->fbvar.xres/2, myfb->fbvar.yres/2, "Sorry, No Apps. registered!", white); #ifdef DEBUG fprintf(stderr, "No Apps!\n"); #endif break; } for (i=head; i != NULL; i=i->next) draw_icon(i); ret = ts_read(ts, &samp, 1); if (ret < 0) { perror("ts_read"); continue; } if (ret != 1) continue; if (samp.x > 310 && samp.y >230) break; for (i=head, j=cmdlist; i != NULL; i=i->next, j=j->next) { if (icon_handle(i, &samp) > 0) { if (chat_count < 20) continue; chat_count = 0; pid = fork(); if (pid == 0) { #ifdef DEBUG fprintf(stderr, " *** This is CHILD! ***\n"); #endif if (j) ret = execl(j->path, j->args, 0); if (ret < 0) { perror("execl"); exit(1); } } else { sleep(1); wait(&state); no_count = 0; put_string_center(myfb->fbvar.xres/2, myfb->fbvar.yres/2, "End of Program!", white); #ifdef DEBUG fprintf(stderr, " *** End of CHILD! ***\n"); #endif } } } } clear_screen(); put_string_center(myfb->fbvar.xres/2, myfb->fbvar.yres/2, "Thanks for Use!", white); free_icon(); free_cmd(); ts_close(ts); free_vfb_buf(1); myfb_close(); return 0; }
cst_val *cst_lex_make_entry(const cst_lexicon *lex, const cst_string *entry) { /* if replace then replace entry in addenda of lex with entry */ /* else append entry to addenda of lex */ cst_tokenstream *e; cst_val *phones = NULL; cst_val *ventry; const cst_string *w, *p; cst_string *word; cst_string *pos; int i; e = ts_open_string(entry, cst_ts_default_whitespacesymbols, "","",""); w = ts_get(e); if (w[0] == '"') /* it was a quoted entry */ { /* so reparse it */ ts_close(e); e = ts_open_string(entry, cst_ts_default_whitespacesymbols, "","",""); w = ts_get_quoted_token(e,'"','\\'); } word = cst_strdup(w); p = ts_get(e); if (!cst_streq(":",p)) /* there is a real pos */ { pos = cst_strdup(p); p = ts_get(e); if (!cst_streq(":",p)) /* there is a real pos */ { cst_fprintf(stdout,"add_addenda: lex %s: expected \":\" in %s\n", lex->name, word); cst_free(word); cst_free(pos); ts_close(e); return NULL; } } else pos = cst_strdup("nil"); while (!ts_eof(e)) { p = ts_get(e); /* Check its a legal phone */ for (i=0; lex->phone_table[i]; i++) { if (cst_streq(p,lex->phone_table[i])) break; } if (cst_streq("#",p)) /* comment to end of line */ break; else if (cst_streq("",p)) /* trailing ws at eoln causes this */ break; else if (lex->phone_table[i]) /* Only add it if its a valid phone */ phones = cons_val(string_val(p),phones); else { cst_fprintf(stdout,"add_addenda: lex: %s word %s phone %s not in lexicon phoneset\n", lex->name, word, p); } } ventry = cons_val(string_val(word),cons_val(string_val(pos), val_reverse(phones))); cst_free(word); cst_free(pos); ts_close(e); #if 0 printf("entry: "); val_print(stdout,ventry); printf("\n"); #endif return ventry; }
cst_file cst_url_open(const char *url) { /* Always opens it for reading */ cst_tokenstream *urlts; const cst_string *protocol; int port; cst_string *host; int fd; char *url_request; char *path; cst_file ofd; int state,n; char c; urlts = ts_open_string(url, "", ":/", "", ""); protocol = ts_get(urlts); if (cst_streq(protocol,"http")) { #ifdef CST_NO_SOCKETS ts_close(urlts); return NULL; #else if (!cst_streq(ts_get(urlts),":") || !cst_streq(ts_get(urlts),"/") || !cst_streq(ts_get(urlts),"/")) { ts_close(urlts); return NULL; } host = cst_strdup(ts_get(urlts)); if (cst_streq(ts_get(urlts),":")) port = (int)cst_atof(ts_get(urlts)); else port = 80; /* Open port to web server */ fd = cst_socket_open(host,port); if (fd < 0) { cst_free(host); ts_close(urlts); return NULL; } url_request = cst_alloc(char,cst_strlen(url)+17); cst_sprintf(url_request,"GET %s HTTP/1.2\n\n",url); n = write(fd,url_request,cst_strlen(url_request)); cst_free(url_request); /* Skip http header -- until \n\n */ state=0; while (state != 4) { n=read(fd,&c,1); if (n == 0) { /* eof or link gone down */ cst_free(host); ts_close(urlts); return NULL; } if ((state == 0) && (c == '\r')) state=1; else if ((state == 1) && (c == '\n')) state=2; else if ((state == 2) && (c == '\r')) state=3; else if ((state == 3) && (c == '\n')) state=4; /* Not sure you can get no CRs in the stream */ else if ((state == 0) && (c == '\n')) state=2; else if ((state == 2) && (c == '\n')) state=4; else state = 0; } ofd = fdopen(fd,"rb"); ts_close(urlts); cst_free(host); return ofd; #endif }
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; }
CStreamInfo2::~CStreamInfo2 () { delete pip; ts_close(); }
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; }
int CStreamInfo2::doSignalStrengthLoop () { #define BAR_WIDTH 150 #define BAR_HEIGHT 12 int res = menu_return::RETURN_REPAINT; neutrino_msg_t msg; uint64_t maxb, minb, lastb, tmp_rate; unsigned int current_pmt_version= pmt_version; int cnt = 0; char tmp_str[150]; int delay_counter = 0; const int delay = 15; int offset = g_Font[font_info]->getRenderWidth(g_Locale->getText (LOCALE_STREAMINFO_BITRATE)); int sw = g_Font[font_info]->getRenderWidth ("99999.999"); maxb = minb = lastb = tmp_rate = 0; ts_setup (); while (1) { neutrino_msg_data_t data; uint64_t timeoutEnd = CRCInput::calcTimeoutEnd_MS (100); g_RCInput->getMsgAbsoluteTimeout (&msg, &data, &timeoutEnd); if (!mp) { signal.sig = frontend->getSignalStrength() & 0xFFFF; signal.snr = frontend->getSignalNoiseRatio() & 0xFFFF; signal.ber = frontend->getBitErrorRate(); } int ret = update_rate (); if (paint_mode == 0) { if (cnt < 12) cnt++; int dheight = g_Font[font_info]->getHeight (); int dx1 = x + 10; if(!mp && delay_counter > delay + 1){ CZapitChannel * channel = CZapit::getInstance()->GetCurrentChannel(); if(channel) pmt_version = channel->getPmtVersion(); if(pmt_version != current_pmt_version){ delay_counter = 0; } } if (ret && (lastb != bit_s)) { lastb = bit_s; if (maxb < bit_s) rate.max_short_average = maxb = bit_s; if ((cnt > 10) && ((minb == 0) || (minb > bit_s))) rate.min_short_average = minb = bit_s; char currate[150]; sprintf(tmp_str, "%s:",g_Locale->getText(LOCALE_STREAMINFO_BITRATE)); g_Font[font_info]->RenderString(dx1 , average_bitrate_pos, offset+10, tmp_str, COL_INFOBAR_TEXT); sprintf(currate, "%5llu.%02llu", rate.short_average / 1000ULL, rate.short_average % 1000ULL); frameBuffer->paintBoxRel (dx1 + average_bitrate_offset , average_bitrate_pos -dheight, sw, dheight, COL_MENUHEAD_PLUS_0); g_Font[font_info]->RenderString (dx1 + average_bitrate_offset , average_bitrate_pos, sw - 10, currate, COL_INFOBAR_TEXT); sprintf(tmp_str, "(%s)",g_Locale->getText(LOCALE_STREAMINFO_AVERAGE_BITRATE)); g_Font[font_info]->RenderString (dx1 + average_bitrate_offset + sw , average_bitrate_pos, sw *2, tmp_str, COL_INFOBAR_TEXT); } if (!mp) { showSNR (); if(pmt_version != current_pmt_version && delay_counter > delay){ current_pmt_version = pmt_version; paint_techinfo (x + 10, y+ hheight +5); } } delay_counter++; } rate.short_average = abit_s; if (signal.max_ber < signal.ber) signal.max_ber = signal.ber; if (signal.max_sig < signal.sig) signal.max_sig = signal.sig; if (signal.max_snr < signal.snr) signal.max_snr = signal.snr; if ((signal.min_ber == 0) || (signal.min_ber > signal.ber)) signal.min_ber = signal.ber; if ((signal.min_sig == 0) || (signal.min_sig > signal.sig)) signal.min_sig = signal.sig; if ((signal.min_snr == 0) || (signal.min_snr > signal.snr)) signal.min_snr = signal.snr; paint_signal_fe(rate, signal); signal.old_sig = signal.sig; signal.old_snr = signal.snr; signal.old_ber = signal.ber; // switch paint mode if (msg == CRCInput::RC_red || msg == CRCInput::RC_blue || msg == CRCInput::RC_green || msg == CRCInput::RC_yellow) { hide (); paint_mode = !paint_mode; paint (paint_mode); continue; } else if(msg == CRCInput::RC_setup) { res = menu_return::RETURN_EXIT_ALL; break; } else if((msg == CRCInput::RC_sat) || (msg == CRCInput::RC_favorites)) { g_RCInput->postMsg (msg, 0); res = menu_return::RETURN_EXIT_ALL; break; } else if (msg == (neutrino_msg_t) g_settings.key_screenshot) { CNeutrinoApp::getInstance ()->handleMsg (msg, data); continue; } // -- any key --> abort if (msg <= CRCInput::RC_MaxRC) break; // -- push other events if (msg > CRCInput::RC_MaxRC && msg != CRCInput::RC_timeout) CNeutrinoApp::getInstance ()->handleMsg (msg, data); } delete signalbox; signalbox = NULL; ts_close (); return res; }
int CStreamInfo2::doSignalStrengthLoop() { #define RED_BAR 40 #define YELLOW_BAR 70 #define GREEN_BAR 100 #define BAR_WIDTH 150 #define BAR_HEIGHT 12 sigscale = new CProgressBar(BAR_WIDTH, BAR_HEIGHT, RED_BAR, GREEN_BAR, YELLOW_BAR); snrscale = new CProgressBar(BAR_WIDTH, BAR_HEIGHT, RED_BAR, GREEN_BAR, YELLOW_BAR); neutrino_msg_t msg; unsigned long long maxb, minb, lastb, tmp_rate; int cnt = 0,i=0; uint16_t ssig, ssnr; uint32_t ber; char tmp_str[150]; int offset_tmp = 0; int offset = g_Font[font_info]->getRenderWidth(g_Locale->getText (LOCALE_STREAMINFO_BITRATE)); int sw = g_Font[font_info]->getRenderWidth ("99999.999"); int mm = g_Font[font_info]->getRenderWidth ("Max");//max min lenght maxb = minb = lastb = 0; frameBuffer->blit(); //channel //CChannelList *channelList = CNeutrinoApp::getInstance ()->channelList; //int curnum = channelList->getActiveChannelNumber(); //CZapitChannel * channel = channelList->getChannel(curnum); //CZapitClient::CCurrentServiceInfo si = g_Zapit->getCurrentServiceInfo(); ts_setup(); while (1) { neutrino_msg_data_t data; unsigned long long timeoutEnd = CRCInput::calcTimeoutEnd_MS (100); g_RCInput->getMsgAbsoluteTimeout (&msg, &data, &timeoutEnd); if(live_fe != NULL) { ssig = live_fe->getSignalStrength(); ssnr = live_fe->getSignalNoiseRatio(); ber = live_fe->getBitErrorRate(); } signal.sig = ssig & 0xFFFF; signal.snr = ssnr & 0xFFFF; signal.ber = ber; int ret = update_rate (); if (paint_mode == 0) { char currate[150]; if (cnt < 12) cnt++; int dheight = g_Font[font_info]->getHeight (); int dx1 = x + 10; //int dy = y+ height - dheight - 5; /**/ if (ret && (lastb != bit_s)) { lastb = bit_s; if (maxb < bit_s) rate.max_short_average = maxb = bit_s; if ((cnt > 10) && ((minb == 0) || (minb > bit_s))) rate.min_short_average = minb = bit_s; for(i = 0; i < 3; i++) { switch (i) { case 0: tmp_rate = bit_s; sprintf(tmp_str, "%s", g_Locale->getText(LOCALE_STREAMINFO_BITRATE)); offset_tmp = 0; break; case 1: tmp_rate = minb; sprintf(tmp_str, "%s", "Min"); offset_tmp = offset+5; break; case 2: tmp_rate = maxb; sprintf(tmp_str, "%s", "Max"); offset_tmp = offset+5+mm; break; } /* Bitrate */ //g_Font[font_info]->RenderString (dx1+offset_tmp+((sw)*i), yypos+(dheight*4), offset, tmp_str, COL_MENUCONTENTDARK, 0, true); sprintf(currate, "%5llu.%03llu", tmp_rate / 1000ULL, tmp_rate % 1000ULL); frameBuffer->paintBoxRel (dx1+offset+5+((sw+mm)*i), yypos+(dheight*3), sw, dheight, /*COL_MENUHEAD_PLUS_0*/ COL_MENUCONTENTDARK_PLUS_0); /* bitrate values max/min */ //g_Font[font_info]->RenderString (dx1+offset+10+((sw+mm)*i), yypos+(dheight*4), sw - 10, currate, COL_MENUCONTENTDARK); } } if(snrscale && sigscale) showSNR (); } rate.short_average = abit_s; if (signal.max_ber < signal.ber) { signal.max_ber = signal.ber; } if (signal.max_sig < signal.sig) { signal.max_sig = signal.sig; } if (signal.max_snr < signal.snr) { signal.max_snr = signal.snr; } if ((signal.min_ber == 0) || (signal.min_ber > signal.ber)) { signal.min_ber = signal.ber; } if ((signal.min_sig == 0) || (signal.min_sig > signal.sig)) { signal.min_sig = signal.sig; } if ((signal.min_snr == 0) || (signal.min_snr > signal.snr)) { signal.min_snr = signal.snr; } paint_signal_fe(rate, signal); signal.old_sig = signal.sig; signal.old_snr = signal.snr; signal.old_ber = signal.ber; // switch paint mode //FIXME picture info if (msg == CRCInput::RC_red || msg == CRCInput::RC_blue || msg == CRCInput::RC_green || msg == CRCInput::RC_yellow) { hide (); if(sigscale) sigscale->reset(); if(snrscale) snrscale->reset(); paint_mode = ++paint_mode % 2; paint(paint_mode); continue; } // -- any key --> abort if (msg <= CRCInput::RC_MaxRC) { break; } // -- push other events if (msg > CRCInput::RC_MaxRC && msg != CRCInput::RC_timeout) { CNeutrinoApp::getInstance ()->handleMsg (msg, data); } frameBuffer->blit(); } if(sigscale) { delete sigscale; sigscale = NULL; } if(snrscale) { delete snrscale; snrscale = NULL; } ts_close (); return msg; }
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); }
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); } } }
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; }