void data_type<T>::free() { if (!is_default()) { if (is_shared()) copy_default(); else { m_repository.free(m_ix); load_default(); } } }
data_type<T>::data_type ( Context* ap_context ) : abstract_data_type(ap_context) , mp_value(NULL) { // Wenn noch kein g_global_default existiert (erste Instanz), dann erstellen if (m_global_default_ix==g_illegal_ix) { m_global_default_ix = m_repository.insert(T()); } // Default setzen load_default(); }
void data_type<T>::free( ix_type a_ix ) { if (a_ix!=get_default_ix()) { if (is_shared()) copy_default(); else { m_repository.free(a_ix); if (m_ix==a_ix) load_default(); } } }
int init_setting(void) { // double data; char temp[128] = {'\0'}; INI_HANDLE handle = ini_open("setting.ini"); if(handle == INI_FAIL){ print_errmsg("%s\n", ini_geterrmsg()); return -1; } // if(mem_set() != 0) { print_errmsg("memory alloc fail!\n"); return -1; } load_default(); ini_get_key_ulong(handle, "system", "CMD_BUFFER_SIZE", &sys->cmd_buffer_size); ini_get_key_ulong(handle, "system", "CMD_BUFFER_NEAR_FULL", &sys->cmd_buffer_near_full); ini_get_key_ulong(handle, "system", "BLOCK_BUFFER_SIZE", &sys->block_buffer_size); ini_get_key_ulong(handle, "system", "BLOCK_BUFFER_BOUND", &sys->block_buffer_bound); ini_get_key_ulong(handle, "system", "MAX_CMD_SIZE", &sys->max_cmd_size); ini_get_key_ulong(handle, "system", "STEPPER_BUFFER_SIZE", &sys->stepper_buffer_size); ini_get_key_ulong(handle, "system", "STEPPER_BUFFER_BOUND", &sys->stepper_buffer_bound); ini_get_key_ulong(handle, "system", "MIN_STEP_PULSE_DUTY", &sys->min_step_pulse_duty); ini_get_key_ulong(handle, "system", "DEFAULT_PULSE_PERIOD", &sys->default_pulse_period); ini_get_key_ulong(handle, "system", "DEFAULT_PULSE_DUTY", &sys->default_pulse_duty); ini_get_key_ulong(handle, "system", "HIT_PULSE_PERIOD", &sys->hit_pulse_period); ini_get_key_ulong(handle, "system", "HIT_PULSE_DUTY", &sys->hit_pulse_duty); ini_get_key_int(handle, "machine", "MIN_SOFTWARE_LIMIT", &machine->min_software_limit); ini_get_key_int(handle, "machine", "MAX_SOFTWARE_LIMIT", &machine->max_software_limit); //TODO:改不管大小寫 ini_get_key(handle, "machine", "TYPE", &temp[0]); if(strcmp(temp, "H_BOT") == 0) machine->type = H_BOT; else if(strcmp(temp, "DELTA") == 0) machine->type = DELTA; else machine->type = NORMAL; ini_get_key_int(handle, "machine", "NUM_AXIS", &machine->num_axis); ini_get_key_double(handle, "machine", "X_MAX_POS_MM", &machine->x_max_pos_mm); ini_get_key_double(handle, "machine", "X_MIN_POS_MM", &machine->x_min_pos_mm); ini_get_key_double(handle, "machine", "X_HOME_POS_MM", &machine->x_home_pos_mm); ini_get_key_double(handle, "machine", "Y_MAX_POS_MM", &machine->y_max_pos_mm); ini_get_key_double(handle, "machine", "Y_MIN_POS_MM", &machine->y_min_pos_mm); ini_get_key_double(handle, "machine", "Y_HOME_POS_MM", &machine->y_home_pos_mm); ini_get_key_double(handle, "machine", "Z_MAX_POS_MM", &machine->z_max_pos_mm); ini_get_key_double(handle, "machine", "Z_MIN_POS_MM", &machine->z_min_pos_mm); ini_get_key_double(handle, "machine", "Z_HOME_POS_MM", &machine->z_home_pos_mm); ini_get_key_double(handle, "machine", "X_HOME_RETRACT_MM", &machine->x_home_retract_mm); ini_get_key_double(handle, "machine", "Y_HOME_RETRACT_MM", &machine->y_home_retract_mm); ini_get_key_double(handle, "machine", "Z_HOME_RETRACT_MM", &machine->z_home_retract_mm); ini_get_key_int(handle, "machine", "X_HOME_DIR", &machine->x_home_dir);; ini_get_key_int(handle, "machine", "Y_HOME_DIR", &machine->y_home_dir); ini_get_key_int(handle, "machine", "Z_HOME_DIR", &machine->z_home_dir); ini_get_key_double(handle, "machine", "QX_STEPS_PER_MM", &machine->qx_steps_per_mm); ini_get_key_double(handle, "machine", "QY_STEPS_PER_MM", &machine->qy_steps_per_mm); ini_get_key_double(handle, "machine", "QZ_STEPS_PER_MM", &machine->qz_steps_per_mm); ini_get_key_double(handle, "machine", "QE_STEPS_PER_MM", &machine->qe_steps_per_mm); ini_get_key_double(handle, "machine", "X_MAX_FEEDRATE", &machine->x_max_feedrate_mps); ini_get_key_double(handle, "machine", "Y_MAX_FEEDRATE", &machine->y_max_feedrate_mps); ini_get_key_double(handle, "machine", "Z_MAX_FEEDRATE", &machine->z_max_feedrate_mps); ini_get_key_double(handle, "machine", "E_MAX_FEEDRATE", &machine->e_max_feedrate_mps); ini_get_key_double(handle, "machine", "X_HOMING_FEEDRATE", &machine->x_homing_feedrate_mpm); ini_get_key_double(handle, "machine", "Y_HOMING_FEEDRATE", &machine->y_homing_feedrate_mpm); ini_get_key_double(handle, "machine", "Z_HOMING_FEEDRATE", &machine->z_homing_feedrate_mpm); ini_get_key_double(handle, "machine", "QX_MAX_ACCELERATION", &machine->qx_max_acceleration); ini_get_key_double(handle, "machine", "QY_MAX_ACCELERATION", &machine->qy_max_acceleration); ini_get_key_double(handle, "machine", "QZ_MAX_ACCELERATION", &machine->qz_max_acceleration); ini_get_key_double(handle, "machine", "QE_MAX_ACCELERATION", &machine->qe_max_acceleration); ini_get_key_double(handle, "machine", "DEFAULT_ACCELERATION", &machine->default_acceleration); ini_get_key_double(handle, "machine", "DEFAULT_RETRACT_ACCELERATION", &machine->default_retract_acceleration); ini_get_key_double(handle, "machine", "DEFAULT_MINIMUMFEEDRATE", &machine->default_minimumfeedrate); ini_get_key_double(handle, "machine", "DEFAULT_MINTRAVELFEEDRATE", &machine->default_mintravelfeedrate); ini_get_key_double(handle, "machine", "DEFAULT_XYJERK", &machine->default_xyjerk); ini_get_key_double(handle, "machine", "DEFAULT_EJERK", &machine->default_ejerk); ini_get_key_double(handle, "machine", "DEFAULT_ZJERK", &machine->default_zjerk); ini_get_key_double(handle, "machine", "MINIMUM_PLANNER_SPEED", &machine->minimum_planner_speed); //這裡必須檔0.5 跟 DUTY_MIN ini_get_key_double(handle, "machine", "STEP_PULSE_DUTY_RATE", &data); if(data < 0.5) machine->step_pulse_duty_ratio = 0.5; else if(data > 1 && data < (double)sys->min_step_pulse_duty) machine->step_pulse_duty_ratio = (double)sys->min_step_pulse_duty; else machine->step_pulse_duty_ratio = data; //TODO:改不管大小寫 ini_get_key(handle, "machine", "LIMIT_SPEED", &temp[0]); if(strcmp(temp, "250k") == 0) machine->mcm_samplecycle = 25; else if(strcmp(temp, "200k") == 0) machine->mcm_samplecycle = 20; else if(strcmp(temp, "100k") == 0) machine->mcm_samplecycle = 10; else if(strcmp(temp, "50k") == 0) machine->mcm_samplecycle = 5; else if(strcmp(temp, "40k") == 0) machine->mcm_samplecycle = 4; else machine->mcm_samplecycle = 1; ini_get_key_int(handle, "machine", "MM_PER_ARC_SEGMENT", &machine->mm_per_arc_segment); ini_get_key_int(handle, "machine", "N_ARC_CORRECTION", &machine->n_arc_correction); ini_get_key_double(handle, "machine", "X_HOME_OFFSET", &machine->home_offset[0]); ini_get_key_double(handle, "machine", "Y_HOME_OFFSET", &machine->home_offset[1]); ini_get_key_double(handle, "machine", "Z_HOME_OFFSET", &machine->home_offset[2]); ini_get_key_int(handle, "pins", "mc_qx", &pins->mc_qx); ini_get_key_int(handle, "pins", "md_qx", &pins->md_qx); ini_get_key_int(handle, "pins", "mc_qy", &pins->mc_qy); ini_get_key_int(handle, "pins", "md_qy", &pins->md_qy); ini_get_key_int(handle, "pins", "mc_qz", &pins->mc_qz); ini_get_key_int(handle, "pins", "md_qz", &pins->md_qz); ini_get_key_int(handle, "pins", "mc_qe", &pins->mc_qe); ini_get_key_int(handle, "pins", "md_qe", &pins->md_qe); ini_get_key_int(handle, "pins", "MC_LIMIT", &pins->mc_limit); ini_get_key_int(handle, "pins", "MD_LIMIT", &pins->md_limit); ini_get_key_int(handle, "pins", "MC_LCD", &pins->mc_lcd); ini_get_key_int(handle, "pins", "MD_LCD", &pins->md_lcd); ini_get_key_int(handle, "pins", "INVERT_X_DIR", &pins->invert_x_dir); ini_get_key_int(handle, "pins", "X_STEP_PIN", &pins->x_step_pin); ini_get_key_int(handle, "pins", "X_DIR_PIN", &pins->x_dir_pin); ini_get_key_int(handle, "pins", "INVERT_Y_DIR", &pins->invert_y_dir); ini_get_key_int(handle, "pins", "Y_STEP_PIN", &pins->y_step_pin); ini_get_key_int(handle, "pins", "Y_DIR_PIN", &pins->y_dir_pin); ini_get_key_int(handle, "pins", "INVERT_Z_DIR", &pins->invert_z_dir); ini_get_key_int(handle, "pins", "Z_STEP_PIN", &pins->z_step_pin); ini_get_key_int(handle, "pins", "Z_DIR_PIN", &pins->z_dir_pin); ini_get_key_int(handle, "pins", "INVERT_E_DIR", &pins->invert_e_dir); ini_get_key_int(handle, "pins", "E_STEP_PIN", &pins->e_step_pin); ini_get_key_int(handle, "pins", "E_DIR_PIN", &pins->e_dir_pin); ini_get_key_int(handle, "pins", "X_ENABLE_PORT", &pins->x_enable_port); ini_get_key_int(handle, "pins", "X_ENABLE_PIN", &pins->x_enable_pin); ini_get_key_int(handle, "pins", "INVERT_X_ENABLE", &pins->invert_x_enable); ini_get_key_int(handle, "pins", "Y_ENABLE_PORT", &pins->y_enable_port); ini_get_key_int(handle, "pins", "Y_ENABLE_PIN", &pins->y_enable_pin); ini_get_key_int(handle, "pins", "INVERT_Y_ENABLE", &pins->invert_y_enable); ini_get_key_int(handle, "pins", "Z_ENABLE_PORT", &pins->z_enable_port); ini_get_key_int(handle, "pins", "Z_ENABLE_PIN", &pins->z_enable_pin); ini_get_key_int(handle, "pins", "INVERT_Z_ENABLE", &pins->invert_z_enable); ini_get_key_int(handle, "pins", "E_ENABLE_PORT", &pins->e_enable_port); ini_get_key_int(handle, "pins", "E_ENABLE_PIN", &pins->e_enable_pin); ini_get_key_int(handle, "pins", "INVERT_E_ENABLE", &pins->invert_e_enable); ini_get_key_int(handle, "temperature", "EXTRUDERS", &tp->extruders); ini_get_key_ulong(handle, "temperature", "PWM_PERIOD", &tp->pwm_period); ini_get_key_double(handle, "temperature", "HEATER_VELOCITY", &tp->heater_velocity); ini_get_key_double(handle, "temperature", "K1", &tp->K1); tp->K2 = 1 - tp->K1; ini_get_key_int(handle, "temperature", "AUTOTUNE_PID_ENABLE", &tp->autotune_pid_enable); ini_get_key_double(handle, "temperature", "DEFAULT_KP", &tp->default_Kp); ini_get_key_double(handle, "temperature", "DEFAULT_KI", &tp->default_Ki); ini_get_key_double(handle, "temperature", "DEFAULT_KD", &tp->default_Kd); ini_get_key_double(handle, "temperature", "DEFAULT_BEDKP", &tp->default_bedKp); ini_get_key_double(handle, "temperature", "DEFAULT_BEDKI", &tp->default_bedKi); ini_get_key_double(handle, "temperature", "DEFAULT_BEDKD", &tp->default_bedKd); ini_get_key_int(handle, "temperature", "BANG_MAX", &tp->bang_max); ini_get_key_int(handle, "temperature", "PID_MAX", &tp->pid_max); ini_get_key_int(handle, "temperature", "MAX_BED_POWER", &tp->max_bed_power); ini_get_key_int(handle, "temperature", "FAN_MAX", &tp->fan_max); ini_get_key_int(handle, "temperature", "PID_INTEGRAL_DRIVE_MAX", &tp->pid_integral_drive_max); ini_get_key_double(handle, "temperature", "HEATER0_MINTEMP", &tp->heater_mintemp[0]); ini_get_key_double(handle, "temperature", "HEATER0_MAXTEMP", &tp->heater_maxtemp[0]); ini_get_key_double(handle, "temperature", "BED_MINTEMP", &tp->bed_mintemp); ini_get_key_double(handle, "temperature", "BED_MAXTEMP", &tp->bed_maxtemp); ini_get_key_int(handle, "temperature", "OVERSAMPLER", &tp->oversampler); ini_get_key_int(handle, "temperature", "PID_FUNCTIONAL_RANGE", &tp->pid_functional_range); // 86Duino Print3D v1.0 ini_get_key_int(handle, "pins", "MC_PWM_HEATER0", &pins->mc_pwm[0]); ini_get_key_int(handle, "pins", "MD_PWM_HEATER0", &pins->md_pwm[0]); ini_get_key_int(handle, "pins", "MC_PWM_HEATER1", &pins->mc_pwm[1]); ini_get_key_int(handle, "pins", "MD_PWM_HEATER1", &pins->md_pwm[1]); ini_get_key_int(handle, "pins", "MC_PWM_BED", &pins->mc_pwm[2]); ini_get_key_int(handle, "pins", "MD_PWM_BED", &pins->md_pwm[2]); ini_get_key_int(handle, "pins", "MC_PWM_FAN0", &pins->mc_pwm[3]); ini_get_key_int(handle, "pins", "MD_PWM_FAN0", &pins->md_pwm[3]); ini_get_key_int(handle, "pins", "MC_PWM_FAN1", &pins->mc_pwm[4]); ini_get_key_int(handle, "pins", "MD_PWM_FAN1", &pins->md_pwm[4]); ini_get_key_int(handle, "pins", "AD_HEATER0", &pins->extruder_ad[0]); ini_get_key_int(handle, "pins", "AD_HEATER1", &pins->extruder_ad[1]); ini_get_key_int(handle, "pins", "AD_BED", &pins->hotedbed_ad); ini_get_key_int(handle, "pins", "AD_POWER", &pins->vin_ad); /* // 86Duino Print3D v2.0 pins->mc_pwm[0] = 3; pins->md_pwm[0] = 0; pins->mc_pwm[1] = 3; pins->md_pwm[1] = 1; pins->mc_pwm[2] = 2; pins->md_pwm[2] = 2; pins->mc_pwm[3] = 2; pins->md_pwm[3] = 0; pins->mc_pwm[4] = 2; pins->md_pwm[4] = 1; pins->extruder_ad[0] = 0; pins->extruder_ad[1] = 1; pins->hotedbed_ad = 2; pins->vin_ad = 3;*/ ini_get_key_int(handle, "Auto Bed Leveling", "ENABLE_AUTO_BED_LEVELING", &level->enable_auto_bed_leveling); ini_get_key_int(handle, "Auto Bed Leveling", "AUTO_BED_LEVELING_GRID", &level->auto_bed_leveling_grid); ini_get_key_double(handle, "Auto Bed Leveling", "ABL_PROBE_PT_1_X", &level->abl_probe_pt_1_x); ini_get_key_double(handle, "Auto Bed Leveling", "ABL_PROBE_PT_1_Y", &level->abl_probe_pt_1_y); ini_get_key_double(handle, "Auto Bed Leveling", "ABL_PROBE_PT_2_X", &level->abl_probe_pt_2_x); ini_get_key_double(handle, "Auto Bed Leveling", "ABL_PROBE_PT_2_Y", &level->abl_probe_pt_2_y ); ini_get_key_double(handle, "Auto Bed Leveling", "ABL_PROBE_PT_3_X", &level->abl_probe_pt_3_x); ini_get_key_double(handle, "Auto Bed Leveling", "ABL_PROBE_PT_3_Y", &level->abl_probe_pt_3_y); ini_get_key_double(handle, "Auto Bed Leveling", "XY_TRAVEL_SPEED", &level->xy_travel_speed); ini_get_key_double(handle, "Auto Bed Leveling", "X_PROBE_OFFSET_FROM_EXTRUDER", &level->x_probe_offset_from_extruder); ini_get_key_double(handle, "Auto Bed Leveling", "Y_PROBE_OFFSET_FROM_EXTRUDER", &level->y_probe_offset_from_extruder); ini_get_key_double(handle, "Auto Bed Leveling", "Z_PROBE_OFFSET_FROM_EXTRUDER", &level->z_probe_offset_from_extruder); ini_get_key_int(handle, "Auto Bed Leveling", "AUTO_BED_LEVELING_GRID_POINTS", &level->auto_bed_leveling_grid_points); ini_get_key_double(handle, "Auto Bed Leveling", "LEFT_PROBE_BED_POSITION", &level->left_probe_bed_position); ini_get_key_double(handle, "Auto Bed Leveling", "RIGHT_PROBE_BED_POSITION", &level->right_probe_bed_position); ini_get_key_double(handle, "Auto Bed Leveling", "BACK_PROBE_BED_POSITION", &level->back_probe_bed_position); ini_get_key_double(handle, "Auto Bed Leveling", "FRONT_PROBE_BED_POSITION", &level->front_probe_bed_position); ini_get_key_double(handle, "Auto Bed Leveling", "Z_RAISE_BEFORE_PROBING", &level->z_raise_before_probing); ini_get_key_double(handle, "Auto Bed Leveling", "Z_RAISE_BETWEEN_PROBINGS", &level->z_raise_between_probings); if(ini_close(handle) == 1){ print_errmsg("ini save fail\n"); } return 0; }
void db_key::load(void) { load_key l; load_default(l); }
void color_manager::show_gui() { const int iHeaderHeight = 4; const int iContentHeight = FULL_SCREEN_HEIGHT - 2 - iHeaderHeight; const int iOffsetX = (TERMX > FULL_SCREEN_WIDTH) ? (TERMX - FULL_SCREEN_WIDTH) / 2 : 0; const int iOffsetY = (TERMY > FULL_SCREEN_HEIGHT) ? (TERMY - FULL_SCREEN_HEIGHT) / 2 : 0; std::vector<int> vLines; vLines.push_back(-1); vLines.push_back(48); const int iTotalCols = vLines.size(); WINDOW *w_colors_help = newwin((FULL_SCREEN_HEIGHT / 2) - 2, FULL_SCREEN_WIDTH * 3 / 4, 7 + iOffsetY + (FULL_SCREEN_HEIGHT / 2) / 2, iOffsetX + 19 / 2); WINDOW_PTR w_colors_helpptr( w_colors_help ); WINDOW *w_colors_border = newwin(FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, iOffsetY, iOffsetX); WINDOW_PTR w_colors_borderptr( w_colors_border ); WINDOW *w_colors_header = newwin(iHeaderHeight, FULL_SCREEN_WIDTH - 2, 1 + iOffsetY, 1 + iOffsetX); WINDOW_PTR w_colors_headerptr( w_colors_header ); WINDOW *w_colors = newwin(iContentHeight, FULL_SCREEN_WIDTH - 2, iHeaderHeight + 1 + iOffsetY, 1 + iOffsetX); WINDOW_PTR w_colorsptr( w_colors ); draw_border( w_colors_border, BORDER_COLOR, _( " COLOR MANAGER " ) ); mvwputch(w_colors_border, 3, 0, c_ltgray, LINE_XXXO); // |- mvwputch(w_colors_border, 3, 79, c_ltgray, LINE_XOXX); // -| for (int i = 0; i < 78; i++) { mvwputch(w_colors_header, 2, i, c_ltgray, LINE_OXOX); // Draw line under header } for( auto &iCol : vLines ) { if ( iCol > -1 ) { mvwputch(w_colors_border, FULL_SCREEN_HEIGHT - 1, iCol + 1, c_ltgray, LINE_XXOX); // _|_ mvwputch(w_colors_header, 2, iCol, c_ltgray, LINE_OXXX); mvwputch(w_colors_header, 3, iCol, c_ltgray, LINE_XOXO); } } wrefresh(w_colors_border); int tmpx = 0; tmpx += shortcut_print(w_colors_header, 0, tmpx, c_white, c_ltgreen, _("<R>emove custom color")) + 2; tmpx += shortcut_print(w_colors_header, 0, tmpx, c_white, c_ltgreen, _("<Arrow Keys> To navigate")) + 2; tmpx += shortcut_print(w_colors_header, 0, tmpx, c_white, c_ltgreen, _("<Enter>-Edit")) + 2; shortcut_print(w_colors_header, 0, tmpx, c_white, c_ltgreen, _("Load <T>emplate")); mvwprintz(w_colors_header, 1, 0, c_white, _("Some color changes may require a restart.")); mvwprintz(w_colors_header, 3, 3, c_white, _("Colorname")); mvwprintz(w_colors_header, 3, 21, c_white, _("Normal")); mvwprintz(w_colors_header, 3, 52, c_white, _("Invert")); wrefresh(w_colors_header); int iCurrentLine = 0; int iCurrentCol = 1; int iStartPos = 0; const int iMaxColors = color_array.size(); bool bStuffChanged = false; input_context ctxt("COLORS"); ctxt.register_cardinal(); ctxt.register_action("CONFIRM"); ctxt.register_action("QUIT"); ctxt.register_action("REMOVE_CUSTOM"); ctxt.register_action("LOAD_TEMPLATE"); ctxt.register_action("HELP_KEYBINDINGS"); std::map<std::string, color_struct> name_color_map; for( const auto &pr : name_map ) { name_color_map[pr.first] = color_array[pr.second]; } while(true) { // Clear all lines for (int i = 0; i < iContentHeight; i++) { for (int j = 0; j < 79; j++) { mvwputch(w_colors, i, j, c_black, ' '); for( auto &iCol : vLines ) { if ( iCol == j ) { mvwputch(w_colors, i, j, c_ltgray, LINE_XOXO); } } } } calcStartPos(iStartPos, iCurrentLine, iContentHeight, iMaxColors); draw_scrollbar(w_colors_border, iCurrentLine, iContentHeight, iMaxColors, 5); wrefresh(w_colors_border); auto iter = name_color_map.begin(); std::advance( iter, iStartPos ); std::string sActive = ""; // display colormanager for (int i=iStartPos; iter != name_color_map.end(); ++iter, ++i) { if (i >= iStartPos && i < iStartPos + ((iContentHeight > iMaxColors) ? iMaxColors : iContentHeight)) { auto &entry = iter->second; if (iCurrentLine == i) { sActive = iter->first; mvwprintz(w_colors, i - iStartPos, vLines[iCurrentCol-1] + 2, c_yellow, ">"); } mvwprintz(w_colors, i - iStartPos, 3, c_white, iter->first.c_str()); //colorname mvwprintz(w_colors, i - iStartPos, 21, entry.color, _("default")); //default color if ( !entry.name_custom.empty() ) { mvwprintz(w_colors, i - iStartPos, 30, name_color_map[entry.name_custom].color, entry.name_custom.c_str()); //custom color } mvwprintz(w_colors, i - iStartPos, 52, entry.invert, _("default")); //invert default color if ( !entry.name_invert_custom.empty() ) { mvwprintz(w_colors, i - iStartPos, 61, name_color_map[entry.name_invert_custom].color, entry.name_invert_custom.c_str()); //invert custom color } } } wrefresh(w_colors); const std::string action = ctxt.handle_input(); if (action == "QUIT") { break; } else if (action == "UP") { iCurrentLine--; if (iCurrentLine < 0) { iCurrentLine = iMaxColors - 1; } } else if (action == "DOWN") { iCurrentLine++; if (iCurrentLine >= (int)iMaxColors) { iCurrentLine = 0; } } else if (action == "LEFT") { iCurrentCol--; if (iCurrentCol < 1) { iCurrentCol = iTotalCols; } } else if (action == "RIGHT") { iCurrentCol++; if (iCurrentCol > iTotalCols) { iCurrentCol = 1; } } else if (action == "REMOVE_CUSTOM") { auto &entry = name_color_map[sActive]; if ( iCurrentCol == 1 && !entry.name_custom.empty() ) { bStuffChanged = true; entry.name_custom = ""; } else if ( iCurrentCol == 2 && !entry.name_invert_custom.empty() ) { bStuffChanged = true; entry.name_invert_custom = ""; } finalize(); // Need to recalculate caches } else if (action == "LOAD_TEMPLATE") { auto vFiles = get_files_from_path(".json", FILENAMES["color_templates"], false, true); if ( vFiles.size() > 0 ) { uimenu ui_templates; ui_templates.w_y = iHeaderHeight + 1 + iOffsetY; ui_templates.w_height = 18; ui_templates.return_invalid = true; ui_templates.text = _("Color templates:"); for ( const auto& filename : vFiles ) { ui_templates.addentry( filename.substr(filename.find_last_of("/") + 1) ); } ui_templates.addentry(std::string(_("Cancel"))); ui_templates.query(); if ( (size_t)ui_templates.ret < vFiles.size() ) { bStuffChanged = true; clear(); load_default(); load_custom(vFiles[ui_templates.ret]); name_color_map.clear(); for( const auto &pr : name_map ) { name_color_map[pr.first] = color_array[pr.second]; } } } finalize(); // Need to recalculate caches } else if (action == "CONFIRM") { uimenu ui_colors; ui_colors.w_y = iHeaderHeight + 1 + iOffsetY; ui_colors.w_height = 18; ui_colors.return_invalid = true; std::string sColorType = _("Normal"); std::string sSelected = name_color_map[sActive].name_custom; if ( iCurrentCol == 2 ) { sColorType = _("Invert"); sSelected = name_color_map[sActive].name_invert_custom; } ui_colors.text = string_format( _("Custom %s color:"), sColorType.c_str() ); int i = 0; for ( auto &iter : name_color_map ) { std::string sColor = iter.first; std::string sType = _("default"); std::string name_custom = ""; if ( sSelected == sColor ) { ui_colors.selected = i; } if ( !iter.second.name_custom.empty() ) { name_custom = " <color_" + iter.second.name_custom + ">" + iter.second.name_custom + "</color>"; } ui_colors.addentry(string_format( "%-17s <color_%s>%s</color>%s", iter.first.c_str(), sColor.c_str(), sType.c_str(), name_custom.c_str() ) ); i++; } ui_colors.addentry(std::string(_("Cancel"))); ui_colors.query(); if ( (size_t)ui_colors.ret < name_color_map.size() ) { bStuffChanged = true; iter = name_color_map.begin(); std::advance( iter, ui_colors.ret ); auto &entry = name_color_map[sActive]; if ( iCurrentCol == 1 ) { entry.name_custom = iter->first; } else if ( iCurrentCol == 2 ) { entry.name_invert_custom = iter->first; } } finalize(); // Need to recalculate caches } } if( bStuffChanged && query_yn(_("Save changes?") ) ) { for( const auto &pr : name_color_map ) { color_id id = name_to_id( pr.first ); color_array[id].name_custom = pr.second.name_custom; color_array[id].name_invert_custom = pr.second.name_invert_custom; } finalize(); save_custom(); clear(); load_default(); load_custom(); } }
void db_x509req::load(void) { load_req l; load_default(l); }
rt_err_t load_setup(void) { int fd, length; char line[64]; fd = open(setup_fn, O_RDONLY, 0); if (fd >= 0) { length = read_line(fd, line, sizeof(line)); if (strcmp(line, "[config]") == 0) { char* begin; // default_volume length = read_line(fd, line, sizeof(line)); if (length == 0) { close(fd); load_default(); return RT_EOK; } if (strncmp(line, kn_volume, sizeof(kn_volume) - 1) == 0) { begin = strchr(line, '='); begin++; radio_setup.default_volume = atoi(begin); } // lcd_brightness length = read_line(fd, line, sizeof(line)); if (length == 0) { close(fd); load_default(); return RT_EOK; } if (strncmp(line, kn_brightness, sizeof(kn_brightness) - 1) == 0) { begin = strchr(line, '='); begin++; radio_setup.lcd_brightness = atoi(begin); } // touch_min_x length = read_line(fd, line, sizeof(line)); if (length == 0) { close(fd); load_default(); return RT_EOK; } if (strncmp(line, kn_touch_min_x, sizeof(kn_touch_min_x) - 1) == 0) { begin = strchr(line, '='); begin++; radio_setup.touch_min_x = atoi(begin); } // touch_max_x length = read_line(fd, line, sizeof(line)); if (length == 0) { close(fd); load_default(); return RT_EOK; } if (strncmp(line, kn_touch_max_x, sizeof(kn_touch_max_x) - 1) == 0) { begin = strchr(line, '='); begin++; radio_setup.touch_max_x = atoi(begin); } // touch_min_y length = read_line(fd, line, sizeof(line)); if (length == 0) { close(fd); load_default(); return RT_EOK; } if (strncmp(line, kn_touch_min_y, sizeof(kn_touch_min_y) - 1) == 0) { begin = strchr(line, '='); begin++; radio_setup.touch_min_y = atoi(begin); } // touch_max_y length = read_line(fd, line, sizeof(line)); if (length == 0) { close(fd); load_default(); return RT_EOK; } if (strncmp(line, kn_touch_max_y, sizeof(kn_touch_max_y) - 1) == 0) { begin = strchr(line, '='); begin++; radio_setup.touch_max_y = atoi(begin); } } else { close(fd); load_default(); return RT_EOK; } } else { load_default(); } close(fd); return RT_EOK; }