From 5c13fa412528214160127e69fe041a372071bb9d Mon Sep 17 00:00:00 2001 From: AEFeinstein Date: Sat, 23 Sep 2023 16:52:38 -0400 Subject: [PATCH 1/4] Automatically set 9th LED to average of 6th, 7th, and 8th --- components/hdw-led/hdw-led.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/components/hdw-led/hdw-led.c b/components/hdw-led/hdw-led.c index fe0f6d8f0..cb298160d 100644 --- a/components/hdw-led/hdw-led.c +++ b/components/hdw-led/hdw-led.c @@ -23,7 +23,7 @@ static rmt_channel_handle_t led_chan = NULL; static rmt_encoder_handle_t led_encoder = NULL; static uint8_t ledBrightness = 0; -static led_t localLeds[CONFIG_NUM_LEDS] = {0}; +static led_t localLeds[CONFIG_NUM_LEDS + 1] = {0}; //============================================================================== // Functions @@ -108,9 +108,9 @@ esp_err_t setLeds(led_t* leds, uint8_t numLeds) }; // Make sure to not overflow - if (numLeds > CONFIG_NUM_LEDS) + if (numLeds > CONFIG_NUM_LEDS + 1) { - numLeds = CONFIG_NUM_LEDS; + numLeds = CONFIG_NUM_LEDS + 1; } // Fill a local copy of LEDs with brightness applied @@ -121,6 +121,27 @@ esp_err_t setLeds(led_t* leds, uint8_t numLeds) localLeds[i].b = (leds[i].b >> ledBrightness); } + // If all eight LEDs are being set, but not the 9th + if(CONFIG_NUM_LEDS == numLeds) + { + // Set the 9th LED to the average of the 6th, 7th, and 8th + int32_t avgR = 0; + int32_t avgG = 0; + int32_t avgB = 0; + for(int32_t lIdx = 5; lIdx < 8; lIdx++) + { + avgR += leds[lIdx].r; + avgG += leds[lIdx].g; + avgB += leds[lIdx].b; + } + localLeds[CONFIG_NUM_LEDS].r = (avgR / 3) >> ledBrightness; + localLeds[CONFIG_NUM_LEDS].g = (avgG / 3) >> ledBrightness; + localLeds[CONFIG_NUM_LEDS].b = (avgB / 3) >> ledBrightness; + + // Set the 9th LED too + numLeds = CONFIG_NUM_LEDS + 1; + } + // Write RGB values to LEDs return rmt_transmit(led_chan, led_encoder, (uint8_t*)localLeds, numLeds * sizeof(led_t), &tx_config); } From 5d22976c7873b3d200543b2225147233fca99040 Mon Sep 17 00:00:00 2001 From: AEFeinstein Date: Sat, 23 Sep 2023 16:52:54 -0400 Subject: [PATCH 2/4] Increase mic atten for 5.1k resistor --- components/hdw-mic/hdw-mic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/hdw-mic/hdw-mic.c b/components/hdw-mic/hdw-mic.c index 7911fa4ec..c98fa45c6 100644 --- a/components/hdw-mic/hdw-mic.c +++ b/components/hdw-mic/hdw-mic.c @@ -62,7 +62,7 @@ void initMic(gpio_num_t gpio) adc_digi_pattern_config_t adc_pattern[SOC_ADC_PATT_LEN_MAX] = {0}; // Configure the ADC pattern. We only configure a single channel - adc_pattern[0].atten = ADC_ATTEN_DB_0; + adc_pattern[0].atten = ADC_ATTEN_DB_11; adc_pattern[0].channel = channel; adc_pattern[0].unit = unit; adc_pattern[0].bit_width = SOC_ADC_DIGI_MAX_BITWIDTH; From ace37070b9076c2fc23bbc1b2b0ceceb11551e8c Mon Sep 17 00:00:00 2001 From: AEFeinstein Date: Sat, 23 Sep 2023 16:54:49 -0400 Subject: [PATCH 3/4] Formatting --- components/hdw-led/hdw-led.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/components/hdw-led/hdw-led.c b/components/hdw-led/hdw-led.c index cb298160d..18d631de6 100644 --- a/components/hdw-led/hdw-led.c +++ b/components/hdw-led/hdw-led.c @@ -20,9 +20,9 @@ // Variables //============================================================================== -static rmt_channel_handle_t led_chan = NULL; -static rmt_encoder_handle_t led_encoder = NULL; -static uint8_t ledBrightness = 0; +static rmt_channel_handle_t led_chan = NULL; +static rmt_encoder_handle_t led_encoder = NULL; +static uint8_t ledBrightness = 0; static led_t localLeds[CONFIG_NUM_LEDS + 1] = {0}; //============================================================================== @@ -122,13 +122,13 @@ esp_err_t setLeds(led_t* leds, uint8_t numLeds) } // If all eight LEDs are being set, but not the 9th - if(CONFIG_NUM_LEDS == numLeds) + if (CONFIG_NUM_LEDS == numLeds) { // Set the 9th LED to the average of the 6th, 7th, and 8th int32_t avgR = 0; int32_t avgG = 0; int32_t avgB = 0; - for(int32_t lIdx = 5; lIdx < 8; lIdx++) + for (int32_t lIdx = 5; lIdx < 8; lIdx++) { avgR += leds[lIdx].r; avgG += leds[lIdx].g; From d3d5d09ddea40fa9ef3360c536421121e3b5911b Mon Sep 17 00:00:00 2001 From: AEFeinstein Date: Sat, 23 Sep 2023 16:59:56 -0400 Subject: [PATCH 4/4] Add documentation --- components/hdw-led/include/hdw-led.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/components/hdw-led/include/hdw-led.h b/components/hdw-led/include/hdw-led.h index ea14a7436..8a2f892cd 100644 --- a/components/hdw-led/include/hdw-led.h +++ b/components/hdw-led/include/hdw-led.h @@ -25,6 +25,10 @@ * Brightness is adjusted per-color-channel, so dimming may produce different colors. * setLedBrightnessSetting() should be called instead if the brightness change should be persistent through reboots. * + * Even though \c CONFIG_NUM_LEDS declares eight LEDs, there is a ninth LED which is controllable. By default, setting + * \c CONFIG_NUM_LEDS LEDs will automatically set the ninth to the average of the sixth, seventh, and eighth, which + * surround it on the PCB. To set the ninth LED, set `CONFIG_NUM_LEDS + 1` LEDs. + * * \section led_example Example * * Set the LEDs to a rough rainbow: