Added ability to configure display rotation

This commit is contained in:
Mark Qvist 2024-12-31 13:23:48 +01:00
parent 786c9990fb
commit 2604b44d64
5 changed files with 80 additions and 37 deletions

View File

@ -201,6 +201,13 @@ bool display_init() {
Wire.begin(SDA_OLED, SCL_OLED); Wire.begin(SDA_OLED, SCL_OLED);
#endif #endif
#if HAS_EEPROM
uint8_t display_rotation = EEPROM.read(eeprom_addr(ADDR_CONF_DROT));
#elif MCU_VARIANT == MCU_NRF52
uint8_t display_rotation = eeprom_read(eeprom_addr(ADDR_CONF_DROT));
#endif
if (display_rotation < 0 or display_rotation > 3) display_rotation = 0xFF;
#if DISP_CUSTOM_ADDR == true #if DISP_CUSTOM_ADDR == true
#if HAS_EEPROM #if HAS_EEPROM
uint8_t display_address = EEPROM.read(eeprom_addr(ADDR_CONF_DADR)); uint8_t display_address = EEPROM.read(eeprom_addr(ADDR_CONF_DADR));
@ -236,43 +243,52 @@ bool display_init() {
return false; return false;
} else { } else {
set_contrast(&display, display_contrast); set_contrast(&display, display_contrast);
#if BOARD_MODEL == BOARD_RNODE_NG_20 if (display_rotation != 0xFF) {
disp_mode = DISP_MODE_PORTRAIT; if (display_rotation == 0 || display_rotation == 2) {
display.setRotation(3); disp_mode = DISP_MODE_LANDSCAPE;
#elif BOARD_MODEL == BOARD_RNODE_NG_21 } else {
disp_mode = DISP_MODE_PORTRAIT; disp_mode = DISP_MODE_PORTRAIT;
display.setRotation(3); }
#elif BOARD_MODEL == BOARD_LORA32_V1_0 display.setRotation(display_rotation);
disp_mode = DISP_MODE_PORTRAIT; } else {
display.setRotation(3); #if BOARD_MODEL == BOARD_RNODE_NG_20
#elif BOARD_MODEL == BOARD_LORA32_V2_0 disp_mode = DISP_MODE_PORTRAIT;
disp_mode = DISP_MODE_PORTRAIT; display.setRotation(3);
display.setRotation(3); #elif BOARD_MODEL == BOARD_RNODE_NG_21
#elif BOARD_MODEL == BOARD_LORA32_V2_1 disp_mode = DISP_MODE_PORTRAIT;
disp_mode = DISP_MODE_LANDSCAPE; display.setRotation(3);
display.setRotation(0); #elif BOARD_MODEL == BOARD_LORA32_V1_0
#elif BOARD_MODEL == BOARD_TBEAM disp_mode = DISP_MODE_PORTRAIT;
disp_mode = DISP_MODE_LANDSCAPE; display.setRotation(3);
display.setRotation(0); #elif BOARD_MODEL == BOARD_LORA32_V2_0
#elif BOARD_MODEL == BOARD_TBEAM_S_V1 disp_mode = DISP_MODE_PORTRAIT;
disp_mode = DISP_MODE_PORTRAIT; display.setRotation(3);
display.setRotation(1); #elif BOARD_MODEL == BOARD_LORA32_V2_1
#elif BOARD_MODEL == BOARD_HELTEC32_V2 disp_mode = DISP_MODE_LANDSCAPE;
disp_mode = DISP_MODE_PORTRAIT; display.setRotation(0);
display.setRotation(1); #elif BOARD_MODEL == BOARD_TBEAM
#elif BOARD_MODEL == BOARD_HELTEC32_V3 disp_mode = DISP_MODE_LANDSCAPE;
disp_mode = DISP_MODE_PORTRAIT; display.setRotation(0);
display.setRotation(1); #elif BOARD_MODEL == BOARD_TBEAM_S_V1
#elif BOARD_MODEL == BOARD_RAK4631 disp_mode = DISP_MODE_PORTRAIT;
disp_mode = DISP_MODE_LANDSCAPE; display.setRotation(1);
display.setRotation(0); #elif BOARD_MODEL == BOARD_HELTEC32_V2
#elif BOARD_MODEL == BOARD_TDECK disp_mode = DISP_MODE_PORTRAIT;
disp_mode = DISP_MODE_PORTRAIT; display.setRotation(1);
display.setRotation(3); #elif BOARD_MODEL == BOARD_HELTEC32_V3
#else disp_mode = DISP_MODE_PORTRAIT;
disp_mode = DISP_MODE_PORTRAIT; display.setRotation(1);
display.setRotation(3); #elif BOARD_MODEL == BOARD_RAK4631
#endif disp_mode = DISP_MODE_LANDSCAPE;
display.setRotation(0);
#elif BOARD_MODEL == BOARD_TDECK
disp_mode = DISP_MODE_PORTRAIT;
display.setRotation(3);
#else
disp_mode = DISP_MODE_PORTRAIT;
display.setRotation(3);
#endif
}
update_area_positions(); update_area_positions();
for (int i = 0; i < WATERFALL_SIZE; i++) { for (int i = 0; i < WATERFALL_SIZE; i++) {

View File

@ -56,6 +56,7 @@
#define CMD_DISP_INT 0x45 #define CMD_DISP_INT 0x45
#define CMD_DISP_ADDR 0x63 #define CMD_DISP_ADDR 0x63
#define CMD_DISP_BLNK 0x64 #define CMD_DISP_BLNK 0x64
#define CMD_DISP_ROT 0x67
#define CMD_NP_INT 0x65 #define CMD_NP_INT 0x65
#define CMD_BT_CTRL 0x46 #define CMD_BT_CTRL 0x46
#define CMD_BT_PIN 0x62 #define CMD_BT_PIN 0x62

View File

@ -1099,6 +1099,21 @@ void serialCallback(uint8_t sbyte) {
display_unblank(); display_unblank();
} }
#endif
} else if (command == CMD_DISP_ROT) {
#if HAS_DISPLAY
if (sbyte == FESC) {
ESCAPE = true;
} else {
if (ESCAPE) {
if (sbyte == TFEND) sbyte = FEND;
if (sbyte == TFESC) sbyte = FESC;
ESCAPE = false;
}
drot_conf_save(sbyte);
display_unblank();
}
#endif #endif
} else if (command == CMD_NP_INT) { } else if (command == CMD_NP_INT) {
#if HAS_NP #if HAS_NP

1
ROM.h
View File

@ -39,6 +39,7 @@
#define ADDR_CONF_DINT 0xB2 #define ADDR_CONF_DINT 0xB2
#define ADDR_CONF_DADR 0xB3 #define ADDR_CONF_DADR 0xB3
#define ADDR_CONF_DBLK 0xB4 #define ADDR_CONF_DBLK 0xB4
#define ADDR_CONF_DROT 0xB8
#define ADDR_CONF_PSET 0xB5 #define ADDR_CONF_PSET 0xB5
#define ADDR_CONF_PINT 0xB6 #define ADDR_CONF_PINT 0xB6
#define ADDR_CONF_BSET 0xB7 #define ADDR_CONF_BSET 0xB7

View File

@ -1507,6 +1507,16 @@ void db_conf_save(uint8_t val) {
#endif #endif
} }
void drot_conf_save(uint8_t val) {
#if HAS_DISPLAY
if (val >= 0x00 and val <= 0x03) {
eeprom_update(eeprom_addr(ADDR_CONF_BSET), CONF_OK_BYTE);
eeprom_update(eeprom_addr(ADDR_CONF_DROT), val);
hard_reset();
}
#endif
}
void np_int_conf_save(uint8_t p_int) { void np_int_conf_save(uint8_t p_int) {
eeprom_update(eeprom_addr(ADDR_CONF_PSET), CONF_OK_BYTE); eeprom_update(eeprom_addr(ADDR_CONF_PSET), CONF_OK_BYTE);
eeprom_update(eeprom_addr(ADDR_CONF_PINT), p_int); eeprom_update(eeprom_addr(ADDR_CONF_PINT), p_int);