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,17 +176,12 @@ 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 (state) {
case MENU:
switch (param.state) { switch (param.state) {
case ButtonState_Up:
Serial.print("Up");
break;
case ButtonState_Down:
Serial.print("Down");
break;
case ButtonState_Click: case ButtonState_Click:
Serial.print("Click"); Serial.print("Click");
switch (param.button) { switch (param.button) {
@ -203,6 +201,32 @@ void ButtonHandler(const ButtonParam& param)
} }
nav.doOutput(); nav.doOutput();
break; break;
}
break;
case JOG:
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 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: case ButtonState_DoubleClick:
Serial.print("Double Click"); Serial.print("Double Click");
break; break;
@ -210,6 +234,8 @@ void ButtonHandler(const ButtonParam& param)
Serial.print("Hold"); Serial.print("Hold");
break; break;
} }
break;
}
Serial.println(); Serial.println();
} }