mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-27 15:03:21 -04:00
added a common cathode input to the seven segment display.
This commit is contained in:
parent
390391c3a4
commit
d0a37fc239
@ -274,4 +274,16 @@ public final class Keys {
|
|||||||
public static final Key<Boolean> RELAY_NORMALLY_CLOSED
|
public static final Key<Boolean> RELAY_NORMALLY_CLOSED
|
||||||
= new Key<>("relayNormallyClosed", false);
|
= new Key<>("relayNormallyClosed", false);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to indicate if the 7-seg display has a common cathode output
|
||||||
|
*/
|
||||||
|
public static final Key<Boolean> COMMON_CATHODE
|
||||||
|
= new Key<>("commonCathode", false);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to enable the storage of the last state in the Seven Seg display.
|
||||||
|
*/
|
||||||
|
public static final Key<Boolean> LED_PERSISTENCE
|
||||||
|
= new Key<>("ledPersistence", false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ public class PinDescriptions extends ImmutableList<PinDescription> {
|
|||||||
* @param key the key to set
|
* @param key the key to set
|
||||||
* @return this for chained calls
|
* @return this for chained calls
|
||||||
*/
|
*/
|
||||||
PinDescriptions setLangKey(String key) {
|
public PinDescriptions setLangKey(String key) {
|
||||||
for (PinDescription pd : this) {
|
for (PinDescription pd : this) {
|
||||||
if (pd instanceof PinInfo) {
|
if (pd instanceof PinInfo) {
|
||||||
((PinInfo) pd).setLangKey(key);
|
((PinInfo) pd).setLangKey(key);
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
package de.neemann.digital.core.io;
|
package de.neemann.digital.core.io;
|
||||||
|
|
||||||
import de.neemann.digital.core.*;
|
import de.neemann.digital.core.*;
|
||||||
import de.neemann.digital.core.element.Element;
|
import de.neemann.digital.core.element.*;
|
||||||
import de.neemann.digital.core.element.ElementAttributes;
|
|
||||||
import de.neemann.digital.core.element.ElementTypeDescription;
|
|
||||||
import de.neemann.digital.core.element.Keys;
|
|
||||||
|
|
||||||
import static de.neemann.digital.core.element.PinInfo.input;
|
import static de.neemann.digital.core.element.PinInfo.input;
|
||||||
|
|
||||||
@ -47,23 +44,14 @@ public class Out implements Element {
|
|||||||
/**
|
/**
|
||||||
* The seven segment display description
|
* The seven segment display description
|
||||||
*/
|
*/
|
||||||
public static final ElementTypeDescription SEVENDESCRIPTION
|
public static final ElementTypeDescription SEVENDESCRIPTION = new SevenSegTypeDescription();
|
||||||
= new ElementTypeDescription("Seven-Seg",
|
|
||||||
attributes -> {
|
|
||||||
return new Out(1, 1, 1, 1, 1, 1, 1, 1);
|
|
||||||
},
|
|
||||||
input("a"), input("b"), input("c"), input("d"), input("e"), input("f"), input("g"), input("dp"))
|
|
||||||
.addAttribute(Keys.LABEL)
|
|
||||||
.addAttribute(Keys.COLOR);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The seven segment hex display description
|
* The seven segment hex display description
|
||||||
*/
|
*/
|
||||||
public static final ElementTypeDescription SEVENHEXDESCRIPTION
|
public static final ElementTypeDescription SEVENHEXDESCRIPTION
|
||||||
= new ElementTypeDescription("Seven-Seg-Hex",
|
= new ElementTypeDescription("Seven-Seg-Hex",
|
||||||
attributes -> {
|
attributes -> new Out(4, 1), input("d"), input("dp"))
|
||||||
return new Out(4, 1);
|
|
||||||
}, input("d"), input("dp"))
|
|
||||||
.addAttribute(Keys.LABEL)
|
.addAttribute(Keys.LABEL)
|
||||||
.addAttribute(Keys.COLOR);
|
.addAttribute(Keys.COLOR);
|
||||||
|
|
||||||
@ -112,4 +100,33 @@ public class Out implements Element {
|
|||||||
public void registerNodes(Model model) {
|
public void registerNodes(Model model) {
|
||||||
model.addOutput(new Signal(label, value).setDescription(description));
|
model.addOutput(new Signal(label, value).setDescription(description));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final static class SevenSegTypeDescription extends ElementTypeDescription {
|
||||||
|
private SevenSegTypeDescription() {
|
||||||
|
super("Seven-Seg", attributes -> {
|
||||||
|
if (attributes.get(Keys.COMMON_CATHODE))
|
||||||
|
return new Out(1, 1, 1, 1, 1, 1, 1, 1, 1);
|
||||||
|
else
|
||||||
|
return new Out(1, 1, 1, 1, 1, 1, 1, 1);
|
||||||
|
});
|
||||||
|
addAttribute(Keys.LABEL);
|
||||||
|
addAttribute(Keys.COLOR);
|
||||||
|
addAttribute(Keys.COMMON_CATHODE);
|
||||||
|
addAttribute(Keys.LED_PERSISTENCE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PinDescriptions getInputDescription(ElementAttributes attributes) throws NodeException {
|
||||||
|
if (attributes.get(Keys.COMMON_CATHODE)) {
|
||||||
|
return new PinDescriptions(
|
||||||
|
input("a"), input("b"), input("c"),
|
||||||
|
input("d"), input("e"), input("f"),
|
||||||
|
input("g"), input("dp"), input("cc")).setLangKey(getPinLangKey());
|
||||||
|
} else
|
||||||
|
return new PinDescriptions(
|
||||||
|
input("a"), input("b"), input("c"),
|
||||||
|
input("d"), input("e"), input("f"),
|
||||||
|
input("g"), input("dp")).setLangKey(getPinLangKey());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,13 +4,17 @@ import de.neemann.digital.core.ObservableValue;
|
|||||||
import de.neemann.digital.core.ObservableValues;
|
import de.neemann.digital.core.ObservableValues;
|
||||||
import de.neemann.digital.core.Observer;
|
import de.neemann.digital.core.Observer;
|
||||||
import de.neemann.digital.core.element.ElementAttributes;
|
import de.neemann.digital.core.element.ElementAttributes;
|
||||||
|
import de.neemann.digital.core.element.Keys;
|
||||||
import de.neemann.digital.core.element.PinDescriptions;
|
import de.neemann.digital.core.element.PinDescriptions;
|
||||||
import de.neemann.digital.draw.elements.IOState;
|
import de.neemann.digital.draw.elements.IOState;
|
||||||
import de.neemann.digital.draw.elements.Pin;
|
import de.neemann.digital.draw.elements.Pin;
|
||||||
import de.neemann.digital.draw.elements.Pins;
|
import de.neemann.digital.draw.elements.Pins;
|
||||||
|
import de.neemann.digital.draw.graphics.Graphic;
|
||||||
|
import de.neemann.digital.draw.graphics.Style;
|
||||||
import de.neemann.digital.draw.graphics.Vector;
|
import de.neemann.digital.draw.graphics.Vector;
|
||||||
|
|
||||||
import static de.neemann.digital.draw.shapes.GenericShape.SIZE;
|
import static de.neemann.digital.draw.shapes.GenericShape.SIZE;
|
||||||
|
import static de.neemann.digital.draw.shapes.GenericShape.SIZE2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A seven seg display with seven single controllable inputs
|
* A seven seg display with seven single controllable inputs
|
||||||
@ -19,8 +23,12 @@ import static de.neemann.digital.draw.shapes.GenericShape.SIZE;
|
|||||||
*/
|
*/
|
||||||
public class SevenSegShape extends SevenShape {
|
public class SevenSegShape extends SevenShape {
|
||||||
private final PinDescriptions inputPins;
|
private final PinDescriptions inputPins;
|
||||||
|
private final boolean commonCatode;
|
||||||
|
private final boolean persistence;
|
||||||
|
private final boolean[] data;
|
||||||
private ObservableValues inputs;
|
private ObservableValues inputs;
|
||||||
private Pins pins;
|
private Pins pins;
|
||||||
|
private ObservableValue ccin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance
|
* Creates a new instance
|
||||||
@ -32,6 +40,9 @@ public class SevenSegShape extends SevenShape {
|
|||||||
public SevenSegShape(ElementAttributes attr, PinDescriptions inputs, PinDescriptions outputs) {
|
public SevenSegShape(ElementAttributes attr, PinDescriptions inputs, PinDescriptions outputs) {
|
||||||
super(attr);
|
super(attr);
|
||||||
this.inputPins = inputs;
|
this.inputPins = inputs;
|
||||||
|
commonCatode = attr.get(Keys.COMMON_CATHODE);
|
||||||
|
persistence = attr.get(Keys.LED_PERSISTENCE);
|
||||||
|
data = new boolean[8];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -46,6 +57,8 @@ public class SevenSegShape extends SevenShape {
|
|||||||
pins.add(new Pin(new Vector(SIZE, SIZE * HEIGHT), inputPins.get(5)));
|
pins.add(new Pin(new Vector(SIZE, SIZE * HEIGHT), inputPins.get(5)));
|
||||||
pins.add(new Pin(new Vector(SIZE * 2, SIZE * HEIGHT), inputPins.get(6)));
|
pins.add(new Pin(new Vector(SIZE * 2, SIZE * HEIGHT), inputPins.get(6)));
|
||||||
pins.add(new Pin(new Vector(SIZE * 3, SIZE * HEIGHT), inputPins.get(7)));
|
pins.add(new Pin(new Vector(SIZE * 3, SIZE * HEIGHT), inputPins.get(7)));
|
||||||
|
if (commonCatode)
|
||||||
|
pins.add(new Pin(new Vector(SIZE * 4, SIZE * HEIGHT), inputPins.get(8)));
|
||||||
}
|
}
|
||||||
return pins;
|
return pins;
|
||||||
}
|
}
|
||||||
@ -55,15 +68,35 @@ public class SevenSegShape extends SevenShape {
|
|||||||
inputs = ioState.getInputs();
|
inputs = ioState.getInputs();
|
||||||
for (ObservableValue o : inputs)
|
for (ObservableValue o : inputs)
|
||||||
o.addObserverToValue(guiObserver);
|
o.addObserverToValue(guiObserver);
|
||||||
|
if (commonCatode)
|
||||||
|
ccin = inputs.get(8);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawTo(Graphic graphic, boolean highLight) {
|
||||||
|
super.drawTo(graphic, highLight);
|
||||||
|
if (commonCatode)
|
||||||
|
graphic.drawLine(
|
||||||
|
new Vector(SIZE * 4 - SIZE2, SIZE * HEIGHT - 1),
|
||||||
|
new Vector(SIZE * 4, SIZE * HEIGHT - 1), Style.NORMAL);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean getStyle(int i) {
|
protected boolean getStyle(int i) {
|
||||||
if (inputs == null)
|
if (inputs == null)
|
||||||
return true;
|
return true;
|
||||||
else return inputs.get(i).getValueIgnoreBurn() > 0;
|
|
||||||
|
if (persistence && commonCatode) {
|
||||||
|
if (!ccin.isHighZ() && !ccin.getBool())
|
||||||
|
data[i] = inputs.get(i).getValueIgnoreBurn() > 0;
|
||||||
|
return data[i];
|
||||||
|
} else {
|
||||||
|
if (commonCatode && (ccin.isHighZ() || ccin.getBool()))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return inputs.get(i).getValueIgnoreBurn() > 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -258,6 +258,7 @@ Die gesammte Speichergröße beträgt damit damit dx*dy*2 Speicherworte.</string
|
|||||||
<string name="elem_Seven-Seg_pin_f">Dieser Eingang steuert die obere linke vertikale Linie.</string>
|
<string name="elem_Seven-Seg_pin_f">Dieser Eingang steuert die obere linke vertikale Linie.</string>
|
||||||
<string name="elem_Seven-Seg_pin_g">Dieser Eingang steuert die mittlere horizontale Linie.</string>
|
<string name="elem_Seven-Seg_pin_g">Dieser Eingang steuert die mittlere horizontale Linie.</string>
|
||||||
<string name="elem_Seven-Seg_pin_dp">Dieser Eingang steuert den Dezimalpunkt.</string>
|
<string name="elem_Seven-Seg_pin_dp">Dieser Eingang steuert den Dezimalpunkt.</string>
|
||||||
|
<string name="elem_Seven-Seg_pin_cc">Gemeinsame Kathode. Nur wenn hier eine Null anliegt, können die LEDs leuchten.</string>
|
||||||
<string name="elem_Seven-Seg-Hex">Siebensegmentanzeige Hex</string>
|
<string name="elem_Seven-Seg-Hex">Siebensegmentanzeige Hex</string>
|
||||||
<string name="elem_Seven-Seg-Hex_tt">Siebensegmentanzeige mit einem 4 Bit hexadezimalen Eingang.</string>
|
<string name="elem_Seven-Seg-Hex_tt">Siebensegmentanzeige mit einem 4 Bit hexadezimalen Eingang.</string>
|
||||||
<string name="elem_Seven-Seg-Hex_pin_d">Der 4-Bit-Wert dieses Eingangs wird als Hex-Ziffer dargestellt.</string>
|
<string name="elem_Seven-Seg-Hex_pin_d">Der 4-Bit-Wert dieses Eingangs wird als Hex-Ziffer dargestellt.</string>
|
||||||
@ -511,6 +512,13 @@ Zur Analyse können Sie die Schaltung im Gatterschrittmodus ausführen.</string>
|
|||||||
<string name="key_ExpressionFormat_tt">Anzeigeformat der Ausdrücke.</string>
|
<string name="key_ExpressionFormat_tt">Anzeigeformat der Ausdrücke.</string>
|
||||||
<string name="key_relayNormallyClosed">Relais ist ein Öffner</string>
|
<string name="key_relayNormallyClosed">Relais ist ein Öffner</string>
|
||||||
<string name="key_relayNormallyClosed_tt">Wenn gesetzt ist das Relais unbestromt geschlossen.</string>
|
<string name="key_relayNormallyClosed_tt">Wenn gesetzt ist das Relais unbestromt geschlossen.</string>
|
||||||
|
<string name="key_commonCathode">Gemeinsame Kathode</string>
|
||||||
|
<string name="key_commonCathode_tt">Wenn gesetzt hat die Anzeige einen Ausgang mit einer gemeinsamen Kathode.</string>
|
||||||
|
<string name="key_ledPersistence">Träges Auge</string>
|
||||||
|
<string name="key_ledPersistence_tt">Die Schaltfrequenz am Bildschirm kann in der Simulation nicht so hoch werden,
|
||||||
|
dass das Auge kein Flimmern mehr wahrnimmt. Um dennoch das Flackern zu unterdrücken, können die LEDs auf
|
||||||
|
"nachleuchten" geschaltet werden.</string>
|
||||||
|
|
||||||
<string name="lib_Logic">Logisch</string>
|
<string name="lib_Logic">Logisch</string>
|
||||||
<string name="lib_arithmetic">Arithmetik</string>
|
<string name="lib_arithmetic">Arithmetik</string>
|
||||||
<string name="lib_flipFlops">FlipFlops</string>
|
<string name="lib_flipFlops">FlipFlops</string>
|
||||||
|
@ -251,6 +251,7 @@
|
|||||||
<string name="elem_Seven-Seg_pin_f">This input controls the upper, left, vertical line.</string>
|
<string name="elem_Seven-Seg_pin_f">This input controls the upper, left, vertical line.</string>
|
||||||
<string name="elem_Seven-Seg_pin_g">This input controls the middle, horizontal line.</string>
|
<string name="elem_Seven-Seg_pin_g">This input controls the middle, horizontal line.</string>
|
||||||
<string name="elem_Seven-Seg_pin_dp">This input controls the decimal point.</string>
|
<string name="elem_Seven-Seg_pin_dp">This input controls the decimal point.</string>
|
||||||
|
<string name="elem_Seven-Seg_pin_cc">Common Cathode. To turn on the LEDs, this input needs to be low.</string>
|
||||||
<string name="elem_Seven-Seg-Hex">Seven-Segment-Hex Display</string>
|
<string name="elem_Seven-Seg-Hex">Seven-Segment-Hex Display</string>
|
||||||
<string name="elem_Seven-Seg-Hex_tt">Seven Segment Display with a 4 bit input</string>
|
<string name="elem_Seven-Seg-Hex_tt">Seven Segment Display with a 4 bit input</string>
|
||||||
<string name="elem_Seven-Seg-Hex_pin_d">The value at this input is visualized at the display.</string>
|
<string name="elem_Seven-Seg-Hex_pin_d">The value at this input is visualized at the display.</string>
|
||||||
@ -497,6 +498,14 @@ To analyse you can run the circuit in single gate step mode.</string>
|
|||||||
<string name="key_ExpressionFormat_tt">Screen format of expressions.</string>
|
<string name="key_ExpressionFormat_tt">Screen format of expressions.</string>
|
||||||
<string name="key_relayNormallyClosed">Relay is normally closed.</string>
|
<string name="key_relayNormallyClosed">Relay is normally closed.</string>
|
||||||
<string name="key_relayNormallyClosed_tt">If set the relay is closed if the input is low.</string>
|
<string name="key_relayNormallyClosed_tt">If set the relay is closed if the input is low.</string>
|
||||||
|
<string name="key_commonCathode">Common Cathode</string>
|
||||||
|
<string name="key_commonCathode_tt">If selected the common cathode input is also simulated.</string>
|
||||||
|
<string name="key_ledPersistence">Slow Eye</string>
|
||||||
|
<string name="key_ledPersistence_tt">It is not possible to increase the frequency so much that the flickering disappears.
|
||||||
|
With this option you can stabilize the display by keeping the LEDs on until the common cathode goes down again.
|
||||||
|
This simulates a frequency above the critical flicker fusion frequency.
|
||||||
|
</string>
|
||||||
|
|
||||||
<string name="lib_Logic">Logic</string>
|
<string name="lib_Logic">Logic</string>
|
||||||
<string name="lib_arithmetic">Arithmetic</string>
|
<string name="lib_arithmetic">Arithmetic</string>
|
||||||
<string name="lib_flipFlops">FlipFlops</string>
|
<string name="lib_flipFlops">FlipFlops</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user