From a134cbfb9c451f06c07c4afa46c4c8282777095c Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Fri, 27 Sep 2024 20:08:05 +0200 Subject: [PATCH] Added NeoPixel intensity control --- Framing.h | 2 ++ RNode_Firmware.ino | 38 ++++++++++++++++++++++++++++++++++++++ ROM.h | 3 +++ Utilities.h | 24 +++++++++++++++++++++++- 4 files changed, 66 insertions(+), 1 deletion(-) diff --git a/Framing.h b/Framing.h index 0236aa9..2b588cc 100644 --- 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 diff --git a/RNode_Firmware.ino b/RNode_Firmware.ino index ab1b2e0..f9f2af6 100644 --- a/RNode_Firmware.ino +++ b/RNode_Firmware.ino @@ -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 7a343c0..4b0eb2e 100644 --- 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 diff --git a/Utilities.h b/Utilities.h index c70568b..07d63f2 100644 --- a/Utilities.h +++ b/Utilities.h @@ -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) {