Moved code from a function into where it was called

and some minor cleanup
This commit is contained in:
Mikael Degerfält 2019-06-23 21:02:08 +02:00
parent 5b59b4cd0f
commit 7a2b70c38d

View file

@ -799,11 +799,7 @@ const MenuEntry* vibratorMenuEntries[] = {
}; };
const MenuPage vibratoMenuPage = { const MenuPage vibratoMenuPage = {
"VIBRATO", "VIBRATO", 0, CursorIdx::EVibrato, SETUP_CT_MENU, ARR_LEN(vibratorMenuEntries), vibratorMenuEntries
0,
CursorIdx::EVibrato,
SETUP_CT_MENU,
ARR_LEN(vibratorMenuEntries), vibratorMenuEntries
}; };
//*********************************************************** //***********************************************************
@ -936,7 +932,6 @@ static bool updateMenuPage(const MenuPage *page, KeyState &input, uint32_t timeN
break; break;
case BTN_MENU: case BTN_MENU:
Serial.print("back to parent...");
menuState= page->parentPage; menuState= page->parentPage;
stateFirstRun = 1; stateFirstRun = 1;
break; break;
@ -961,9 +956,6 @@ static bool updateMenuPage(const MenuPage *page, KeyState &input, uint32_t timeN
return redraw; return redraw;
} }
static void checkForPatchView(int buttons);
static bool updatePage(const MenuPage *page, KeyState &input, uint32_t timeNow) { static bool updatePage(const MenuPage *page, KeyState &input, uint32_t timeNow) {
if(page->flags & EMenuPageCustom) { if(page->flags & EMenuPageCustom) {
auto custom = (const MenuPageCustom*)page; auto custom = (const MenuPageCustom*)page;
@ -981,40 +973,32 @@ static bool updatePage(const MenuPage *page, KeyState &input, uint32_t timeNow)
} else { } else {
redraw = updateMenuPage(page, input, timeNow); redraw = updateMenuPage(page, input, timeNow);
if((page->flags & EMenuPageRoot) && input.changed) if((page->flags & EMenuPageRoot) && input.changed) {
checkForPatchView(input.current); int trills = readTrills();
} switch (input.current) {
case BTN_MENU+BTN_ENTER:
if (trills) {
menuState = PATCH_VIEW;
stateFirstRun = 1;
setFPS(trills, patch);
}
break;
case BTN_MENU+BTN_UP:
if (trills) {
menuState = PATCH_VIEW;
stateFirstRun = 1;
clearFPS(trills);
}
break;
default: break;
}
}
}
return redraw; return redraw;
} }
//***********************************************************
static void checkForPatchView(int buttons) {
int trills = readTrills();
switch (buttons) {
case BTN_MENU+BTN_ENTER:
if (trills) {
menuState= PATCH_VIEW;
stateFirstRun = 1;
setFPS(trills, patch);
}
break;
case BTN_MENU+BTN_UP:
if (trills) {
menuState= PATCH_VIEW;
stateFirstRun = 1;
clearFPS(trills);
}
break;
default: break;
}
}
//*********************************************************** //***********************************************************
// This should be moved to a separate file/process that handles only led // This should be moved to a separate file/process that handles only led
static void statusBlink() { static void statusBlink() {
@ -1083,7 +1067,6 @@ static bool patchPageUpdate(KeyState& input, uint32_t timeNow) {
int trills = readTrills(); int trills = readTrills();
switch (input.current){ switch (input.current){
case BTN_DOWN: case BTN_DOWN:
// down
if (trills && (fastPatch[trills-1] > 0)){ if (trills && (fastPatch[trills-1] > 0)){
patch = fastPatch[trills-1]; patch = fastPatch[trills-1];
activePatch = 0; activePatch = 0;
@ -1101,8 +1084,8 @@ static bool patchPageUpdate(KeyState& input, uint32_t timeNow) {
drawPatchView(); drawPatchView();
redraw = true; redraw = true;
break; break;
case BTN_ENTER: case BTN_ENTER:
// enter
if (trills && (fastPatch[trills-1] > 0)){ if (trills && (fastPatch[trills-1] > 0)){
patch = fastPatch[trills-1]; patch = fastPatch[trills-1];
activePatch = 0; activePatch = 0;
@ -1112,8 +1095,8 @@ static bool patchPageUpdate(KeyState& input, uint32_t timeNow) {
redraw = true; redraw = true;
} }
break; break;
case BTN_UP: case BTN_UP:
// up
if (trills && (fastPatch[trills-1] > 0)){ if (trills && (fastPatch[trills-1] > 0)){
patch = fastPatch[trills-1]; patch = fastPatch[trills-1];
activePatch = 0; activePatch = 0;
@ -1239,9 +1222,9 @@ static KeyState readInput(uint32_t timeNow) {
static uint8_t lastDeumButtons = 0; static uint8_t lastDeumButtons = 0;
static uint8_t deumButtonState = 0; static uint8_t deumButtonState = 0;
KeyState keys = { deumButtonState, 0 }; KeyState keys = { deumButtonState, 0 };
// read the state of the switches (note that they are active low, so we invert the values)
uint8_t deumButtons = 0x0f ^(digitalRead(dPin) | (digitalRead(ePin) << 1) | (digitalRead(uPin) << 2) | (digitalRead(mPin)<<3)); uint8_t deumButtons = 0x0f ^(digitalRead(dPin) | (digitalRead(ePin) << 1) | (digitalRead(uPin) << 2) | (digitalRead(mPin)<<3));
// check to see if you just pressed the button // check to see if you just pressed the button
@ -1287,7 +1270,6 @@ void menu() {
bool redraw = stateFirstRun; bool redraw = stateFirstRun;
KeyState input = readInput(timeNow); KeyState input = readInput(timeNow);
// read the state of the switches
// shut off menu system if not used for a while (changes not stored by exiting a setting manually will not be stored in EEPROM) // shut off menu system if not used for a while (changes not stored by exiting a setting manually will not be stored in EEPROM)
if (menuState&& ((timeNow - menuTime) > menuTimeUp)) { if (menuState&& ((timeNow - menuTime) > menuTimeUp)) {