auto shutdown option

pull/22/head
Rysiek Labus 2021-03-13 13:50:04 +01:00
rodzic 691a3eda4d
commit 41b20ba518
4 zmienionych plików z 80 dodań i 4 usunięć

Wyświetl plik

@ -128,13 +128,27 @@
<div>
<label for="led_enable">LED signaling</label>
<input name="led_enable" id="led_enable" type="checkbox" value="1" title="enable or disable LED" DISABLED>
</div>
</div>
<div>
<label for="shutdown_act">Auto shutdown</label>
<input name="shutdown_act" id="shutdown_act" type="checkbox" value="1" title="activate auto shutdown after usb plug off">
</div>
</div>
<div class="grid-container quarters">
<div>
<label for="sh_rxtime">Display show RX time (s)</label>
<input name="sh_rxtime" id="sh_rxtime" type="number" min="1" max="45" title="show RX packet for seconds">
</div>
</div>
<div>
</div>
<div>
</div>
<div>
<label for="shutdown_dt">Auto shutdown delay (s)</label>
<input name="shutdown_dt" id="shutdown_dt" type="number" min="3" max="300" title="auto shutdown delay in seconds">
</div>
</div>
<div class="grid-container full">
<div>

Wyświetl plik

@ -45,6 +45,10 @@ static const char *const PREF_DEV_OL_EN = "oled_enabled";
static const char *const PREF_DEV_OL_EN_INIT = "ol_enabled_init";
static const char *const PREF_DEV_SHOW_RX_TIME = "sh_rxtime";
static const char *const PREF_DEV_SHOW_RX_TIME_INIT = "sh_rxtime_init";
static const char *const PREF_DEV_AUTO_SHUT = "shutdown_act";
static const char *const PREF_DEV_AUTO_SHUT_INIT = "shutdown_actini";
static const char *const PREF_DEV_AUTO_SHUT_PRESET = "shutdown_dt";
static const char *const PREF_DEV_AUTO_SHUT_PRESET_INIT = "shutdown_dtini";
typedef struct {
String callsign;

Wyświetl plik

@ -68,6 +68,7 @@ boolean key_up = true;
boolean t_lock = false;
boolean fixed_beacon_enabled = false;
boolean show_cmt = true;
#ifdef SHOW_ALT
boolean showAltitude = true;
#else
@ -118,6 +119,7 @@ byte lora_TXPacketL; //length of packet to send, includes source, destin
unsigned long lastTX = 0L;
float BattVolts;
float InpVolts;
// variables for smart beaconing
float average_speed[5] = {0,0,0,0,0}, average_speed_final=0, max_speed=30, min_speed=0;
@ -131,6 +133,12 @@ ulong next_fixed_beacon = 0;
ulong fix_beacon_interval = FIX_BEACON_INTERVAL;
ulong showRXTime = SHOW_RX_TIME;
ulong time_delay = 0;
ulong shutdown_delay = 0;
ulong shutdown_delay_time = 10000;
ulong shutdown_countdown_timer = 0;
boolean shutdown_active =true;
boolean shutdown_countdown_timer_enable = false;
boolean shutdown_usb_status_bef = false;
#define ANGLE 60 // angle to send packet at smart beaconing
#define ANGLE_AVGS 3 // angle averaging - x times
float average_course[ANGLE_AVGS];
@ -288,6 +296,7 @@ void loraSend(byte lora_LTXPower, float lora_FREQ, const String &message) {
void batt_read(){
#ifdef T_BEAM_V1_0
BattVolts = axp.getBattVoltage()/1000;
InpVolts = axp.getVbusVoltage()/1000;
#else
BattVolts = analogRead(35)*7.221/4096;
#endif
@ -333,9 +342,18 @@ void writedisplaytext(String HeaderTxt, String Line1, String Line2, String Line3
String getSatAndBatInfo() {
String line5;
if(gps_state == true){
line5 = "SAT: " + String(gps.satellites.value()) + " BAT: " + String(BattVolts, 1) + "V";
if(InpVolts > 4){
line5 = "SAT: " + String(gps.satellites.value()) + " BAT: " + String(BattVolts, 1) + "V *";
}else{
line5 = "SAT: " + String(gps.satellites.value()) + " BAT: " + String(BattVolts, 1) + "V";
}
}else{
line5 = "SAT: X BAT: " + String(BattVolts, 1) + "V";
if(InpVolts > 4){
line5 = "SAT: X BAT: " + String(BattVolts, 1) + "V *";
}else{
line5 = "SAT: X BAT: " + String(BattVolts, 1) + "V";
}
}
#if defined(ENABLE_BLUETOOTH) && defined(KISS_PROTOCOL)
if (SerialBT.hasClient()){
@ -491,6 +509,17 @@ void setup(){
}
showRXTime = preferences.getInt(PREF_DEV_SHOW_RX_TIME) * 1000;
if (!preferences.getBool(PREF_DEV_AUTO_SHUT_PRESET_INIT)){
preferences.putBool(PREF_DEV_AUTO_SHUT_PRESET_INIT, true);
preferences.putInt(PREF_DEV_AUTO_SHUT_PRESET, shutdown_delay_time/1000);
}
shutdown_delay_time = preferences.getInt(PREF_DEV_AUTO_SHUT_PRESET) * 1000;
if (!preferences.getBool(PREF_DEV_AUTO_SHUT_INIT)){
preferences.putBool(PREF_DEV_AUTO_SHUT_INIT, true);
preferences.putBool(PREF_DEV_AUTO_SHUT, shutdown_active);
}
shutdown_active = preferences.getBool(PREF_DEV_AUTO_SHUT);
if (clear_preferences){
delay(1000);
@ -683,6 +712,29 @@ void loop() {
}
}
#ifdef T_BEAM_V1_0
if(shutdown_active){
if(InpVolts> 4){
shutdown_usb_status_bef = true;
shutdown_countdown_timer_enable = false;
}
if(InpVolts < 4 && shutdown_usb_status_bef == true){
shutdown_usb_status_bef = false;
shutdown_countdown_timer_enable = true;
shutdown_countdown_timer = millis() + shutdown_delay_time;
}
if(shutdown_countdown_timer_enable){
if(millis() >= shutdown_countdown_timer){
axp.shutdown();
}
}
}
#endif
#ifdef KISS_PROTOCOL
String *TNC2DataFrame = nullptr;
if (tncToSendQueue) {

Wyświetl plik

@ -123,6 +123,8 @@ void handle_Cfg() {
jsonData += jsonLineFromPreferenceBool(PREF_APRS_SHOW_CMT);
jsonData += jsonLineFromPreferenceBool(PREF_DEV_BT_EN);
jsonData += jsonLineFromPreferenceInt(PREF_DEV_SHOW_RX_TIME);
jsonData += jsonLineFromPreferenceBool(PREF_DEV_AUTO_SHUT);
jsonData += jsonLineFromPreferenceInt(PREF_DEV_AUTO_SHUT_PRESET);
jsonData += jsonLineFromString("FreeHeap", String(ESP.getFreeHeap()).c_str());
jsonData += jsonLineFromString("HeapSize", String(ESP.getHeapSize()).c_str());
jsonData += jsonLineFromString("FreeSketchSpace", String(ESP.getFreeSketchSpace()).c_str(), true);
@ -173,6 +175,10 @@ void handle_saveDeviceCfg(){
if (server.hasArg(PREF_DEV_SHOW_RX_TIME)){
preferences.putInt(PREF_DEV_SHOW_RX_TIME, server.arg(PREF_DEV_SHOW_RX_TIME).toInt());
}
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());
}
server.sendHeader("Location", "/");
server.send(302,"text/html", "");
}