RGB LED indications for RNode NG
This commit is contained in:
		
							parent
							
								
									bc57f695e1
								
							
						
					
					
						commit
						8307b3c0d1
					
				
							
								
								
									
										24
									
								
								Config.h
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								Config.h
									
									
									
									
									
								
							@ -20,6 +20,8 @@
 | 
			
		||||
	#define BOARD_GENERIC_ESP32 0x35
 | 
			
		||||
	#define BOARD_LORA32_V2_0   0x36
 | 
			
		||||
	#define BOARD_LORA32_V2_1   0x37
 | 
			
		||||
	#define BOARD_RNODE_NG_20   0x40
 | 
			
		||||
	#define BOARD_RNODE_NG_21   0x41
 | 
			
		||||
 | 
			
		||||
	#define MODE_HOST 0x11
 | 
			
		||||
	#define MODE_TNC  0x12
 | 
			
		||||
@ -127,6 +129,28 @@
 | 
			
		||||
				const int pin_led_rx = 25;
 | 
			
		||||
				const int pin_led_tx = 25;
 | 
			
		||||
			#endif
 | 
			
		||||
		#elif BOARD_MODEL == BOARD_RNODE_NG_20
 | 
			
		||||
			const int pin_cs = 18;
 | 
			
		||||
			const int pin_reset = 12;
 | 
			
		||||
			const int pin_dio = 26;
 | 
			
		||||
			#if defined(EXTERNAL_LEDS)
 | 
			
		||||
				const int pin_led_rx = 2;
 | 
			
		||||
				const int pin_led_tx = 0;
 | 
			
		||||
			#else
 | 
			
		||||
				const int pin_led_rx = 22;
 | 
			
		||||
				const int pin_led_tx = 22;
 | 
			
		||||
			#endif
 | 
			
		||||
		#elif BOARD_MODEL == BOARD_RNODE_NG_21
 | 
			
		||||
			const int pin_cs = 18;
 | 
			
		||||
			const int pin_reset = 23;
 | 
			
		||||
			const int pin_dio = 26;
 | 
			
		||||
			#if defined(EXTERNAL_LEDS)
 | 
			
		||||
				const int pin_led_rx = 15;
 | 
			
		||||
				const int pin_led_tx = 4;
 | 
			
		||||
			#else
 | 
			
		||||
				const int pin_led_rx = 25;
 | 
			
		||||
				const int pin_led_tx = 25;
 | 
			
		||||
			#endif
 | 
			
		||||
		#else
 | 
			
		||||
			#error An unsupported board was selected. Cannot compile RNode firmware.
 | 
			
		||||
		#endif
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										6
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								Makefile
									
									
									
									
									
								
							@ -30,6 +30,9 @@ firmware-lora32_v20_extled:
 | 
			
		||||
firmware-lora32_v21_extled:
 | 
			
		||||
	arduino-cli compile --fqbn esp32:esp32:ttgo-lora32 --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x37\" \"-DEXTERNAL_LEDS=true\""
 | 
			
		||||
 | 
			
		||||
firmware-rnode_ng_20:
 | 
			
		||||
	arduino-cli compile --fqbn esp32:esp32:ttgo-lora32 --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x40\""
 | 
			
		||||
 | 
			
		||||
firmware-featheresp32:
 | 
			
		||||
	arduino-cli compile --fqbn esp32:esp32:featheresp32 --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x34\""
 | 
			
		||||
 | 
			
		||||
@ -53,6 +56,9 @@ upload-lora32_v20:
 | 
			
		||||
upload-lora32_v21:
 | 
			
		||||
	arduino-cli upload -p /dev/ttyACM0 --fqbn esp32:esp32:ttgo-lora32
 | 
			
		||||
 | 
			
		||||
upload-rnode_ng_20:
 | 
			
		||||
	arduino-cli upload -p /dev/ttyUSB0 --fqbn esp32:esp32:ttgo-lora32
 | 
			
		||||
 | 
			
		||||
upload-featheresp32:
 | 
			
		||||
	arduino-cli upload -p /dev/ttyUSB0 --fqbn esp32:esp32:featheresp32
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -24,6 +24,8 @@
 | 
			
		||||
#include <SPI.h>
 | 
			
		||||
#include "Utilities.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
FIFOBuffer serialFIFO;
 | 
			
		||||
