|
NanoLux (Device) 3.0
Codebase for the open-source AudioLux device.
|
#include "cmath"#include <FastLED.h>#include <Arduino.h>#include "patterns.h"#include "nanolux_types.h"#include "nanolux_util.h"#include "storage.h"#include <AiEsp32RotaryEncoder.h>Functions | |
| void | nanolux_serial_print (char *msg) |
| Prints a character array message if allowed to. | |
| void | bound_byte (uint8_t *val, int lower, int upper) |
| Bounds a byte between an upper and a lower value. | |
| int | remap (double x, double oMin, double oMax, double nMin, double nMax) |
| Remaps a value in one range to another range. | |
| int | largest (float arr[], int n) |
| Returns the index of the largest array element. | |
| void | reset_button_state () |
| Resets the button state to false. | |
| void IRAM_ATTR | buttonISR () |
| A debounced interrupt to set the button state. | |
| void | led_on_forever () |
| Causes the LED to turn on/off forever. | |
| void | process_reset_button (int button_value) |
| If the hardware button is held for RESET_TIME, clear the list of saves and call led_on_forever(). | |
| void | begin_loop_timer (long ms) |
| Logs the current program loop start time and the expected loop end time. | |
| long | timer_overrun () |
| Returns the amount of time since expected loop termination. | |
| void IRAM_ATTR | readEncoderISR () |
| Processes the interrupt for the rotary encoder on 2.0 hardware. | |
| void | setup_rotary_encoder () |
| Performs initial setup for the rotary encoder. | |
| bool | isEncoderButtonPressed () |
| Returns the current state of the rotary encoder button. | |
| int | encoder_delta () |
| Returns the difference between the encoder's previous and new position. | |
Variables | |
| Config_Data | config |
| The currently-loaded device config. | |
| bool | button_pressed |
| Contains the current state of the button (true is pressed). | |
| int | NUM_PATTERNS |
| unsigned long | start_millis = NULL |
| long | loop_start_time = 0 |
| Holds the start time of the current program loop. | |
| long | loop_end_time = 0 |
| Holds the expected end time of the current program loop. | |
| AiEsp32RotaryEncoder | rotaryEncoder |
| Defines the rotary encoder object for the 2.0 boards. | |
This file contains functions that interface with the phyiscal on-board hardware, such as encoders or buttons.
This file also contains helper functions that don't make sense to define elsewhere.
| void begin_loop_timer | ( | long | ms | ) |
Logs the current program loop start time and the expected loop end time.
| ms | The user-specified loop time. |
| void bound_byte | ( | uint8_t * | val, |
| int | lower, | ||
| int | upper ) |
Bounds a byte between an upper and a lower value.
| val | The pointer to the value to modify. |
| lower | The lower value the value can be. |
| upper | The upper value the value can be. |
| void IRAM_ATTR buttonISR | ( | ) |
A debounced interrupt to set the button state.
If the device button is pressed, wait 5 milliseconds. If the button pin still reads a press, set button_pressed to True.
| int encoder_delta | ( | ) |
Returns the difference between the encoder's previous and new position.
| bool isEncoderButtonPressed | ( | ) |
Returns the current state of the rotary encoder button.
| int largest | ( | float | arr[], |
| int | n ) |
Returns the index of the largest array element.
| arr | The array to iterate through. |
| n | The number of elements to check. |
| void led_on_forever | ( | ) |
Causes the LED to turn on/off forever.
This function is an infinite loop that never terminates. It clears the LED strip, then causes the built-in LED to turn on and off with 1 second states.
| void nanolux_serial_print | ( | char * | msg | ) |
Prints a character array message if allowed to.
| msg | The message to print out to serial. |
| void process_reset_button | ( | int | button_value | ) |
If the hardware button is held for RESET_TIME, clear the list of saves and call led_on_forever().
The inital button press sets start_millis to the current device time. If the delta between the current time and start_millis is equal to 1.5 seconds, turn on the LED.
If the delta is more than RESET_TIME, reset the device and call led_on_forever(). This is an infinite loop, which requires a device reset to clear. This is intended behavior.
This function requires constant monitoring of the button, so direct hardware calls are used here.
| int remap | ( | double | x, |
| double | oMin, | ||
| double | oMax, | ||
| double | nMin, | ||
| double | nMax ) |
Remaps a value in one range to another range.
| x | The value to remap. |
| oMin | The old range minimum. |
| oMax | The old range maximum. |
| nMin | The new range minimum. |
| nMax | The new range maximum. |
| void reset_button_state | ( | ) |
Resets the button state to false.
If the button state is currently true, print to serial if debug is enabled in the device config.
| long timer_overrun | ( | ) |
Returns the amount of time since expected loop termination.
Returns 0 if the expected end time has not been reached, or a -1 if an error has occured.
If the loop end time has been reached, return the delta between the expected time plus 1.
1 is added to the output time to distinguish between positive and negative 0. This probably should be refactored in the future.
|
extern |
Contains the current state of the button (true is pressed).
Checks if the device button is pressed, defined in main.ino.
|
extern |
The currently-loaded device config.
The current config of the device, defined in main.ino. Used to check if serial printing is allowed.
| AiEsp32RotaryEncoder rotaryEncoder |
Defines the rotary encoder object for the 2.0 boards.
| unsigned long start_millis = NULL |
Stores the inital time the button was pressed. Used to determine if the button has been held long enough to reset the device.