Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ninth led #80

Merged
merged 4 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions components/hdw-led/hdw-led.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
// Variables
//==============================================================================

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 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};

//==============================================================================
// Functions
Expand Down Expand Up @@ -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
Expand All @@ -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);
}
4 changes: 4 additions & 0 deletions components/hdw-led/include/hdw-led.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion components/hdw-mic/hdw-mic.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down