uint8_t serialBuffer[CONFIG_UART_BUFFER_SIZE+1];
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										137
									
								
								Utilities.h
									
									
									
									
									
								
							
							
						
						
									
										137
									
								
								Utilities.h
									
									
									
									
									
								
							@ -30,6 +30,26 @@ uint8_t boot_vector = 0x00;
 | 
			
		||||
	// TODO: Get ESP32 boot flags
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if BOARD_MODEL == BOARD_RNODE_NG_20
 | 
			
		||||
	#include <Adafruit_NeoPixel.h>
 | 
			
		||||
	#define NP_PIN 4
 | 
			
		||||
	#define NUMPIXELS 1
 | 
			
		||||
	#define NP_M 0.15
 | 
			
		||||
	Adafruit_NeoPixel pixels(NUMPIXELS, NP_PIN, NEO_GRB + NEO_KHZ800);
 | 
			
		||||
 | 
			
		||||
	uint8_t npr = 0;
 | 
			
		||||
  uint8_t npg = 0;
 | 
			
		||||
  uint8_t npb = 0;
 | 
			
		||||
  void npset(uint8_t r, uint8_t g, uint8_t b) {
 | 
			
		||||
  	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, npg, npb));
 | 
			
		||||
  		pixels.show();
 | 
			
		||||
  	}
 | 
			
		||||
  }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if MCU_VARIANT == MCU_1284P || MCU_VARIANT == MCU_2560
 | 
			
		||||
	void led_rx_on()  { digitalWrite(pin_led_rx, HIGH); }
 | 
			
		||||
	void led_rx_off() {	digitalWrite(pin_led_rx, LOW); }
 | 
			
		||||
@ -58,6 +78,16 @@ uint8_t boot_vector = 0x00;
 | 
			
		||||
		void led_rx_off() {	digitalWrite(pin_led_rx, LOW); }
 | 
			
		||||
		void led_tx_on()  { digitalWrite(pin_led_tx, HIGH); }
 | 
			
		||||
		void led_tx_off() { digitalWrite(pin_led_tx, LOW); }
 | 
			
		||||
	#elif BOARD_MODEL == BOARD_RNODE_NG_20
 | 
			
		||||
		void led_rx_on()  { npset(0, 0, 0xFF); }
 | 
			
		||||
		void led_rx_off() {	npset(0, 0, 0); }
 | 
			
		||||
		void led_tx_on()  { npset(0xFF, 0x50, 0x00); }
 | 
			
		||||
		void led_tx_off() { npset(0, 0, 0); }
 | 
			
		||||
	#elif BOARD_MODEL == BOARD_RNODE_NG_21
 | 
			
		||||
		void led_rx_on()  { digitalWrite(pin_led_rx, HIGH); }
 | 
			
		||||
		void led_rx_off() {	digitalWrite(pin_led_rx, LOW); }
 | 
			
		||||
		void led_tx_on()  { digitalWrite(pin_led_tx, HIGH); }
 | 
			
		||||
		void led_tx_off() { digitalWrite(pin_led_tx, LOW); }
 | 
			
		||||
	#elif BOARD_MODEL == BOARD_HUZZAH32
 | 
			
		||||
		void led_rx_on()  { digitalWrite(pin_led_rx, HIGH); }
 | 
			
		||||
		void led_rx_off() {	digitalWrite(pin_led_rx, LOW); }
 | 
			
		||||
@ -82,7 +112,19 @@ void hard_reset(void) {
 | 
			
		||||
	#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// LED Indication: Error
 | 
			
		||||
void led_indicate_error(int cycles) {
 | 
			
		||||
	#if BOARD_MODEL == BOARD_RNODE_NG_20
 | 
			
		||||
		bool forever = (cycles == 0) ? true : false;
 | 
			
		||||
		cycles = forever ? 1 : cycles;
 | 
			
		||||
		while(cycles > 0) {
 | 
			
		||||
			npset(0xFF, 0x00, 0x00);
 | 
			
		||||
			delay(100);
 | 
			
		||||
			npset(0xFF, 0x50, 0x00);
 | 
			
		||||
			delay(100);
 | 
			
		||||
		}
 | 
			
		||||
		npset(0,0,0);
 | 
			
		||||
	#else
 | 
			
		||||
		bool forever = (cycles == 0) ? true : false;
 | 
			
		||||
		cycles = forever ? 1 : cycles;
 | 
			
		||||
		while(cycles > 0) {
 | 
			
		||||
@ -96,9 +138,16 @@ void led_indicate_error(int cycles) {
 | 
			
		||||
	    }
 | 
			
		||||
	    led_rx_off();
 | 
			
		||||
	    led_tx_off();
 | 
			
		||||
	#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// LED Indication: Boot Error
 | 
			
		||||
void led_indicate_boot_error() {
 | 
			
		||||
	#if BOARD_MODEL == BOARD_RNODE_NG_20
 | 
			
		||||
		while(true) {
 | 
			
		||||
			npset(0xFF, 0xFF, 0xFF);
 | 
			
		||||
		}
 | 
			
		||||
	#else
 | 
			
		||||
		while (true) {
 | 
			
		||||
		    led_tx_on();
 | 
			
		||||
		    led_rx_off();
 | 
			
		||||
@ -107,9 +156,22 @@ void led_indicate_boot_error() {
 | 
			
		||||
		    led_tx_off();
 | 
			
		||||
		    delay(5);
 | 
			
		||||
		}
 | 
			
		||||
	#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// LED Indication: Warning
 | 
			
		||||
void led_indicate_warning(int cycles) {
 | 
			
		||||
	#if BOARD_MODEL == BOARD_RNODE_NG_20
 | 
			
		||||
		bool forever = (cycles == 0) ? true : false;
 | 
			
		||||
		cycles = forever ? 1 : cycles;
 | 
			
		||||
		while(cycles > 0) {
 | 
			
		||||
			npset(0xFF, 0x50, 0x00);
 | 
			
		||||
			delay(100);
 | 
			
		||||
			npset(0x00, 0x00, 0x00);
 | 
			
		||||
			delay(100);
 | 
			
		||||
		}
 | 
			
		||||
		npset(0,0,0);
 | 
			
		||||
	#else
 | 
			
		||||
		bool forever = (cycles == 0) ? true : false;
 | 
			
		||||
		cycles = forever ? 1 : cycles;
 | 
			
		||||
		digitalWrite(pin_led_tx, HIGH);
 | 
			
		||||
@ -121,8 +183,10 @@ void led_indicate_warning(int cycles) {
 | 
			
		||||
	        if (!forever) cycles--;
 | 
			
		||||
    }
 | 
			
		||||
    led_tx_off();
 | 
			
		||||
	#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// LED Indication: Info
 | 
			
		||||
#if MCU_VARIANT == MCU_1284P || MCU_VARIANT == MCU_2560
 | 
			
		||||
	void led_indicate_info(int cycles) {
 | 
			
		||||
		bool forever = (cycles == 0) ? true : false;
 | 
			
		||||
@ -137,7 +201,19 @@ void led_indicate_warning(int cycles) {
 | 
			
		||||
	  led_rx_off();
 | 
			
		||||
	}
 | 
			
		||||
#elif MCU_VARIANT == MCU_ESP32
 | 
			
		||||
	#if BOARD_MODEL == BOARD_LORA32_V2_1
 | 
			
		||||
	#if BOARD_MODEL == BOARD_RNODE_NG_20
 | 
			
		||||
		void led_indicate_info(int cycles) {
 | 
			
		||||
			bool forever = (cycles == 0) ? true : false;
 | 
			
		||||
			cycles = forever ? 1 : cycles;
 | 
			
		||||
			while(cycles > 0) {
 | 
			
		||||
		    npset(0x00, 0x00, 0xFF);
 | 
			
		||||
  			delay(100);
 | 
			
		||||
  			npset(0x00, 0x00, 0x00);
 | 
			
		||||
  			delay(100);
 | 
			
		||||
		  }
 | 
			
		||||
		  npset(0,0,0);
 | 
			
		||||
		}
 | 
			
		||||
	#elif BOARD_MODEL == BOARD_LORA32_V2_1
 | 
			
		||||
		void led_indicate_info(int cycles) {
 | 
			
		||||
			bool forever = (cycles == 0) ? true : false;
 | 
			
		||||
			cycles = forever ? 1 : cycles;
 | 
			
		||||
@ -185,7 +261,21 @@ unsigned long led_standby_ticks = 0;
 | 
			
		||||
	uint8_t led_standby_min = 1;
 | 
			
		||||
	uint8_t led_standby_max = 40;
 | 
			
		||||
	unsigned long led_standby_wait = 11000;
 | 
			
		||||
 | 
			
		||||
#elif MCU_VARIANT == MCU_ESP32
 | 
			
		||||
 | 
			
		||||
	#if BOARD_MODEL == BOARD_RNODE_NG_20
 | 
			
		||||
		uint8_t led_standby_min = 0;
 | 
			
		||||
		uint8_t led_standby_max = 255;
 | 
			
		||||
		uint8_t led_notready_min = 0;
 | 
			
		||||
		uint8_t led_notready_max = led_standby_max;
 | 
			
		||||
		uint8_t led_notready_value = led_notready_min;
 | 
			
		||||
		int8_t  led_notready_direction = 0;
 | 
			
		||||
		unsigned long led_notready_ticks = 0;
 | 
			
		||||
		unsigned long led_standby_wait = 5000;
 | 
			
		||||
		unsigned long led_notready_wait = 20000;
 | 
			
		||||
	
 | 
			
		||||
	#else
 | 
			
		||||
		uint8_t led_standby_min = 200;
 | 
			
		||||
		uint8_t led_standby_max = 255;
 | 
			
		||||
		uint8_t led_notready_min = 0;
 | 
			
		||||
@ -195,7 +285,9 @@ unsigned long led_standby_ticks = 0;
 | 
			
		||||
		unsigned long led_notready_ticks = 0;
 | 
			
		||||
		unsigned long led_standby_wait = 1768;
 | 
			
		||||
		unsigned long led_notready_wait = 150;
 | 
			
		||||
	#endif
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
uint8_t led_standby_value = led_standby_min;
 | 
			
		||||
int8_t  led_standby_direction = 0;
 | 
			
		||||
 | 
			
		||||
@ -214,7 +306,27 @@ int8_t  led_standby_direction = 0;
 | 
			
		||||
			led_tx_off();
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
#elif MCU_VARIANT == MCU_ESP32
 | 
			
		||||
	#if BOARD_MODEL == BOARD_RNODE_NG_20
 | 
			
		||||
		void led_indicate_standby() {
 | 
			
		||||
			led_standby_ticks++;
 | 
			
		||||
 | 
			
		||||
			if (led_standby_ticks > led_standby_wait) {
 | 
			
		||||
				led_standby_ticks = 0;
 | 
			
		||||
				
 | 
			
		||||
				if (led_standby_value <= led_standby_min) {
 | 
			
		||||
					led_standby_direction = 1;
 | 
			
		||||
				} else if (led_standby_value >= led_standby_max) {
 | 
			
		||||
					led_standby_direction = -1;
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				led_standby_value += led_standby_direction;
 | 
			
		||||
  			npset(0x00, 0x00, led_standby_value);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
	#else
 | 
			
		||||
		void led_indicate_standby() {
 | 
			
		||||
			led_standby_ticks++;
 | 
			
		||||
			if (led_standby_ticks > led_standby_wait) {
 | 
			
		||||
@ -243,6 +355,7 @@ int8_t  led_standby_direction = 0;
 | 
			
		||||
				#endif
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
  #endif
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if MCU_VARIANT == MCU_1284P || MCU_VARIANT == MCU_2560
 | 
			
		||||
@ -261,6 +374,25 @@ int8_t  led_standby_direction = 0;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
#elif MCU_VARIANT == MCU_ESP32
 | 
			
		||||
	#if BOARD_MODEL == BOARD_RNODE_NG_20
 | 
			
		||||
    void led_indicate_not_ready() {
 | 
			
		||||
			led_notready_ticks++;
 | 
			
		||||
			if (led_notready_ticks > led_notready_wait) {
 | 
			
		||||
				led_notready_ticks = 0;
 | 
			
		||||
				if (led_notready_value <= led_notready_min) {
 | 
			
		||||
					led_notready_direction = 1;
 | 
			
		||||
				} else if (led_notready_value >= led_notready_max) {
 | 
			
		||||
					led_notready_direction = -1;
 | 
			
		||||
				}
 | 
			
		||||
				led_notready_value += led_notready_direction;
 | 
			
		||||
				if (led_notready_value > 252) {
 | 
			
		||||
					npset(0xFF, 0x00, 0x00);
 | 
			
		||||
				} else {
 | 
			
		||||
					npset(0x00, 0x00, 0x00);
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	#else
 | 
			
		||||
		void led_indicate_not_ready() {
 | 
			
		||||
			led_notready_ticks++;
 | 
			
		||||
			if (led_notready_ticks > led_notready_wait) {
 | 
			
		||||
@ -289,6 +421,7 @@ int8_t  led_standby_direction = 0;
 | 
			
		||||
				#endif
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	#endif
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
void escapedSerialWrite(uint8_t byte) {
 | 
			
		||||
@ -651,6 +784,8 @@ bool eeprom_model_valid() {
 | 
			
		||||
	if (model == MODEL_B3 || model == MODEL_B8) {
 | 
			
		||||
	#elif BOARD_MODEL == BOARD_LORA32_V2_1
 | 
			
		||||
	if (model == MODEL_B4 || model == MODEL_B9) {
 | 
			
		||||
	#elif BOARD_MODEL == BOARD_RNODE_NG_20
 | 
			
		||||
	if (model == MODEL_B3 || model == MODEL_B8) {
 | 
			
		||||
	#elif BOARD_MODEL == BOARD_HUZZAH32
 | 
			
		||||
	if (model == MODEL_FF) {
 | 
			
		||||
	#elif BOARD_MODEL == BOARD_GENERIC_ESP32
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user