NanoLux (Device) 3.0
Codebase for the open-source AudioLux device.
|
#include <ArduinoJson.h>
#include <ArduinoJson.hpp>
#include <FastLED.h>
#include <Arduino.h>
#include "patterns.h"
#include "nanolux_types.h"
#include "nanolux_util.h"
#include "core_analysis.h"
#include "ext_analysis.h"
#include "storage.h"
#include "globals.h"
#include <AiEsp32RotaryEncoder.h>
#include "WebServer.h"
#include "api.h"
Functions | |
void | setup () |
Sets up various objects needed by the device. | |
void | loop () |
Runs the main program loop. | |
void | audio_analysis () |
Performs audio analysis by running audio_analysis.cpp's audio processing functions. | |
void | calculate_layering (CRGB *a, CRGB *b, CRGB *out, int length, uint8_t blur) |
Layers two CRGB arrays together and places the result in another array. | |
void | update_web_server () |
Checks if the web server has new data, and marks settings as dirty if required. | |
void | scale_crgb_array (CRGB *arr, uint8_t len, uint8_t factor) |
Scales all LEDs in a CRGB array by (factor)/255. | |
void | reverse_buffer (CRGB *buf, uint8_t len) |
Reverses the LED buffer supplied given a length. | |
void | unfold_buffer (CRGB *buf, uint8_t len, bool even) |
Unfolds the buffer by mirroring it across the right side. | |
void | process_pattern (Pattern_Data *p, Strip_Buffer *buf, uint8_t len) |
Runs a specified pattern and performs postprocessing effects on it. | |
void | run_strip_splitting () |
Runs the strip splitting LED strip mode. | |
void | run_pattern_layering () |
Runs the pattern layering output mode. | |
void | print_buffer (CRGB *buf, uint8_t len) |
Prints a buffer to serial. | |
void | update_hardware () |
Processes all calls to hardware and manages the results of those calls. | |
Variables | |
CRGB | output_buffer [MAX_LEDS] |
Unprocessed output buffer. | |
CRGB | smoothed_output [MAX_LEDS] |
Postprocessed output buffer. | |
bool | button_pressed = false |
Contains the current state of the button (true is pressed). | |
double | peak = 0. |
Contains the peak frequency detected by the FFT. | |
uint8_t | fHue = 0 |
Contains the "base" hue, calculated from the peak frequency. | |
double | volume = 0. |
Contains the current volume detected by the FFT. | |
uint8_t | vbrightness = 0 |
Contains the "base" brightness value, calculated from the current volume. | |
volatile bool | pattern_changed = false |
Updated to "true" when the web server changes significant pattern settings. | |
Strip_Data | loaded_patterns |
The current strip configuration being ran by the device. | |
Strip_Data | saved_patterns [NUM_SAVES] |
All patterns and strip configuration currently loaded from storage. | |
Config_Data | config |
The currently-loaded device config. | |
Strip_Buffer | histories [PATTERN_LIMIT] |
History of all currently-running patterns. | |
Pattern | mainPatterns [] |
The current list of patterns, externed from globals.h. | |
volatile bool | manual_control_enabled = false |
MANUAL CONTROL VARIABLES. | |
Strip_Buffer | manual_strip_buffer |
Pattern_Data | manual_pattern |
bool | lastEncoderBtnPressed = false |
Stores the last state of the rotary encoder button. | |
This file is the main driver of the NanoLux codebase.
void audio_analysis | ( | ) |
Performs audio analysis by running audio_analysis.cpp's audio processing functions.
If the macro SHOW_TIMINGS is defined, it will print out the amount of time audio processing takes via serial.
void calculate_layering | ( | CRGB * | a, |
CRGB * | b, | ||
CRGB * | out, | ||
int | length, | ||
uint8_t | blur ) |
Layers two CRGB arrays together and places the result in another array.
a | The first array to layer. |
b | The second array to layer. |
out | The array to output to. |
length | The number of pixels to layer. |
blur | The ratio between the first and second array in the output. 0-255. |
void loop | ( | ) |
Runs the main program loop.
Carries out functions related to timing and updating the LED strip.
void print_buffer | ( | CRGB * | buf, |
uint8_t | len ) |
Prints a buffer to serial.
buf | The CRGB buffer to print. |
len | The number of RGB values to print. |
void process_pattern | ( | Pattern_Data * | p, |
Strip_Buffer * | buf, | ||
uint8_t | len ) |
Runs a specified pattern and performs postprocessing effects on it.
p | The pattern to run. |
buf | The buffer to read/write to/from. |
len | How many pixels this pattern can run on. |
void reverse_buffer | ( | CRGB * | buf, |
uint8_t | len ) |
Reverses the LED buffer supplied given a length.
buf | The LED buffer to reverse. |
len | The length of the buffer to reverse. |
void run_pattern_layering | ( | ) |
Runs the pattern layering output mode.
This function layers two patterns onto each other, covering the entire length of the LED strip.
Each pattern buffer is moved into a temp buffer, which scales the brightness of each pattern according to user settings.
Then, the patterns are merged into the unsmoothed buffer, which then is combined with the smoothed buffer.
void run_strip_splitting | ( | ) |
Runs the strip splitting LED strip mode.
This function allocates a number of LEDs per pattern, then moves LED data from the pattern's history buffer to the unsmoothed output buffer.
Once the data is in the unsmoothed buffer, the buffer is "smoothed" into the output smoothed buffer.
void scale_crgb_array | ( | CRGB * | arr, |
uint8_t | len, | ||
uint8_t | factor ) |
Scales all LEDs in a CRGB array by (factor)/255.
arr | The array to scale |
len | The number of LEDs to scale |
factor | The factor to scale by. Divided by 255. |
void setup | ( | ) |
Sets up various objects needed by the device.
Initalizes the button pin, serial, pattern index, the FastLED object, and all stored saves.
void unfold_buffer | ( | CRGB * | buf, |
uint8_t | len, | ||
bool | even ) |
Unfolds the buffer by mirroring it across the right side.
buf | The buffer to unfold. |
len | The length to unfold. |
even | If the LED strip length is even/odd. When odd, duplicates the middle pixel a second time to fill space. |
void update_hardware | ( | ) |
Processes all calls to hardware and manages the results of those calls.
This function includes an ifdef else directive which checks for a macro called VERSION_2_HARDWARE. This macro is defined or commented out at the start of nanolux_util.h. If your hardware has a rotary encoder and button combo, ensure this macro is not commented.
void update_web_server | ( | ) |
Checks if the web server has new data, and marks settings as dirty if required.
Some settings are updated inside a more constrained context without enough stack space for a "disk" operation so we defer the save to here.
bool button_pressed = false |
Contains the current state of the button (true is pressed).
Checks if the device button is pressed, defined in main.ino.
Config_Data config |
The currently-loaded device config.
The current config of the device, defined in main.ino. Used to check if serial printing is allowed.
Strip_Data loaded_patterns |
The current strip configuration being ran by the device.
The currently strip configuration, externed from main.ino.
double peak = 0. |
Contains the peak frequency detected by the FFT.
Global variable used to store preak audio frequency.
Strip_Data saved_patterns[NUM_SAVES] |
All patterns and strip configuration currently loaded from storage.
The array for storing saved strip configurations, externed from main.ino.
double volume = 0. |
Contains the current volume detected by the FFT.
Global variable used to access the current volume.