diff --git a/src/main/java/de/neemann/digital/core/io/RealLED.java b/src/main/java/de/neemann/digital/core/io/RealLED.java new file mode 100644 index 000000000..3e04c17a2 --- /dev/null +++ b/src/main/java/de/neemann/digital/core/io/RealLED.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2017 Helmut Neemann + * Use of this source code is governed by the GPL v3 license + * that can be found in the LICENSE file. + */ +package de.neemann.digital.core.io; + +import de.neemann.digital.core.Model; +import de.neemann.digital.core.NodeException; +import de.neemann.digital.core.ObservableValues; +import de.neemann.digital.core.element.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; + +/** + * A real LED + */ +public class RealLED implements Element { + + /** + * The LED description + */ + public static final ElementTypeDescription DESCRIPTION + = new ElementTypeDescription(RealLED.class, input("A"), input("C")) + .addAttribute(Keys.ROTATE) + .addAttribute(Keys.LABEL) + .addAttribute(Keys.COLOR); + + /** + * Creates a new light bulb + * + * @param attr the attributes + */ + public RealLED(ElementAttributes attr) { + } + + @Override + public void setInputs(ObservableValues inputs) throws NodeException { + inputs.get(0).checkBits(1, null, 0); + inputs.get(1).checkBits(1, null, 1); + } + + @Override + public ObservableValues getOutputs() { + return ObservableValues.EMPTY_LIST; + } + + @Override + public void registerNodes(Model model) { + } +} diff --git a/src/main/java/de/neemann/digital/draw/library/ElementLibrary.java b/src/main/java/de/neemann/digital/draw/library/ElementLibrary.java index 265656fc9..260c33b81 100644 --- a/src/main/java/de/neemann/digital/draw/library/ElementLibrary.java +++ b/src/main/java/de/neemann/digital/draw/library/ElementLibrary.java @@ -117,6 +117,7 @@ public class ElementLibrary implements Iterable .add(Probe.DESCRIPTION) .add(new LibraryNode(Lang.get("lib_more")) .add(LightBulb.DESCRIPTION) + .add(RealLED.DESCRIPTION) .add(Out.SEVENDESCRIPTION) .add(Out.SEVENHEXDESCRIPTION) .add(Out.SIXTEENDESCRIPTION) diff --git a/src/main/java/de/neemann/digital/draw/shapes/RealLEDShape.java b/src/main/java/de/neemann/digital/draw/shapes/RealLEDShape.java new file mode 100644 index 000000000..028d01168 --- /dev/null +++ b/src/main/java/de/neemann/digital/draw/shapes/RealLEDShape.java @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2017 Helmut Neemann + * Use of this source code is governed by the GPL v3 license + * that can be found in the LICENSE file. + */ +package de.neemann.digital.draw.shapes; + +import de.neemann.digital.core.ObservableValue; +import de.neemann.digital.core.Observer; +import de.neemann.digital.core.Value; +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.draw.elements.IOState; +import de.neemann.digital.draw.elements.Pin; +import de.neemann.digital.draw.elements.Pins; +import de.neemann.digital.draw.graphics.Graphic; +import de.neemann.digital.draw.graphics.Polygon; +import de.neemann.digital.draw.graphics.Style; +import de.neemann.digital.draw.graphics.Vector; + + +import static de.neemann.digital.draw.shapes.GenericShape.SIZE; +import static de.neemann.digital.draw.shapes.GenericShape.SIZE2; +import static de.neemann.digital.draw.shapes.PullDownShape.HEIGHT; +import static de.neemann.digital.draw.shapes.PullDownShape.WIDTH2; + +/** + * The light bulb shape + */ +public class RealLEDShape implements Shape { + private static final int RAD = SIZE * 3 / 4; + private final PinDescriptions inputs; + private final Style style; + private ObservableValue aValue; + private ObservableValue cValue; + private Value a; + private Value c; + + /** + * Creates a new instance + * + * @param attr the attributes + * @param inputs the inputs + * @param outputs the outputs + */ + public RealLEDShape(ElementAttributes attr, PinDescriptions inputs, PinDescriptions outputs) { + this.inputs = inputs; + style = Style.NORMAL.deriveFillStyle(attr.get(Keys.COLOR)); + } + + @Override + public Pins getPins() { + return new Pins() + .add(new Pin(new Vector(0, 0), inputs.get(0))) + .add(new Pin(new Vector(0, SIZE * 4), inputs.get(1))); + } + + @Override + public InteractorInterface applyStateMonitor(IOState ioState, Observer guiObserver) { + aValue = ioState.getInput(0).addObserverToValue(guiObserver); + cValue = ioState.getInput(1).addObserverToValue(guiObserver); + return null; + } + + @Override + public void readObservableValues() { + if (aValue != null && cValue != null) { + a = aValue.getCopy(); + c = cValue.getCopy(); + } + } + + @Override + public void drawTo(Graphic graphic, Style highLight) { + + graphic.drawPolygon( + new Polygon(true) + .add(-WIDTH2, SIZE * 4 - SIZE2 - 1) + .add(-WIDTH2, SIZE * 4 - SIZE2 - HEIGHT) + .add(WIDTH2, SIZE * 4 - SIZE2 - HEIGHT) + .add(WIDTH2, SIZE * 4 - SIZE2 - 1), + Style.NORMAL + ); + graphic.drawLine(new Vector(0, SIZE * 4 - SIZE2), new Vector(0, SIZE * 4), Style.NORMAL); + + if (a == null || c == null) { + graphic.drawPolygon( + new Polygon(true) + .add(-SIZE2, -SIZE + 1 + SIZE + SIZE2) + .add(SIZE2, -SIZE + 1 + SIZE + SIZE2) + .add(0, -1 + SIZE + SIZE2), + Style.NORMAL + ); + graphic.drawLine(new Vector(-SIZE2, -1 + SIZE + SIZE2), new Vector(SIZE2, -1 + SIZE + SIZE2), Style.NORMAL); + graphic.drawLine(new Vector(0, -1 + SIZE + SIZE2), new Vector(0, SIZE * 4 - HEIGHT - SIZE2), Style.NORMAL); + graphic.drawLine(new Vector(0, 0), new Vector(0, -1 + SIZE2), Style.NORMAL); + + graphic.drawLine(new Vector(SIZE - 1, SIZE2 + 1), new Vector(SIZE2, SIZE), Style.THIN); + graphic.drawLine(new Vector(SIZE - 3, SIZE2), new Vector(SIZE, SIZE2), Style.THIN); + graphic.drawLine(new Vector(SIZE, SIZE2 + 3), new Vector(SIZE, SIZE2), Style.THIN); + graphic.drawLine(new Vector(SIZE - 1 + 4, SIZE2 + 1 + 4), new Vector(SIZE2 + 4, SIZE + 4), Style.THIN); + graphic.drawLine(new Vector(SIZE - 3 + 4, SIZE2 + 4), new Vector(SIZE + 4, SIZE2 + 4), Style.THIN); + graphic.drawLine(new Vector(SIZE + 4, SIZE2 + 3 + 4), new Vector(SIZE + 4, SIZE2 + 4), Style.THIN); + } else { + Vector center = new Vector(0, SIZE); + Vector rad = new Vector(RAD, RAD); + + graphic.drawLine(new Vector(0, SIZE * 4 - SIZE2 - HEIGHT), new Vector(0, SIZE * 2 - 4), Style.NORMAL); + graphic.drawLine(new Vector(0, 0), new Vector(0, 5), Style.NORMAL); + graphic.drawCircle(center.sub(rad), center.add(rad), Style.FILLED); + + if (a.getBool() && !c.getBool()) { + Vector radL = new Vector(RAD - 2, RAD - 2); + graphic.drawCircle(center.sub(radL), center.add(radL), style); + } + } + } +} diff --git a/src/main/java/de/neemann/digital/draw/shapes/ShapeFactory.java b/src/main/java/de/neemann/digital/draw/shapes/ShapeFactory.java index f6bfba88f..9fd367c40 100644 --- a/src/main/java/de/neemann/digital/draw/shapes/ShapeFactory.java +++ b/src/main/java/de/neemann/digital/draw/shapes/ShapeFactory.java @@ -90,6 +90,7 @@ public final class ShapeFactory { map.put(Out.DESCRIPTION.getName(), OutputShape::new); map.put(Out.LEDDESCRIPTION.getName(), LEDShape::new); map.put(LightBulb.DESCRIPTION.getName(), LightBulbShape::new); + map.put(RealLED.DESCRIPTION.getName(), RealLEDShape::new); map.put(Button.DESCRIPTION.getName(), ButtonShape::new); map.put(Probe.DESCRIPTION.getName(), ProbeShape::new); map.put(Clock.DESCRIPTION.getName(), ClockShape::new); diff --git a/src/main/resources/lang/lang_de.xml b/src/main/resources/lang/lang_de.xml index 58fc9907a..8199e8fd2 100644 --- a/src/main/resources/lang/lang_de.xml +++ b/src/main/resources/lang/lang_de.xml @@ -167,6 +167,13 @@ Anschluss Anschluss + + LED mit zwei Anschlüssen + LED mit zwei Anschlüssen für die Kathode und die Anode. Die LED leuchtet + nur, wenn die Anode auf High und die Kathode auf Low gelegt wird. + Die Anode der LED. + Die Kathode der LED. + Siebensegmentanzeige Siebensegmentanzeige, bei der jedes Segment über einen eigenen Eingang gesteuert werden kann. diff --git a/src/main/resources/lang/lang_en.xml b/src/main/resources/lang/lang_en.xml index 5658b5eed..688e60b99 100644 --- a/src/main/resources/lang/lang_en.xml +++ b/src/main/resources/lang/lang_en.xml @@ -132,6 +132,13 @@ A LED can be used to visualize an output value. Accepts a single bit. Lights up if the input is set to 1. LED Input. LED lights up if the input is set to 1. + + LED with two connections. + LED with connections for the cathode and the anode. The LED lights up, + if the anode is connected to high and the cathode is connected to low. + The anode connection of the LED. + The cathode connection of the LED. + Input Can be used to interactively manipulate an input signal in a circuit with the mouse. This element is also used to connect a circuit to an embedding circuit. diff --git a/src/test/resources/dig/backtrack/AllComponents.dig b/src/test/resources/dig/backtrack/AllComponents.dig index 34798384b..2c238c6ce 100644 --- a/src/test/resources/dig/backtrack/AllComponents.dig +++ b/src/test/resources/dig/backtrack/AllComponents.dig @@ -534,6 +534,11 @@ + + RealLED + + + @@ -636,13 +641,17 @@ + + + + - - + + @@ -696,18 +705,22 @@ - - - - + + + + + + + + @@ -1492,6 +1505,14 @@ + + + + + + + + diff --git a/src/test/resources/dig/shapes.dig b/src/test/resources/dig/shapes.dig index 74631dc04..ed7a42e7c 100644 --- a/src/test/resources/dig/shapes.dig +++ b/src/test/resources/dig/shapes.dig @@ -96,17 +96,17 @@ Seven-Seg - + Seven-Seg-Hex - + Data - + Multiplexer @@ -406,7 +406,7 @@ RotEncoder - + RAMSinglePortSel @@ -466,7 +466,12 @@ SixteenSeg - + + + + RealLED + +