Added NeoPixel intensity control
This commit is contained in:
		@@ -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
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										3
									
								
								ROM.h
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								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
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										24
									
								
								Utilities.h
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								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) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user