Interrupt/Watchdog Window

This commit is contained in:
2024-05-15 13:46:42 +02:00
parent 0b932966c5
commit 073ad3dada
3 changed files with 24 additions and 10 deletions

View File

@ -8,7 +8,11 @@ import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.FileChooser;
import java.io.File;
@ -81,12 +85,26 @@ public class Controller_Frontend {
private static volatile boolean isAutoRunActive = true;
private static volatile boolean isSleeping = false;
public static void stopRunFromBackend(){
public static void stopRunFromBackend(String message){
isAutoRunActive = false;
if (isSleeping)
isSleeping = false;
else
DataRegister.resetPC();
Stage stoppedStage = new Stage();
stoppedStage.setTitle("Programm unterbrochen!");
VBox vbox = new VBox();
vbox.setAlignment(javafx.geometry.Pos.CENTER);
Label grundlabel = new Label("Grund: " + message);
grundlabel.setStyle("-fx-font-size: 16px; -fx-font-weight: bold;");
Label ueberlabel = new Label("Programm unterbrochen!");
vbox.getChildren().add(ueberlabel);
vbox.getChildren().add(grundlabel);
VBox.setMargin(grundlabel, new javafx.geometry.Insets(10, 10, 10, 10));
Scene scene = new Scene(vbox, 300, 90);
stoppedStage.setAlwaysOnTop(true);
stoppedStage.setScene(scene);
stoppedStage.show();
}
public static void sleep() {
@ -116,7 +134,7 @@ public class Controller_Frontend {
e.printStackTrace();
}
});
Thread.sleep(50); //Verzögerungszeit in Millisekunden
Thread.sleep(20); //Verzögerungszeit in Millisekunden
}
} catch (InterruptedException e) {
e.printStackTrace();
@ -124,8 +142,6 @@ public class Controller_Frontend {
});
autoRunThread.setDaemon(true);
autoRunThread.start();
}
@ -152,9 +168,9 @@ public class Controller_Frontend {
String selectedRowStyle;
if (!isSleeping)
selectedRowStyle = "-fx-background-color: red;";
selectedRowStyle = "-fx-background-color: red; -fx-text-fill: white;";
else
selectedRowStyle = "-fx-background-color: teal;";
selectedRowStyle = "-fx-background-color: teal; -fx-text-fill: white;";
lstContentListView.setCellFactory(column -> new ListCell<String>() {
@Override
protected void updateItem(String item, boolean empty) {

View File

@ -12,12 +12,10 @@ public class WatchdogTimer {
public static void testAndTrigger() {
watchdogTime = getTimeFromRegister() * 1000;
if (enabled) {
System.err.println("Remaining: " + ((watchdogTime + lastReset - 1) - Commands.getTotalExecutionTime()));
if (Commands.getTotalExecutionTime() >= (watchdogTime + lastReset - 1)) {
System.err.println("Watchdog Timer triggered");
DataRegister.clearBit(3, 4);
lastReset = Commands.getTotalExecutionTime();
Controller_Frontend.stopRunFromBackend();
Controller_Frontend.stopRunFromBackend("Watchdog Timer");
}
}
}

View File

@ -46,7 +46,7 @@
</HBox>
<VBox layoutX="14.0" layoutY="727.0">
<children>
<Label fx:id="totalExecutionTimeLabel" text="Total Execution Time: 0µs" />
<Label fx:id="totalExecutionTimeLabel" text="Total Execution Time: 0µs"/>
<CheckBox fx:id="wdtCheck" mnemonicParsing="false" onAction="#toggleWatchdog" text="Watchdog-Timer">
<VBox.margin>
<Insets top="10.0" />