Migrate to Pshell 2.0

This commit is contained in:
alexgobbo
2025-08-08 10:51:04 +02:00
parent 578428d444
commit a8f0508daa
31 changed files with 493 additions and 486 deletions

View File

@@ -3,9 +3,10 @@
*/
import ch.psi.pshell.device.Device;
import ch.psi.pshell.ui.Panel;
import ch.psi.utils.State;
import ch.psi.utils.swing.SwingUtils;
import ch.psi.pshell.framework.Context;
import ch.psi.pshell.framework.Panel;
import ch.psi.pshell.utils.State;
import ch.psi.pshell.swing.SwingUtils;
import java.awt.Color;
import java.io.IOException;
import java.util.List;
@@ -26,7 +27,7 @@ public class Recovery extends Panel {
//Overridable callbacks
@Override
public void onInitialize(int runCount) {
getContext().setGlobal("recovering", null);
Context.setGlobal("recovering", null);
}
@Override
@@ -41,7 +42,7 @@ public class Recovery extends Panel {
}
void updateButton(){
buttonRecover.setEnabled((getContext().getState().isNormal()) &&
buttonRecover.setEnabled((Context.getState().isNormal()) &&
(textPosition.getText().trim().isEmpty()) &&
(!textSegment.getText().trim().isEmpty()) &&
!isRecovering()
@@ -50,7 +51,7 @@ public class Recovery extends Panel {
}
boolean isRecovering(){
return "true".equals(getContext().getGlobal("recovering"));
return "true".equals(Context.getGlobal("recovering"));
}
@Override
@@ -62,7 +63,7 @@ public class Recovery extends Panel {
@Override
protected void onTimer() {
System.out.println(".");
Device robot = getContext().getDevicePool().getByName("robot", Device.class);
Device robot = Context.getDevicePool().getByName("robot", Device.class);
if ((robot==null) || (!robot.getState().isNormal())){
System.out.println("*");
ledValidSegment.setColor(Color.BLACK);
@@ -225,27 +226,27 @@ public class Recovery extends Panel {
return;
}
buttonAbort.setEnabled(true);
getContext().setGlobal("recovering", "true");
Device robot = getContext().getDevicePool().getByName("robot", Device.class);
Context.setGlobal("recovering", "true");
Device robot = Context.getDevicePool().getByName("robot", Device.class);
abort();
getContext().waitState(State.Ready, 5000);
Context.waitState(State.Ready, 5000);
eval("robot.stop_task()", false);
robot.waitReady(5000);
evalAsync("recover()", false).handle((ret, ex) -> {
if (ex != null){
if (!getContext().isAborted()){
if (!Context.isAborted()){
showException((Exception)ex);
}
} else {
SwingUtils.showMessage(getTopLevel(), "Return", String.valueOf(ret));
}
getContext().setGlobal("recovering", null);
Context.setGlobal("recovering", null);
buttonAbort.setEnabled(false);
return ret;
});
} catch (Exception ex) {
showException(ex);
getContext().setGlobal("recovering", null);
Context.setGlobal("recovering", null);
buttonAbort.setEnabled(false);
}
}//GEN-LAST:event_buttonRecoverActionPerformed