static void refresh_screen () { int i; fillrect (0, 0, xres - 1, yres - 1, 0); put_string_center (xres/2, yres/4, "TSLIB test program", 1); put_string_center (xres/2, yres/4+20,"Touch screen to move crosshair", 2); for (i = 0; i < NR_BUTTONS; i++) button_draw (&buttons [i]); }
static void button_draw (struct ts_button *button) { //if button is active s==3 else s==0. int s = (button->flags & BUTTON_ACTIVE) ? 3 : 0; //draw rectangle's outline with palette[3] color when it's active or palette[0] when it's not. rect (button->x, button->y, button->x + button->w - 1, button->y + button->h - 1, button_palette [s]); //fill in the rectagle with palette[4] or [1]. fillrect (button->x + 1, button->y + 1, button->x + button->w - 2, button->y + button->h - 2, button_palette [s + 1]); //and draw fonts inside the button with palette[5] or [2]. if(strcmp(button->text,"Exit")==0) {//when it's exit button. //let's draw decent exit button. //put_string(button->x + 2,button->y + 2,button->text, button_palette[s + 2]); line(button->x, button->y, button->x+button->w-1, button->y+button->h-1,button_palette[s+2]); line(button->x, button->y+button->h -1, button->x+button->w-1, button->y,button_palette[s+2]); } else{ put_string_center (button->x + button->w / 2, button->y + button->h / 2, button->text, button_palette [s + 2]); } }
static void button_draw (struct ts_button *button) { int s = (button->flags & BUTTON_ACTIVE) ? 3 : 0; rect (button->x, button->y, button->x + button->w - 1, button->y + button->h - 1, button_palette [s]); fillrect (button->x + 1, button->y + 1, button->x + button->w - 2, button->y + button->h - 2, button_palette [s + 1]); put_string_center (button->x + button->w / 2, button->y + button->h / 2, button->text, button_palette [s + 2]); }
void *read_ts(void *data) { int x,y; unsigned int i; unsigned int mode =0; while(1) { struct ts_sample samp; int ret; ret = ts_read(data, &samp,1); 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://clear button clicked mode = 0; refresh_screen(); break; case 1://exit button clicked mode = 1; put_string_center(xres/2,yres/2, "Bye~!!",1); sleep(2); fillrect(0,0,xres-1,yres-1,0); exit(1); break; } if(samp.pressure>0) { if(mode == 0x80000000) line(x,y,samp.x,samp.y,2); x = samp.x; y = samp.y; mode|=0x80000000; } else { mode&=~0x80000000; } } }
void draw_icon(struct icon *icon) { int i, j; bmphandle_t bh; if (icon->mode) { bh = bmp_open(icon->name); if (bh == NULL) { perror("bmp_open"); return; } for (i=icon->y; i<icon->y+bmp_height(bh); i++) for (j=icon->x; j<icon->x+bmp_width(bh); j++) *(myfb->fb + i*myfb->fbvar.xres +j) = makepixel(bmp_getpixel(bh, j-icon->x, i-icon->y)); bmp_close(bh); } else { drow_rect(icon->x, icon->y, icon->x + icon->w, icon->y + icon->h, icon->color); put_string_center(icon->x + icon->w/2, icon->y + icon->h/2, icon->name, icon->color); } }
static int button_handle (struct ts_button *button, struct ts_sample *samp) { int inside = (samp->x >= button->x) && (samp->y >= button->y) && (samp->x < button->x + button->w) && (samp->y < button->y + button->h); if (samp->pressure > 0) { if (inside) { if (!(button->flags & BUTTON_ACTIVE)) { button->flags |= BUTTON_ACTIVE; button_draw (button); /*Calculator Process*/ if(button->text[0] == 'C'){ // Clear opVal = 0; value = 0; isCaculate = 0; } else if(button->text[0] == "D"){ // DELete opVal = 0; value /= 10; isCaculate = 0; } else if(button->text[0] == '+'){ if(opSort) caculate(opSort); opVal = value; value = 0; opSort = 1; isCaculate = 0; } else if(button->text[0] == '-'){ if(opSort) caculate(opSort); opVal = value; value = 0; opSort = 2; isCaculate = 0; } else if(button->text[0] == '*'){ if(opSort) caculate(opSort); opVal = value; value = 0; opSort = 3; isCaculate = 0; } else if(button->text[0] == '/'){ if(opSort) caculate(opSort); opVal = value; value = 0; opSort = 4; isCaculate = 0; } else if(button->text[0] == '='){ switch(opSort){ case 1: opVal += value; break; case 2: opVal -= value; break; case 3: opVal *= value; break; case 4: opVal /= value; break; } value = opVal; isCaculate = 1; opSort = 0; } else{ //number if(isCaculate){ isCaculate = 0; value = 0; } value = 10*value + button->text[0] - '0';//char->int } refresh_screen(); char str_value[50];//int -> char for display sprintf(str_value,"%lf",value); put_string_center(xres/2,7*yres/50,str_value,1); } } else if (button->flags & BUTTON_ACTIVE) { button->flags &= ~BUTTON_ACTIVE; button_draw (button); } } else if (button->flags & BUTTON_ACTIVE) { button->flags &= ~BUTTON_ACTIVE; button_draw (button); return 1; } return 0; }
void draw_icon(struct icon *icon) { drow_rect(icon->x, icon->y, icon->x+icon->w, icon->y+icon->h, white); put_string_center(icon->x+icon->w/2, icon->y+icon->h/2, icon->name, white); }
int main(void) { pthread_t ts_thread; void* thread_result; int thread_res; int count ; int offset =0; unsigned short buf_pix ; struct color tmp_color; int i,j; int tmp = 0; signal(SIGSEGV, sig); signal(SIGINT, sig); signal(SIGTERM, sig); myfb = myfb_open(); insert_ipaddr(); for(i=0 ; i <10; i++) printf("\n"); for(i =0 ; i<4 ; i++) { printf(" ipaddr set [%d] = ", i ); for(j=0 ; j <16 ; j++) { printf("%c",ipaddr[i][j]); } printf("\n"); } set_vfb_buf(VFB_MAX); #if DEBUG printf(" set_ vfb buf () \n"); #endif register_icon(&icon[0], 40, 198,60,40, "Single", "" ); register_icon(&icon[1], 130, 198,60,40, "Mult", ""); register_icon(&icon[2], 220, 198,60,40, "Full Screen", ""); register_icon(&icon[3], 298, 5,20,20, "x", ""); thread_res = pthread_create(&ts_thread, NULL, ts_click,NULL); if (thread_res !=0) { perror (" thread create failed\n"); exit(1); } clear_screen(); for (i=0; i<myicon_count; i++) draw_icon(&icon[i]); while( event ==0) { sleep(1); // input delay } while(1) { // insert_ipaddr(); if (event == 9) { put_string_center(140, 100, " exit cam app ", white); sleep(2); goto end; } cam_set(func); if(func == 2 || func == 3) { for(i =0 ; i <VFB_MAX ; i++) { if(i == get_MyLocation()) continue; if (strlen(ipaddr[i]) > 13) { sock[i] = tcp_client_connect(ipaddr[i], ip2port(ipaddr[i],8000)); if (sock[i] < 0) { fprintf(stderr, "%s connect error\n", ipaddr[i]); } } } tmp = 1 ; } event = 0; while(1) { #if DEBUG printf(" main loop start func is %d \n",func); #endif count = read(cam_fd, (unsigned char*)cam_data, image_size); if( count <0) { perror(" cam_data read err \n"); exit(1); } offset = 0; for (i =0 ; i <camif_cfg.dst_y ; i++) { for(j = 0 ; j < camif_cfg.dst_x; j++) { memcpy(&buf_pix,cam_data+offset, sizeof(unsigned short)); offset+= 2; tmp_color = reveres_pixel(buf_pix); buf_pixel(j,i,tmp_color); } } for (i=0; i<myicon_count; i++) draw_icon(&icon[i]); if(func == 1) { show_vfb(vfb_list[0]);// demo ver need change 0 to mylocation } else if (func == 2) { if (tmp ==0) break; send_data(func); show_vfb(vfb_list[0]);// demo ver need change 0 to mylocation } else if (func == 3) { if (tmp ==0) break; send_data(func); show_vfb(vfb_list[get_MyLocation()]);// demo ver need change 0 to mylocation } for (i=0; i<myicon_count; i++) draw_icon(&icon[i]); if (event == 9) { put_string_center(140, 100, " exit cam app ", white); sleep(2); goto end; } else if( event != 0 ) { break; } }// end while "main lool" write(cam_fd,"X",2); /* Stop Camera */ if (cam_fd) close(cam_fd); for(i =0 ; i< VFB_MAX; i++) { if(sock[i]) close(sock[i]); } //clear_all_screen(); } end: clear_screen(); // clear_all_screen(); thread_res= pthread_join(ts_thread, &thread_result); for(i =0 ; i< VFB_MAX; i++) { if(sock[i]) close(sock[i]); } if (cam_fd > 0) { write(cam_fd,"X",2); close(cam_fd); } if (cam_data >0) free(cam_data); myfb_close(); free_vfb_buf(VFB_MAX); return 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); }
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; }