moved real time clock enable to clock element

This commit is contained in:
hneemann 2016-04-12 22:10:19 +02:00
parent 3aecf4150f
commit 0ffd7f1705
8 changed files with 1062 additions and 19 deletions

1001
src/main/dig/bcd.hex Normal file

File diff suppressed because it is too large Load Diff

View File

@ -35,10 +35,11 @@ public class AttributeKey<VALUE> {
public static final AttributeKey<Boolean> ShowDataTable = new AttributeKey<>("showDataTable", Lang.get("key_showDataTable"), false);
public static final AttributeKey<Boolean> ShowDataGraph = new AttributeKey<>("showDataGraph", Lang.get("key_showDataGraph"), false);
public static final AttributeKey<Boolean> StartTimer = new AttributeKey<>("startTimer", Lang.get("key_startClock"), false);
//public static final AttributeKey<Boolean> StartTimer = new AttributeKey<>("startTimer", Lang.get("key_startClock"), false);
public static final AttributeKey<Boolean> MicroStep = new AttributeKey<>("microStep", Lang.get("key_microStep"), false);
public static final AttributeKey<Boolean> IsHighZ = new AttributeKey<>("isHighZ", Lang.get("key_isHighZ"), false);
public static final AttributeKey<Boolean> RunAtRealTime = new AttributeKey<>("runRealTime", Lang.get("key_runRealTime"), false);
private final String key;
private final VALUE def;

View File

@ -14,20 +14,32 @@ import de.neemann.digital.lang.Lang;
*/
public class Clock implements Element {
/**
* the clocks description
*/
public static final ElementTypeDescription DESCRIPTION = new ElementTypeDescription("Clock", Clock.class)
.addAttribute(AttributeKey.Rotate)
.addAttribute(AttributeKey.Label)
.addAttribute(AttributeKey.RunAtRealTime)
.addAttribute(AttributeKey.Frequency);
private final ObservableValue output;
private final int frequency;
private final String label;
/**
* Creates a new instance
*
* @param attributes the clocks attributes
*/
public Clock(ElementAttributes attributes) {
output = new ObservableValue("C", 1);
int f = attributes.get(AttributeKey.Frequency);
if (f < 1) f = 1;
frequency = f;
if (attributes.get(AttributeKey.RunAtRealTime)) {
int f = attributes.get(AttributeKey.Frequency);
if (f < 1) f = 1;
frequency = f;
} else
frequency = 0;
label = attributes.get(AttributeKey.Label);
}
@ -47,10 +59,16 @@ public class Clock implements Element {
model.addSignal(label, output);
}
/**
* @return the clock output value
*/
public ObservableValue getClockOutput() {
return output;
}
/**
* @return the clocks frequency
*/
public int getFrequency() {
return frequency;
}

View File

@ -50,9 +50,6 @@ public class ElementLibrary implements Iterable<ElementLibrary.ElementContainer>
add(Out.LEDDESCRIPTION, menu);
add(Button.DESCRIPTION, menu);
add(Probe.DESCRIPTION, menu);
add(Clock.DESCRIPTION, menu);
add(Reset.DESCRIPTION, menu);
add(Break.DESCRIPTION, menu);
add(Out.SEVENDESCRIPTION, menu);
add(Out.SEVENHEXDESCRIPTION, menu);
add(Terminal.DESCRIPTION, menu);
@ -64,10 +61,13 @@ public class ElementLibrary implements Iterable<ElementLibrary.ElementContainer>
add(Decoder.DESCRIPTION, menu);
menu = Lang.get("lib_wires");
add(Splitter.DESCRIPTION, menu);
add(Const.DESCRIPTION, menu);
add(Splitter.DESCRIPTION, menu);
add(Clock.DESCRIPTION, menu);
add(Delay.DESCRIPTION, menu);
add(Driver.DESCRIPTION, menu);
add(Reset.DESCRIPTION, menu);
add(Break.DESCRIPTION, menu);
menu = Lang.get("lib_flipFlops");
add(RS_FF.DESCRIPTION, menu);

View File

@ -19,9 +19,16 @@ import static de.neemann.digital.draw.shapes.OutputShape.SIZE;
* @author hneemann
*/
public class ClockShape implements Shape {
private static final int WI = SIZE / 2;
private static final Vector POS = new Vector(-SIZE * 2 + WI / 2, WI / 2);
private final String label;
/**
* Creates a new instance
*
* @param attr
*/
public ClockShape(ElementAttributes attr) {
this.label = attr.getLabel();
}
@ -49,7 +56,19 @@ public class ClockShape implements Shape {
@Override
public void drawTo(Graphic graphic, boolean heighLight) {
graphic.drawPolygon(new Polygon(true).add(-SIZE * 2 - 1, -SIZE).add(-1, -SIZE).add(-1, SIZE).add(-SIZE * 2 - 1, SIZE), Style.NORMAL);
graphic.drawPolygon(new Polygon(true)
.add(-SIZE * 2 - 1, -SIZE)
.add(-1, -SIZE)
.add(-1, SIZE)
.add(-SIZE * 2 - 1, SIZE), Style.NORMAL);
graphic.drawPolygon(new Polygon(false)
.add(POS)
.add(POS.add(WI, 0))
.add(POS.add(WI, -WI))
.add(POS.add(2 * WI, -WI))
.add(POS.add(2 * WI, 0))
.add(POS.add(3 * WI, 0)), Style.THIN);
Vector textPos = new Vector(-SIZE * 3, 0);
graphic.drawText(textPos, textPos.add(1, 0), label, Orientation.RIGHTCENTER, Style.NORMAL);

View File

@ -45,7 +45,6 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
private static final ArrayList<AttributeKey> ATTR_LIST = new ArrayList<>();
static {
ATTR_LIST.add(AttributeKey.StartTimer);
ATTR_LIST.add(AttributeKey.ShowDataTable);
ATTR_LIST.add(AttributeKey.ShowDataGraph);
ATTR_LIST.add(AttributeKey.ShowListing);
@ -376,7 +375,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
@Override
public void enter() {
super.enter();
if (createAndStartModel(settings.get(AttributeKey.StartTimer), ModelEvent.STEP))
if (createAndStartModel(true, ModelEvent.STEP))
circuitComponent.setManualChangeObserver(new FullStepObserver(model));
}
});
@ -418,12 +417,21 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
}
private boolean createAndStartModel(boolean runClock, ModelEvent updateEvent) {
private boolean createAndStartModel(boolean globalRunClock, ModelEvent updateEvent) {
try {
circuitComponent.removeHighLighted();
circuitComponent.setModeAndReset(true);
setModelDescription(new ModelDescription(circuitComponent.getCircuit(), library));
boolean runClock = false;
if (globalRunClock)
for (Clock c : model.getClocks())
if (c.getFrequency() > 0) {
model.addObserver(new RealTimeClock(model, c, timerExecuter, this));
runClock = true;
}
if (runClock) {
// if clock is running, enable automatic update of gui
GuiModelObserver gmo = new GuiModelObserver(circuitComponent, updateEvent);
@ -433,11 +441,6 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
// all repainting is initiated by user actions!
modelDescription.connectToGui(null);
if (runClock) {
for (Clock c : model.getClocks())
model.addObserver(new RealTimeClock(model, c, timerExecuter, this));
}
runToBreak.setEnabled(!runClock && model.isFastRunModel());
List<String> ordering = circuitComponent.getCircuit().getMeasurementOrdering();

View File

@ -35,9 +35,10 @@ key_valueIsProbe=Als Messwert verwenden
key_showListing=Zeige Listing an, wenn verf\u00FCgbar
key_showDataTable=Zeige Messwertetabelle
key_showDataGraph=Zeige Messwertegraph
key_startClock=Starte den Takt
key_microStep=Zeige Mikroschritte
key_isHighZ=Eingang kann hochohmig sein
key_runRealTime=Echtzeittakt starten
rot_0=0\u00B0
rot_90=90\u00B0

View File

@ -35,9 +35,9 @@ key_valueIsProbe=Use as measurment value
key_showListing=Show list file if available
key_showDataTable=Show measurement values
key_showDataGraph=Show measurement graph
key_startClock=Start timer
key_microStep=Show micro steps
key_isHighZ=Is three-state input
key_runRealTime=Start real time clock
rot_0=0\u00B0
rot_90=90\u00B0