void sig_handler(int signo) { if (signo == SIGINT) { end_display(); exit(EXIT_SUCCESS); } }
int main(int argc, char* argv[]) { int res; int i; // Initialize the hidapi library printf("Starting to initialize HID library...\n"); res = hid_init(); printf("Initialized HID library.\n"); // Open the device using the VID, PID, // and optionally the Serial number. printf("Trying to open device...\n"); handle = hid_open(0x04d8, 0x003f, NULL); if(handle != NULL) { printf("Opened device successfully.\n"); } else { printf("Could not open device.\n"); exit(EXIT_FAILURE); } read_device_info(); toggle_led1(); printf("Button is %spressed.\n", get_push1_state() ? "" : "not "); printf("The decimal result is %d\n", get_pot1_val()); // Register signal handler if (signal(SIGINT, sig_handler) == SIG_ERR) { printf("\nCan't catch SIGINT\n"); exit(EXIT_FAILURE); } // Enter ncurses mode initialize_display(); // Main loop while(1) { int a; a = (int)((100 / 1023.0) * get_pot1_val()); print_percent_bar(2, a); refresh(); sleep(0.1); } // Leave ncurses mode end_display(); // Unregister signal handler signal(SIGINT, SIG_DFL); // Finalize the hidapi library res = hid_exit(); return 0; }
int execute(button *bp) { char buf[100]; snprintf(buf, sizeof(buf), "exec run_exhibit %s", bp->name); end_display(); fprintf(stderr, "running '%s'\n", buf); system(buf); exit(0); /* NOTREACHED */ }
void kbd_hit(char key) { set_active(); switch (key) { case 'd': dump_screen(0); break; case 'w': case 'W': save_image(); break; case 'q': case 'Q': case 'x': case 'X': /* exit the program */ end_display(); exit(0); case 'v': show_video_settings = !show_video_settings; refresh_screen = 1; break; case 'h': set_hue(get_hue() - 1); refresh_screen = 1; break; case 'H': set_hue(get_hue() + 1); refresh_screen = 1; break; case 's': set_saturation(get_saturation() - 1); refresh_screen = 1; break; case 'S': set_saturation(get_saturation() + 1); refresh_screen = 1; break; case 'b': set_brightness(get_brightness() - 1); refresh_screen = 1; break; case 'B': set_brightness(get_brightness() + 1); refresh_screen = 1; break; case 'c': set_contrast(get_contrast() - 1); refresh_screen = 1; break; case 'C': set_contrast(get_contrast() + 1); refresh_screen = 1; break; } }
void update_display() { if ( !is_display_on() ) return; int nb_ticks = _compute_nb_ticks(_current) - _compute_nb_ticks(_last_displayed); if (nb_ticks > 0) { _last_displayed = _current; _display_ticks(nb_ticks); } if ( _current >= _max ) end_display(); }
void list_all_groups(void) { char *argv[5]; argv[0] = argv[1] = argv[3] = "true"; argv[4] = "dontcare"; argv[2] = "false"; first_time = 1; if ((status = mr_query("qualified_get_lists", 5, argv, print_all, NULL))) { display_buff("\n"); com_err(whoami, status, " in list_all_groups\n"); } end_display(); }
void kbd_hit(char key) { char buf[100]; switch (key) { case 'a': abort(); case 'd': dump_screen(0); break; case 'q': case 'Q': case 'x': case 'X': /* exit the program */ end_display(); exit(0); } }
int main (int argc, char **argv) { int r, c; begin_display(&r, &c); /* reserve one line for message row */ make_board(r-1, c); msg_row = r-1; prompt("Welcome to Life, Version %s, Copyright 1995, Jim Wise", VERSION_STR); clear_board(); while (1) { if (!edit()) break; run(); } end_display(); exit(0); }
void list_members(void) { char *argv[1]; char *buf; char buffer[80]; found_some = 0; move(DISPROW, STARTCOL); mvcur(0, 0, DISPROW, STARTCOL); refresh(); buf = calloc(LISTMAX, 1); if (Prompt("Enter List Name: ", buf, LISTSIZE, 1) == 1) { sprintf(buffer, "The members of list '%s' are:", buf); show_text(DISPROW + 1, STARTCOL, buffer); argv[0] = buf; if ((status = mr_query("get_members_of_list", 1, argv, print_2, NULL))) { display_buff("\n"); com_err(whoami, status, " found.\n"); currow++; } if (!found_some) { show_text(currow, STARTCOL, "List is empty (no members)."); currow++; show_text(currow, STARTCOL, "Press any key to continue..."); getchar(); clrwin(DISPROW); goto cleanup; } end_display(); goto cleanup; } clrwin(DISPROW); cleanup: free(buf); }
void quit_game(int err_code) { end_display(); exit(err_code); }
int main() { init_environment(); init_data(); init_display(); cuss::interface i_editor; Window w_editor(0, 0, 80, 24); if (!i_editor.load_from_file("cuss/i_element_ed.cuss")) { debugmsg("Can't load cuss/i_element_ed.cuss"); end_display(); return 1; } std::vector<std::string> element_names; std::vector<std::string> transform_names; std::vector<std::string> damage_names; i_editor.ref_data("list_elements", &element_names); i_editor.ref_data("list_transformations", &transform_names); i_editor.ref_data("list_damagetypes", &damage_names); i_editor.select ("list_elements"); bool quit = false; while (!quit) { element_names = get_names(); cuss::element* selected = i_editor.selected(); int ele_num = i_editor.get_int("list_elements"); element* cur_element = NULL; if (ele_num < ELEMENTS_POOL.size()) { cur_element = &(ELEMENTS_POOL[ele_num]); std::stringstream color_data; color_data << "<c=" << color_tag_name(cur_element->color) << ">************<c=/>"; i_editor.set_data("text_color", color_data.str()); i_editor.ref_data("entry_name", &(cur_element->name)); } transform_names = get_tra_names(cur_element); damage_names = get_dmg_names(cur_element); i_editor.draw(&w_editor); long ch = getch(); if (selected->name == "entry_name" && ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || ch == ' ')) { cur_element->name += ch; } else if (selected->name == "entry_name" && is_backspace(ch) && !cur_element->name.empty()) { cur_element->name = cur_element->name.substr( 0, cur_element->name.length() - 1); } else if (ch == 's' || ch == 'S') { quit = true; } else if (ch == 'c' || ch == 'C') { change_color(cur_element); } else if (ch == 'a' || ch == 'A') { // Where are we adding an element? if (selected->name == "list_elements") { element tmp; tmp.name = string_input_popup("Name:"); ELEMENTS_POOL.push_back(tmp); i_editor.set_data("list_elements", 999); } else if (selected->name == "list_transformations") { add_transformation(cur_element); i_editor.set_data("list_transformations", 0); } else if (selected->name == "list_damagetypes") { add_damagetype(cur_element); i_editor.set_data("list_damagetypes", 0); } } else if (ch == 'd' || ch == 'D') { // Where are we deleting an element? if (selected->name == "list_elements" && cur_element) { delete_element(ele_num); i_editor.set_data("list_elements", 0); } else if (selected->name == "list_transformations") { int index = i_editor.get_int("list_transformations"); if (cur_element && index >= 0 && index < cur_element->transformations.size()) { delete_transformation(cur_element, index); i_editor.set_data("list_transformations", 0); } } else if (selected->name == "list_damagetypes") { int index = i_editor.get_int("list_damagetypes"); if (cur_element && index >= 0 && index < cur_element->damages.size()) { delete_damagetype(cur_element, index); i_editor.set_data("list_damagetypes", 0); } } } else { i_editor.handle_action(ch); } } // while (!quit) save_data(); end_display(); return 0; }
int do_exit(void *param, image in, image out) { end_display(); exit(0); }
int main() { init_environment(); init_data(); init_display(); cuss::interface i_editor; Window w_editor(0, 0, 80, 24); if (!i_editor.load_from_file("cuss/i_terrain.cuss")) { debugmsg("Couldn't load cuss/i_terrain.cuss!"); end_display(); return 1; } std::vector<std::string> type_names; std::vector<std::string> flags; std::vector<std::string> transformations; i_editor.ref_data("list_types", &type_names); i_editor.ref_data("list_flags", &flags); i_editor.ref_data("list_transformations", &transformations); i_editor.select("list_types"); for (int i = 0; i < TER_MAX; i++) { if (i >= TERRAIN_POOL.size() || TERRAIN_POOL[i] == NULL) { TERRAIN_POOL.push_back( new terrain_type ); TERRAIN_POOL[i]->name = default_terrain_name( terrain_id(i) ); } } // Main loop bool quit = false; do { type_names = get_names(); cuss::element* selected = i_editor.selected(); int ter_num = i_editor.get_int("list_types"); terrain_type* current_ter = NULL; if (ter_num < TERRAIN_POOL.size()) { current_ter = TERRAIN_POOL[ i_editor.get_int("list_types") ]; flags = get_flag_names(current_ter); transformations = get_transformation_names(current_ter); i_editor.ref_data("num_move", &(current_ter->move_cost)); i_editor.ref_data("num_sight", &(current_ter->sight_cost)); i_editor.ref_data("text_name", &(current_ter->name)); } i_editor.draw(&w_editor); long ch = getch(); if (selected->name == "text_name" && ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || ch == ' ')) { current_ter->name += ch; } else if (selected->name == "text_name" && is_backspace(ch) && !current_ter->name.empty()) { current_ter->name = current_ter->name.substr(0, current_ter->name.length() - 1); } else if (ch == 's' || ch == 'S') { quit = true; } else if (ch == 'c' || ch == 'C') { set_symbol(current_ter); } else if (ch == 'a' || ch == 'A') { if (selected->name == "list_types") { terrain_type *tmp = new terrain_type; tmp->move_cost = 10; tmp->name = string_input_popup("Name:"); set_symbol(tmp); TERRAIN_POOL.push_back(tmp); i_editor.set_data("list_types", 999); } else if (selected->name == "list_flags") { add_flag(current_ter); i_editor.set_data("list_flags", 0); } else if (selected->name == "list_transformations") { add_transformation(current_ter); i_editor.set_data("list_transformations", 0); } } else if (ch == 'd' || ch == 'D') { if (selected->name == "list_flags") { int index = i_editor.get_int("list_flags"); if (index < flags.size()) { remove_flag(current_ter, index); i_editor.set_data("list_flags", 0); } } else if (selected->name == "list_transformations") { int index = i_editor.get_int("list_transformations"); if (index < transformations.size()) { remove_transformation(current_ter, index); i_editor.set_data("list_transformations", 0); } } } else if (ch == '?') { debugmsg("%d of %d", i_editor.get_int("list_transformations"), transformations.size()); debugmsg("%d (\\n = %d", TERRAIN_POOL[1]->name[0], '\n'); } else { i_editor.handle_action(ch); } } while (!quit); save_data(); end_display(); return 0; }
int do_exit(void) { end_display(); exit(0); }