diff --git a/RX_FSK/RX_FSK.ino b/RX_FSK/RX_FSK.ino index 0ed51d4..2594557 100644 --- a/RX_FSK/RX_FSK.ino +++ b/RX_FSK/RX_FSK.ino @@ -613,6 +613,7 @@ struct st_configitems config_list[] = { {"rxalt", -7, &sonde.config.rxalt}, {"screenfile", 0, &sonde.config.screenfile}, {"display", -6, sonde.config.display}, + {"dispsaver", 0, &sonde.config.dispsaver}, /* Spectrum display settings */ {"spectrum", 0, &sonde.config.spectrum}, {"startfreq", 0, &sonde.config.startfreq}, @@ -2503,6 +2504,7 @@ void loopDecoder() { //Serial.println("Writing rdzclient OK"); } Serial.print("MAIN: updateDisplay started\n"); + sonde.dispsavectlOFF( (res & 0xff) == 0 ); // handle screen saver (disp auto off) if (forceReloadScreenConfig) { disp.initFromFile(sonde.config.screenfile); sonde.clearDisplay(); diff --git a/RX_FSK/data/cfg.js b/RX_FSK/data/cfg.js index 9ef3bc5..12ab5cf 100644 --- a/RX_FSK/data/cfg.js +++ b/RX_FSK/data/cfg.js @@ -11,6 +11,7 @@ var cfgs = [ [ "", "OLED/TFT display configuration", "https://github.com/dl9rdz/rdz_ttgo_sonde/wiki/Display-configuration" ], [ "screenfile", "Screen config (0=automatic; 1-5=predefined; other=custom)" ], [ "display", "Display screens (scan, default, ...)" ], +[ "dispsaver", "Display saver (0=never/1=always/2=ifnorx [+10*n: after n sec.])" ], [ "norx_timeout", "No-RX-timeout in seconds (-1=disabled)"], [ "tft_orient", "TFT orientation (0/1/2/3), OLED flip: 3"], [ "", "Spectrum display configuration", "https://github.com/dl9rdz/rdz_ttgo_sonde/wiki/Spectrum-configuration" ], diff --git a/RX_FSK/data/config.txt b/RX_FSK/data/config.txt index d039f5b..9f3ad74 100644 --- a/RX_FSK/data/config.txt +++ b/RX_FSK/data/config.txt @@ -51,6 +51,8 @@ kisstnc.active = 1 # second entry: default "Receiver" display # additional entries: alternative receiver display, activated by button display=0,1,2,3,4 +# turn off display: 0=never, 1=always, 2=if no RX; (+n*10: after n seconds) +dispsaver=0 # set to -1 to disable (used for "N" values in timers in screens.txt). Value in seconds norx_timeout=20 #-------------------------------# diff --git a/RX_FSK/src/Display.cpp b/RX_FSK/src/Display.cpp index 082d4e8..762d553 100644 --- a/RX_FSK/src/Display.cpp +++ b/RX_FSK/src/Display.cpp @@ -779,6 +779,7 @@ void Display::init() { delay(100); Serial.println("Display initialized"); rdis->clear(); + dispstate = 1; // display active by default } @@ -1773,10 +1774,30 @@ void Display::updateDisplayIP() { } void Display::updateDisplay() { + if( dispstate == 0 ) return; // do not display anything calcGPS(); for(DispEntry *di=layout->de; di->func != NULL; di++) { di->func(di); } } +// Called when key is pressed or new RX starts +void Display::dispsavectlON() { + // nothing to do to turn display on, may add power on code here later + dispstate = 1; +} + +// Should be called 1x / sec to update display +// parameter: rxactive (1=currently receiving something, 0=no rx) +void Display::dispsavectlOFF(int rxactive) { + if( sonde.config.dispsaver == 0 ) return; // screensaver disabled + if( dispstate == 0 ) return; // already OFF + if( rxactive && ((sonde.config.dispsaver%10)==2) ) return; // OFF only if no RX, but rxactive is 0 + dispstate++; + if( dispstate > (sonde.config.dispsaver/10) ) { + rdis->clear(); + dispstate = 0; + } +} + Display disp = Display(); diff --git a/RX_FSK/src/Display.h b/RX_FSK/src/Display.h index 5178621..db4f38c 100644 --- a/RX_FSK/src/Display.h +++ b/RX_FSK/src/Display.h @@ -160,6 +160,7 @@ public: DispInfo *layouts; int nLayouts; static RawDisplay *rdis; + char dispstate; Display(); void init(); @@ -193,7 +194,8 @@ public: void updateDisplayRXConfig(); void updateDisplayIP(); void updateDisplay(); - + void dispsavectlON(); + void dispsavectlOFF(int rxactive); void setLayout(int layout); }; diff --git a/RX_FSK/src/Sonde.cpp b/RX_FSK/src/Sonde.cpp index 832d072..085de6f 100644 --- a/RX_FSK/src/Sonde.cpp +++ b/RX_FSK/src/Sonde.cpp @@ -490,6 +490,7 @@ void Sonde::receive() { if(si->lastState != 1) { si->rxStart = millis(); si->lastState = 1; + sonde.dispsavectlON(); } } else { // RX Timeout //Serial.printf("Sonde::receive(): result %d (%s), laststate was %d\n", res, (res<=3)?RXstr[res]:"?", si->lastState); @@ -507,6 +508,7 @@ void Sonde::receive() { int event = getKeyPressEvent(); if (!event) event = timeoutEvent(si); + else sonde.dispsavectlON(); int action = (event==EVT_NONE) ? ACT_NONE : disp.layout->actions[event]; //if(action!=ACT_NONE) { Serial.printf("event %x: action is %x\n", event, action); } // If action is to move to a different sonde index, we do update things here, set activate @@ -716,6 +718,15 @@ void Sonde::clearDisplay() { disp.rdis->clear(); } +void Sonde::dispsavectlON() { + disp.dispsavectlON(); +} + +void Sonde::dispsavectlOFF(int rxactive) { + disp.dispsavectlOFF(rxactive); +} + + SondeType Sonde::realType(SondeInfo *si) { if(TYPE_IS_METEO(si->type) && si->d.subtype>0 ) { return si->d.subtype==1 ? STYPE_M10:STYPE_M20; } else return si->type; diff --git a/RX_FSK/src/Sonde.h b/RX_FSK/src/Sonde.h index 5e31a3a..07c01d2 100644 --- a/RX_FSK/src/Sonde.h +++ b/RX_FSK/src/Sonde.h @@ -263,6 +263,8 @@ typedef struct st_rdzconfig { int wifi; // connect to known WLAN 0=skip int screenfile; int8_t display[30]; // list of display mode (0:scanner, 1:default, 2,... additional modes) + int dispsaver; // Turn display on/off (0=always on, 10*n+1: off after n seconds, + // 10*n+2: scanner off after n seconds, RX always shown) int startfreq; // spectrum display start freq (400, 401, ...) int channelbw; // spectrum channel bandwidth (valid: 5, 10, 20, 25, 50, 100 kHz) int spectrum; // show freq spectrum for n seconds -1=disable; 0=forever @@ -360,6 +362,8 @@ public: void updateDisplayIP(); void updateDisplay(); void clearDisplay(); + void dispsavectlON(); + void dispsavectlOFF(int rxactive); void setIP(String ip, bool isAP); }; diff --git a/RX_FSK/src/json.cpp b/RX_FSK/src/json.cpp index a64aad7..15b80da 100644 --- a/RX_FSK/src/json.cpp +++ b/RX_FSK/src/json.cpp @@ -18,7 +18,7 @@ const char *getType(SondeInfo *si) { return sondeTypeStrSH[sonde.realType(si)]; } -int float2json(char **buf, int *maxlen, char *fmt, float value) { +int float2json(char **buf, int *maxlen, const char *fmt, float value) { if(isnan(value)) return 0; int n = snprintf(*buf, *maxlen, fmt, value); if(n>*maxlen) return -1; diff --git a/RX_FSK/version.h b/RX_FSK/version.h index fe78c3e..38f3121 100644 --- a/RX_FSK/version.h +++ b/RX_FSK/version.h @@ -1,4 +1,4 @@ const char *version_name = "rdzTTGOsonde"; -const char *version_id = "devel20220414"; +const char *version_id = "devel20220418"; const int SPIFFS_MAJOR=2; const int SPIFFS_MINOR=16;