Skip to content
Snippets Groups Projects
Commit 49a842aa authored by David Huss's avatar David Huss :speech_balloon:
Browse files

More generic functions for ui setup

parent 1145822a
Branches
Tags
No related merge requests found
...@@ -93,36 +93,33 @@ class ButtonGrid { ...@@ -93,36 +93,33 @@ class ButtonGrid {
void setup() { void setup() {
Serial.println("Running Setup for ButtonGrid"); Serial.println("Running Setup for ButtonGrid");
for (int n=0; n<6; n++) { for (int n=0; n<6; n++) {
// If this is the home button setup callbacks if (!grid_buttons_[n].is_home) {
if (grid_buttons_[n].is_home) {
Serial.print("Home button ");
Serial.println(n);
// // When homebutton is held switch to this UI Mode
// grid_buttons_[n].button.onHold([ui, n](){ ui->setMode(ui_mode); });
// // When homebutton is released hide ALL button descriptions
// grid_buttons_[n].button.onReleased([ui, n](){
// ui->setMode(UI_MODE_DEFAULT);
// for (int i=0; i<6; i++) {
// grid_buttons_[i].should_render_description = false;
// }
// });
} else {
Serial.println(n); Serial.println(n);
// Not a home button, display help on long hold and hide on release // Not a home button, display help on long hold and hide on release
grid_buttons_[n].button->onLongHold([this, n](){ grid_buttons_[n].button->onLongHold([this, n](){
// TODO: Doesn't register for some reason?
Serial.println("Show DESCROOOTT");
grid_buttons_[n].should_render_description = true; grid_buttons_[n].should_render_description = true;
}); });
grid_buttons_[n].button->onReleased([this, n](){ grid_buttons_[n].button->onReleased([this, n](){
// TODO: Doesn't register for some reason?
Serial.println("NOPE");
grid_buttons_[n].should_render_description = false; grid_buttons_[n].should_render_description = false;
}); });
} }
} }
} }
int homeButtonIndex() {
for (int i=0; i<6; i++) {
if (grid_buttons_[i].is_home) {
return i;
}
}
}
void hideAllDescriptions() {
for (int i=0; i<6; i++) {
grid_buttons_[i].should_render_description = false;
}
}
void render(int button_enum) { void render(int button_enum) {
int width = display.width(); int width = display.width();
int height = display.height(); int height = display.height();
......
...@@ -20,7 +20,10 @@ ...@@ -20,7 +20,10 @@
#include "helpers.h" #include "helpers.h"
#include "ui.h" #include "ui.h"
static const size_t buffer_length = 48000 * 5;
#define BUFFER_LENGTH_SECONDS 5
static const size_t buffer_length = 48000 * BUFFER_LENGTH_SECONDS;
static float DSY_SDRAM_BSS buffer[buffer_length]; static float DSY_SDRAM_BSS buffer[buffer_length];
// Create instances of audio stuff // Create instances of audio stuff
......
...@@ -4,6 +4,15 @@ ...@@ -4,6 +4,15 @@
#ifndef Ui_h #ifndef Ui_h
#define Ui_h #define Ui_h
#ifdef DEBUG
#define DEBUG_PRINT(x) Serial.print (x)
#define DEBUG_PRINTLN(x) Serial.println (x)
#else
#define DEBUG_PRINT(x)
#define DEBUG_PRINTLN(x)
#endif
#include "Adafruit_SH110X.h" #include "Adafruit_SH110X.h"
#include "Adafruit_GFX.h" #include "Adafruit_GFX.h"
#include "potentiometers.h" #include "potentiometers.h"
...@@ -224,18 +233,39 @@ class Ui { ...@@ -224,18 +233,39 @@ class Ui {
button_6.reset(); button_6.reset();
} }
Button* setupButtonGrid(int n) {
Serial.println("[UI] Setup Rec Menu");
// Find the index of the home button
int home_button_index = button_grids[n].homeButtonIndex();
// Create a pointer to the hoime button
Button* home_button = button_grids[n].grid_buttons_[home_button_index].button;
// Reset the controls
resetControls();
// Setup the button grid
button_grids[n].setup();
// Return to default mode on release
home_button->onReleased([this, n](){
this->setMode(UI_MODE_DEFAULT);
this->button_grids[n].hideAllDescriptions();
});
// Return pointer to the home button
return home_button;
}
// Setup the Recording Menu // Setup the Recording Menu
void setupRecMenu() { void setupRecMenu() {
// Only run once when the ui_mode changed // Only run once when the ui_mode changed
if (ui_mode == UI_MODE_REC_MENU && last_ui_mode != UI_MODE_REC_MENU) { if (ui_mode == UI_MODE_REC_MENU && last_ui_mode != UI_MODE_REC_MENU) {
int n = 0; int n = 0;
Serial.println("[UI] Setup Rec Menu");
// Reset controls // Setup button Grid
resetControls(); Button* home_button = setupButtonGrid(n);
// Setup
button_grids[n].setup();
// Toggle between momentary and toggle recording modes // Toggle between momentary and toggle recording modes
button_2.onPress([this, n](){ button_2.onPress([this, n](){
...@@ -280,48 +310,6 @@ class Ui { ...@@ -280,48 +310,6 @@ class Ui {
looper.setRecStartMode((atoav::RecStartMode) button_grids[n].grid_buttons_[5].active); looper.setRecStartMode((atoav::RecStartMode) button_grids[n].grid_buttons_[5].active);
}); });
// // Display descriptions on Long Hold:
// button_2.onLongHold([this, n](){
// button_grids[n].grid_buttons_[1].should_render_description = true;
// });
// button_2.onReleased([this, n](){
// button_grids[n].grid_buttons_[1].should_render_description = false;
// });
// button_3.onLongHold([this, n](){
// button_grids[n].grid_buttons_[2].should_render_description = true;
// });
// button_3.onReleased([this, n](){
// button_grids[n].grid_buttons_[2].should_render_description = false;
// });
// button_4.onLongHold([this, n](){
// button_grids[n].grid_buttons_[3].should_render_description = true;
// });
// button_4.onReleased([this, n](){
// button_grids[n].grid_buttons_[3].should_render_description = false;
// });
// button_5.onLongHold([this, n](){
// button_grids[n].grid_buttons_[4].should_render_description = true;
// });
// button_5.onReleased([this, n](){
// button_grids[n].grid_buttons_[4].should_render_description = false;
// });
// button_6.onLongHold([this, n](){
// button_grids[n].grid_buttons_[5].should_render_description = true;
// });
// button_6.onReleased([this, n](){
// button_grids[n].grid_buttons_[5].should_render_description = false;
// });
// Store the last ui mode, for the check on top // Store the last ui mode, for the check on top
last_ui_mode = ui_mode; last_ui_mode = ui_mode;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment