This commit is contained in:
2024-05-16 10:01:22 +02:00
parent 073ad3dada
commit 8025de69a9
3 changed files with 405 additions and 7 deletions

View File

@ -3,6 +3,10 @@ package fabrik.simulator.pic16f84;
import com.gluonhq.charm.glisten.control.ToggleButtonGroup;
import javafx.collections.ObservableList;
import javafx.scene.control.ToggleButton;
import javafx.scene.paint.Color;
import javafx.scene.paint.RadialGradient;
import javafx.scene.paint.Stop;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;
import java.io.IOException;
@ -17,6 +21,10 @@ public class IOPorts {
private static int [] trisLatch = {0xFF, 0xFF};
private static int [] dataLatch = new int[2];
private static boolean isLEDenabledA = false;
private static boolean isLEDenabledB = false;
private static Circle[] allLEDsA;
private static Circle[] allLEDsB;
public static void setBit (int address, int bit){
if (address < 7) {
@ -76,6 +84,22 @@ public class IOPorts {
buttonsPORT[i].setDisable(!val);
buttonsTRIS[i].getToggles().get(0).setSelected(val);
buttonsTRIS[i].getToggles().get(1).setSelected(!val);
if(i < 8){
if (isLEDenabledA && !val){
if (DataRegister.getDirectBit(PORTA, i) == 1)
allLEDsA[i].setFill(new RadialGradient(0, 0, 0.5, 0.5, 0.7, true, null, new Stop(0, Color.BLACK), new Stop(1, Color.DARKGRAY)));
else
allLEDsA[i].setFill(new RadialGradient(0, 0, 0.5, 0.5, 0.7, true, null, new Stop(0, Color.BLACK), new Stop(1, Color.DARKGRAY)));
}
}
else{
if (isLEDenabledB){
if (DataRegister.getDirectBit(PORTB, i-8) == 1)
allLEDsB[i-8].setFill(new RadialGradient(0, 0, 0.5, 0.5, 0.7, true, null, new Stop(0, Color.RED), new Stop(1, Color.DARKGRAY)));
else
allLEDsB[i-8].setFill(new RadialGradient(0, 0, 0.5, 0.5, 0.7, true, null, new Stop(0, Color.BLACK), new Stop(1, Color.DARKGRAY)));
}
}
}
}
@ -112,6 +136,28 @@ public class IOPorts {
refreshTable(parent);
}
public static void setLEDs (boolean[] leds) {
boolean isAnowDisabled = isLEDenabledA && !leds[0];
isLEDenabledA = leds[0];
boolean isBnowDisabled = isLEDenabledB && !leds[1];
isLEDenabledB = leds[1];
if (isAnowDisabled){
for (int i = 0; i < allLEDsA.length; i++){
allLEDsA[i].setFill(new RadialGradient(0, 0, 0.5, 0.5, 0.7, true, null, new Stop(0, Color.BLACK), new Stop(1, Color.DARKGRAY)));
}
}
if (isBnowDisabled){
for (int i = 0; i < allLEDsB.length; i++){
allLEDsB[i].setFill(new RadialGradient(0, 0, 0.5, 0.5, 0.7, true, null, new Stop(0, Color.BLACK), new Stop(1, Color.DARKGRAY)));
}
}
}
public static void setLEDs (Circle[] a, Circle[] b){
allLEDsA = a;
allLEDsB = b;
}
private static void refreshTable(ToggleButtonGroup parent) throws IOException {
Stage stage = (Stage) parent.getScene().getWindow();
Table.refresh();