Browse Source

Rewrite some code

pull/1/head
US1GHQ 3 months ago
parent
commit
194d238f2f
  1. 22
      data_embed/index.html
  2. 11
      include/preference_storage.h
  3. 22
      src/TTGO_T-Beam_LoRa_APRS.ino
  4. 21
      src/taskWebServer.cpp

22
data_embed/index.html

@ -106,19 +106,19 @@
<div class="grid-container quarters">
<div>
<label for="sb_min_interv">Min interval [s]</label>
<input name="sb_min_interv" id="sb_min_interv" type="number" min="60" title="Minimal time for Smart Beaconing">
<input name="sb_min_interv" id="sb_min_interv" size="10" type="number" min="60" title="Minimal time for Smart Beaconing">
</div>
<div>
<label for="sb_max_interv">Max interval [s]</label>
<input name="sb_max_interv" id="sb_max_interv" type="number" min="120" title="Maximal time for Smart Beaconing">
<input name="sb_max_interv" id="sb_max_interv" size="10" type="number" min="120" title="Maximal time for Smart Beaconing">
</div>
<div>
<label for="sb_min_speed">Min speed [km/h]</label>
<input name="sb_min_speed" id="sb_min_speed" type="number" min="0" title="Minimal speed for Smart Beaconing">
<input name="sb_min_speed" id="sb_min_speed" size="10" type="number" min="0" title="Minimal speed for Smart Beaconing">
</div>
<div>
<label for="sb_max_speed">Max speed [km/h]</label>
<input name="sb_max_speed" id="sb_max_speed" type="number" min="1" title="Maximal speed for Smart Beaconing">
<input name="sb_max_speed" id="sb_max_speed" size="10" type="number" min="1" title="Maximal speed for Smart Beaconing">
</div>
</div>
<div class="grid-container quarters">
@ -143,16 +143,18 @@
</div>
<div class="grid-container quarters">
<div>
<label for="aprs_freq">APRS Freq KHz</label>
<input name="aprs_freq" id="aprs_freq" type="number" min="410000" max="510000" title="Working freq, default 433.775">
<label for="aprs_freq">APRS FREQ MHz:</label>
<input class="u-full-width" type="number" min="0" step="0.001" name="aprs_freq" id="aprs_freq" title="APRS FREQ Default 433.775">
</div>
<div>
<label for="aprs_mode">APRS Mode</label>
<input name="aprs_mode" id="aprs_mode" type="number" min="410000" max="510000" title="APRS Mode 300/1200b">
<label for="aprs_mode">APRS MODE:</label>
<select name="aprs_mode" id="aprs_mode" title="APRS MODE 1200 or 300">
<option value="1200">1200</option>
<option value="300">300</option>
</select>
</div>
<div>
<label for="aprs_txpower">TX Power</label>
<input name="aprs_txpower" id="aprs_txpower" type="number" min="0" max="23" title="TX Power dbm">
</div>
<div>

11
include/preference_storage.h

@ -8,11 +8,6 @@
extern Preferences preferences;
// MAX 15 chars for preferenece key!!!
// FREQ AND MODE SET
static const char *const PREF_APRS_MODE = "aprs_mode"; //300 or 1200b
static const char *const PREF_APRS_FREQ = "aprs_freq"; //freq default: 433.775
static const char *const PREF_APRS_TXPOWER = "aprs_txpower"; //txpower default 20dBm
//MAIN SETTINGS
static const char *const PREF_WIFI_SSID = "wifi_ssid";
static const char *const PREF_WIFI_PASSWORD = "wifi_password";
@ -45,7 +40,13 @@ static const char *const PREF_APRS_SB_MIN_SPEED_PRESET = "sb_min_speed";
static const char *const PREF_APRS_SB_MIN_SPEED_PRESET_INIT = "sb_min_speed_i";
static const char *const PREF_APRS_SB_MAX_SPEED_PRESET = "sb_max_speed";
static const char *const PREF_APRS_SB_MAX_SPEED_PRESET_INIT = "sb_max_speed_i";
// FREQ AND MODE SET
static const char *const PREF_APRS_FREQ = "aprs_freq"; //freq default: 433.775
static const char *const PREF_APRS_FREQ_INIT = "aprs_freq_i";
static const char *const PREF_APRS_MODE = "aprs_mode"; //300 or 1200b
static const char *const PREF_APRS_MODE_INIT = "aprs_mode_i";
//Other settings
static const char *const PREF_APRS_GPS_EN = "gps_enabled";
static const char *const PREF_APRS_GPS_EN_INIT = "gps_state_init";
static const char *const PREF_APRS_SHOW_CMT = "show_cmt";

