mirror of
https://github.com/markqvist/RNode_Firmware.git
synced 2024-10-01 03:15:39 -04:00
Added display blanking timeout
This commit is contained in:
parent
97806d1684
commit
a4ecc0d6f3
14
Bluetooth.h
14
Bluetooth.h
@ -64,6 +64,7 @@ char bt_devname[11];
|
|||||||
}
|
}
|
||||||
|
|
||||||
void bt_stop() {
|
void bt_stop() {
|
||||||
|
display_unblank();
|
||||||
if (bt_state != BT_STATE_OFF) {
|
if (bt_state != BT_STATE_OFF) {
|
||||||
SerialBT.end();
|
SerialBT.end();
|
||||||
bt_allow_pairing = false;
|
bt_allow_pairing = false;
|
||||||
@ -72,6 +73,7 @@ char bt_devname[11];
|
|||||||
}
|
}
|
||||||
|
|
||||||
void bt_start() {
|
void bt_start() {
|
||||||
|
display_unblank();
|
||||||
if (bt_state == BT_STATE_OFF) {
|
if (bt_state == BT_STATE_OFF) {
|
||||||
SerialBT.begin(bt_devname);
|
SerialBT.begin(bt_devname);
|
||||||
bt_state = BT_STATE_ON;
|
bt_state = BT_STATE_ON;
|
||||||
@ -79,6 +81,7 @@ char bt_devname[11];
|
|||||||
}
|
}
|
||||||
|
|
||||||
void bt_enable_pairing() {
|
void bt_enable_pairing() {
|
||||||
|
display_unblank();
|
||||||
if (bt_state == BT_STATE_OFF) bt_start();
|
if (bt_state == BT_STATE_OFF) bt_start();
|
||||||
bt_allow_pairing = true;
|
bt_allow_pairing = true;
|
||||||
bt_pairing_started = millis();
|
bt_pairing_started = millis();
|
||||||
@ -86,12 +89,14 @@ char bt_devname[11];
|
|||||||
}
|
}
|
||||||
|
|
||||||
void bt_disable_pairing() {
|
void bt_disable_pairing() {
|
||||||
|
display_unblank();
|
||||||
bt_allow_pairing = false;
|
bt_allow_pairing = false;
|
||||||
bt_ssp_pin = 0;
|
bt_ssp_pin = 0;
|
||||||
bt_state = BT_STATE_ON;
|
bt_state = BT_STATE_ON;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bt_pairing_complete(boolean success) {
|
void bt_pairing_complete(boolean success) {
|
||||||
|
display_unblank();
|
||||||
if (success) {
|
if (success) {
|
||||||
bt_disable_pairing();
|
bt_disable_pairing();
|
||||||
} else {
|
} 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) {
|
if(event == ESP_SPP_SRV_OPEN_EVT) {
|
||||||
bt_state = BT_STATE_CONNECTED;
|
bt_state = BT_STATE_CONNECTED;
|
||||||
cable_state = CABLE_STATE_DISCONNECTED;
|
cable_state = CABLE_STATE_DISCONNECTED;
|
||||||
@ -163,6 +169,7 @@ char bt_devname[11];
|
|||||||
|
|
||||||
#elif HAS_BLE == true
|
#elif HAS_BLE == true
|
||||||
void bt_stop() {
|
void bt_stop() {
|
||||||
|
display_unblank();
|
||||||
if (bt_state != BT_STATE_OFF) {
|
if (bt_state != BT_STATE_OFF) {
|
||||||
bt_allow_pairing = false;
|
bt_allow_pairing = false;
|
||||||
bt_state = BT_STATE_OFF;
|
bt_state = BT_STATE_OFF;
|
||||||
@ -170,17 +177,20 @@ char bt_devname[11];
|
|||||||
}
|
}
|
||||||
|
|
||||||
void bt_disable_pairing() {
|
void bt_disable_pairing() {
|
||||||
|
display_unblank();
|
||||||
bt_allow_pairing = false;
|
bt_allow_pairing = false;
|
||||||
bt_ssp_pin = 0;
|
bt_ssp_pin = 0;
|
||||||
bt_state = BT_STATE_ON;
|
bt_state = BT_STATE_ON;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bt_connect_callback(uint16_t conn_handle) {
|
void bt_connect_callback(uint16_t conn_handle) {
|
||||||
|
display_unblank();
|
||||||
bt_state = BT_STATE_CONNECTED;
|
bt_state = BT_STATE_CONNECTED;
|
||||||
cable_state = CABLE_STATE_DISCONNECTED;
|
cable_state = CABLE_STATE_DISCONNECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bt_disconnect_callback(uint16_t conn_handle, uint8_t reason) {
|
void bt_disconnect_callback(uint16_t conn_handle, uint8_t reason) {
|
||||||
|
display_unblank();
|
||||||
bt_state = BT_STATE_ON;
|
bt_state = BT_STATE_ON;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,6 +227,7 @@ char bt_devname[11];
|
|||||||
}
|
}
|
||||||
|
|
||||||
void bt_start() {
|
void bt_start() {
|
||||||
|
display_unblank();
|
||||||
if (bt_state == BT_STATE_OFF) {
|
if (bt_state == BT_STATE_OFF) {
|
||||||
bt_state = BT_STATE_ON;
|
bt_state = BT_STATE_ON;
|
||||||
// TODO: Implement
|
// TODO: Implement
|
||||||
@ -234,6 +245,7 @@ char bt_devname[11];
|
|||||||
}
|
}
|
||||||
|
|
||||||
void bt_enable_pairing() {
|
void bt_enable_pairing() {
|
||||||
|
display_unblank();
|
||||||
if (bt_state == BT_STATE_OFF) bt_start();
|
if (bt_state == BT_STATE_OFF) bt_start();
|
||||||
bt_allow_pairing = true;
|
bt_allow_pairing = true;
|
||||||
bt_pairing_started = millis();
|
bt_pairing_started = millis();
|
||||||
|
1
Config.h
1
Config.h
@ -181,6 +181,7 @@
|
|||||||
uint8_t battery_state = 0x00;
|
uint8_t battery_state = 0x00;
|
||||||
uint8_t display_intensity = 0xFF;
|
uint8_t display_intensity = 0xFF;
|
||||||
uint8_t display_addr = 0xFF;
|
uint8_t display_addr = 0xFF;
|
||||||
|
bool display_blanking_enabled = false;
|
||||||
bool display_diagnostics = true;
|
bool display_diagnostics = true;
|
||||||
bool device_init_done = false;
|
bool device_init_done = false;
|
||||||
bool eeprom_ok = false;
|
bool eeprom_ok = false;
|
||||||
|
47
Display.h
47
Display.h
@ -59,10 +59,14 @@ Adafruit_SSD1306 display(DISP_W, DISP_H, &Wire, DISP_RST);
|
|||||||
#define DISP_MODE_LANDSCAPE 0x01
|
#define DISP_MODE_LANDSCAPE 0x01
|
||||||
#define DISP_MODE_PORTRAIT 0x02
|
#define DISP_MODE_PORTRAIT 0x02
|
||||||
#define DISP_PIN_SIZE 6
|
#define DISP_PIN_SIZE 6
|
||||||
|
#define DISPLAY_BLANKING_TIMEOUT 15*1000
|
||||||
uint8_t disp_mode = DISP_MODE_UNKNOWN;
|
uint8_t disp_mode = DISP_MODE_UNKNOWN;
|
||||||
uint8_t disp_ext_fb = false;
|
uint8_t disp_ext_fb = false;
|
||||||
unsigned char fb[512];
|
unsigned char fb[512];
|
||||||
uint32_t last_disp_update = 0;
|
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;
|
uint8_t disp_target_fps = 7;
|
||||||
int disp_update_interval = 1000/disp_target_fps;
|
int disp_update_interval = 1000/disp_target_fps;
|
||||||
uint32_t last_page_flip = 0;
|
uint32_t last_page_flip = 0;
|
||||||
@ -144,6 +148,17 @@ bool display_init() {
|
|||||||
uint8_t display_address = DISP_ADDR;
|
uint8_t display_address = DISP_ADDR;
|
||||||
#endif
|
#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)) {
|
if(!display.begin(SSD1306_SWITCHCAPVCC, display_address)) {
|
||||||
return false;
|
return false;
|
||||||
@ -567,13 +582,29 @@ void update_disp_area() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void update_display(bool blank = false) {
|
void update_display(bool blank = false) {
|
||||||
if (blank) {
|
if (display_blanking_enabled && millis()-last_unblank_event >= display_blanking_timeout) {
|
||||||
if (display_contrast != display_intensity) {
|
blank = true;
|
||||||
display_contrast = display_intensity;
|
if (display_intensity != 0) {
|
||||||
set_contrast(&display, display_contrast);
|
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 {
|
} else {
|
||||||
if (millis()-last_disp_update >= disp_update_interval) {
|
if (millis()-last_disp_update >= disp_update_interval) {
|
||||||
if (display_contrast != display_intensity) {
|
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() {
|
void ext_fb_enable() {
|
||||||
disp_ext_fb = true;
|
disp_ext_fb = true;
|
||||||
}
|
}
|
||||||
|
4
Makefile
4
Makefile
@ -175,8 +175,8 @@ upload-rnode_ng_21:
|
|||||||
arduino-cli upload -p /dev/ttyACM0 --fqbn esp32:esp32:ttgo-lora32
|
arduino-cli upload -p /dev/ttyACM0 --fqbn esp32:esp32:ttgo-lora32
|
||||||
@sleep 1
|
@sleep 1
|
||||||
rnodeconf /dev/ttyACM0 --firmware-hash $$(./partition_hashes ./build/esp32.esp32.ttgo-lora32/RNode_Firmware.ino.bin)
|
rnodeconf /dev/ttyACM0 --firmware-hash $$(./partition_hashes ./build/esp32.esp32.ttgo-lora32/RNode_Firmware.ino.bin)
|
||||||
@sleep 3
|
#@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
|
#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:
|
upload-t3s3:
|
||||||
@echo
|
@echo
|
||||||
|
@ -170,6 +170,7 @@ void setup() {
|
|||||||
eeprom_update(eeprom_addr(ADDR_CONF_DSET), CONF_OK_BYTE);
|
eeprom_update(eeprom_addr(ADDR_CONF_DSET), CONF_OK_BYTE);
|
||||||
eeprom_update(eeprom_addr(ADDR_CONF_DINT), 0xFF);
|
eeprom_update(eeprom_addr(ADDR_CONF_DINT), 0xFF);
|
||||||
}
|
}
|
||||||
|
display_unblank();
|
||||||
disp_ready = display_init();
|
disp_ready = display_init();
|
||||||
update_display();
|
update_display();
|
||||||
#endif
|
#endif
|
||||||
@ -421,6 +422,7 @@ void flushQueue(void) {
|
|||||||
if (!queue_flushing) {
|
if (!queue_flushing) {
|
||||||
queue_flushing = true;
|
queue_flushing = true;
|
||||||
|
|
||||||
|
display_unblank();
|
||||||
led_tx_on();
|
led_tx_on();
|
||||||
uint16_t processed = 0;
|
uint16_t processed = 0;
|
||||||
|
|
||||||
@ -581,6 +583,7 @@ void serialCallback(uint8_t sbyte) {
|
|||||||
fifo16_push(&packet_lengths, l);
|
fifo16_push(&packet_lengths, l);
|
||||||
|
|
||||||
current_packet_start = queue_cursor;
|
current_packet_start = queue_cursor;
|
||||||
|
display_unblank();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -594,7 +597,10 @@ void serialCallback(uint8_t sbyte) {
|
|||||||
if (frame_len == 0 && command == CMD_UNKNOWN) {
|
if (frame_len == 0 && command == CMD_UNKNOWN) {
|
||||||
command = sbyte;
|
command = sbyte;
|
||||||
} else if (command == CMD_DATA) {
|
} 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) {
|
if (sbyte == FESC) {
|
||||||
ESCAPE = true;
|
ESCAPE = true;
|
||||||
} else {
|
} else {
|
||||||
@ -699,6 +705,7 @@ void serialCallback(uint8_t sbyte) {
|
|||||||
kiss_indicate_implicit_length();
|
kiss_indicate_implicit_length();
|
||||||
} else if (command == CMD_LEAVE) {
|
} else if (command == CMD_LEAVE) {
|
||||||
if (sbyte == 0xFF) {
|
if (sbyte == 0xFF) {
|
||||||
|
display_unblank();
|
||||||
cable_state = CABLE_STATE_DISCONNECTED;
|
cable_state = CABLE_STATE_DISCONNECTED;
|
||||||
current_rssi = -292;
|
current_rssi = -292;
|
||||||
last_rssi = -292;
|
last_rssi = -292;
|
||||||
@ -706,7 +713,10 @@ void serialCallback(uint8_t sbyte) {
|
|||||||
last_snr_raw = 0x80;
|
last_snr_raw = 0x80;
|
||||||
}
|
}
|
||||||
} else if (command == CMD_RADIO_STATE) {
|
} 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) {
|
if (sbyte == 0xFF) {
|
||||||
kiss_indicate_radiostate();
|
kiss_indicate_radiostate();
|
||||||
} else if (sbyte == 0x00) {
|
} else if (sbyte == 0x00) {
|
||||||
@ -949,6 +959,7 @@ void serialCallback(uint8_t sbyte) {
|
|||||||
}
|
}
|
||||||
display_intensity = sbyte;
|
display_intensity = sbyte;
|
||||||
di_conf_save(display_intensity);
|
di_conf_save(display_intensity);
|
||||||
|
display_unblank();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@ -977,11 +988,8 @@ void serialCallback(uint8_t sbyte) {
|
|||||||
if (sbyte == TFESC) sbyte = FESC;
|
if (sbyte == TFESC) sbyte = FESC;
|
||||||
ESCAPE = false;
|
ESCAPE = false;
|
||||||
}
|
}
|
||||||
if (sbyte == 0x00) {
|
db_conf_save(sbyte);
|
||||||
db_conf_save(0x00);
|
display_unblank();
|
||||||
} else {
|
|
||||||
db_conf_save(0x01);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@ -1364,6 +1372,7 @@ void sleep_now() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void button_event(uint8_t event, unsigned long duration) {
|
void button_event(uint8_t event, unsigned long duration) {
|
||||||
|
display_unblank();
|
||||||
if (duration > 6000) {
|
if (duration > 6000) {
|
||||||
bt_enable_pairing();
|
bt_enable_pairing();
|
||||||
} else if (duration > 4000) {
|
} else if (duration > 4000) {
|
||||||
|
1
ROM.h
1
ROM.h
@ -74,6 +74,7 @@
|
|||||||
#define ADDR_CONF_DSET 0xB1
|
#define ADDR_CONF_DSET 0xB1
|
||||||
#define ADDR_CONF_DINT 0xB2
|
#define ADDR_CONF_DINT 0xB2
|
||||||
#define ADDR_CONF_DADR 0xB3
|
#define ADDR_CONF_DADR 0xB3
|
||||||
|
#define ADDR_CONF_BSET 0xB7
|
||||||
#define ADDR_CONF_DBLK 0xB4
|
#define ADDR_CONF_DBLK 0xB4
|
||||||
#define ADDR_CONF_PSET 0xB5
|
#define ADDR_CONF_PSET 0xB5
|
||||||
#define ADDR_CONF_PINT 0xB6
|
#define ADDR_CONF_PINT 0xB6
|
||||||
|
@ -1439,6 +1439,13 @@ void da_conf_save(uint8_t dadr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void db_conf_save(uint8_t val) {
|
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);
|
eeprom_update(eeprom_addr(ADDR_CONF_DBLK), val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user