„wt32pamon.ino“ ändern

This commit is contained in:
Michael Clemens // DK1MI 2023-05-24 12:20:12 +00:00
parent 65a4ac7ed1
commit 557aeb1ced

View File

@ -28,10 +28,12 @@
String version = "0.9"; String version = "0.9";
Preferences config; Preferences config;
Preferences global_config;
String band_config_items[] = { "b_show_mV", "b_show_dBm", "b_show_watt", "s_vswr_thresh", "b_vswr_beep", "x_selected_band", "s_ant_name", "s_max_led_pwr_f", "s_max_led_pwr_r", "s_max_led_vswr", "b_show_led_fwd", "b_show_led_ref", "b_show_led_vswr" };
String band_config_defaults[] = { "true", "true", "true", "2", "true", "70cm", " ", "100", "100", "3", "true", "true", "true" };
String band_config_nice_names[] = {"Show voltage in mV (yes/no)", "Show power level in dBm (yes/no)", "Show Power in Watt (yes/no)", "VSWR Threshold that triggers a warning (e.g. 3)", "Beep if VSWR threshold is exceeded (yes/no)", "", "Name of the antenna", "Max. FWD Power displayed by LED bar graph in W (e.g. 100)", "Max. REF Power displayed by LED bar graph in W (e.g. 100)", "Max. VSWR displayed by LED bar graph (e.g. 3)", "Show LED graph for FWD power (yes/no)", "Show LED graph for REF power (yes/no)", "Show LED graph for VSWR (yes/no)" };
String config_items[] = { "b_show_mV", "b_show_dBm", "b_show_watt", "s_vswr_thresh", "b_vswr_beep", "x_selected_band", "s_ant_name", "s_max_led_pwr_f", "s_max_led_pwr_r", "s_max_led_vswr", "b_show_led_fwd", "b_show_led_ref", "b_show_led_vswr" };
String config_defaults[] = { "true", "true", "true", "2", "true", "70cm", " ", "100", "100", "3", "true", "true", "true" };
String config_nice_names[] = {"Show voltage in mV (yes/no)", "Show power level in dBm (yes/no)", "Show Power in Watt (yes/no)", "VSWR Threshold that triggers a warning (e.g. 3)", "Beep if VSWR threshold is exceeded (yes/no)", "", "Name of the antenna", "Max. FWD Power displayed by LED bar graph in W (e.g. 100)", "Max. REF Power displayed by LED bar graph in W (e.g. 100)", "Max. VSWR displayed by LED bar graph (e.g. 3)", "Show LED graph for FWD power (yes/no)", "Show LED graph for REF power (yes/no)", "Show LED graph for VSWR (yes/no)" };
double fwd_array[3300] = {}; double fwd_array[3300] = {};
double ref_array[3300] = {}; double ref_array[3300] = {};
@ -469,25 +471,25 @@ void build_config_table() {
conf_config_table = "<form action=\"/modcfg\" method=\"POST\">"; conf_config_table = "<form action=\"/modcfg\" method=\"POST\">";
conf_config_table += "<table class='styled-table'>"; conf_config_table += "<table class='styled-table'>";
conf_config_table += "<thead><tr><td>Key</td><td>Value</td></td></tr></thead>"; conf_config_table += "<thead><tr><td>Key</td><td>Value</td></td></tr></thead>";
for (int i = 0; i < sizeof config_items / sizeof config_items[0]; i++) { for (int i = 0; i < sizeof band_config_items / sizeof band_config_items[0]; i++) {
if (!config_items[i].startsWith("x_")) { if (!band_config_items[i].startsWith("x_")) {
String stored_val = config.getString(config_items[i].c_str(), "xxx"); String stored_val = config.getString(band_config_items[i].c_str(), "xxx");
if (stored_val == "xxx") { if (stored_val == "xxx") {
config.putString(config_items[i].c_str(), config_defaults[i]); config.putString(band_config_items[i].c_str(), band_config_defaults[i]);
stored_val = config.getString(config_items[i].c_str(), ""); stored_val = config.getString(band_config_items[i].c_str(), "");
} }
conf_config_table += "<tr><td>"; conf_config_table += "<tr><td>";
conf_config_table += config_nice_names[i]; conf_config_table += band_config_nice_names[i];
conf_config_table += "</td><td>"; conf_config_table += "</td><td>";
if (String(stored_val).equalsIgnoreCase("true")) { if (String(stored_val).equalsIgnoreCase("true")) {
//conf_config_table += "<input type='hidden' name='" + config_items[i] + "' value='false'>"; //conf_config_table += "<input type='hidden' name='" + band_config_items[i] + "' value='false'>";
conf_config_table += "<input type='checkbox' name='" + config_items[i] + "' id='" + config_items[i] + "' value='true' checked>"; conf_config_table += "<input type='checkbox' name='" + band_config_items[i] + "' id='" + band_config_items[i] + "' value='true' checked>";
} else if (String(stored_val).equalsIgnoreCase("false")) { } else if (String(stored_val).equalsIgnoreCase("false")) {
//conf_config_table += "<input type='hidden' name='" + config_items[i] + "' value='false'>"; //conf_config_table += "<input type='hidden' name='" + band_config_items[i] + "' value='false'>";
conf_config_table += "<input type='checkbox' name='" + config_items[i] + "' id='" + config_items[i] + "' value='false'>"; conf_config_table += "<input type='checkbox' name='" + band_config_items[i] + "' id='" + band_config_items[i] + "' value='false'>";
} else { } else {
conf_config_table += "<input name='" + config_items[i] + "' value='" + String(stored_val) + "' valuelength=16>"; conf_config_table += "<input name='" + band_config_items[i] + "' value='" + String(stored_val) + "' valuelength=16>";
} }
conf_config_table += "</td></tr>"; conf_config_table += "</td></tr>";
} }
@ -567,23 +569,23 @@ void save_string_to_array(String table_data, double arr[]) {
void handleMODCFG() { void handleMODCFG() {
//String key = server.arg("conf_key"); //String key = server.arg("conf_key");
//String value = server.arg("conf_value"); //String value = server.arg("conf_value");
for (int i = 0; i < sizeof config_items / sizeof config_items[0]; i++) { for (int i = 0; i < sizeof band_config_items / sizeof band_config_items[0]; i++) {
Serial.println(config_items[i] + ": " + server.arg(config_items[i])); Serial.println(band_config_items[i] + ": " + server.arg(band_config_items[i]));
/* /*
if (config_items[i] == key) { if (band_config_items[i] == key) {
if (key != "" and value != "") { if (key != "" and value != "") {
config.putString(config_items[i].c_str(), value); config.putString(band_config_items[i].c_str(), value);
conf_config_table = ""; conf_config_table = "";
break; break;
} }
} }
*/ */
if (!server.hasArg(config_items[i]) and config_items[i].startsWith("b_")){ if (!server.hasArg(band_config_items[i]) and band_config_items[i].startsWith("b_")){
config.putString(config_items[i].c_str(), "false"); config.putString(band_config_items[i].c_str(), "false");
} else if (server.hasArg(config_items[i]) and config_items[i].startsWith("b_")){ } else if (server.hasArg(band_config_items[i]) and band_config_items[i].startsWith("b_")){
config.putString(config_items[i].c_str(), "true"); config.putString(band_config_items[i].c_str(), "true");
} else { } else {
config.putString(config_items[i].c_str(), server.arg(config_items[i])); config.putString(band_config_items[i].c_str(), server.arg(band_config_items[i]));
} }
} }
conf_config_table = ""; conf_config_table = "";
@ -598,7 +600,10 @@ void handleBAND() {
band = server.arg("bands"); band = server.arg("bands");
band_fwd = band + "_fwd"; band_fwd = band + "_fwd";
band_ref = band + "_ref"; band_ref = band + "_ref";
config.putString(String("x_selected_band").c_str(), band); global_config.putString(String("x_selected_band").c_str(), band);
config.end();
String bnd_cnf = "config_" + band;
config.begin(bnd_cnf.c_str(), false);
conf_textareas = ""; conf_textareas = "";
conf_config_table = ""; conf_config_table = "";
//build_config_table(); //build_config_table();
@ -654,12 +659,15 @@ void setup() {
analogReadResolution(12); analogReadResolution(12);
config.begin("config", false); global_config.begin("config", false);
band = config.getString(String("x_selected_band").c_str()); band = global_config.getString(String("x_selected_band").c_str());
if (band == "") { if (band == "") {
config.putString(String("x_selected_band").c_str(), default_band); global_config.putString(String("x_selected_band").c_str(), default_band);
band = default_band; band = default_band;
} }
String bnd_cnf = "config_" + band;
config.begin(bnd_cnf.c_str(), false);
//config.begin("config_" + band, false);
build_textareas(); build_textareas();
} }