22
src/TTGO_T-Beam_LoRa_APRS.ino

@ -113,6 +113,9 @@ String relay_path;
String aprsComment = MY_COMMENT;
String aprsLatPreset = LATIDUDE_PRESET;
String aprsLonPreset = LONGITUDE_PRESET;
String aprsFreq = "433.775";
String aprsMode = "1200";
boolean gps_state = true;
boolean key_up = true;
boolean t_lock = false;
@ -574,8 +577,8 @@ void setup(){
preferences.putString(PREF_APRS_SYMBOL, APRS_SYMBOL);
aprsSymbol = preferences.getString(PREF_APRS_SYMBOL, APRS_SYMBOL);
}
if (!preferences.getBool(PREF_APRS_COMMENT_INIT)){
if (!preferences.getBool(PREF_APRS_COMMENT_INIT)){
preferences.putBool(PREF_APRS_COMMENT_INIT, true);
preferences.putString(PREF_APRS_COMMENT, MY_COMMENT);
}
@ -644,7 +647,6 @@ void setup(){
}
sb_max_interval = preferences.getInt(PREF_APRS_SB_MAX_INTERVAL_PRESET) * 1000;
if (!preferences.getBool(PREF_APRS_SB_MIN_SPEED_PRESET_INIT)){
preferences.putBool(PREF_APRS_SB_MIN_SPEED_PRESET_INIT, true);
preferences.putInt(PREF_APRS_SB_MIN_SPEED_PRESET, sb_min_speed);
@ -656,7 +658,19 @@ void setup(){
preferences.putInt(PREF_APRS_SB_MAX_SPEED_PRESET, sb_max_speed);
}
sb_max_speed = preferences.getInt(PREF_APRS_SB_MAX_SPEED_PRESET);
//
//Set parameters (freq,mode,txpower)
if (!preferences.getBool(PREF_APRS_FREQ_INIT)){
preferences.putBool(PREF_APRS_FREQ_INIT, true);
preferences.putString(PREF_APRS_FREQ, aprsFreq);
}
aprsFreq = preferences.getString(PREF_APRS_FREQ);
if (!preferences.getBool(PREF_APRS_MODE_INIT)){
preferences.putBool(PREF_APRS_MODE_INIT, true);
preferences.putString(PREF_APRS_MODE, aprsMode);
}
aprsMode = preferences.getString(PREF_APRS_MODE);
//End set parameters
if (!preferences.getBool(PREF_DEV_SHOW_RX_TIME_INIT)){
preferences.putBool(PREF_DEV_SHOW_RX_TIME_INIT, true);
preferences.putInt(PREF_DEV_SHOW_RX_TIME, showRXTime/1000);

21
src/taskWebServer.cpp

@ -128,9 +128,6 @@ void handle_Restore() {
void handle_Cfg() {
String jsonData = "{";
jsonData += jsonLineFromPreferenceString(PREF_APRS_MODE);
jsonData += jsonLineFromPreferenceString(PREF_APRS_FREQ);
jsonData += jsonLineFromPreferenceString(PREF_APRS_TXPOWER);
jsonData += String("\"") + PREF_WIFI_PASSWORD + "\": \"" + jsonEscape((preferences.getString(PREF_WIFI_PASSWORD).isEmpty() ? String("") : "*")) + R"(",)";
jsonData += jsonLineFromPreferenceString(PREF_WIFI_SSID);
jsonData += jsonLineFromPreferenceString(PREF_APRS_CALLSIGN);
@ -149,6 +146,8 @@ void handle_Cfg() {
jsonData += jsonLineFromPreferenceBool(PREF_APRS_FIXED_BEACON_PRESET);
jsonData += jsonLineFromPreferenceBool(PREF_APRS_SHOW_ALTITUDE);
jsonData += jsonLineFromPreferenceBool(PREF_APRS_GPS_EN);
jsonData += jsonLineFromPreferenceString(PREF_APRS_FREQ);
jsonData += jsonLineFromPreferenceString(PREF_APRS_MODE);
jsonData += jsonLineFromPreferenceBool(PREF_DEV_OL_EN);
jsonData += jsonLineFromPreferenceBool(PREF_APRS_SHOW_CMT);
jsonData += jsonLineFromPreferenceBool(PREF_DEV_BT_EN);
@ -181,18 +180,9 @@ void handle_ReceivedList() {
}
void handle_SaveAPRSCfg() {
if (server.hasArg(PREF_APRS_MODE) && !server.arg(PREF_APRS_MODE).isEmpty()){
preferences.putString(PREF_APRS_MODE, server.arg(PREF_APRS_MODE));
}
if (server.hasArg(PREF_APRS_FREQ) && !server.arg(PREF_APRS_FREQ).isEmpty()){
preferences.putString(PREF_APRS_FREQ, server.arg(PREF_APRS_FREQ));
}
if (server.hasArg(PREF_APRS_CALLSIGN) && !server.arg(PREF_APRS_CALLSIGN).isEmpty()){
preferences.putString(PREF_APRS_CALLSIGN, server.arg(PREF_APRS_CALLSIGN));
}
if (server.hasArg(PREF_APRS_TXPOWER) && !server.arg(PREF_APRS_TXPOWER).isEmpty()){
preferences.putString(PREF_APRS_TXPOWER, server.arg(PREF_APRS_TXPOWER));
}
if (server.hasArg(PREF_APRS_SYMBOL_TABLE) && !server.arg(PREF_APRS_SYMBOL_TABLE).isEmpty()){
preferences.putString(PREF_APRS_SYMBOL_TABLE, server.arg(PREF_APRS_SYMBOL_TABLE));
}
@ -227,6 +217,7 @@ void handle_SaveAPRSCfg() {
preferences.putString(PREF_APRS_LONGITUDE_PRESET, server.arg(PREF_APRS_LONGITUDE_PRESET));
}
preferences.putBool(PREF_APRS_SHOW_BATTERY, server.hasArg(PREF_APRS_SHOW_BATTERY));
preferences.putBool(PREF_APRS_SHOW_ALTITUDE, server.hasArg(PREF_APRS_SHOW_ALTITUDE));
preferences.putBool(PREF_APRS_FIXED_BEACON_PRESET, server.hasArg(PREF_APRS_FIXED_BEACON_PRESET));
@ -246,6 +237,12 @@ void handle_saveDeviceCfg(){
preferences.putBool(PREF_DEV_AUTO_SHUT, server.hasArg(PREF_DEV_AUTO_SHUT));
if (server.hasArg(PREF_DEV_AUTO_SHUT_PRESET)){
preferences.putInt(PREF_DEV_AUTO_SHUT_PRESET, server.arg(PREF_DEV_AUTO_SHUT_PRESET).toInt());
}
if (server.hasArg(PREF_APRS_FREQ)){
preferences.putString(PREF_APRS_FREQ, server.arg(PREF_APRS_FREQ));
}
if (server.hasArg(PREF_APRS_MODE)){
preferences.putString(PREF_APRS_MODE, server.arg(PREF_APRS_MODE));
}
server.sendHeader("Location", "/");
server.send(302,"text/html", "");

Loading…
Cancel
Save