static void scan_start (unsigned int timestamp) { ScanState *state = scan_state(); switch (state->timer_state) { case SCAN_IDLE: state->timer_state = SCAN_LINES; state->scan_column = 0; state->scan_row = 0; g_timeout_add_full (G_PRIORITY_HIGH_IDLE, 600, increment_scan, state, NULL); select_line (state->scan_row); break; case SCAN_LINES_DONE: state->timer_state = SCAN_KEYS; g_timeout_add_full (G_PRIORITY_HIGH_IDLE, 600, increment_scan, state, NULL); deselect_line (state->scan_row); select_key (state->scan_row, state->scan_column); break; case SCAN_KEYS_DONE: gtk_button_clicked (buttons[state->scan_row][state->scan_column]); deselect_key (state->scan_row, state->scan_column); state->timer_state = SCAN_IDLE; break; default: g_print("unexpected state for 'scan start'\n"); } }
static void scan_stop (unsigned int timestamp) { /* find the element correspondin to this event's timestamp */ ScanState *state = scan_state(); switch (state->timer_state) { case SCAN_LINES: state->timer_state = SCAN_LINES_DONE; break; case SCAN_KEYS: state->timer_state = SCAN_KEYS_DONE; g_timeout_add_full (G_PRIORITY_HIGH_IDLE, 1200, timeout_scan, state, NULL); break; case SCAN_IDLE: break; default: g_print("unexpected state for 'scan stop'\n"); } }
int main(int argc, char **argv) { int i; char errbuf[128]; FILE *file; if (argc<2) { printf("usage: %s keymap\n", argv[0]); return 1; } file = fopen(argv[1], "rt"); if (!file) { printf("cannot open file %s\n", argv[1]); return 2; } if (load_keymap(file, errbuf, sizeof(errbuf))) { printf("load_keymap error: %s\n", errbuf); exit(1); } fclose(file); tcgetattr(0, &ts); ts0 = ts; cfmakeraw(&ts); tcsetattr(0, TCSANOW, &ts); atexit(exit_f); signal(SIGINT, sig_f); signal(SIGTERM, sig_f); signal(SIGHUP, sig_f); /* switch into scanmode */ printf("\033[S"); printf("\r\n"); for (i = 0; i < 100; i++) { unsigned char b; long key; int state; state = scan_state(); printf("\r\nstate: %d\r\n", state ); if (!read(0, &b, 1)) break; /*printf("read: %x\r\n", (int)b); */ key = scan_key(b); if (key) { state = scan_state(); printf("scan_key: %ld (%c), state=%d\r\n", key, (int) ((key > 32 && key < 256) ? key : 32), state); if (key == 'q') exit(0); } } return 0; }