void menu_file(warehouse *warehouses) { boolean loop = TRUE; int option; FILE *load_data = NULL; char filename[FILENAME_SIZE] = {0}; while(loop) { show_menu(4); int_input(&option, 3); switch(option) { case 1: { if((warehouses->hallways_size > 0) && (warehouses->hallways[warehouses->hallways_size - 1].storages_size > 0)) { get_filename(filename, FILENAME_SIZE); load_data = get_file(filename, "r"); if (load_data != NULL) { update_stock(warehouses, load_data); fclose(load_data); printf("\n"); } else { printf("Nao foi possivel carregar o ficheiro.\n\n"); } } else { printf("Nao existem corredores ou armarios.\n\n"); } break; } case 2: { if((warehouses->hallways_size > 0) && (warehouses->hallways[warehouses->hallways_size - 1].storages_size > 0)) { get_filename(filename, FILENAME_SIZE); load_data = get_file(filename, "r"); if (load_data != NULL) { process_order(warehouses, load_data); fclose(load_data); printf("\n"); } else { printf("Nao foi possivel carregar o ficheiro.\n\n"); } } else { printf("Nao existem corredores ou armarios.\n\n"); } break; } case 9: { loop = FALSE; break; } default: { printf("Essa opcao nao existe.\n\n"); break; } } } }
void menu_insert(warehouse *warehouses) { boolean loop = TRUE; int option; int option2; while(loop) { show_menu(3); int_input(&option, 3); switch(option) { case 1: { int hallway_number = choose_hallway(warehouses); int storage_number = choose_storage(warehouses, &hallway_number); if ((hallway_number >= 0) && (storage_number >= 0)) { printf("Numero do produto: "); int_input(&option, 9); if(option > 0) { if(search_product(warehouses, option) == NULL) { printf("Stock do produto: "); int_input(&option2, 9); if(option2 > 0) { insert_product(&warehouses->hallways[hallway_number].storages[storage_number], option, option2); printf("Produto %d inserido\n\n", option); } else { printf("Numero invalido\n\n"); } } else { printf("Esse produto ja existe.\n\n"); } } else { printf("Numero invalido\n\n"); } } break; } case 2: { int hallway_number = choose_hallway(warehouses); int storage_number = choose_storage(warehouses, &hallway_number); int product_number = choose_product(warehouses, &hallway_number, &storage_number); if ((hallway_number >= 0) && (storage_number >= 0) && (product_number >= 0)) { printf("Novo valor de stock do produto: "); int_input(&option, 9); if (option > 0) { warehouses->hallways[hallway_number].storages[storage_number].products[product_number].product_stock = option; printf("Stock alterado para %d\n\n", option); } else { printf("Numero invalido\n\n"); } } break; } case 9: { loop = FALSE; break; } default: { printf("Essa opcao nao existe.\n\n"); break; } } } }
void initialize_interface() { warehouse *warehouses = NULL; FILE *database = NULL; boolean loop = TRUE; int option; int db_type; database = get_file(DBNAME, "rb"); db_type = identify(database); //db_type = 2; if(db_type == 0) { warehouses = initialize(database); } else if(db_type == 1) { warehouses = initialize_legacy(database); } else if(db_type == 2) { warehouses = initialize_random(); } if(database != NULL) { fclose(database); } printf("Digite o numero da opcao a esquerda para navegar entre menus.\n\n"); while(loop) { show_menu(1); int_input(&option, 3); switch(option) { case 1: { menu_search(warehouses); break; } case 2: { menu_insert(warehouses); break; } case 3: { menu_file(warehouses); break; } case 4: { menu_warehouse(warehouses); break; } case 9: { loop = FALSE; break; } default: { printf("Essa opcao nao existe.\n\n"); break; } } } show_sold_products(warehouses, TRUE); shutdown(get_file(DBNAME, "wb"), warehouses, TRUE); }
static int action1_cb(Ihandle* ih) { // IupSetAttribute(IupGetDialog(ih), "BACKGROUND", "255 128 128"); show_menu(ih); return IUP_DEFAULT; }
void menu_search(const warehouse *warehouses) { boolean loop = TRUE; char *data = NULL; int option; while(loop) { show_menu(2); int_input(&option, 3); switch(option) { case 1: { data = show_tree(warehouses); break; } case 2: { data = show_products(warehouses); break; } case 3: { data = show_products_by_hallway(warehouses, choose_hallway(warehouses)); break; } case 4: { int hallway_number = choose_hallway(warehouses); int storage_number = choose_storage(warehouses, &hallway_number); data = show_products_by_storage(warehouses, hallway_number, storage_number); break; } case 5: { printf("Numero do produto: "); int_input(&option, 9); if(option > 0) { data = show_products_by_type(warehouses, option); } else { printf("Numero invalido\n\n"); } break; } case 6: { printf("Stock do produto: "); int_input(&option, 9); if(option > 0) { data = show_products_by_stock(warehouses, option); } else { printf("Numero invalido\n\n"); } break; } case 7: { data = show_sold_products(warehouses, FALSE); break; } case 9: { loop = FALSE; break; } default: { printf("Essa opcao nao existe.\n\n"); break; } } if (data != NULL) { printf("%s\n", data); print_file(data); free(data); data = NULL; } } }
int main(int argc, const char *argv[]){ config(); show_menu(); return 0; }
void menu(void) { Key_t key; uint8_t x_size, y_size, exit; menu_item=0; submenu_item=0; exit=0; y_size = sizeof(menu_strings)/sizeof(menu_strings[0]); // ilosc podmenu x_size = sizeof(menu_strings[0])/sizeof(menu_strings[0][0]); // ilosc menu LcdClearLine(2); LcdClearLine(3); show_menu(menu_item, submenu_item); do { key=getkey(); if(key==KEY_R) // menu(submenu) + { if(submenu_item==0) // jezelipoziom glowny menu { if((++menu_item)==x_size) menu_item=0; // menu + } else // jezeli poziom podmenu if((++submenu_item)==y_size) submenu_item=y_size - 1; // submenu max if((menu_strings[submenu_item][menu_item])=="") submenu_item--; // puste submenu show_menu(menu_item, submenu_item); } else if(key==KEY_L) // menu(submenu) - { if(submenu_item==0) // jezeli poziom glowny menu { if((--menu_item)<0) menu_item=x_size-1; // menu - } else // jezeli poziom podmenu if((--submenu_item)==0) submenu_item=1; // submenu = 1 show_menu(menu_item, submenu_item); } else if(key==KEY_OK) // ENTER { if(submenu_item==0) // jezeli poziom glowny menu if(menu_strings[1][menu_item]!="") // jezeli menu poziada jakies podmenu { submenu_item++; // submenu + ( w zasadzie submenu = 1) show_menu(menu_item, submenu_item); } else // jezeli menu nie posiada zadnych podmenu enter_menu(menu_item, submenu_item); // wejscie w obsluge menu else // jezeli poziom podmenu enter_menu(menu_item, submenu_item); // wejscie w obsluge podmenu } if(key==KEY_UP) // ESC { if(submenu_item>0) // jezeli poziom podmenu submenu_item=0; // wyjscie do poziomu glownego menu else // jezeli poziom glowny menu exit=1; // wyjscie z obslugi menu show_menu(menu_item, submenu_item); } }while(exit==0); // koniec procedury exit_from_menu(); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { rnum = 5; cnum = 5; mod = 10; data.assign(rnum * cnum, 0); ui->setupUi(this); update_matrix(); sub_menu = new QMenu(this); ui->tableWidget->setContextMenuPolicy(Qt::CustomContextMenu); connect(ui->tableWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(show_menu(QPoint))); createAct = new QAction(this); createAct->setIcon(QIcon::fromTheme("window-new")); createAct->setText("Create new matrix..."); createAct->setStatusTip("CTRL + N"); createAct->setShortcut(Qt::CTRL + Qt::Key_N); connect(createAct, SIGNAL(triggered()),this, SLOT(create_mat())); sub_menu->addAction(createAct); ui->menuFiles->addAction(createAct); ui->mainToolBar->addAction(createAct); fillAct = new QAction(this); fillAct->setIcon(QIcon::fromTheme("view-refresh")); fillAct->setText("Generate matrix values"); fillAct->setStatusTip("CTRL + G"); fillAct->setShortcut(Qt::CTRL + Qt::Key_G); connect(fillAct, SIGNAL(triggered()),this, SLOT(fill_matrix())); sub_menu->addAction(fillAct); ui->menuFiles->addAction(fillAct); ui->mainToolBar->addAction(fillAct); searchAct = new QAction(this); searchAct->setIcon(QIcon::fromTheme("system-search")); searchAct->setEnabled(0); searchAct->setText("Find max"); searchAct->setStatusTip("CTRL + F"); searchAct->setShortcut(Qt::CTRL + Qt::Key_F); connect(searchAct, SIGNAL(triggered()),this, SLOT(find_max())); sub_menu->addAction(searchAct); ui->menuFiles->addAction(searchAct); ui->mainToolBar->addAction(searchAct); deleteAct = new QAction(this); deleteAct->setIcon(QIcon::fromTheme("edit-delete")); deleteAct->setEnabled(0); deleteAct->setText("Delete current row"); deleteAct->setStatusTip("CTRL + X"); deleteAct->setShortcut(Qt::CTRL + Qt::Key_X); connect(deleteAct, SIGNAL(triggered()),this, SLOT(delete_row())); sub_menu->addAction(deleteAct); ui->menuFiles->addAction(deleteAct); ui->mainToolBar->addAction(deleteAct); ui->menuFiles->addSeparator(); closeAct = new QAction(this); closeAct->setIcon(QIcon::fromTheme("window-close")); closeAct->setText("Close file"); closeAct->setStatusTip("CTRL + Q"); closeAct->setShortcut(Qt::CTRL + Qt::Key_Q); connect(closeAct, SIGNAL(triggered()),this, SLOT(close())); ui->menuFiles->addAction(closeAct); ui->mainToolBar->addAction(closeAct); //QToolBar* pr_bar = this->addToolBar("Main toolbar"); //pr_bar->addAction(closeAct); }
static bool_t init (void) { search_tool = aud_plugin_lookup_basename ("search-tool"); aud_config_set_defaults ("gtkui", gtkui_defaults); pw_col_init (); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_has_resize_grip ((GtkWindow *) window, FALSE); g_signal_connect(G_OBJECT(window), "delete-event", G_CALLBACK(window_delete), NULL); accel = gtk_accel_group_new (); gtk_window_add_accel_group ((GtkWindow *) window, accel); vbox_outer = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_container_add ((GtkContainer *) window, vbox_outer); menu_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); gtk_box_pack_start ((GtkBox *) vbox_outer, menu_box, FALSE, FALSE, 0); toolbar = gtk_toolbar_new (); gtk_toolbar_set_style ((GtkToolbar *) toolbar, GTK_TOOLBAR_ICONS); GtkStyleContext * context = gtk_widget_get_style_context (toolbar); gtk_style_context_add_class (context, GTK_STYLE_CLASS_PRIMARY_TOOLBAR); gtk_box_pack_start ((GtkBox *) vbox_outer, toolbar, FALSE, FALSE, 0); /* search button */ if (search_tool) { search_button = toggle_button_new ("edit-find", toggle_search_tool); gtk_toolbar_insert ((GtkToolbar *) toolbar, search_button, -1); gtk_toggle_tool_button_set_active ((GtkToggleToolButton *) search_button, aud_plugin_get_enabled (search_tool)); aud_plugin_add_watch (search_tool, search_tool_toggled, NULL); } /* playback buttons */ toolbar_button_add (toolbar, button_open_pressed, "document-open"); toolbar_button_add (toolbar, button_add_pressed, "list-add"); button_play = toolbar_button_add (toolbar, aud_drct_play_pause, "media-playback-start"); button_stop = toolbar_button_add (toolbar, aud_drct_stop, "media-playback-stop"); toolbar_button_add (toolbar, aud_drct_pl_prev, "media-skip-backward"); toolbar_button_add (toolbar, aud_drct_pl_next, "media-skip-forward"); /* time slider and label */ GtkToolItem * boxitem1 = gtk_tool_item_new (); gtk_tool_item_set_expand (boxitem1, TRUE); gtk_toolbar_insert ((GtkToolbar *) toolbar, boxitem1, -1); GtkWidget * box1 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); gtk_container_add ((GtkContainer *) boxitem1, box1); slider = gtk_scale_new (GTK_ORIENTATION_HORIZONTAL, NULL); gtk_range_set_increments ((GtkRange *) slider, 5000, 5000); gtk_scale_set_draw_value(GTK_SCALE(slider), FALSE); gtk_widget_set_size_request(slider, 120, -1); gtk_widget_set_valign (slider, GTK_ALIGN_CENTER); gtk_widget_set_can_focus(slider, FALSE); gtk_box_pack_start ((GtkBox *) box1, slider, TRUE, TRUE, 6); label_time = markup_label_new(NULL); gtk_box_pack_end ((GtkBox *) box1, label_time, FALSE, FALSE, 6); gtk_widget_set_no_show_all (slider, TRUE); gtk_widget_set_no_show_all (label_time, TRUE); /* repeat and shuffle buttons */ button_repeat = toggle_button_new ("media-playlist-repeat", toggle_repeat); gtk_toolbar_insert ((GtkToolbar *) toolbar, button_repeat, -1); button_shuffle = toggle_button_new ("media-playlist-shuffle", toggle_shuffle); gtk_toolbar_insert ((GtkToolbar *) toolbar, button_shuffle, -1); /* volume button */ GtkToolItem * boxitem2 = gtk_tool_item_new (); gtk_toolbar_insert ((GtkToolbar *) toolbar, boxitem2, -1); GtkWidget * box2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); gtk_container_add ((GtkContainer *) boxitem2, box2); volume = gtk_volume_button_new(); gtk_button_set_relief(GTK_BUTTON(volume), GTK_RELIEF_NONE); gtk_scale_button_set_adjustment(GTK_SCALE_BUTTON(volume), GTK_ADJUSTMENT(gtk_adjustment_new(0, 0, 100, 1, 5, 0))); gtk_widget_set_can_focus(volume, FALSE); int lvol = 0, rvol = 0; aud_drct_get_volume(&lvol, &rvol); gtk_scale_button_set_value(GTK_SCALE_BUTTON(volume), (lvol + rvol) / 2); gtk_box_pack_start ((GtkBox *) box2, volume, FALSE, FALSE, 0); /* main UI layout */ layout_load (); GtkWidget * layout = layout_new (); gtk_box_pack_start ((GtkBox *) vbox_outer, layout, TRUE, TRUE, 0); vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); layout_add_center (vbox); ui_playlist_notebook_new (); gtk_box_pack_start ((GtkBox *) vbox, (GtkWidget *) UI_PLAYLIST_NOTEBOOK, TRUE, TRUE, 0); /* optional UI elements */ show_menu (aud_get_bool ("gtkui", "menu_visible")); show_infoarea (aud_get_bool ("gtkui", "infoarea_visible")); if (aud_get_bool ("gtkui", "statusbar_visible")) { statusbar = ui_statusbar_new (); gtk_box_pack_end ((GtkBox *) vbox_outer, statusbar, FALSE, FALSE, 0); } AUDDBG("hooks associate\n"); ui_hooks_associate(); AUDDBG("playlist associate\n"); ui_playlist_notebook_populate(); g_signal_connect(slider, "change-value", G_CALLBACK(ui_slider_change_value_cb), NULL); g_signal_connect(slider, "button-press-event", G_CALLBACK(ui_slider_button_press_cb), NULL); g_signal_connect(slider, "button-release-event", G_CALLBACK(ui_slider_button_release_cb), NULL); volume_change_handler_id = g_signal_connect(volume, "value-changed", G_CALLBACK(ui_volume_value_changed_cb), NULL); g_signal_connect(volume, "pressed", G_CALLBACK(ui_volume_pressed_cb), NULL); g_signal_connect(volume, "released", G_CALLBACK(ui_volume_released_cb), NULL); update_volume_timeout_source = g_timeout_add(250, (GSourceFunc) ui_volume_slider_update, volume); g_signal_connect (window, "map-event", (GCallback) window_mapped_cb, NULL); g_signal_connect (window, "key-press-event", (GCallback) window_keypress_cb, NULL); g_signal_connect (UI_PLAYLIST_NOTEBOOK, "key-press-event", (GCallback) playlist_keypress_cb, NULL); if (aud_drct_get_playing ()) { ui_playback_begin (); if (aud_drct_get_ready ()) ui_playback_ready (); } else ui_playback_stop (); title_change_cb (); gtk_widget_show_all (vbox_outer); update_toggles (NULL, NULL); menu_rclick = make_menu_rclick (accel); menu_tab = make_menu_tab (accel); return TRUE; }
void main(int argc, char *argv[]) { menu_options current_option; cdc_entry current_cdc_entry; int command_result; memset(¤t_cdc_entry, '\0', sizeof(current_cdc_entry)); if (argc > 1) { command_result = command_mode(argc, argv); exit(command_result); } announce(); if (!database_initialize(0)) { fprintf(stderr, "Sorry, unable to initialize database\n"); fprintf(stderr, "To create a new database use %s -i\n", argv[0]); exit(EXIT_FAILURE); } while (current_option != mo_exit) { current_option = show_menu(¤t_cdc_entry); switch (current_option) { case mo_add_cat: if (enter_new_cat_entry(¤t_cdc_entry)) { if (!add_cdc_entry(current_cdc_entry)) { fprintf(stderr, "Failed to add new entry\n"); memset(¤t_cdc_entry, '\0', sizeof(current_cdc_entry)); } } break; case mo_add_tracks: enter_new_track_entries(¤t_cdc_entry); break; case mo_del_cat: del_cat_entry(¤t_cdc_entry); break; case mo_find_cat: current_cdc_entry = find_cat(); break; case mo_list_cat_tracks: list_tracks(¤t_cdc_entry); break; case mo_del_tracks: del_track_entries(¤t_cdc_entry); break; case mo_count_entries: count_all_entries(); break; case mo_exit: break; case mo_invalid: break; default: break; } /* switch */ } /* while */ database_close(); exit(EXIT_SUCCESS); }
/** command_executor override */ void show_menu(const std::vector<std::string>& items_arg, int xloc, int yloc, bool context_menu, display& /*gui*/) { show_menu(items_arg, xloc, yloc, context_menu); }
void gp32_menu(void) { sound_silence(); show_menu(main_menu, 1, 1, 38, 18); }
int main(int argc, const char **argv) { /* Check uid */ if (getuid() != 0) { fprintf(stderr,"Swifer must be run as root.\n"); return 1; } /* Check config file for interface and dhcp */ FILE *cfg; if ( (cfg=fopen(config,"r")) ) { char *line = calloc(MAX_LINE+1,sizeof(char)); char *val = calloc(MAX_LINE+1,sizeof(char)); while (fgets(line,MAX_LINE,cfg) != NULL) { if (line[0] == '#') continue; if (sscanf(line,"INTERFACE = %s",val)) strncpy(ifname,val,IFNAMSIZ); else if (sscanf(line,"DHCP = %s",val)) strncpy(dhcp,val,DHCPLEN); else if (sscanf(line,"PRE_UP = %s",val)) hook_preup = strdup(val); else if (sscanf(line,"POST_UP = %s",val)) hook_postup = strdup(val); else if (strncmp(line,"[NETWORKS]",10)==0) break; } free(line); free(val); fclose(cfg); } /* Get basic wifi info */ we_ver = iw_get_kernel_we_version(); skfd = iw_sockets_open(); iw_get_basic_config(skfd,ifname,&cur); /* Bring up interface (eg "ip link set IFACE up") */ struct ifreq req; int err; strncpy(req.ifr_name,ifname,IFNAMSIZ); if ( (err=ioctl(skfd,SIOCGIFFLAGS,&req)) ){ int loop = 0; while ( (err=ioctl(skfd,SIOCGIFFLAGS,&req)) ) { usleep(100000); if (loop++ > 50) break; } if (err) { close(skfd); return 2; } } req.ifr_flags |= IFF_UP; if (ioctl(skfd,SIOCSIFFLAGS,&req)) { close(skfd); return 3; } /* Processes command line arguments */ int i; for (i = 1; i < argc; i++) { if (strncmp(argv[i],"ad",2)==0) mode |= MODE_ADD; else if (strncmp(argv[i],"au",2)==0) mode |= MODE_AUTO; else if (strncmp(argv[i],"hi",2)==0) mode |= MODE_HIDDEN; else if (strncmp(argv[i],"an",2)==0) mode |= (MODE_ANY | MODE_AUTO); else if (strncmp(argv[i],"re",2)==0) mode |= (MODE_RECONNECT | MODE_AUTO); else if (strncmp(argv[i],"ve",2)==0) mode |= MODE_VERBOSE; else if (strncmp(argv[i],"wa",2)==0) mode |= MODE_WAIT; else if (strncmp(argv[i],"de",2)==0) { if (argc > i+1) remove_network(argv[i+1]); } else fprintf(stderr,"[%s] Ignoring unknown parameter: %s\n", argv[0],argv[i]); } if ( (mode & MODE_VERBOSE) && (mode & MODE_AUTO) ) mode &= ~MODE_VERBOSE; /* Scan and select network */ iw_scan(skfd,ifname,we_ver,&context); wireless_scan *ws; if (mode & MODE_AUTO) { if (mode && MODE_WAIT) { int loops; /* keep trying for up to 5 minutes */ for (loops = 0; loops < 30 && !(ws=get_best()); ++loops) sleep(TIMEOUT); } else ws = get_best(); } else ws = show_menu(); const char *arg[4]; if (ws) { /* Stop any current processes then connect to "ws" */ arg[0] = killall; arg[1] = dhcp; arg[2] = NULL; if (fork()==0) { fclose(stdout); fclose(stderr); execvp(arg[0],(char * const *) arg); } arg[1] = wpa_sup; if (fork()==0) { fclose(stdout); fclose(stderr); execvp(arg[0],(char * const *) arg); } sleep(1); if ( (mode & MODE_ADD) && is_known(ws) ) mode &= ~MODE_ADD; if (ws->b.key_flags == 2048) mode |= MODE_SECURE; mode_t pre = umask(S_IWGRP|S_IWOTH|S_IRGRP|S_IROTH); ws_connect(ws); umask(pre); } else if ( !(mode & MODE_RECONNECT) ) { fprintf(stderr,"[swifer] no suitable networks found.\n"); return 5; } /* Keep alive to reconnect? */ iw_sockets_close(skfd); if (mode & MODE_RECONNECT) { if (fork() == 0) { setsid(); int level = THRESHOLD + 1, ret; char scanline[256]; snprintf(scanline,255,"%%*[^\n]\n%%*[^\n]\n%s: %%*d %%d.",ifname); FILE *procw; while (level > THRESHOLD) { sleep(TIMEOUT); procw = fopen(PROC_NET_WIRELESS,"r"); ret = fscanf(procw,scanline,&level); fclose(procw); if (ret != 1) level = 0; } arg[0] = argv[0]; arg[1] = re; arg[2] = an; arg[3] = NULL; if ( !(mode & MODE_ANY)) arg[2] = NULL; execvp(arg[0],(char * const *) arg); } } if (hook_preup) free(hook_preup); if (hook_postup) free(hook_postup); return 0; }
int process(void) { PARAMS params; DERIVED derived; FILE *fp = NULL; BOOLEAN bTest; double d; int iChoice,i; params.bPKDUnits = get_yn("Use PKDGRAV units (AU, M_sun, etc.)","n"); params.dMass = 4.0/3.0*M_PI/1.0e3; /* kg (1 cm radius @ 1 g/cc) */ params.dRadius = 0.01; /* m (1 cm) */ params.dVmax = 0.01; /* m/s (1 cm/s) */ params.dXmaxOverR = 0.01; params.dGravAcc = 9.8; /* m/s^2 */ params.dHeight = 1.0; /* m */ params.dPackEff = 0.65; params.nStepsPerOverlap = 30; while (/*CONSTCOND*/1) { analyze(¶ms,&derived); printf("\n"); show_menu(¶ms,&derived,stdout); printf("\n"); printf("Enter number to change (or 0 when done): "); scanf("%i",&iChoice); getchar(); /* chomp \n since getchar() may be needed later */ switch (iChoice) { case Quit: fp = fopen(LOGFILE,"w"); assert(fp != NULL); show_menu(¶ms,&derived,fp); fclose(fp); return 0; } switch (iChoice) { case Mass: bTest = get_yn("Keep particle density constant","n"); do { printf("Enter new mass (-ve ==> scale mass instead): "); scanf("%lf",&d); if (d == 0.0) printf("Mass cannot be zero.\n"); } while (d == 0.0); getchar(); if (d < 0.0) d *= -params.dMass; else { if (params.bPKDUnits) d *= M_SCALE; /* M_Sun -> kg */ else d /= 1000.0; /* g -> kg */ } if (bTest) params.dRadius *= pow(d/params.dMass,1.0/3.0); params.dMass = d; break; case Radius: bTest = get_yn("Keep particle density constant","n"); do { printf("Enter new radius (-ve ==> scale radius instead): "); scanf("%lf",&d); if (d == 0.0) printf("Radius cannot be zero.\n"); } while (d == 0.0); getchar(); if (d < 0.0) d *= -params.dRadius; else { if (params.bPKDUnits) d *= L_SCALE; /* AU -> m */ else d /= 100.0; /* cm -> m */ } if (bTest) params.dMass *= CUBE(d/params.dRadius); params.dRadius = d; break; case Density: bTest = get_yn("Keep radius constant","y"); do { printf("Enter new density (-ve ==> scale density instead): "); scanf("%lf",&d); if (d == 0.0) printf("Density cannot be zero.\n"); } while (d == 0); getchar(); if (d < 0.0) d *= -derived.dDensity; else { if (params.bPKDUnits) d *= D_SCALE; /* M_Sun/AU^3 -> kg/m^3 */ else d *= 1000.0; /* g/cc -> kg/m^3 */ } if (bTest) params.dMass *= d/derived.dDensity; else params.dRadius *= pow(d/derived.dDensity,1.0/3.0); break; case Speed: printf("Enter new speed (-ve ==> scale speed instead): "); scanf("%lf",&d); getchar(); if (d < 0.0) d *= -params.dVmax; else { if (params.bPKDUnits) d *= V_SCALE; /* AU/(yr/2pi) -> m/s */ else d /= 100.0; /* cm/s -> m/s */ } params.dVmax = d; break; case Overlap: do { printf("Enter new fractional overlap: "); scanf("%lf",&d); if (d <= 0.0) printf("Fraction overlap must be positive.\n"); } while (d <= 0.0); getchar(); params.dXmaxOverR = d; break; case Gravity: printf("Enter new gravitational acceleration (-ve ==> scale gravity instead): "); scanf("%lf",&d); getchar(); if (d < 0.0) d *= -params.dGravAcc; else if (params.bPKDUnits) d *= L_SCALE/SQ(T_SCALE); /* AU/(yr/2pi)^2 --> m/s^2 */ params.dGravAcc = d; break; case Height: printf("Enter new system height/bulk radius (-ve ==> scale instead): "); scanf("%lf",&d); getchar(); if (d < 0.0) d *= -params.dHeight; else { if (params.bPKDUnits) d *= L_SCALE; /* AU --> m */ else d /= 100.0; /* cm -> m */ } params.dHeight = d; break; case Packing: do { printf("Enter new packing efficiency: "); scanf("%lf",&d); if (d < 0.0 || d > 1.0) printf("Packing efficiency must be between 0 and 1.\n"); } while (d < 0.0 || d > 1.0); getchar(); params.dPackEff = d; break; case BulkDensity: bTest = get_yn("OK to change packing efficiency","y"); if (!bTest) break; do { printf("Enter new bulk density (-ve ==> scale instead): "); scanf("%lf",&d); if (d == 0.0) printf("Bulk density cannot be zero.\n"); } while (d == 0); getchar(); if (d < 0.0) d *= -derived.dBulkDensity; else { if (params.bPKDUnits) d *= D_SCALE; /* M_Sun/AU^3 -> kg/m^3 */ else d *= 1000.0; /* g/cc -> kg/m^3 */ } params.dPackEff = d/derived.dDensity; break; case Steps: do { printf("Enter new number of steps per overlap: "); scanf("%i",&i); if (i < 1) printf("Number of steps must be positive.\n"); } while (i < 1); getchar(); params.nStepsPerOverlap = i; break; default: printf("Invalid menu choice.\n"); } } }
int main(int argc,char **argv) { turret_comm_t *r; create_comm_t *c; int i2c_fd; int command; int i,angle; double vx,va; char ch; /* allocate device objects */ c = create_create("/dev/ttyS2"); r = turret_create(); /* open the create serial comm */ if(create_open(c,FULLCONTROL) < 0) { printf("create open failed\n"); return(-1); } /* Open the i2c device */ if(turret_open(r) < 0) { printf("failed to connect to robostix\n"); return(-1); } /* init the robostix board interfaces */ turret_init(r); /* robot is set up and ready -- select tests and run */ for(command = show_menu(); command != 0; command = show_menu() ) switch(command) { case TEST_SONAR: printf("testing Sonars, next 500 readings\n"); for(i=0;i<5;i++) { if((!turret_get_sonar(r))) printf("sensor read timeout\n"); else printf("%d\t%d\n",r->sonar[0],r->sonar[1]); } break; case TEST_IR: printf("testing IR, next 5 readings\n"); for(i=0;i<5;i++) { if(!turret_get_ir(r)) printf("sensor read timeout\n"); else printf("%d\t%d\n",r->ir[0],r->ir[1]); } break; case TEST_TURRET: printf("testing Servo\nEnter angle: "); for(angle == 0;(angle <180) | (angle >180); scanf("%d",&angle)) { printf("setting servo to %d degrees\n",angle); turret_SetServo(r,angle); } break; case TEST_MOVE: printf("i- speed up\nn-slow down\nk- angle right\nj - angle left\n, x- stop\n"); vx=0.;va=0.; for( ch=getchar(); ch != 'x'; ch=getchar()) { switch(ch) { case 'i': vx += INCREMENT; break; case 'n': vx -= INCREMENT; break; case 'j': va += INCREMENT; break; case 'k': va -= INCREMENT; break; case 'x': va = 0.; vx = 0.; break; default: break; } if(vx > 1.) vx = 1.; if(va > 1.) va = 1.; create_set_speeds(c,vx,va); } break; default: command = -1; break; } }
/* * Single click handler on select button */ static void select_single_click_handler(ClickRecognizerRef recognizer, void *context) { // Bring clock up to date if a button is pressed revive_clock_on_movement(CLOCK_UPDATE_THRESHOLD); if (!is_notice_showing()) show_menu(); }