]> git.tnoah.ca Git - lora-radio.git/commitdiff
Added ability to set custom display address
authorMark Qvist <mark@unsigned.io>
Tue, 19 Sep 2023 16:32:29 +0000 (18:32 +0200)
committerMark Qvist <mark@unsigned.io>
Tue, 19 Sep 2023 16:32:29 +0000 (18:32 +0200)
Config.h
Display.h
Framing.h
RNode_Firmware.ino
ROM.h
Utilities.h

index aef43a205ff1ca05864a293ef89faa3d2b4a736d..dd3c8b3dbbb8bd10b61688d6346c46d9256c60ab 100644 (file)
--- a/Config.h
+++ b/Config.h
     float battery_percent = 0.0;
     uint8_t battery_state = 0x00;
     uint8_t display_intensity = 0xFF;
+    uint8_t display_addr = 0xFF;
     bool display_diagnostics = true;    
     bool device_init_done = false;
     bool eeprom_ok = false;
index 99989737cf29badc993ee00ef1a21b585153b74c..51bff3f377e8c68e67d881370297cb141d68597c 100644 (file)
--- a/Display.h
+++ b/Display.h
   #define DISP_ADDR 0x3C
 #elif BOARD_MODEL == BOARD_TBEAM
   #define DISP_RST 13
-  #define DISP_ADDR 0x3D
-  // #define DISP_ADDR 0x3C
+  #define DISP_ADDR 0x3C
+  #define DISP_CUSTOM_ADDR true
 #elif BOARD_MODEL == BOARD_HELTEC32_V2 || BOARD_MODEL == BOARD_LORA32_V1_0
   #define DISP_RST 16
   #define DISP_ADDR 0x3C
   #define SCL_OLED 15
   #define SDA_OLED 4
+#elif BOARD_MODEL == BOARD_RNODE_NG_21
+  #define DISP_RST -1
+  #define DISP_ADDR 0x3C
 #else
   #define DISP_RST -1
   #define DISP_ADDR 0x3C
+  #define DISP_CUSTOM_ADDR true
 #endif
 
 #define SMALL_FONT &Org_01
@@ -104,8 +108,16 @@ bool display_init() {
       digitalWrite(pin_display_en, HIGH);
       Wire.begin(SDA_OLED, SCL_OLED);
     #endif
+
+    #if DISP_CUSTOM_ADDR == true
+      uint8_t display_address = EEPROM.read(eeprom_addr(ADDR_CONF_DADR));
+      if (display_address == 0xFF) display_address = DISP_ADDR;
+    #else
+      uint8_t display_address = DISP_ADDR;
+    #endif
+
     
-    if(!display.begin(SSD1306_SWITCHCAPVCC, DISP_ADDR)) {
+    if(!display.begin(SSD1306_SWITCHCAPVCC, display_address)) {
       return false;
     } else {
       set_contrast(&display, display_contrast);
index 97dce7cb6a23e619e48f8e5997465ed6fef977c3..d95bf9308eca4f0df77d8ccf03b183c5960c86ec 100644 (file)
--- a/Framing.h
+++ b/Framing.h
@@ -52,6 +52,7 @@
   #define CMD_FB_WRITE    0x43
   #define CMD_FB_READL    0x44
   #define CMD_DISP_INT    0x45
+  #define CMD_DISP_ADDR   0x63
   #define CMD_BT_CTRL     0x46
   #define CMD_BT_PIN      0x62
 
index e5852ea30116049a2dbe881e7ef721e02958a986..953948c5bd208ffd68297d5947fc579f89da3a5d 100644 (file)
@@ -898,6 +898,21 @@ void serialCallback(uint8_t sbyte) {
             di_conf_save(display_intensity);
         }
 
+      #endif
+    } else if (command == CMD_DISP_ADDR) {
+      #if HAS_DISPLAY
+        if (sbyte == FESC) {
+            ESCAPE = true;
+        } else {
+            if (ESCAPE) {
+                if (sbyte == TFEND) sbyte = FEND;
+                if (sbyte == TFESC) sbyte = FESC;
+                ESCAPE = false;
+            }
+            display_addr = sbyte;
+            da_conf_save(display_addr);
+        }
+
       #endif
     }
   }
diff --git a/ROM.h b/ROM.h
index 91559101570e8a7e5e01176d901468fd24e29064..05c89dc40c1d928916b122ad2299a2f96223d442 100644 (file)
--- a/ROM.h
+++ b/ROM.h
@@ -63,6 +63,7 @@
        #define ADDR_CONF_BT   0xB0
        #define ADDR_CONF_DSET 0xB1
        #define ADDR_CONF_DINT 0xB2
+       #define ADDR_CONF_DADR 0xB3
 
        #define INFO_LOCK_BYTE 0x73
        #define CONF_OK_BYTE   0x73
index 97697b298b00176ce5a5716ccd6a2a88a448b505..0c7f741fd921fed7da36a0aa45a1a1428dbe4d50 100644 (file)
@@ -1212,6 +1212,10 @@ void di_conf_save(uint8_t dint) {
        eeprom_update(eeprom_addr(ADDR_CONF_DINT), dint);
 }
 
+void da_conf_save(uint8_t dadr) {
+       eeprom_update(eeprom_addr(ADDR_CONF_DADR), dadr);
+}
+
 bool eeprom_have_conf() {
        if (EEPROM.read(eeprom_addr(ADDR_CONF_OK)) == CONF_OK_BYTE) {
                return true;