7 Commits

3 changed files with 56 additions and 30 deletions

View File

@ -72,8 +72,6 @@ public class Controller_Frontend extends PICComponent implements FrontendControl
@FXML @FXML
private CheckBox wdtCheck; private CheckBox wdtCheck;
private static volatile boolean isAutoRunActive = false;
private static volatile boolean isSleeping = false;
public Controller_Frontend() { public Controller_Frontend() {
@ -82,55 +80,67 @@ public class Controller_Frontend extends PICComponent implements FrontendControl
} }
public boolean isSleeping (){
return isSleeping;
//Refactoring
public void stopRunFromBackend(String message) {
ExecutionState.setAutoRunActive(false);
handleSleepOrReset();
showStopDialog(message);
}
private void handleSleepOrReset() {
if (ExecutionState.isSleeping()) {
ExecutionState.wakeUp();
} else {
dataRegister.resetPC();
}
} }
public void stopRunFromBackend(String message){ private static void showStopDialog(String message) {
isAutoRunActive = false;
if (isSleeping)
wakeUpFromSleep();
else
dataRegister.resetPC();
Stage stoppedStage = new Stage(); Stage stoppedStage = new Stage();
stoppedStage.setTitle("Programm unterbrochen!"); stoppedStage.setTitle("Programm unterbrochen!");
VBox vbox = new VBox(); VBox vbox = new VBox();
vbox.setAlignment(javafx.geometry.Pos.CENTER); vbox.setAlignment(javafx.geometry.Pos.CENTER);
Label grundlabel = new Label("Grund: " + message); Label grundlabel = new Label("Grund: " + message);
grundlabel.setStyle("-fx-font-size: 16px; -fx-font-weight: bold;"); grundlabel.setStyle("-fx-font-size: 16px; -fx-font-weight: bold;");
Label ueberlabel = new Label("Programm unterbrochen!"); Label ueberlabel = new Label("Programm unterbrochen!");
vbox.getChildren().add(ueberlabel); vbox.getChildren().addAll(ueberlabel, grundlabel);
vbox.getChildren().add(grundlabel);
VBox.setMargin(grundlabel, new javafx.geometry.Insets(10, 10, 10, 10)); VBox.setMargin(grundlabel, new javafx.geometry.Insets(10, 10, 10, 10));
Scene scene = new Scene(vbox, 300, 90); Scene scene = new Scene(vbox, 300, 90);
stoppedStage.setAlwaysOnTop(true); stoppedStage.setAlwaysOnTop(true);
stoppedStage.setScene(scene); stoppedStage.setScene(scene);
stoppedStage.show(); stoppedStage.show();
} }
public void sleep() {
isSleeping = true;
}
public void wakeUpFromSleep() {
isSleeping = false; //Refactoring Ende
}
@FXML @FXML
private void stopAutoRun(ActionEvent event) { private void stopAutoRun(ActionEvent event) {
isAutoRunActive = false; ExecutionState.setAutoRunActive(false);
} }
@FXML @FXML
public void autoRunGUI(ActionEvent event) { public void autoRunGUI(ActionEvent event) {
if (!isAutoRunActive) { if (!ExecutionState.isAutoRunActive()) {
isAutoRunActive = true; ExecutionState.setAutoRunActive(true) ;
} }
Thread autoRunThread = new Thread(() -> { Thread autoRunThread = new Thread(() -> {
try { try {
while (dataRegister.getPC() < prog.length && isAutoRunActive){ while (dataRegister.getPC() < prog.length && ExecutionState.isAutoRunActive()){
Platform.runLater(() -> { Platform.runLater(() -> {
try { try {
@ -150,6 +160,7 @@ public class Controller_Frontend extends PICComponent implements FrontendControl
} }
private void updateExecutionTimeMultiplier() { private void updateExecutionTimeMultiplier() {
String selectedOption = executionTimeComboBox.getValue(); String selectedOption = executionTimeComboBox.getValue();
commands.setExecutionTimeMultiplier(selectedOption); commands.setExecutionTimeMultiplier(selectedOption);
@ -164,7 +175,7 @@ public class Controller_Frontend extends PICComponent implements FrontendControl
int currentIndex; int currentIndex;
// Aktuelle Zeile abrufen // Aktuelle Zeile abrufen
if (!isSleeping) if (!ExecutionState.isSleeping())
currentIndex = ind[dataRegister.getPC()]; currentIndex = ind[dataRegister.getPC()];
else else
currentIndex = ind[dataRegister.getPC()]-1; currentIndex = ind[dataRegister.getPC()]-1;
@ -193,14 +204,14 @@ public class Controller_Frontend extends PICComponent implements FrontendControl
lstContentListView.getSelectionModel().select(currentIndex); lstContentListView.getSelectionModel().select(currentIndex);
String selectedRowStyle; String selectedRowStyle;
if (!isSleeping) if (!ExecutionState.isSleeping())
selectedRowStyle = "-fx-background-color: red; -fx-text-fill: white;"; selectedRowStyle = "-fx-background-color: red; -fx-text-fill: white;";
else else
selectedRowStyle = "-fx-background-color: teal; -fx-text-fill: white;"; selectedRowStyle = "-fx-background-color: teal; -fx-text-fill: white;";
markSelectedRow(currentIndex, selectedRowStyle); markSelectedRow(currentIndex, selectedRowStyle);
if (!isSleeping) { if (!ExecutionState.isSleeping()) {
commands.decode(prog[dataRegister.getPC()]); commands.decode(prog[dataRegister.getPC()]);
dataRegister.increasePC(); dataRegister.increasePC();
} }
@ -268,7 +279,7 @@ public class Controller_Frontend extends PICComponent implements FrontendControl
} catch (NullPointerException ignored) {} } catch (NullPointerException ignored) {}
} }
programStack.reset(); programStack.reset();
wakeUpFromSleep(); ExecutionState.wakeUp();
breakpoints.clear(); breakpoints.clear();
ioPorts.refreshUI(getTRISbuttons(), getPORTbuttons()); ioPorts.refreshUI(getTRISbuttons(), getPORTbuttons());
commands.resetTotalExecutionTime(); commands.resetTotalExecutionTime();

View File

@ -0,0 +1,19 @@
package fabrik.simulator.pic16f84;
public class ExecutionState {
private static boolean isAutoRunActive = false;
private static boolean isSleeping = false;
private static double executionTimeMultiplier = 1;
public static boolean isAutoRunActive() { return isAutoRunActive; }
public static void setAutoRunActive(boolean active) { isAutoRunActive = active; }
public static boolean isSleeping() { return isSleeping; }
public static void sleep() { isSleeping = true; }
public static void wakeUp() { isSleeping = false; }
public static double getExecutionTimeMultiplier() { return executionTimeMultiplier; }
public static void setExecutionTimeMultiplier(double multiplier) { executionTimeMultiplier = multiplier; }
}

View File

@ -2,11 +2,7 @@ package fabrik.simulator.pic16f84.interfaces;
public interface FrontendControllerInterface extends PICComponentInterface { public interface FrontendControllerInterface extends PICComponentInterface {
void sleep();
void wakeUpFromSleep();
boolean isSleeping();
void stopRunFromBackend(String watchdogTimer); void stopRunFromBackend(String watchdogTimer);
} }