static bool create_rscope(char* line, GrowableArray<RDatabaseScope*>* stack) { // remove the cr int len = strlen(line); if (len > 1 && line[len-1] == '\n') line[len-1] = '\0'; int bci = 0; int level = 0; methodOop method = NULL; klassOop receiver_klass = NULL; RScope* result = NULL; if (stack->isEmpty()) { // the root scope if (!scan_key(NULL, line, &receiver_klass, &method)) return false; stack->push(new RDatabaseScope(NULL, -1, receiver_klass, method, 0)); } else { // sub scope int index = scan_prefix(line, &bci, &level); if (index <= 0) return false; while (stack->length() > level) stack->pop(); RDatabaseScope* sender = stack->top(); if (scan_uncommon(&line[index])) { sender->mark_as_uncommon(bci); } else if (scan_key(sender, &line[index], &receiver_klass, &method)) { stack->push(new RDatabaseScope(sender, bci, receiver_klass, method, level)); } else { return false; } } return true; }
uint8_t do_prompt() { print(PSTR(">")); char group[10]; // scanf("%4s",group); scan_key(group,10); if (strcmp(group,"rf")==0) { return rf_do_prompt(); } else if (strcmp(group,"io")==0) { return io_do_prompt(); } else if (strcmp(group,"test")==0) { print_test(); scan_test(); } else if (strcmp(group,"timer")==0) { return timer_do_prompt(); } else if (strcmp(group,"server")==0) { return server_do_prompt(); } else if (strcmp(group,"client")==0) { return client_do_prompt(); } else if (strcmp(group,"set")==0) { return set_do_prompt(); } else if (strcmp(group,"pad")==0) { return pad_do_prompt(); } else if (strcmp(group,".")==0) { return 0; } return 1; }
main() { uint key_flag; on_off = 1; position = 0; while (1) { key_flag = scan_key(); if (key_flag == 3) { on_off = !on_off; } if ((key_flag == 1) | (key_flag == 0)) { jdc_switch(key_flag); } transf_temper(); if (on_off == 1) { temp_ctl(); } trans_data(); } }
static int kp_irq_func(void) { l4_cap_idx_t irq_cap = l4re_util_cap_alloc(); l4_cap_idx_t thread_cap = pthread_getl4cap(_pthread); l4_msgtag_t tag; l4_debugger_set_object_name(thread_cap, "kp-omap3.irq"); if (l4io_request_irq(7, irq_cap) < 0) return -2; // was L4_IRQ_F_LEVEL_LOW tag = l4_irq_attach(irq_cap, 0, thread_cap); if (l4_ipc_error(tag, l4_utcb())) return -3; while (1) { tag = l4_irq_receive(irq_cap, L4_IPC_NEVER); if (l4_ipc_error(tag, l4_utcb())) { printf("[KEYP] Error: Receive irq failed\n"); continue; } kp_write(REG_KEYP_IMR1, 0xf); if (kp_handler) scan_key(); l4_uint8_t value = 0; kp_read(REG_KEYP_ISR1, &value); kp_write(REG_KEYP_IMR1, 0x0); } }
static void output_func_add_money(fsm_t* fsm){ nevera_fsm_t* nevera = (nevera_fsm_t*) fsm; display_add_money_menu(); add_saldo(nevera->user_selected,scan_float()); display_total_money(nevera->user_selected->saldo); scan_key(); nevera->option_selected = -1; }
uint8_t set_do_prompt() { char cmd[17]; scan_key(cmd,17); if (strcmp(cmd,"auto_client")==0) { eewr_b(EE_AUTO_MODE,0); print_ok_nl(); return 1; } if (strcmp(cmd,"auto_server")==0) { eewr_b(EE_AUTO_MODE,1); print_ok_nl(); return 1; } if (strcmp(cmd,"client_id")==0) { uint8_t cid = scan_uint8(); eewr_b(EE_CLIENT_ID,cid); print_ok_nl(); return 1; } if (strcmp(cmd,"slot_size")==0) { uint8_t slot_size = scan_uint8(); eewr_b(EE_SLOT_SIZE,slot_size); print_ok_nl(); return 1; } if (strcmp(cmd,"slot_count")==0) { uint8_t slot_count = scan_uint8(); eewr_b(EE_SLOT_COUNT,slot_count); print_ok_nl(); return 1; } if (strcmp(cmd,"slot_rest_delay")==0) { uint8_t slot_rest_delay = scan_uint8(); eewr_b(EE_SLOT_REST_DELAY,slot_rest_delay); print_ok_nl(); return 1; } if (strcmp(cmd,"slot_rf_timeout")==0) { uint8_t slot_rf_timeout = scan_uint8(); eewr_b(EE_SLOT_RF_TIMEOUT,slot_rf_timeout); print_ok_nl(); return 1; } if (strcmp(cmd,"info")==0) { set_print_info(); return 1; } return 1; }
int getchp(int mask) { /* read a character with scan mode conversion */ if (scan_mode) { tc_putp(req_for_input); fflush(stdout); return scan_key(); } else return getnext(mask); }
main() { unsigned char key_s,key_v; key_v = 0x03; P2 = 0xfe; while(1) { key_s = scan_key(); if(key_s != key_v) { delayms(10); key_s = scan_key(); if(key_s != key_v) { key_v = key_s; proc_key(key_v); } } } }
void InliningDatabase::load_index_file() { ResourceMark rm; TraceTime t("Loading index for inlining database"); // Open the file FILE* stream = fopen(index_file_name(), "rt"); if (!stream) return; char line[1000]; LookupKey first; LookupKey second; while (fgets( line, 1000, stream)) { if (scan_key(line, &first)) { if (first.is_block_type()) { if (fgets( line, 1000, stream)) { if (scan_key(line, &second)) { // std->print("Block "); // first.print_on(std); // std->print(" outer "); // second.print_on(std); // std->cr(); add_lookup_entry(&second, &first); } else { std->print_cr("Index file parsing block failed for %s", line); } } } else { // std->print("Method "); // first.print_on(std); // std->cr(); add_lookup_entry(&first); } } else { std->print_cr("Index file parsing failed for %s", line); } } fclose(stream); }
int main(void) { timer1_initialize(); DDRA = 0xFF; PORTD |= 0x0F; while (1) //sei(); { scan_key(); show_direction(); pwm_set(); _delay_ms(10); } }
void main(void) { P0 = 0xff; P2 = 0xff; TMOD = 0x11; // 定时器0, 1工作模式1, 16位定时方式 TH1 = 0xdc; TL1 = 0; TH0 = 0xFC; TL0 = 0x17; clr_time(); // dis_digit = 0x7f; // 初始显示P20口数码管 dis_index = 0; // key_times = 0; key_v = 0x01; IE = 0x8a; // 使能timer0, timer1中断 TR0 = 1; TR1 = 0; while(1) { if(scan_key()) { delayms(10); if(scan_key()) { key_v = key_s; proc_key(); } } } }
// Wrapper that parses results from ANSI probe to update screensize. // Otherwise acts like scan_key() int scan_key_getsize(char *scratch, int miliwait, unsigned *xx, unsigned *yy) { int key; if (512&(key = scan_key(scratch, miliwait))) { if (key>0) { if (xx) *xx = (key>>10)&1023; if (yy) *yy = (key>>20)&1023; toys.signal = SIGWINCH; return -3; } } return key; }
/*============================================================================= Function : kfront_thread Description : Input : Output : Return : =============================================================================*/ static int kfront_thread(void *__us) { struct kfront_tag *us = (struct kfront_tag *)__us; int pulse = 0; display_msg("----"); while (!us->bQuit) { scan_key(); msleep(LOOP_DELAY); #ifdef REPEAT_KEY_SUPPORT cur_loop_count++; #endif if (kfront_mode) // run { if (kfront_display_mode == 1) full(0x00); else if (kfront_display_mode == 2) full(0xff); else { } } else // standby { /* display time pulse */ pulse++; if (pulse >= (500 / LOOP_DELAY)) { toggle_time_pulse(); pulse = 0; } } /* display new string */ if (display_flag) { display_msg(display_data); display_flag = 0; } } }
uint8_t pad_do_prompt() { char cmd[17]; scan_key(cmd,17); if (strcmp(cmd,"init")==0) { pad_init(); return 1; } if ((strcmp(cmd,"test")==0) || (strcmp(cmd,"ping")==0)) { if (pad_ping()) { print_ok_nl(); } else { print_err_nl(); } return 1; } if (strcmp(cmd,"state")==0) { uint8_t d = pad_state(); if (d == PAD_REMOTE_ERROR) { print_err_nl(); } else { print_hb(0,d); print_nl(); } return 1; } if (strcmp(cmd,"led")==0) { pad_led(); return 1; } if (strcmp(cmd,"rled")==0) { pad_remote_led(); return 1; } if (strcmp(cmd,"read")==0) { uint8_t d = pad_read(); print_hb(0,d); print_nl(); return 1; } if (strcmp(cmd,"write")==0) { uint8_t v0 = scan_uint8(); if (pad_write(v0)) { print_ok_nl(); } else { print_err_nl(); } return 1; } if (strcmp(cmd,"autoread")==0) { pad_autoread(); return 1; } return 1; }
uint8_t client_do_prompt() { char cmd[17]; //scanf("%16s",cmd); scan_key(cmd,17); if (strcmp(cmd,"init")==0) { client_init(); print_ok_nl(); return 1; } if (strcmp(cmd,"loop")==0) { uint16_t count = scan_uint16(); if (count == 0) { print(PSTR("client loop....")); while(!uart_read_ready()) { client_loop(); } print(PSTR(" end\n\r")); } else { while(count--) { print_char('.'); client_loop(); } } return 1; } if (strcmp(cmd,"autotune")==0) { client_autotune(); return 1; } if (strcmp(cmd,"channel")==0) { uint8_t c = scan_uint8(); client_select_channel(c); return 1; } if (strcmp(cmd,"check")==0) { uint8_t c = scan_uint8(); if (client_check_for_server(c)) { print(PSTR("ok\r\n")); } else { print(PSTR("fail\r\n")); } return 1; } if (strcmp(cmd,"pad")==0) { uint8_t l = client_read_pad(); print_hb(0,l); while(!uart_read_ready()) { uint8_t d = client_read_pad(); if (d!=l) { l = d; print_hb(PSTR(" "), d); } } return 1; } if (strcmp(cmd,"reset_stats")==0) { stats_ok = 0; stats_inv_seq = 0; stats_bad_crc = 0; stats_timeout = 0; print(PSTR("stat reset ok")); return 1; } if (strcmp(cmd,"stats")==0) { print_dw(PSTR("ok: "), stats_ok); print_dw(PSTR(" inv_seq: "), stats_inv_seq); print_dw(PSTR(" bad_crc: "), stats_bad_crc); print_dw(PSTR(" timeout: "), stats_timeout); print_nl(); return 1; } return 1; }
static int scan_match_Key(ScreenBase * base, unsigned char b, unsigned long *keyp) { long key; if (xterm_mouse && b == RAWMODE_ESC) { xterm_pos = 1; return 0; } if (xterm_mouse && xterm_pos) { int mb, t, bb = 0; static struct timeval tv1 = { 0, 0 }, tv2; static int clicks = 0; switch (xterm_pos) { case 1: xterm_buttons = b; xterm_pos = 2; return 0; case 2: xterm_x = b; xterm_pos = 3; return 0; case 3: default: xterm_y = b; xterm_pos = 0; if (xterm_x < base->mouse_left) xterm_x = base->mouse_left; if (xterm_x > base->mouse_right) xterm_x = base->mouse_right; if (xterm_y < base->mouse_top) xterm_y = base->mouse_top; if (xterm_y > base->mouse_bottom) xterm_y = base->mouse_bottom; base->mouse_x = xterm_x; base->mouse_y = xterm_y; base->mouse_auto_visible = 1; if (xterm_buttons & 0x4) { t = MOUSE_TYPE_MOVE; bb = base->mouse_buttons; } else { mb = xterm_buttons & 0x3; if (mb != 3) { long dt; if (mb == 0) bb = MOUSE_BUTTONS_LEFT; else if (mb == 1) bb = MOUSE_BUTTONS_MIDDLE; else if (mb == 2) bb = MOUSE_BUTTONS_RIGHT; base->mouse_buttons = bb; gettimeofday(&tv2, 0); dt = (tv2.tv_sec - tv1.tv_sec) * 1000 + (tv2.tv_usec - tv1.tv_usec) / 1000; if (tv1.tv_sec && dt < base->mouse_dclick_speed) { clicks++; clicks %= 2; } else clicks = 0; t = MOUSE_TYPE_DOWN; } else { bb = base->mouse_buttons; if (bb == MOUSE_BUTTONS_LEFT) base->mouse_clicks_left++; if (bb == MOUSE_BUTTONS_RIGHT) base->mouse_clicks_right++; if (bb == MOUSE_BUTTONS_MIDDLE) base->mouse_clicks_middle++; base->mouse_buttons = 0; t = MOUSE_TYPE_UP | (MOUSE_TYPE_SINGLE << clicks); gettimeofday(&tv1, 0); clicks = 0; } } _clip_logg(3, "got xterm rawmode mouse event: type=%d y=%d x=%d xt_buttons=%d buttons=%d clicks=%d", t, xterm_y, xterm_x, xterm_buttons, bb, clicks); key = MOUSE_MASK; key |= MOUSE_SET_TYPE(t); key |= MOUSE_SET_ROW(xterm_y); key |= MOUSE_SET_COL(xterm_x); key |= MOUSE_SET_BUTTONS(bb); *keyp = key; return 1; } } key = scan_key(b); if (key) { *keyp = key; //scan_reset(); return 1; } else return 0; }
static void output_func_check_money(fsm_t* fsm){ nevera_fsm_t* nevera = (nevera_fsm_t*) fsm; display_total_money(nevera->user_selected->saldo); scan_key(); nevera->option_selected = -1; }
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; }