Skip to content

Commit

Permalink
Fixed pattern saving/loading, encapsulated code for hardware revisions
Browse files Browse the repository at this point in the history
  • Loading branch information
shillinc-osu committed May 24, 2024
1 parent 72a30a0 commit 5c711aa
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
4 changes: 2 additions & 2 deletions main/main.ino
Original file line number Diff line number Diff line change
Expand Up @@ -380,15 +380,15 @@ void update_hardware(){

#else

reset_button_state(); // Check for user button input

process_reset_button(!digitalRead(BUTTON_PIN)); // Manage resetting saves if button held

if(button_pressed){
manual_pattern.idx = (manual_control_enabled + manual_pattern.idx) % NUM_PATTERNS;
manual_control_enabled = true;
}

reset_button_state(); // Check for user button input

#endif

}
Expand Down
4 changes: 2 additions & 2 deletions main/nanolux_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ void led_on_forever() {
///
/// This function requires constant monitoring of the button, so
/// direct hardware calls are used here.
void process_reset_button() {
void process_reset_button(int button_value) {

if (!digitalRead(BUTTON_PIN)) {
if (button_value) {

if (start_millis == NULL)
start_millis = millis();
Expand Down
7 changes: 6 additions & 1 deletion main/nanolux_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

#include <AiEsp32RotaryEncoder.h>

// Uncomment this macro if using the new hardware
// with the rotary encoder.

//#define VERSION_2_HARDWARE

void IRAM_ATTR buttonISR();
void reset_button_state();
int remap( double x,double oMin,double oMax,double nMin,double nMax );
Expand All @@ -12,7 +17,7 @@ void IRAM_ATTR button_up();
void begin_loop_timer(long ms);
long timer_overrun();
void bound_byte(uint8_t * val, int lower, int upper);
void process_reset_button();
void process_reset_button(int button_value);
void nanolux_serial_print(char * msg);

void IRAM_ATTR readEncoderISR();
Expand Down
17 changes: 9 additions & 8 deletions main/storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void load_slot(int slot) {
memcpy(
&loaded_patterns,
&saved_patterns[slot],
sizeof(Pattern_Data));
sizeof(Strip_Data));
}

/// @brief Saves the currently-loaded pattern to a save slot.
Expand All @@ -116,7 +116,7 @@ void set_slot(int slot) {
memcpy(
&saved_patterns[slot],
&loaded_patterns,
sizeof(Pattern_Data));
sizeof(Strip_Data));

bound_user_data();
}
Expand All @@ -129,7 +129,7 @@ void save_to_nvs() {
storage.putBytes(
PATTERN_KEY,
&saved_patterns[0],
sizeof(Pattern_Data) * NUM_SAVES);
sizeof(Strip_Data) * NUM_SAVES);
storage.end();
}

Expand All @@ -139,10 +139,11 @@ void save_to_nvs() {
/// volatile storage as well.
void clear_all() {
clear_nvs();
memset(
&saved_patterns[0],
0,
sizeof(Pattern_Data) * NUM_SAVES);

for(uint8_t i = 0; i < NUM_SAVES; i++){
saved_patterns[i] = Strip_Data();
}

save_to_nvs();

config = Config_Data();
Expand Down Expand Up @@ -182,7 +183,7 @@ void load_from_nvs() {
storage.getBytes(
PATTERN_KEY,
&saved_patterns[0],
sizeof(Pattern_Data) * NUM_SAVES);
sizeof(Strip_Data) * NUM_SAVES);
}

storage.end();
Expand Down

0 comments on commit 5c711aa

Please sign in to comment.