]> git.tnoah.ca Git - lora-radio.git/commitdiff
Added display blanking timeout
authorMark Qvist <mark@unsigned.io>
Sun, 29 Sep 2024 00:33:02 +0000 (02:33 +0200)
committerMark Qvist <mark@unsigned.io>
Sun, 29 Sep 2024 00:33:02 +0000 (02:33 +0200)
Bluetooth.h
Config.h
Display.h
Makefile
RNode_Firmware.ino
ROM.h
Utilities.h

index 38951f759c7d231416c315711fec99b8cce84ceb..32cc8a66c41e4bdc1748bc1baac75b36a76ca973 100644 (file)
@@ -64,6 +64,7 @@ char bt_devname[11];
     }
 
     void bt_stop() {
+      display_unblank();
       if (bt_state != BT_STATE_OFF) {
         SerialBT.end();
         bt_allow_pairing = false;
@@ -72,6 +73,7 @@ char bt_devname[11];
     }
 
     void bt_start() {
+      display_unblank();
       if (bt_state == BT_STATE_OFF) {
         SerialBT.begin(bt_devname);
         bt_state = BT_STATE_ON;
@@ -79,6 +81,7 @@ char bt_devname[11];
     }
 
     void bt_enable_pairing() {
+      display_unblank();
       if (bt_state == BT_STATE_OFF) bt_start();
       bt_allow_pairing = true;
       bt_pairing_started = millis();
@@ -86,12 +89,14 @@ char bt_devname[11];
     }
 
     void bt_disable_pairing() {
+      display_unblank();
       bt_allow_pairing = false;
       bt_ssp_pin = 0;
       bt_state = BT_STATE_ON;
     }
 
     void bt_pairing_complete(boolean success) {
+      display_unblank();
       if (success) {
         bt_disable_pairing();
       } else {
@@ -99,7 +104,8 @@ char bt_devname[11];
       }
     }
 
-    void bt_connection_callback(esp_spp_cb_event_t event, esp_spp_cb_param_t *param){
+    void bt_connection_callback(esp_spp_cb_event_t event, esp_spp_cb_param_t *param) {
+      display_unblank();
       if(event == ESP_SPP_SRV_OPEN_EVT) {
         bt_state = BT_STATE_CONNECTED;
         cable_state = CABLE_STATE_DISCONNECTED;
@@ -163,6 +169,7 @@ char bt_devname[11];
 
   #elif HAS_BLE == true
     void bt_stop() {
+      display_unblank();
       if (bt_state != BT_STATE_OFF) {
         bt_allow_pairing = false;
         bt_state = BT_STATE_OFF;
@@ -170,17 +177,20 @@ char bt_devname[11];
     }
 
     void bt_disable_pairing() {
+      display_unblank();
       bt_allow_pairing = false;
       bt_ssp_pin = 0;
       bt_state = BT_STATE_ON;
     }
 
     void bt_connect_callback(uint16_t conn_handle) {
+      display_unblank();
       bt_state = BT_STATE_CONNECTED;
       cable_state = CABLE_STATE_DISCONNECTED;
     }
 
     void bt_disconnect_callback(uint16_t conn_handle, uint8_t reason) {
+      display_unblank();
       bt_state = BT_STATE_ON;
     }
 
@@ -217,6 +227,7 @@ char bt_devname[11];
     }
 
     void bt_start() {
+      display_unblank();
       if (bt_state == BT_STATE_OFF) {
         bt_state = BT_STATE_ON;
         // TODO: Implement
@@ -234,6 +245,7 @@ char bt_devname[11];
     }
 
     void bt_enable_pairing() {
+      display_unblank();
       if (bt_state == BT_STATE_OFF) bt_start();
       bt_allow_pairing = true;
       bt_pairing_started = millis();
index 56e2d5192345fedc0e314dbdd7922388e66e57f5..d92f134cfe351b3a3f3ca3553d2b73689b968965 100644 (file)
--- a/Config.h
+++ b/Config.h
     uint8_t battery_state = 0x00;
     uint8_t display_intensity = 0xFF;
     uint8_t display_addr = 0xFF;
+    bool display_blanking_enabled = false;
     bool display_diagnostics = true;    
     bool device_init_done = false;
     bool eeprom_ok = false;
index 7622635e37be9b0202ed4c982689d55e278384c6..82e6264cd3a8ad65eeb4c5eacea890eae4533c32 100644 (file)
--- a/Display.h
+++ b/Display.h
@@ -59,10 +59,14 @@ Adafruit_SSD1306 display(DISP_W, DISP_H, &Wire, DISP_RST);
 #define DISP_MODE_LANDSCAPE 0x01
 #define DISP_MODE_PORTRAIT  0x02
 #define DISP_PIN_SIZE   6
+#define DISPLAY_BLANKING_TIMEOUT 15*1000
 uint8_t disp_mode = DISP_MODE_UNKNOWN;
 uint8_t disp_ext_fb = false;
 unsigned char fb[512];
 uint32_t last_disp_update = 0;
+uint32_t last_unblank_event = 0;
+uint32_t display_blanking_timeout = DISPLAY_BLANKING_TIMEOUT;
+uint8_t display_unblank_intensity = display_intensity;
 uint8_t disp_target_fps = 7;
 int disp_update_interval = 1000/disp_target_fps;
 uint32_t last_page_flip = 0;
@@ -144,6 +148,17 @@ bool display_init() {
       uint8_t display_address = DISP_ADDR;
     #endif
 
+    #if HAS_EEPROM
+      if (EEPROM.read(eeprom_addr(ADDR_CONF_BSET)) == CONF_OK_BYTE) {
+        uint8_t db_timeout = EEPROM.read(eeprom_addr(ADDR_CONF_DBLK));
+        if (db_timeout == 0x00) {
+          display_blanking_enabled = false;
+        } else {
+          display_blanking_enabled = true;
+          display_blanking_timeout = db_timeout*1000;
+        }
+      }
+    #endif
     
     if(!display.begin(SSD1306_SWITCHCAPVCC, display_address)) {
       return false;
@@ -567,13 +582,29 @@ void update_disp_area() {
 }
 
 void update_display(bool blank = false) {
+  if (display_blanking_enabled && millis()-last_unblank_event >= display_blanking_timeout) {
+    blank = true;
+    if (display_intensity != 0) {
+      display_unblank_intensity = display_intensity;
+    }
+    display_intensity = 0;
+  } else {
+    if (display_unblank_intensity != 0x00) {
+      display_intensity = display_unblank_intensity;
+      display_unblank_intensity = 0x00;
+    }
+  }
+
   if (blank) {
-    if (display_contrast != display_intensity) {
-      display_contrast = display_intensity;
-      set_contrast(&display, display_contrast);
+    if (millis()-last_disp_update >= disp_update_interval) {
+      if (display_contrast != display_intensity) {
+        display_contrast = display_intensity;
+        set_contrast(&display, display_contrast);
+      }
+      display.clearDisplay();
+      display.display();
+      last_disp_update = millis();
     }
-    display.clearDisplay();
-    display.display();    
   } else {
     if (millis()-last_disp_update >= disp_update_interval) {
       if (display_contrast != display_intensity) {
@@ -589,6 +620,10 @@ void update_display(bool blank = false) {
   }
 }
 
+void display_unblank() {
+  last_unblank_event = millis();
+}
+
 void ext_fb_enable() {
   disp_ext_fb = true;
 }
index 16d1eee81b814fe3136f1b7d179f339225ebd8f1..f6c297a61d1105c2955e30de3e6a51c3f270419b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -175,8 +175,8 @@ upload-rnode_ng_21:
        arduino-cli upload -p /dev/ttyACM0 --fqbn esp32:esp32:ttgo-lora32
        @sleep 1
        rnodeconf /dev/ttyACM0 --firmware-hash $$(./partition_hashes ./build/esp32.esp32.ttgo-lora32/RNode_Firmware.ino.bin)
-       @sleep 3
-       python ./Release/esptool/esptool.py --chip esp32 --port /dev/ttyACM0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x210000 ./Release/console_image.bin
+       #@sleep 3
+       #python ./Release/esptool/esptool.py --chip esp32 --port /dev/ttyACM0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x210000 ./Release/console_image.bin
 
 upload-t3s3:
        @echo
index eac60f374583ca9213500658f44e40d99a067064..b085644d720fff4818b7ce5be874decf07634433 100644 (file)
@@ -170,6 +170,7 @@ void setup() {
       eeprom_update(eeprom_addr(ADDR_CONF_DSET), CONF_OK_BYTE);
       eeprom_update(eeprom_addr(ADDR_CONF_DINT), 0xFF);
     }
+    display_unblank();
     disp_ready = display_init();
     update_display();
   #endif
@@ -421,6 +422,7 @@ void flushQueue(void) {
   if (!queue_flushing) {
     queue_flushing = true;
 
+    display_unblank();
     led_tx_on();
     uint16_t processed = 0;
 
@@ -581,6 +583,7 @@ void serialCallback(uint8_t sbyte) {
             fifo16_push(&packet_lengths, l);
 
             current_packet_start = queue_cursor;
+            display_unblank();
         }
 
     }
@@ -594,7 +597,10 @@ void serialCallback(uint8_t sbyte) {
     if (frame_len == 0 && command == CMD_UNKNOWN) {
         command = sbyte;
     } else if (command == CMD_DATA) {
-        if (bt_state != BT_STATE_CONNECTED) cable_state = CABLE_STATE_CONNECTED;
+        if (bt_state != BT_STATE_CONNECTED) {
+          cable_state = CABLE_STATE_CONNECTED;
+          display_unblank();
+        }
         if (sbyte == FESC) {
             ESCAPE = true;
         } else {
@@ -699,6 +705,7 @@ void serialCallback(uint8_t sbyte) {
       kiss_indicate_implicit_length();
     } else if (command == CMD_LEAVE) {
       if (sbyte == 0xFF) {
+        display_unblank();
         cable_state   = CABLE_STATE_DISCONNECTED;
         current_rssi  = -292;
         last_rssi     = -292;
@@ -706,7 +713,10 @@ void serialCallback(uint8_t sbyte) {
         last_snr_raw  = 0x80;
       }
     } else if (command == CMD_RADIO_STATE) {
-      if (bt_state != BT_STATE_CONNECTED) cable_state = CABLE_STATE_CONNECTED;
+      if (bt_state != BT_STATE_CONNECTED) {
+        cable_state = CABLE_STATE_CONNECTED;
+        display_unblank();
+      }
       if (sbyte == 0xFF) {
         kiss_indicate_radiostate();
       } else if (sbyte == 0x00) {
@@ -949,6 +959,7 @@ void serialCallback(uint8_t sbyte) {
             }
             display_intensity = sbyte;
             di_conf_save(display_intensity);
+            display_unblank();
         }
 
       #endif
@@ -977,11 +988,8 @@ void serialCallback(uint8_t sbyte) {
                 if (sbyte == TFESC) sbyte = FESC;
                 ESCAPE = false;
             }
-            if (sbyte == 0x00) {
-              db_conf_save(0x00);
-            } else {
-              db_conf_save(0x01);
-            }
+            db_conf_save(sbyte);
+            display_unblank();
         }
 
       #endif
@@ -1364,6 +1372,7 @@ void sleep_now() {
 }
 
 void button_event(uint8_t event, unsigned long duration) {
+  display_unblank();
   if (duration > 6000) {
     bt_enable_pairing();
   } else if (duration > 4000) {
diff --git a/ROM.h b/ROM.h
index 4b0eb2e1ebde15c8207ea501a1228b1e93200969..b67f94aba487b505a210bc713f3f5ee22386819d 100644 (file)
--- a/ROM.h
+++ b/ROM.h
@@ -74,6 +74,7 @@
        #define ADDR_CONF_DSET 0xB1
        #define ADDR_CONF_DINT 0xB2
        #define ADDR_CONF_DADR 0xB3
+       #define ADDR_CONF_BSET 0xB7
        #define ADDR_CONF_DBLK 0xB4
        #define ADDR_CONF_PSET 0xB5
        #define ADDR_CONF_PINT 0xB6
index 7c9cbccc81064a38c2b585567eaa7fdd48111ae2..634dcb47174e96fc997493b049b39802c84bc00c 100644 (file)
@@ -1439,6 +1439,13 @@ void da_conf_save(uint8_t dadr) {
 }
 
 void db_conf_save(uint8_t val) {
+       if (val == 0x00) {
+               display_blanking_enabled = false;
+       } else {
+               display_blanking_enabled = true;
+               display_blanking_timeout = val*1000;
+       }
+       eeprom_update(eeprom_addr(ADDR_CONF_BSET), CONF_OK_BYTE);
        eeprom_update(eeprom_addr(ADDR_CONF_DBLK), val);
 }