Skip to content

Commit

Permalink
Minor docs changes, removal of old functions
Browse files Browse the repository at this point in the history
  • Loading branch information
shillinc-osu committed May 25, 2024
1 parent 1e0cf9a commit 088f2dd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
8 changes: 7 additions & 1 deletion main/main.ino
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ extern Pattern mainPatterns[];
volatile bool manual_control_enabled = false;
Strip_Buffer manual_strip_buffer;
Pattern_Data manual_pattern;

/// Stores the last state of the rotary encoder button.
bool lastEncoderBtnPressed = false;

/**********************************************************
Expand Down Expand Up @@ -210,6 +212,11 @@ void unfold_buffer(CRGB* buf, uint8_t len, bool even){
}
}

/// @brief Runs a specified pattern and performs postprocessing effects on it.
///
/// @param p The pattern to run.
/// @param buf The buffer to read/write to/from.
/// @param len How many pixels this pattern can run on.
void process_pattern(Pattern_Data * p, Strip_Buffer * buf, uint8_t len){

// Pull the current postprocessing effects from the struct integer.
Expand Down Expand Up @@ -239,7 +246,6 @@ void process_pattern(Pattern_Data * p, Strip_Buffer * buf, uint8_t len){
unfold_buffer(buf->leds, processed_len, (len == processed_len * 2));
}


/// @brief Runs the strip splitting LED strip mode
///
/// This function allocates a number of LEDs per pattern, then
Expand Down
27 changes: 18 additions & 9 deletions main/nanolux_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ long loop_start_time = 0;
/// Holds the expected end time of the current program loop.
long loop_end_time = 0;

/// Defines the rotary encoder object for the 2.0 boards
AiEsp32RotaryEncoder rotaryEncoder = AiEsp32RotaryEncoder(
ROTARY_ENCODER_A_PIN,
ROTARY_ENCODER_B_PIN,
ROTARY_ENCODER_BUTTON_PIN,
ROTARY_ENCODER_VCC_PIN,
ROTARY_ENCODER_STEPS
);

/************************************************
*
* HELPERS:
Expand Down Expand Up @@ -271,28 +280,28 @@ long timer_overrun(){
return (millis() < loop_end_time) ? 0 : millis() - loop_end_time + 1;
}

AiEsp32RotaryEncoder rotaryEncoder = AiEsp32RotaryEncoder(ROTARY_ENCODER_A_PIN, ROTARY_ENCODER_B_PIN, ROTARY_ENCODER_BUTTON_PIN, ROTARY_ENCODER_VCC_PIN, ROTARY_ENCODER_STEPS);

/// @brief Processes the interrupt for the rotary encoder on 2.0 hardware
void IRAM_ATTR readEncoderISR(){
rotaryEncoder.readEncoder_ISR();
}

/// @brief Performs initial setup for the rotary encoder
void setup_rotary_encoder(){
rotaryEncoder.begin();
rotaryEncoder.setup(readEncoderISR);
rotaryEncoder.setBoundaries(0, 1000, true); //minValue, maxValue, circleValues true|false (when max go to min and vice versa)
rotaryEncoder.setAcceleration(250);
}
int calculate_pattern_index(){
int index = static_cast<int>(floor(rotaryEncoder.readEncoder() / ROTARY_ENCODER_STEPS)) % NUM_PATTERNS;

return index;
/// @brief Calculates the pattern index the rotary encoder currently
/// corresponds to.
/// @returns The pattern index the encoder is set to.
int calculate_pattern_index(){
return static_cast<int>(floor(rotaryEncoder.readEncoder() / ROTARY_ENCODER_STEPS)) % NUM_PATTERNS;
}

/// @brief Returns the current state of the rotary encoder button.
/// @returns True if pressed, false if not.
bool isEncoderButtonPressed(){
return rotaryEncoder.isEncoderButtonClicked();
}

bool isEncoderBtnDown() {
return rotaryEncoder.isEncoderButtonDown();
}
3 changes: 0 additions & 3 deletions main/nanolux_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@ long timer_overrun();
void bound_byte(uint8_t * val, int lower, int upper);
void process_reset_button(int button_value);
void nanolux_serial_print(char * msg);

void IRAM_ATTR readEncoderISR();
void setup_rotary_encoder();
int calculate_pattern_index();
bool isEncoderButtonPressed();
bool isEncoderBtnDown();


#endif

0 comments on commit 088f2dd

Please sign in to comment.