refactored

This commit is contained in:
Ronald Schaten 2022-02-01 18:39:59 +01:00
parent 9b76d6766a
commit d92f47ee26

View File

@ -98,69 +98,69 @@ NAVROOT(nav, mainMenu, MAX_DEPTH, in, out);
// === // ===
void ButtonHandler(const ButtonParam& param) { void ButtonHandler_menu(const ButtonParam& param) {
Serial.print("ButtonHandler_menu(");
Serial.print(param.button); Serial.print(param.button);
Serial.print(" "); Serial.println(")");
switch (state) { switch (param.state) {
case STATE_MENU: case ButtonState_Click:
Serial.print("menu - "); Serial.print("Click");
switch (param.state) { switch (param.button) {
case ButtonState_Click: case KEY_UP:
Serial.print("Click"); nav.doNav(upCmd);
switch (param.button) { break;
case KEY_RIGHT: case KEY_DOWN:
break; nav.doNav(downCmd);
case KEY_UP: break;
nav.doNav(upCmd); case KEY_SELECT:
break; nav.doNav(enterCmd);
case KEY_DOWN: break;
nav.doNav(downCmd); }
break; nav.doOutput();
case KEY_LEFT: break;
break; }
case KEY_SELECT: }
nav.doNav(enterCmd);
break; void ButtonHandler_jog(const ButtonParam& param) {
} Serial.print("ButtonHandler_jog(");
Serial.print(param.button);
Serial.println(")");
switch (param.state) {
case ButtonState_Up:
Serial.print("Up");
break;
case ButtonState_Down:
Serial.print("Down");
break;
case ButtonState_Click:
Serial.print("Click");
switch (param.button) {
case KEY_UP:
stepper.startRotate(-30);
break;
case KEY_DOWN:
stepper.startRotate(30);
break;
case KEY_SELECT:
state = STATE_MENU;
nav.doNav(leftCmd);
nav.doOutput(); nav.doOutput();
break; break;
} }
break; break;
case STATE_JOG: case ButtonState_DoubleClick:
Serial.print("jogging - "); Serial.print("Double Click");
switch (param.state) { break;
case ButtonState_Up: case ButtonState_Hold:
Serial.print("Up"); Serial.print("Hold");
break;
case ButtonState_Down:
Serial.print("Down");
break;
case ButtonState_Click:
Serial.print("Click");
switch (param.button) {
case KEY_UP:
stepper.startRotate(-30);
break;
case KEY_DOWN:
stepper.startRotate(30);
break;
case KEY_SELECT:
state = STATE_MENU;
nav.doNav(leftCmd);
nav.doOutput();
break;
}
break;
case ButtonState_DoubleClick:
Serial.print("Double Click");
break;
case ButtonState_Hold:
Serial.print("Hold");
break;
}
break; break;
} }
Serial.println(); }
void ButtonHandler_run(const ButtonParam& param) {
Serial.print("ButtonHandler_run(");
Serial.print(param.button);
Serial.println(")");
} }
void setup() { void setup() {
@ -183,6 +183,16 @@ void setup() {
} }
void loop() { void loop() {
keypad.loop(ButtonHandler); switch (state) {
case STATE_MENU:
keypad.loop(ButtonHandler_menu);
break;
case STATE_JOG:
keypad.loop(ButtonHandler_jog);
break;
case STATE_RUN:
keypad.loop(ButtonHandler_run);
break;
}
stepper.nextAction(); stepper.nextAction();
} }