int button_process(Button *b) { struct input_event ev; ssize_t l; assert(b); l = read(b->fd, &ev, sizeof(ev)); if (l < 0) return errno != EAGAIN ? -errno : 0; if ((size_t) l < sizeof(ev)) return -EIO; if (ev.type == EV_KEY && ev.value > 0) { switch (ev.code) { case KEY_POWER: case KEY_POWER2: log_info("Power key pressed."); return button_handle(b, INHIBIT_HANDLE_POWER_KEY, b->manager->handle_power_key, b->manager->power_key_ignore_inhibited, true); /* The kernel is a bit confused here: KEY_SLEEP = suspend-to-ram, which everybody else calls "suspend" KEY_SUSPEND = suspend-to-disk, which everybody else calls "hibernate" */ case KEY_SLEEP: log_info("Suspend key pressed."); return button_handle(b, INHIBIT_HANDLE_SUSPEND_KEY, b->manager->handle_suspend_key, b->manager->suspend_key_ignore_inhibited, true); case KEY_SUSPEND: log_info("Hibernate key pressed."); return button_handle(b, INHIBIT_HANDLE_HIBERNATE_KEY, b->manager->handle_hibernate_key, b->manager->hibernate_key_ignore_inhibited, true); } } else if (ev.type == EV_SW && ev.value > 0) { switch (ev.code) { case SW_LID: log_info("Lid closed."); b->lid_close_queued = true; return button_handle(b, INHIBIT_HANDLE_LID_SWITCH, b->manager->handle_lid_switch, b->manager->lid_switch_ignore_inhibited, true); } } else if (ev.type == EV_SW && ev.value == 0) { switch (ev.code) { case SW_LID: log_info("Lid opened."); b->lid_close_queued = false; break; } } return 0; }
int button_recheck(Button *b) { assert(b); if (!b->lid_close_queued) return 0; return button_handle(b, INHIBIT_HANDLE_LID_SWITCH, b->manager->handle_lid_switch, b->manager->lid_switch_ignore_inhibited, false); }
void buttons_step() { if (config.gui.disp_flags & CFG_DISP_FLIP) { button_handle(2, GpioRead(SWITCH1)); button_handle(0, GpioRead(SWITCH3)); } else { button_handle(0, GpioRead(SWITCH1)); button_handle(2, GpioRead(SWITCH3)); } button_handle(1, GpioRead(SWITCH2)); if (buttons_state[0] > BS_IDLE || buttons_state[1] > BS_IDLE || buttons_state[2] > BS_IDLE) button_lock.Lock(); else button_lock.Unlock(); }
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; } } }
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(); }
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(); }