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);
#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 HAS_EEPROM
uint8_t display_address = EEPROM.read(eeprom_addr(ADDR_CONF_DADR));
@ -236,6 +243,14 @@ bool display_init() {
return false;
} else {
set_contrast(&display, display_contrast);
if (display_rotation != 0xFF) {
if (display_rotation == 0 || display_rotation == 2) {
disp_mode = DISP_MODE_LANDSCAPE;
} else {
disp_mode = DISP_MODE_PORTRAIT;
}
display.setRotation(display_rotation);
} else {
#if BOARD_MODEL == BOARD_RNODE_NG_20
disp_mode = DISP_MODE_PORTRAIT;
display.setRotation(3);
@ -273,6 +288,7 @@ bool display_init() {
disp_mode = DISP_MODE_PORTRAIT;
display.setRotation(3);
#endif
}
update_area_positions();
for (int i = 0; i < WATERFALL_SIZE; i++) {

View File

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

View File

@ -1099,6 +1099,21 @@ void serialCallback(uint8_t sbyte) {
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
} else if (command == CMD_NP_INT) {
#if HAS_NP

1
ROM.h
View File

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

View File

@ -1507,6 +1507,16 @@ void db_conf_save(uint8_t val) {
#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) {
eeprom_update(eeprom_addr(ADDR_CONF_PSET), CONF_OK_BYTE);
eeprom_update(eeprom_addr(ADDR_CONF_PINT), p_int);