implement and react to jog mode

This commit is contained in:
Ronald Schaten 2022-01-30 21:00:05 +01:00
parent 19d263deb7
commit 56b1ca8627

View File

@ -58,6 +58,9 @@ LiquidCrystal lcd(PIN_LCD_RS, PIN_LCD_EN, PIN_LCD_DB4, PIN_LCD_DB5, PIN_LCD_DB6,
BasicStepperDriver stepper(STEPPER_STEPS, PIN_STEPPER_DIR, PIN_STEPPER_STEP); BasicStepperDriver stepper(STEPPER_STEPS, PIN_STEPPER_DIR, PIN_STEPPER_STEP);
enum State { MENU, JOG, RUN };
State state = MENU;
// === // ===
result doAlert(eventMask e, prompt &item); result doAlert(eventMask e, prompt &item);
@ -122,18 +125,18 @@ MENU(subMenu,"Sub-Menu",doNothing,anyEvent,wrapStyle
,EXIT("<Back") ,EXIT("<Back")
); );
MENU(mainMenu,"Main menu",doNothing,noEvent,wrapStyle MENU(mainMenu, "PhotoStepper", doNothing, noEvent, wrapStyle
,OP("Op1",action1,anyEvent) //,SUBMENU(subMenu)
,OP("Op2",action2,enterEvent) ,OP("Op1", action1, anyEvent)
,FIELD(test,"Test","%",0,100,10,1,doNothing,noEvent,wrapStyle) //,OP("Op2",action2,enterEvent)
,SUBMENU(subMenu) //,FIELD(test,"Test","%",0,100,10,1,doNothing,noEvent,wrapStyle)
,SUBMENU(setLed) //,SUBMENU(setLed)
,OP("LED On",myLedOn,enterEvent) //,OP("LED On",myLedOn,enterEvent)
,OP("LED Off",myLedOff,enterEvent) //,OP("LED Off",myLedOff,enterEvent)
,SUBMENU(selMenu) //,SUBMENU(selMenu)
,SUBMENU(chooseMenu) //,SUBMENU(chooseMenu)
,OP("Alert test",doAlert,enterEvent) ,OP("Alert test",doAlert,enterEvent)
,EXIT("<Back") //,EXIT("<Back")
); );
MENU_OUTPUTS(out,MAX_DEPTH MENU_OUTPUTS(out,MAX_DEPTH
@ -152,7 +155,7 @@ result alert(menuOut& o,idleEvent e) {
o.setCursor(0,1); o.setCursor(0,1);
o.print("[select] to continue..."); o.print("[select] to continue...");
Serial.println("rotating..."); Serial.println("rotating...");
stepper.startRotate(360); state = JOG;
} }
return proceed; return proceed;
} }
@ -173,41 +176,64 @@ result idle(menuOut& o,idleEvent e) {
// === // ===
void ButtonHandler(const ButtonParam& param) void ButtonHandler(const ButtonParam& param) {
{
Serial.print(param.button); Serial.print(param.button);
Serial.print(" "); Serial.print(" ");
switch (param.state) { switch (state) {
case ButtonState_Up: case MENU:
Serial.print("Up"); switch (param.state) {
break; case ButtonState_Click:
case ButtonState_Down: Serial.print("Click");
Serial.print("Down"); switch (param.button) {
break; case 0: // right
case ButtonState_Click: break;
Serial.print("Click"); case 1: // up
switch (param.button) { nav.doNav(upCmd);
case 0: // right break;
break; case 2: // down
case 1: // up nav.doNav(downCmd);
nav.doNav(upCmd); break;
break; case 3: // left
case 2: // down break;
nav.doNav(downCmd); case 4: // select
break; nav.doNav(enterCmd);
case 3: // left break;
break; }
case 4: // select nav.doOutput();
nav.doNav(enterCmd);
break; break;
} }
nav.doOutput();
break; break;
case ButtonState_DoubleClick: case JOG:
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 1: // up
stepper.startRotate(-30);
break;
case 2: // down
stepper.startRotate(30);
break;
case 4: // select
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(); Serial.println();