diff --git a/Bluetooth.h b/Bluetooth.h index 38951f7..32cc8a6 100644 --- a/Bluetooth.h +++ b/Bluetooth.h @@ -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(); diff --git a/Config.h b/Config.h index 56e2d51..d92f134 100644 --- a/Config.h +++ b/Config.h @@ -181,6 +181,7 @@ 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; diff --git a/Display.h b/Display.h index 7622635..82e6264 100644 --- 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 (blank) { - if (display_contrast != display_intensity) { - display_contrast = display_intensity; - set_contrast(&display, display_contrast); + 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 (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; } diff --git a/Makefile b/Makefile index 16d1eee..f6c297a 100644 --- 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 diff --git a/RNode_Firmware.ino b/RNode_Firmware.ino index eac60f3..b085644 100644 --- a/RNode_Firmware.ino +++ b/RNode_Firmware.ino @@ -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 4b0eb2e..b67f94a 100644 --- 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 diff --git a/Utilities.h b/Utilities.h index 7c9cbcc..634dcb4 100644 --- a/Utilities.h +++ b/Utilities.h @@ -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); }