allows fsm dc values

This commit is contained in:
hneemann 2021-08-04 11:53:56 +02:00
parent 71e638c98f
commit fb7a2cbe73
5 changed files with 24 additions and 3 deletions

View File

@ -28,6 +28,7 @@ public class State extends Movable<State> {
private int radius;
private boolean isInitial;
private int initialAngle = 12;
private boolean defaultDC;
/**
* Creates a new state
@ -46,6 +47,7 @@ public class State extends Movable<State> {
this.number = other.number;
this.isInitial = other.isInitial;
this.initialAngle = other.initialAngle;
this.defaultDC = other.defaultDC;
setValues(other.getValues());
setPos(other.getPos());
}
@ -277,4 +279,12 @@ public class State extends Movable<State> {
}
};
}
public boolean isDefaultDC() {
return defaultDC;
}
public void setDefaultDC(boolean defaultDC) {
this.defaultDC = defaultDC;
}
}

View File

@ -115,8 +115,9 @@ public class TransitionTableCreator {
int row = s.getNumber();
int col = stateBits * 2;
for (String name : results) {
int def = s.isDefaultDC() ? 2 : 0;
Integer val = getValues(s).get(name);
int v = val == null ? 0 : val;
int v = val == null ? def : val;
truthTable.setValue(row, col, v);
col++;
}
@ -129,7 +130,10 @@ public class TransitionTableCreator {
int m = row;
for (int j = 0; j < stateBits; j++) {
c--;
truthTable.setValue(row, c, m & 1);
int aValue = 2;
if (!s.isDefaultDC())
aValue = m & 1;
truthTable.setValue(row, c, aValue);
m >>= 1;
}
}

View File

@ -31,6 +31,7 @@ import static de.neemann.digital.gui.components.CircuitComponent.ICON_DELETE;
public class FSMComponent extends JComponent {
private static final Key<Integer> KEY_NUMBER = new Key.KeyInteger("stateNum", 0);
private static final Key<Boolean> KEY_INITIAL = new Key<>("isInitialState", false);
private static final Key<Boolean> KEY_DEFAULT_DC = new Key<>("defaultsDC", false);
private static final Key<String> KEY_VALUES = new Key<>("stateValues", "");
private static final Key<String> KEY_CONDITION = new Key<>("transCond", "");
private static final Key<Integer> KEY_RADIUS = new Key.KeyInteger("transRad", 70)
@ -179,7 +180,7 @@ public class FSMComponent extends JComponent {
setPreferredSize(new Dimension(600, 600));
}
private static final Key<?>[] STATE_EDIT_KEYS = {Keys.LABEL, KEY_NUMBER, KEY_INITIAL, KEY_VALUES, KEY_RADIUS};
private static final Key<?>[] STATE_EDIT_KEYS = {Keys.LABEL, KEY_NUMBER, KEY_INITIAL, KEY_VALUES, KEY_RADIUS, KEY_DEFAULT_DC};
private void createNewState(Vector posVector, Point point) {
ElementAttributes attr = new ElementAttributes();
@ -207,6 +208,7 @@ public class FSMComponent extends JComponent {
ElementAttributes attr = new ElementAttributes()
.set(KEY_NUMBER, state.getNumber())
.set(KEY_INITIAL, state.isInitial())
.set(KEY_DEFAULT_DC, state.isDefaultDC())
.set(KEY_VALUES, state.getValues())
.set(KEY_RADIUS, state.getVisualRadius())
.set(Keys.LABEL, state.getName());
@ -218,6 +220,7 @@ public class FSMComponent extends JComponent {
if (newAttr != null) {
state.setNumber(newAttr.get(KEY_NUMBER));
state.setInitial(newAttr.get(KEY_INITIAL));
state.setDefaultDC(newAttr.get(KEY_DEFAULT_DC));
state.setValues(newAttr.get(KEY_VALUES));
state.setRadius(newAttr.get(KEY_RADIUS));
state.setName(newAttr.get(Keys.LABEL));

View File

@ -2426,6 +2426,8 @@ Sie dürfen jedoch nicht oberhalb der Kopfzeile mit den Signalnamen verwendet we
<string name="key_isInitialState_tt">Wenn gesetzt, ist dies der Initialzustand, in welchem der Automat gestartet
wird.
</string>
<string name="key_defaultsDC">Nicht definierte Werte auf DC setzen</string>
<string name="key_defaultsDC_tt">Setzt alle nicht definierten Werte (Folgezustand und Ausgänge) auf "Don't care"</string>
<string name="key_stateValues">Ausgänge</string>
<string name="key_stateValues_tt">Legt Ausgangswerte fest.
Mit einfachen Zuweisungen wie "A=1, B=0" können Ausgänge gesetzt werden.

View File

@ -2401,6 +2401,8 @@ However, they must not be used above the header line listing the signal names.</
<string name="key_stateNum_tt">The number which represents this state.</string>
<string name="key_isInitialState">Initial State</string>
<string name="key_isInitialState_tt">If set, this state is the initial state.</string>
<string name="key_defaultsDC">Set undefined values to DC</string>
<string name="key_defaultsDC_tt">Sets all undefined values (following state and outputs) to "Don't Care".</string>
<string name="key_stateValues">Outputs</string>
<string name="key_stateValues_tt">Defines the output values.
With simple assignments like "A=1, B=0" outputs can be set.