From 055d3a054e76cc29f26697d94d6a5134cc4ea5ed Mon Sep 17 00:00:00 2001 From: Sottosistema W10 Date: Mon, 13 Sep 2021 21:47:37 +0200 Subject: [PATCH 1/4] Added OLED timeout --- src/TTGO_T-Beam_LoRa_APRS.ino | 55 +++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 9 deletions(-) diff --git a/src/TTGO_T-Beam_LoRa_APRS.ino b/src/TTGO_T-Beam_LoRa_APRS.ino index 22b1a20..9737c28 100644 --- a/src/TTGO_T-Beam_LoRa_APRS.ino +++ b/src/TTGO_T-Beam_LoRa_APRS.ino @@ -181,6 +181,12 @@ boolean shutdown_active =true; boolean shutdown_countdown_timer_enable = false; boolean shutdown_usb_status_bef = false; +// Variables added by LucaFRL +ulong oled_timeout = 20000; +bool tempOled = true; +ulong oled_timer = millis(); +//------------------------------- + #define ANGLE_AVGS 3 // angle averaging - x times float average_course[ANGLE_AVGS]; float avg_c_y, avg_c_x; @@ -356,7 +362,7 @@ void batt_read(){ BattVolts = axp.getBattVoltage()/1000; InpVolts = axp.getVbusVoltage()/1000; #else - BattVolts = analogRead(35)*7.221/4096; + BattVolts = analogRead(35)*7.221/8192; #endif } @@ -387,10 +393,10 @@ void writedisplaytext(String HeaderTxt, String Line1, String Line2, String Line3 display.println(Line5); if (enabled_oled){ //axp.setPowerOutPut(AXP192_DCDC1, AXP202_ON); // enable oled - display.dim(true); + //display.dim(true); }else{ //axp.setPowerOutPut(AXP192_DCDC1, AXP202_OFF); // disable oled - display.dim(false); + //display.dim(false); } display.display(); time_to_refresh = millis() + showRXTime; @@ -821,6 +827,11 @@ void setup(){ digitalWrite(TXLED, HIGH); } +void enableOled() { + tempOled = true; + oled_timer = millis() + oled_timeout; +} + // +---------------------------------------------------------------------+// // + MAINLOOP -----------------------------------------------------------+// // +---------------------------------------------------------------------+// @@ -832,19 +843,36 @@ void loop() { delay(300); time_delay = millis() + 1500; if(digitalRead(BUTTON)==HIGH){ - if(gps_state == true && gps.location.isValid()){ - writedisplaytext("((MAN TX))","","","","",""); - sendpacket(); - }else{ - writedisplaytext("((FIX TX))","","","","",""); - sendpacket(); + if (!tempOled) { + // turn ON OLED temporary + enableOled(); + //---------------------------- + } else { + if(gps_state == true && gps.location.isValid()){ + writedisplaytext("((MAN TX))","","","","",""); + sendpacket(); + }else{ + writedisplaytext("((FIX TX))","","","","",""); + sendpacket(); + } } key_up = true; } } } + // Only wake up OLED when necessary + display.dim(!tempOled); + + if (tempOled && millis()>= oled_timer) { + tempOled = false; + } + //------------------------------------ + if(digitalRead(BUTTON)==LOW && key_up == false && millis() >= time_delay && t_lock == false){ + // enable OLED + enableOled(); + //--------------- t_lock = true; if(gps_state){ gps_state = false; @@ -877,6 +905,9 @@ void loop() { if (fixed_beacon_enabled) { if (millis() >= next_fixed_beacon && !gps_state) { + // enable OLED + enableOled(); + //--------------- next_fixed_beacon = millis() + fix_beacon_interval; writedisplaytext("((AUT TX))", "", "", "", "", ""); sendpacket(); @@ -932,6 +963,9 @@ void loop() { loraReceivedFrameString = ""; //int rssi = rf95.lastSNR(); //Serial.println(rssi); + // enable OLED + enableOled(); + //--------------- for (int i=0 ; i < loraReceivedLength ; i++) { loraReceivedFrameString += (char) lora_RXBUFF[i]; } @@ -999,6 +1033,9 @@ void loop() { } if ( (lastTX+nextTX) <= millis() ) { if (gps.location.age() < 2000) { + // enable OLED + enableOled(); + //--------------- writedisplaytext(" ((TX))","","LAT: "+LatShown,"LON: "+LongShown,"SPD: "+String(gps.speed.kmph(),1)+" CRS: "+String(gps.course.deg(),1),getSatAndBatInfo()); sendpacket(); } else { From d6e82b6e77754b44cfca0ee08d0b83aac6639bcf Mon Sep 17 00:00:00 2001 From: Luca Date: Mon, 13 Sep 2021 22:12:12 +0200 Subject: [PATCH 2/4] new battery decimal places --- src/TTGO_T-Beam_LoRa_APRS.ino | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/TTGO_T-Beam_LoRa_APRS.ino b/src/TTGO_T-Beam_LoRa_APRS.ino index 9737c28..31886ed 100644 --- a/src/TTGO_T-Beam_LoRa_APRS.ino +++ b/src/TTGO_T-Beam_LoRa_APRS.ino @@ -406,15 +406,15 @@ String getSatAndBatInfo() { String line5; if(gps_state == true){ if(InpVolts > 4){ - line5 = "SAT: " + String(gps.satellites.value()) + " BAT: " + String(BattVolts, 1) + "V *"; + line5 = "SAT: " + String(gps.satellites.value()) + " BAT: " + String(BattVolts, 2) + "V *"; }else{ - line5 = "SAT: " + String(gps.satellites.value()) + " BAT: " + String(BattVolts, 1) + "V"; + line5 = "SAT: " + String(gps.satellites.value()) + " BAT: " + String(BattVolts, 2) + "V"; } }else{ if(InpVolts > 4){ - line5 = "SAT: X BAT: " + String(BattVolts, 1) + "V *"; + line5 = "SAT: X BAT: " + String(BattVolts, 2) + "V *"; }else{ - line5 = "SAT: X BAT: " + String(BattVolts, 1) + "V"; + line5 = "SAT: X BAT: " + String(BattVolts, 2) + "V"; } } @@ -785,7 +785,7 @@ void setup(){ adc1_config_channel_atten(ADC1_CHANNEL_7,ADC_ATTEN_DB_6); #endif batt_read(); - writedisplaytext("LoRa-APRS","","Init:","ADC OK!","BAT: "+String(BattVolts,1),""); + writedisplaytext("LoRa-APRS","","Init:","ADC OK!","BAT: "+String(BattVolts,2),""); if(lora_speed==1200) rf95.setModemConfig(BG_RF95::Bw125Cr47Sf512); From 40234f4d50be751efde8514d33dd0f74add3b7a8 Mon Sep 17 00:00:00 2001 From: Sottosistema W10 Date: Tue, 14 Sep 2021 18:53:37 +0200 Subject: [PATCH 3/4] Improved OLED battery save functions --- src/TTGO_T-Beam_LoRa_APRS.ino | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/src/TTGO_T-Beam_LoRa_APRS.ino b/src/TTGO_T-Beam_LoRa_APRS.ino index e37a2d5..b1d2d1a 100644 --- a/src/TTGO_T-Beam_LoRa_APRS.ino +++ b/src/TTGO_T-Beam_LoRa_APRS.ino @@ -181,11 +181,10 @@ boolean shutdown_active =true; boolean shutdown_countdown_timer_enable = false; boolean shutdown_usb_status_bef = false; -// Variables added by LucaFRL -ulong oled_timeout = 20000; -bool tempOled = true; +// Variables required to Power Save OLED +ulong oled_timeout = 20000; // OLED Timeout +bool tempOled = true; // Turn ON OLED at first startup ulong oled_timer = millis(); -//------------------------------- #define ANGLE_AVGS 3 // angle averaging - x times float average_course[ANGLE_AVGS]; @@ -828,6 +827,7 @@ void setup(){ } void enableOled() { + // This function enables OLED display after pressing a button tempOled = true; oled_timer = millis() + oled_timeout; } @@ -844,9 +844,7 @@ void loop() { time_delay = millis() + 1500; if(digitalRead(BUTTON)==HIGH){ if (!tempOled) { - // turn ON OLED temporary - enableOled(); - //---------------------------- + enableOled(); // turn ON OLED temporary } else { if(gps_state == true && gps.location.isValid()){ writedisplaytext("((MAN TX))","","","","",""); @@ -861,13 +859,12 @@ void loop() { } } - // Only wake up OLED when necessary + // Only wake up OLED when necessary, note that DIM is to turn OFF the backlight display.dim(!tempOled); if (tempOled && millis()>= oled_timer) { - tempOled = false; + tempOled = false; // After some time reset backlight } - //------------------------------------ if(digitalRead(BUTTON)==LOW && key_up == false && millis() >= time_delay && t_lock == false){ // enable OLED @@ -884,8 +881,6 @@ void loop() { #ifdef ENABLE_PREFERENCES preferences.putBool(PREF_APRS_GPS_EN, false); #endif - - }else{ gps_state = true; #ifdef T_BEAM_V1_0 @@ -905,9 +900,7 @@ void loop() { if (fixed_beacon_enabled) { if (millis() >= next_fixed_beacon && !gps_state) { - // enable OLED - enableOled(); - //--------------- + enableOled(); // enable OLED next_fixed_beacon = millis() + fix_beacon_interval; writedisplaytext("((AUT TX))", "", "", "", "", ""); sendpacket(); @@ -939,6 +932,7 @@ void loop() { String *TNC2DataFrame = nullptr; if (tncToSendQueue) { if (xQueueReceive(tncToSendQueue, &TNC2DataFrame, (1 / portTICK_PERIOD_MS)) == pdPASS) { + enableOled(); // enable OLED writedisplaytext("((KISSTX))","","","","",""); time_to_refresh = millis() + showRXTime; loraSend(txPower, lora_freq, *TNC2DataFrame); @@ -963,9 +957,7 @@ void loop() { loraReceivedFrameString = ""; //int rssi = rf95.lastSNR(); //Serial.println(rssi); - // enable OLED - enableOled(); - //--------------- + enableOled(); // enable OLED for (int i=0 ; i < loraReceivedLength ; i++) { loraReceivedFrameString += (char) lora_RXBUFF[i]; } @@ -1033,9 +1025,7 @@ void loop() { } if ( (lastTX+nextTX) <= millis() ) { if (gps.location.age() < 2000) { - // enable OLED - enableOled(); - //--------------- + enableOled(); // enable OLED writedisplaytext(" ((TX))","","LAT: "+LatShown,"LON: "+LongShown,"SPD: "+String(gps.speed.kmph(),1)+" CRS: "+String(gps.course.deg(),1),getSatAndBatInfo()); sendpacket(); } else { From 8dd7e45e40a19738b9d06b81be8a462dcc906e18 Mon Sep 17 00:00:00 2001 From: Sottosistema W10 Date: Tue, 14 Sep 2021 19:58:35 +0200 Subject: [PATCH 4/4] Improved OLED power save functions --- data_embed/index.html | 6 +++--- src/TTGO_T-Beam_LoRa_APRS.ino | 16 +++++++++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/data_embed/index.html b/data_embed/index.html index af976eb..7d23e11 100644 --- a/data_embed/index.html +++ b/data_embed/index.html @@ -166,8 +166,8 @@
- - + +
@@ -179,7 +179,7 @@
- +
diff --git a/src/TTGO_T-Beam_LoRa_APRS.ino b/src/TTGO_T-Beam_LoRa_APRS.ino index b1d2d1a..66a9d1c 100644 --- a/src/TTGO_T-Beam_LoRa_APRS.ino +++ b/src/TTGO_T-Beam_LoRa_APRS.ino @@ -182,7 +182,9 @@ boolean shutdown_countdown_timer_enable = false; boolean shutdown_usb_status_bef = false; // Variables required to Power Save OLED -ulong oled_timeout = 20000; // OLED Timeout +// With "Display dimmer enabled" it will turn OLED off after some time +// if the checkbox is disabled the display stays OFF +uint oled_timeout; // OLED Timeout, same as "Display show RX Time" bool tempOled = true; // Turn ON OLED at first startup ulong oled_timer = millis(); @@ -392,10 +394,10 @@ void writedisplaytext(String HeaderTxt, String Line1, String Line2, String Line3 display.println(Line5); if (enabled_oled){ //axp.setPowerOutPut(AXP192_DCDC1, AXP202_ON); // enable oled - //display.dim(true); + //display.dim(false); }else{ //axp.setPowerOutPut(AXP192_DCDC1, AXP202_OFF); // disable oled - //display.dim(false); + display.dim(true); } display.display(); time_to_refresh = millis() + showRXTime; @@ -658,6 +660,8 @@ void setup(){ preferences.putInt(PREF_DEV_SHOW_RX_TIME, showRXTime/1000); } showRXTime = preferences.getInt(PREF_DEV_SHOW_RX_TIME) * 1000; + // Use same timer for OLED timeout + oled_timeout = showRXTime; if (!preferences.getBool(PREF_DEV_AUTO_SHUT_PRESET_INIT)){ preferences.putBool(PREF_DEV_AUTO_SHUT_PRESET_INIT, true); @@ -843,7 +847,7 @@ void loop() { delay(300); time_delay = millis() + 1500; if(digitalRead(BUTTON)==HIGH){ - if (!tempOled) { + if (!tempOled && enabled_oled) { enableOled(); // turn ON OLED temporary } else { if(gps_state == true && gps.location.isValid()){ @@ -860,7 +864,9 @@ void loop() { } // Only wake up OLED when necessary, note that DIM is to turn OFF the backlight - display.dim(!tempOled); + if (enabled_oled) { + display.dim(!tempOled); + } if (tempOled && millis()>= oled_timer) { tempOled = false; // After some time reset backlight