]> git.tnoah.ca Git - lora-radio.git/commitdiff
Added NeoPixel intensity control
authorMark Qvist <mark@unsigned.io>
Fri, 27 Sep 2024 18:08:05 +0000 (20:08 +0200)
committerMark Qvist <mark@unsigned.io>
Fri, 27 Sep 2024 18:08:05 +0000 (20:08 +0200)
Framing.h
RNode_Firmware.ino
ROM.h
Utilities.h

index 0236aa96fb9e26ede8f4c31a1aa83302bd0debc9..2b588cc2857cabaf12c2b9c682d08a6d226d4bb7 100644 (file)
--- a/Framing.h
+++ b/Framing.h
@@ -54,6 +54,8 @@
   #define CMD_FB_READL    0x44
   #define CMD_DISP_INT    0x45
   #define CMD_DISP_ADDR   0x63
+  #define CMD_DISP_BLNK   0x64
+  #define CMD_NP_INT      0x65
   #define CMD_BT_CTRL     0x46
   #define CMD_BT_PIN      0x62
 
index ab1b2e0824833775b3391f821858dcb35bc0fc4e..f9f2af6fb69a89778d9905b11fce961d01bfce59 100644 (file)
@@ -78,6 +78,10 @@ void setup() {
 
   Serial.begin(serial_baudrate);
 
+  #if HAS_NP
+    led_init();
+  #endif
+
   #if BOARD_MODEL != BOARD_RAK4631 && BOARD_MODEL != BOARD_RNODE_NG_22
   // Some boards need to wait until the hardware UART is set up before booting
   // the full firmware. In the case of the RAK4631, the line below will wait
@@ -962,6 +966,40 @@ void serialCallback(uint8_t sbyte) {
             da_conf_save(display_addr);
         }
 
+      #endif
+    } else if (command == CMD_DISP_BLNK) {
+      #if HAS_NP
+        if (sbyte == FESC) {
+            ESCAPE = true;
+        } else {
+            if (ESCAPE) {
+                if (sbyte == TFEND) sbyte = FEND;
+                if (sbyte == TFESC) sbyte = FESC;
+                ESCAPE = false;
+            }
+            if (sbyte == 0x00) {
+              db_conf_save(0x00);
+            } else {
+              db_conf_save(0x01);
+            }
+        }
+
+      #endif
+    } else if (command == CMD_NP_INT) {
+      #if HAS_NP
+        if (sbyte == FESC) {
+            ESCAPE = true;
+        } else {
+            if (ESCAPE) {
+                if (sbyte == TFEND) sbyte = FEND;
+                if (sbyte == TFESC) sbyte = FESC;
+                ESCAPE = false;
+            }
+            npi = sbyte;
+            led_set_intensity(npi);
+            np_int_conf_save(npi);
+        }
+
       #endif
     }
   }
diff --git a/ROM.h b/ROM.h
index 7a343c071415ba06edf93e046ff48a2afd5592dc..4b0eb2e1ebde15c8207ea501a1228b1e93200969 100644 (file)
--- a/ROM.h
+++ b/ROM.h
@@ -74,6 +74,9 @@
        #define ADDR_CONF_DSET 0xB1
        #define ADDR_CONF_DINT 0xB2
        #define ADDR_CONF_DADR 0xB3
+       #define ADDR_CONF_DBLK 0xB4
+       #define ADDR_CONF_PSET 0xB5
+       #define ADDR_CONF_PINT 0xB6
 
        #define INFO_LOCK_BYTE 0x73
        #define CONF_OK_BYTE   0x73
index c70568b7030781e3f533a28cb75ede425eb52599..07d63f235e6425f80ce0ae9b0f9fa78210fc50b3 100644 (file)
@@ -109,7 +109,19 @@ uint8_t boot_vector = 0x00;
        uint8_t npr = 0;
   uint8_t npg = 0;
   uint8_t npb = 0;
+  float npi = NP_M;
   bool pixels_started = false;
+
+  void led_set_intensity(uint8_t intensity) {
+       npi = (float)intensity/255.0;
+  }
+
+  void led_init() {
+       if (EEPROM.read(eeprom_addr(ADDR_CONF_PSET)) != 0xFF) {
+               led_set_intensity(EEPROM.read(eeprom_addr(ADDR_CONF_PINT)));
+       }
+  }
+
   void npset(uint8_t r, uint8_t g, uint8_t b) {
        if (pixels_started != true) {
                pixels.begin();
@@ -118,7 +130,7 @@ uint8_t boot_vector = 0x00;
 
        if (r != npr || g != npg || b != npb) {
                npr = r; npg = g; npb = b;
-               pixels.setPixelColor(0, pixels.Color(npr*NP_M, npg*NP_M, npb*NP_M));
+               pixels.setPixelColor(0, pixels.Color(npr*npi, npg*npi, npb*npi));
                pixels.show();
        }
   }
@@ -1425,6 +1437,16 @@ void da_conf_save(uint8_t dadr) {
        eeprom_update(eeprom_addr(ADDR_CONF_DADR), dadr);
 }
 
+void db_conf_save(uint8_t val) {
+       eeprom_update(eeprom_addr(ADDR_CONF_DBLK), val);
+}
+
+void np_int_conf_save(uint8_t p_int) {
+       eeprom_update(eeprom_addr(ADDR_CONF_PSET), 0x01);
+       eeprom_update(eeprom_addr(ADDR_CONF_PINT), p_int);
+}
+
+
 bool eeprom_have_conf() {
     #if HAS_EEPROM
            if (EEPROM.read(eeprom_addr(ADDR_CONF_OK)) == CONF_OK_BYTE) {