mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-26 14:31:02 -04:00
added a light bulb
This commit is contained in:
parent
8b1a109fa4
commit
d08584eb68
311
src/main/dig/74xx/traficInv.dig
Normal file
311
src/main/dig/74xx/traficInv.dig
Normal file
@ -0,0 +1,311 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<circuit>
|
||||
<version>1</version>
|
||||
<attributes>
|
||||
<entry>
|
||||
<string>Description</string>
|
||||
<string>simple red-yellow-green traffic light</string>
|
||||
</entry>
|
||||
</attributes>
|
||||
<visualElements>
|
||||
<visualElement>
|
||||
<elementName>7476.dig</elementName>
|
||||
<elementAttributes/>
|
||||
<pos x="300" y="180"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>VDD</elementName>
|
||||
<elementAttributes/>
|
||||
<pos x="280" y="160"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>VDD</elementName>
|
||||
<elementAttributes/>
|
||||
<pos x="440" y="160"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>Clock</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<string>runRealTime</string>
|
||||
<boolean>true</boolean>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="240" y="180"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>7400.dig</elementName>
|
||||
<elementAttributes/>
|
||||
<pos x="540" y="220"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>Ground</elementName>
|
||||
<elementAttributes/>
|
||||
<pos x="680" y="440"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>Ground</elementName>
|
||||
<elementAttributes/>
|
||||
<pos x="520" y="280"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>LightBulb</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<string>Color</string>
|
||||
<awt-color>
|
||||
<red>0</red>
|
||||
<green>204</green>
|
||||
<blue>0</blue>
|
||||
<alpha>255</alpha>
|
||||
</awt-color>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>rotation</string>
|
||||
<rotation rotation="1"/>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="580" y="160"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>LightBulb</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<string>Color</string>
|
||||
<awt-color>
|
||||
<red>255</red>
|
||||
<green>255</green>
|
||||
<blue>0</blue>
|
||||
<alpha>255</alpha>
|
||||
</awt-color>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>rotation</string>
|
||||
<rotation rotation="1"/>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="580" y="120"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>LightBulb</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<string>rotation</string>
|
||||
<rotation rotation="1"/>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="580" y="80"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>VDD</elementName>
|
||||
<elementAttributes/>
|
||||
<pos x="640" y="60"/>
|
||||
</visualElement>
|
||||
</visualElements>
|
||||
<wires>
|
||||
<wire>
|
||||
<p1 x="460" y="80"/>
|
||||
<p2 x="580" y="80"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="620" y="80"/>
|
||||
<p2 x="640" y="80"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="500" y="160"/>
|
||||
<p2 x="580" y="160"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="620" y="160"/>
|
||||
<p2 x="640" y="160"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="280" y="260"/>
|
||||
<p2 x="300" y="260"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="420" y="260"/>
|
||||
<p2 x="480" y="260"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="520" y="260"/>
|
||||
<p2 x="540" y="260"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="660" y="260"/>
|
||||
<p2 x="680" y="260"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="280" y="420"/>
|
||||
<p2 x="300" y="420"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="660" y="420"/>
|
||||
<p2 x="680" y="420"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="500" y="420"/>
|
||||
<p2 x="540" y="420"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="480" y="340"/>
|
||||
<p2 x="540" y="340"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="420" y="340"/>
|
||||
<p2 x="440" y="340"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="420" y="180"/>
|
||||
<p2 x="440" y="180"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="240" y="180"/>
|
||||
<p2 x="260" y="180"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="260" y="180"/>
|
||||
<p2 x="300" y="180"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="480" y="120"/>
|
||||
<p2 x="580" y="120"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="620" y="120"/>
|
||||
<p2 x="640" y="120"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="280" y="300"/>
|
||||
<p2 x="300" y="300"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="660" y="300"/>
|
||||
<p2 x="680" y="300"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="280" y="460"/>
|
||||
<p2 x="300" y="460"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="420" y="460"/>
|
||||
<p2 x="440" y="460"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="420" y="220"/>
|
||||
<p2 x="440" y="220"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="280" y="220"/>
|
||||
<p2 x="300" y="220"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="520" y="220"/>
|
||||
<p2 x="540" y="220"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="420" y="380"/>
|
||||
<p2 x="460" y="380"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="260" y="380"/>
|
||||
<p2 x="300" y="380"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="660" y="380"/>
|
||||
<p2 x="680" y="380"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="460" y="380"/>
|
||||
<p2 x="540" y="380"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="480" y="120"/>
|
||||
<p2 x="480" y="260"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="480" y="260"/>
|
||||
<p2 x="480" y="340"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="640" y="60"/>
|
||||
<p2 x="640" y="80"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="640" y="80"/>
|
||||
<p2 x="640" y="120"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="640" y="120"/>
|
||||
<p2 x="640" y="160"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="500" y="160"/>
|
||||
<p2 x="500" y="420"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="260" y="180"/>
|
||||
<p2 x="260" y="380"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="520" y="220"/>
|
||||
<p2 x="520" y="260"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="520" y="260"/>
|
||||
<p2 x="520" y="280"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="280" y="160"/>
|
||||
<p2 x="280" y="220"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="280" y="420"/>
|
||||
<p2 x="280" y="460"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="280" y="300"/>
|
||||
<p2 x="280" y="420"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="280" y="220"/>
|
||||
<p2 x="280" y="260"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="280" y="260"/>
|
||||
<p2 x="280" y="300"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="440" y="160"/>
|
||||
<p2 x="440" y="180"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="440" y="220"/>
|
||||
<p2 x="440" y="340"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="440" y="340"/>
|
||||
<p2 x="440" y="460"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="680" y="260"/>
|
||||
<p2 x="680" y="300"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="680" y="300"/>
|
||||
<p2 x="680" y="380"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="680" y="380"/>
|
||||
<p2 x="680" y="420"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="680" y="420"/>
|
||||
<p2 x="680" y="440"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="460" y="80"/>
|
||||
<p2 x="460" y="380"/>
|
||||
</wire>
|
||||
</wires>
|
||||
</circuit>
|
50
src/main/java/de/neemann/digital/core/io/LightBulb.java
Normal file
50
src/main/java/de/neemann/digital/core/io/LightBulb.java
Normal file
@ -0,0 +1,50 @@
|
||||
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 de.neemann.digital.draw.elements.PinException;
|
||||
|
||||
import static de.neemann.digital.core.element.PinInfo.input;
|
||||
|
||||
/**
|
||||
* A light bulb
|
||||
* Created by hneemann on 19.05.17.
|
||||
*/
|
||||
public class LightBulb implements Element {
|
||||
|
||||
/**
|
||||
* The LED description
|
||||
*/
|
||||
public static final ElementTypeDescription DESCRIPTION
|
||||
= new ElementTypeDescription(LightBulb.class, input("A"), input("B"))
|
||||
.addAttribute(Keys.ROTATE)
|
||||
.addAttribute(Keys.LABEL)
|
||||
.addAttribute(Keys.COLOR);
|
||||
|
||||
/**
|
||||
* Creates a new light bulb
|
||||
* @param attr the attributes
|
||||
*/
|
||||
public LightBulb(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() throws PinException {
|
||||
return ObservableValues.EMPTY_LIST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerNodes(Model model) {
|
||||
}
|
||||
}
|
@ -78,6 +78,7 @@ public class ElementLibrary implements Iterable<ElementLibrary.ElementContainer>
|
||||
.add(DummyElement.TEXTDESCRIPTION)
|
||||
.add(Probe.DESCRIPTION)
|
||||
.add(new LibraryNode(Lang.get("lib_more"))
|
||||
.add(LightBulb.DESCRIPTION)
|
||||
.add(Out.SEVENDESCRIPTION)
|
||||
.add(Out.SEVENHEXDESCRIPTION)
|
||||
.add(LedMatrix.DESCRIPTION)
|
||||
|
@ -0,0 +1,70 @@
|
||||
package de.neemann.digital.draw.shapes;
|
||||
|
||||
import de.neemann.digital.core.ObservableValue;
|
||||
import de.neemann.digital.core.Observer;
|
||||
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.Style;
|
||||
import de.neemann.digital.draw.graphics.Vector;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
import static de.neemann.digital.draw.shapes.GenericShape.SIZE;
|
||||
|
||||
/**
|
||||
* The light bulb shape
|
||||
* Created by hneemann on 19.05.17.
|
||||
*/
|
||||
public class LightBulbShape implements Shape {
|
||||
private static final Vector CENTER = new Vector(0, SIZE);
|
||||
private static final int BORDER = 2;
|
||||
private static final int RAD = (SIZE - BORDER * 2) * 707 / 1000;
|
||||
private final PinDescriptions inputs;
|
||||
private final Style style;
|
||||
private ObservableValue a;
|
||||
private ObservableValue b;
|
||||
|
||||
/**
|
||||
* Creates a new instance
|
||||
*
|
||||
* @param attr the attributes
|
||||
* @param inputs the inputs
|
||||
* @param outputs the outputs
|
||||
*/
|
||||
public LightBulbShape(ElementAttributes attr, PinDescriptions inputs, PinDescriptions outputs) {
|
||||
this.inputs = inputs;
|
||||
style = new Style(1, true, 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 * 2), inputs.get(1)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractorInterface applyStateMonitor(IOState ioState, Observer guiObserver) {
|
||||
a = ioState.getInput(0);
|
||||
b = ioState.getInput(1);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawTo(Graphic graphic, boolean highLight) {
|
||||
if (a != null && b != null) {
|
||||
boolean on = !a.isHighZ() && !b.isHighZ() && (a.getBool() != b.getBool());
|
||||
if (on)
|
||||
graphic.drawCircle(new Vector(-SIZE + BORDER + 1, BORDER + 1), new Vector(SIZE - BORDER - 1, 2 * SIZE - BORDER - 1), style);
|
||||
} else {
|
||||
graphic.drawLine(CENTER.add(-RAD, -RAD), CENTER.add(RAD, RAD), Style.NORMAL);
|
||||
graphic.drawLine(CENTER.add(-RAD, RAD), CENTER.add(RAD, -RAD), Style.NORMAL);
|
||||
}
|
||||
graphic.drawCircle(new Vector(-SIZE + BORDER, BORDER), new Vector(SIZE - BORDER, 2 * SIZE - BORDER), Style.NORMAL);
|
||||
}
|
||||
}
|
@ -91,6 +91,7 @@ public final class ShapeFactory {
|
||||
map.put(TransGate.DESCRIPTION.getName(), TransGateShape::new);
|
||||
map.put(Out.DESCRIPTION.getName(), OutputShape::new);
|
||||
map.put(Out.LEDDESCRIPTION.getName(), LEDShape::new);
|
||||
map.put(LightBulb.DESCRIPTION.getName(), LightBulbShape::new);
|
||||
map.put(Button.DESCRIPTION.getName(), ButtonShape::new);
|
||||
map.put(Probe.DESCRIPTION.getName(), ProbeShape::new);
|
||||
map.put(Clock.DESCRIPTION.getName(), ClockShape::new);
|
||||
|
@ -431,6 +431,11 @@ Die gesammte Speichergröße beträgt damit damit dx*dy*2 Speicherworte.</string
|
||||
<string name="elem_TransGate_pin_S">Steuereingang</string>
|
||||
<string name="elem_TransGate_pin_~S">Steuereingang, invertiert</string>
|
||||
|
||||
<string name="elem_LightBulb">Glühlämpchen</string>
|
||||
<string name="elem_LightBulb_tt">Glühlämpchen mit zwei Anschlüssen: Wenn ein Strom fließt, leuchtet das Lämpchen.</string>
|
||||
<string name="elem_LightBulb_pin_A">Anschluss</string>
|
||||
<string name="elem_LightBulb_pin_B">Anschluss</string>
|
||||
|
||||
<string name="error">Fehler</string>
|
||||
<string name="err_N_isNotInputOrOutput">Pin {0} in Element {1} ist werder Eingang noch Ausgang</string>
|
||||
<string name="err_aSingleClockNecessary">Es muss genau ein Taktelement geben. Alle Flipflops müssen an diesem Takt hängen.</string>
|
||||
|
@ -421,6 +421,11 @@
|
||||
<string name="elem_TransGate_pin_S">control input.</string>
|
||||
<string name="elem_TransGate_pin_~S">inverted control input</string>
|
||||
|
||||
<string name="elem_LightBulb">Light Bulb</string>
|
||||
<string name="elem_LightBulb_tt">Light bulb with two connections. If a current flows, the bulb lights up!</string>
|
||||
<string name="elem_LightBulb_pin_A">Connection</string>
|
||||
<string name="elem_LightBulb_pin_B">Connection</string>
|
||||
|
||||
<string name="error">Error</string>
|
||||
<string name="err_N_isNotInputOrOutput">Pin {0} in component {1} is not a input or output</string>
|
||||
<string name="err_aSingleClockNecessary">A single clock component is necessary. All flip-flops must use this clock signal.</string>
|
||||
|
@ -28,7 +28,7 @@ public class TestExamples extends TestCase {
|
||||
*/
|
||||
public void testDistExamples() throws Exception {
|
||||
File examples = new File(Resources.getRoot().getParentFile().getParentFile(), "/main/dig");
|
||||
assertEquals(173, new FileScanner(this::check).scan(examples));
|
||||
assertEquals(174, new FileScanner(this::check).scan(examples));
|
||||
assertEquals(78, testCasesInFiles);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user