added a led with an anode and a cathode connection

This commit is contained in:
hneemann 2018-03-30 13:57:50 +02:00
parent 8b2016ce29
commit 763d68b22f
8 changed files with 226 additions and 11 deletions

View File

@ -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) {
}
}

View File

@ -117,6 +117,7 @@ public class ElementLibrary implements Iterable<ElementLibrary.ElementContainer>
.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)

View File

@ -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);
}
}
}
}

View File

@ -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);

View File

@ -167,6 +167,13 @@
</string>
<string name="elem_LightBulb_pin_A">Anschluss</string>
<string name="elem_LightBulb_pin_B">Anschluss</string>
<string name="elem_RealLED">LED mit zwei Anschlüssen</string>
<string name="elem_RealLED_tt">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.</string>
<string name="elem_RealLED_pin_A">Die Anode der LED.</string>
<string name="elem_RealLED_pin_C">Die Kathode der LED.</string>
<string name="elem_Seven-Seg">Siebensegmentanzeige</string>
<string name="elem_Seven-Seg_tt">Siebensegmentanzeige, bei der jedes Segment über einen eigenen Eingang gesteuert
werden kann.</string>

View File

@ -132,6 +132,13 @@
<string name="elem_LED_tt">A LED can be used to visualize an output value. Accepts a single bit.
Lights up if the input is set to 1.</string>
<string name="elem_LED_pin_in">LED Input. LED lights up if the input is set to 1.</string>
<string name="elem_RealLED">LED with two connections.</string>
<string name="elem_RealLED_tt">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.</string>
<string name="elem_RealLED_pin_A">The anode connection of the LED.</string>
<string name="elem_RealLED_pin_C">The cathode connection of the LED.</string>
<string name="elem_In">Input</string>
<string name="elem_In_tt">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.

View File

@ -534,6 +534,11 @@
</elementAttributes>
<pos x="800" y="860"/>
</visualElement>
<visualElement>
<elementName>RealLED</elementName>
<elementAttributes/>
<pos x="1200" y="420"/>
</visualElement>
</visualElements>
<wires>
<wire>
@ -636,13 +641,17 @@
<p1 x="1080" y="520"/>
<p2 x="1100" y="520"/>
</wire>
<wire>
<p1 x="580" y="520"/>
<p2 x="640" y="520"/>
</wire>
<wire>
<p1 x="1140" y="520"/>
<p2 x="1160" y="520"/>
</wire>
<wire>
<p1 x="580" y="520"/>
<p2 x="640" y="520"/>
<p1 x="1160" y="520"/>
<p2 x="1200" y="520"/>
</wire>
<wire>
<p1 x="240" y="780"/>
@ -696,18 +705,22 @@
<p1 x="760" y="400"/>
<p2 x="800" y="400"/>
</wire>
<wire>
<p1 x="1080" y="400"/>
<p2 x="1120" y="400"/>
</wire>
<wire>
<p1 x="600" y="400"/>
<p2 x="620" y="400"/>
</wire>
<wire>
<p1 x="1080" y="400"/>
<p2 x="1120" y="400"/>
</wire>
<wire>
<p1 x="400" y="400"/>
<p2 x="440" y="400"/>
</wire>
<wire>
<p1 x="1160" y="400"/>
<p2 x="1200" y="400"/>
</wire>
<wire>
<p1 x="1120" y="400"/>
<p2 x="1160" y="400"/>
@ -1492,6 +1505,14 @@
<p1 x="880" y="840"/>
<p2 x="880" y="880"/>
</wire>
<wire>
<p1 x="1200" y="400"/>
<p2 x="1200" y="420"/>
</wire>
<wire>
<p1 x="1200" y="500"/>
<p2 x="1200" y="520"/>
</wire>
<wire>
<p1 x="500" y="740"/>
<p2 x="500" y="760"/>

View File

@ -96,17 +96,17 @@
<visualElement>
<elementName>Seven-Seg</elementName>
<elementAttributes/>
<pos x="200" y="160"/>
<pos x="240" y="160"/>
</visualElement>
<visualElement>
<elementName>Seven-Seg-Hex</elementName>
<elementAttributes/>
<pos x="300" y="160"/>
<pos x="340" y="160"/>
</visualElement>
<visualElement>
<elementName>Data</elementName>
<elementAttributes/>
<pos x="500" y="160"/>
<pos x="520" y="160"/>
</visualElement>
<visualElement>
<elementName>Multiplexer</elementName>
@ -406,7 +406,7 @@
<visualElement>
<elementName>RotEncoder</elementName>
<elementAttributes/>
<pos x="780" y="180"/>
<pos x="760" y="180"/>
</visualElement>
<visualElement>
<elementName>RAMSinglePortSel</elementName>
@ -466,7 +466,12 @@
<visualElement>
<elementName>SixteenSeg</elementName>
<elementAttributes/>
<pos x="400" y="160"/>
<pos x="440" y="160"/>
</visualElement>
<visualElement>
<elementName>RealLED</elementName>
<elementAttributes/>
<pos x="200" y="160"/>
</visualElement>
</visualElements>
<wires/>