mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-26 14:31:02 -04:00
added a power supply
This commit is contained in:
parent
3c85fd402b
commit
eeaa3c4f5f
54
src/main/java/de/neemann/digital/core/io/PowerSupply.java
Normal file
54
src/main/java/de/neemann/digital/core/io/PowerSupply.java
Normal file
@ -0,0 +1,54 @@
|
||||
package de.neemann.digital.core.io;
|
||||
|
||||
import de.neemann.digital.core.*;
|
||||
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 de.neemann.digital.lang.Lang;
|
||||
|
||||
import static de.neemann.digital.core.element.PinInfo.input;
|
||||
|
||||
/**
|
||||
* Enforces a power supply
|
||||
* Created by hneemann on 15.07.17.
|
||||
*/
|
||||
public class PowerSupply implements Element {
|
||||
|
||||
/**
|
||||
* Enforces a power supply
|
||||
*/
|
||||
public static final ElementTypeDescription DESCRIPTION
|
||||
= new ElementTypeDescription(PowerSupply.class, input("VDD"), input("GND"))
|
||||
.addAttribute(Keys.ROTATE)
|
||||
.addAttribute(Keys.LABEL);
|
||||
|
||||
/**
|
||||
* Creates a new instance
|
||||
*
|
||||
* @param attributes attributes
|
||||
*/
|
||||
public PowerSupply(ElementAttributes attributes) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInputs(ObservableValues inputs) throws NodeException {
|
||||
check(inputs.get(0).checkBits(1, null, 0), 1);
|
||||
check(inputs.get(1).checkBits(1, null, 1), 0);
|
||||
}
|
||||
|
||||
private void check(ObservableValue val, int expected) throws NodeException {
|
||||
if (!val.isConstant() || val.getValue() != expected)
|
||||
throw new NodeException(Lang.get("err_errorInPowerSupply"), val);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObservableValues getOutputs() throws PinException {
|
||||
return ObservableValues.EMPTY_LIST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerNodes(Model model) {
|
||||
}
|
||||
}
|
@ -74,6 +74,21 @@ public class VisualElement implements Drawable, Movable, AttributeListener {
|
||||
return elementName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a key.
|
||||
* Use only to construct an instance.
|
||||
* Don't use this function to modify an existing instance!
|
||||
*
|
||||
* @param key the key
|
||||
* @param val the value to set
|
||||
* @param <V> the type of the value
|
||||
* @return this for chained calls
|
||||
*/
|
||||
public <V> VisualElement setAttribute(Key<V> key, V val) {
|
||||
elementAttributes.set(key, val);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the elements attributes
|
||||
*/
|
||||
|
@ -137,6 +137,7 @@ public class ElementLibrary implements Iterable<ElementLibrary.ElementContainer>
|
||||
.add(TransGate.DESCRIPTION))
|
||||
.add(new LibraryNode(Lang.get("lib_misc"))
|
||||
.add(TestCaseElement.TESTCASEDESCRIPTION)
|
||||
.add(PowerSupply.DESCRIPTION)
|
||||
.add(Reset.DESCRIPTION)
|
||||
.add(Break.DESCRIPTION));
|
||||
|
||||
|
@ -10,6 +10,7 @@ import de.neemann.digital.core.element.Key;
|
||||
import de.neemann.digital.core.element.Keys;
|
||||
import de.neemann.digital.core.io.In;
|
||||
import de.neemann.digital.core.io.Out;
|
||||
import de.neemann.digital.core.io.PowerSupply;
|
||||
import de.neemann.digital.core.memory.ROM;
|
||||
import de.neemann.digital.core.wiring.Clock;
|
||||
import de.neemann.digital.draw.elements.*;
|
||||
@ -63,6 +64,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
|
||||
import static de.neemann.digital.draw.shapes.GenericShape.SIZE;
|
||||
import static javax.swing.JOptionPane.showInputDialog;
|
||||
|
||||
/**
|
||||
@ -709,6 +711,42 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
||||
}
|
||||
}
|
||||
}.setToolTip(Lang.get("menu_removePinNumbers_tt")).createJMenuItem());
|
||||
|
||||
special.add(new ToolTipAction(Lang.get("menu_addPowerSupply")) {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
if (!circuitComponent.isLocked()) {
|
||||
int maxNum = 0;
|
||||
for (VisualElement v : circuitComponent.getCircuit().getElements()) {
|
||||
if (v.equalsDescription(In.DESCRIPTION) || v.equalsDescription(Out.DESCRIPTION))
|
||||
maxNum = Math.max(maxNum, v.getElementAttributes().get(Keys.PINNUMBER));
|
||||
}
|
||||
if ((maxNum & 1) != 0) maxNum++;
|
||||
|
||||
// defines the power supply circuit
|
||||
ArrayList<Movable> list = new ArrayList<>();
|
||||
list.add(new VisualElement(PowerSupply.DESCRIPTION.getName())
|
||||
.setShapeFactory(shapeFactory)
|
||||
.setPos(new Vector(SIZE * 2, 0)));
|
||||
list.add(new VisualElement(In.DESCRIPTION.getName())
|
||||
.setShapeFactory(shapeFactory)
|
||||
.setAttribute(Keys.LABEL, "VDD")
|
||||
.setAttribute(Keys.PINNUMBER, maxNum)
|
||||
.setPos(new Vector(0, 0)));
|
||||
list.add(new VisualElement(In.DESCRIPTION.getName())
|
||||
.setShapeFactory(shapeFactory)
|
||||
.setAttribute(Keys.LABEL, "GND")
|
||||
.setAttribute(Keys.PINNUMBER, maxNum / 2)
|
||||
.setPos(new Vector(0, SIZE * 2)));
|
||||
list.add(new Wire(new Vector(0, 0), new Vector(SIZE * 2, 0)));
|
||||
list.add(new Wire(new Vector(0, SIZE * 2), new Vector(SIZE, SIZE * 2)));
|
||||
list.add(new Wire(new Vector(SIZE, SIZE * 2), new Vector(SIZE, SIZE)));
|
||||
list.add(new Wire(new Vector(SIZE, SIZE), new Vector(SIZE * 2, SIZE)));
|
||||
circuitComponent.setPartsToInsert(list);
|
||||
}
|
||||
}
|
||||
}.setToolTip(Lang.get("menu_addPowerSupply_tt")).createJMenuItem());
|
||||
|
||||
return special;
|
||||
}
|
||||
|
||||
|
@ -653,6 +653,17 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the given list of elements to insert to the circuit
|
||||
*
|
||||
* @param elements the list of elements to insert
|
||||
*/
|
||||
public void setPartsToInsert(ArrayList<Movable> elements) {
|
||||
parent.ensureModelIsStopped();
|
||||
mouseInsertList.activate(elements, getPosVector(lastMousePos.x, lastMousePos.y));
|
||||
repaintNeeded();
|
||||
}
|
||||
|
||||
|
||||
private BufferedImage buffer;
|
||||
private int highlightedPaintedSize;
|
||||
@ -1732,6 +1743,23 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
||||
super.activate();
|
||||
this.elements = elements;
|
||||
lastPos = pos;
|
||||
|
||||
Vector max = null;
|
||||
for (Movable m : elements)
|
||||
if (m instanceof VisualElement) {
|
||||
GraphicMinMax mm = ((VisualElement) m).getMinMax(false);
|
||||
if (max == null)
|
||||
max = mm.getMax();
|
||||
else
|
||||
max = Vector.max(max, mm.getMax());
|
||||
}
|
||||
|
||||
if (max != null) {
|
||||
Vector delta = CircuitComponent.raster(lastPos.sub(max));
|
||||
for (Movable m : elements)
|
||||
m.move(delta);
|
||||
}
|
||||
|
||||
deleteAction.setActive(true);
|
||||
rotateAction.setEnabled(true);
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import com.thoughtworks.xstream.io.xml.PrettyPrintWriter;
|
||||
import de.neemann.digital.draw.elements.Circuit;
|
||||
import de.neemann.digital.draw.elements.Movable;
|
||||
import de.neemann.digital.draw.elements.VisualElement;
|
||||
import de.neemann.digital.draw.graphics.GraphicMinMax;
|
||||
import de.neemann.digital.draw.graphics.Vector;
|
||||
import de.neemann.digital.draw.shapes.ShapeFactory;
|
||||
|
||||
@ -74,27 +73,14 @@ public class CircuitTransferable implements Transferable {
|
||||
return null;
|
||||
|
||||
XStream xStream = Circuit.getxStream();
|
||||
Vector max = null;
|
||||
try (Reader in = new StringReader(data.toString())) {
|
||||
ArrayList<Movable> elements = (ArrayList<Movable>) xStream.fromXML(in);
|
||||
if (elements == null)
|
||||
return null;
|
||||
|
||||
for (Movable m : elements)
|
||||
if (m instanceof VisualElement) {
|
||||
if (m instanceof VisualElement)
|
||||
((VisualElement) m).setShapeFactory(shapeFactory);
|
||||
GraphicMinMax mm = ((VisualElement) m).getMinMax(false);
|
||||
if (max == null)
|
||||
max = mm.getMax();
|
||||
else
|
||||
max = Vector.max(max, mm.getMax());
|
||||
}
|
||||
|
||||
if (max != null) {
|
||||
Vector delta = CircuitComponent.raster(lastMousePos.sub(max));
|
||||
for (Movable m : elements)
|
||||
m.move(delta);
|
||||
}
|
||||
|
||||
return elements;
|
||||
}
|
||||
|
@ -449,6 +449,14 @@ Die gesammte Speichergröße beträgt damit damit dx*dy*2 Speicherworte.</string
|
||||
<string name="elem_LightBulb_pin_A">Anschluss</string>
|
||||
<string name="elem_LightBulb_pin_B">Anschluss</string>
|
||||
|
||||
<string name="elem_PowerSupply">Versorgung</string>
|
||||
<string name="elem_PowerSupply_tt">Hat keine weitere Funktion. Stellt nur sicher, dass VDD und GND angeschlossen sind.
|
||||
Kann im Zusammenhang mit den 74xx Bausteinen verwendet werden, um Anschlüsse für die Spannungsversorgung
|
||||
zu erzeugen, welche dann auch auf korrekte Beschaltung geprüft werden.</string>
|
||||
<string name="elem_PowerSupply_pin_VDD">Muss mit VDD verbunden werden!</string>
|
||||
<string name="elem_PowerSupply_pin_GND">Muss mit GND verbunden werden!</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>
|
||||
@ -547,6 +555,7 @@ Sind evtl. die Namen der Variablen nicht eindeutig?</string>
|
||||
<string name="err_nameUsedTwice_N">Signal {0} wurde mehrfach verwendet!</string>
|
||||
<string name="err_errorParsingTestdata">Fehler beim Einlesen der Testdaten.</string>
|
||||
<string name="err_backtrackOf_N_isImpossible">Die Modelkomponente {0} kann nicht analysiert werden.</string>
|
||||
<string name="err_errorInPowerSupply">Fehler in der Stromversorgung.</string>
|
||||
|
||||
<string name="key_AddrBits">Adress-Bits</string>
|
||||
<string name="key_AddrBits_tt">Anzahl der Adress-Bits die verwendet werden.</string>
|
||||
@ -890,6 +899,8 @@ Sind evtl. die Namen der Variablen nicht eindeutig?</string>
|
||||
<string name="menu_showDataAsGraph_tt">Zeigt die Daten als Graph an.</string>
|
||||
<string name="menu_showDataAsTable">Zeige Tabelle</string>
|
||||
<string name="menu_showDataAsTable_tt">Zeigt die Daten als Tabelle an.</string>
|
||||
<string name="menu_addPowerSupply">Spannungsversorung ergänzen</string>
|
||||
<string name="menu_addPowerSupply_tt">Erweitert die Schaltung um eine Spannungsversorung.</string>
|
||||
|
||||
<string name="message">Digital
|
||||
|
||||
|
@ -439,6 +439,12 @@
|
||||
<string name="elem_LightBulb_pin_A">Connection</string>
|
||||
<string name="elem_LightBulb_pin_B">Connection</string>
|
||||
|
||||
<string name="elem_PowerSupply">Power</string>
|
||||
<string name="elem_PowerSupply_tt">Has no function. Makes sure that VDD and GND are connected.
|
||||
Can be used in 74xx circuits to generate the pins for the voltage supply, which are tested for correct wiring.</string>
|
||||
<string name="elem_PowerSupply_pin_VDD">Must be connected to VDD!</string>
|
||||
<string name="elem_PowerSupply_pin_GND">Must be connected to GND!</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>
|
||||
@ -537,6 +543,7 @@ The names of the variables may not be unique.</string>
|
||||
<string name="err_nameUsedTwice_N">Signal {0} is used twice!</string>
|
||||
<string name="err_errorParsingTestdata">Error parsing the test data.</string>
|
||||
<string name="err_backtrackOf_N_isImpossible">The model component {0} can not be analysed.</string>
|
||||
<string name="err_errorInPowerSupply">Error in wiring of power supply.</string>
|
||||
|
||||
<string name="key_AddrBits">Address Bits</string>
|
||||
<string name="key_AddrBits_tt">Number of address bits used.</string>
|
||||
@ -878,6 +885,8 @@ The names of the variables may not be unique.</string>
|
||||
<string name="menu_showDataAsGraph_tt">Show the data as a Graph.</string>
|
||||
<string name="menu_showDataAsTable">Show table</string>
|
||||
<string name="menu_showDataAsTable_tt">Shows values as a table.</string>
|
||||
<string name="menu_addPowerSupply">Add power supply</string>
|
||||
<string name="menu_addPowerSupply_tt">Adds a power supply to the circuit.</string>
|
||||
|
||||
|
||||
<string name="message">Digital
|
||||
|
@ -39,7 +39,7 @@ public class TestExamples extends TestCase {
|
||||
*/
|
||||
public void testTestExamples() throws Exception {
|
||||
File examples = new File(Resources.getRoot(), "/dig/test");
|
||||
assertEquals(80, new FileScanner(this::check).scan(examples));
|
||||
assertEquals(85, new FileScanner(this::check).scan(examples));
|
||||
assertEquals(74, testCasesInFiles);
|
||||
}
|
||||
|
||||
|
40
src/test/resources/dig/test/power/power.dig
Normal file
40
src/test/resources/dig/test/power/power.dig
Normal file
@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<circuit>
|
||||
<version>1</version>
|
||||
<attributes/>
|
||||
<visualElements>
|
||||
<visualElement>
|
||||
<elementName>PowerSupply</elementName>
|
||||
<elementAttributes/>
|
||||
<pos x="400" y="320"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>Ground</elementName>
|
||||
<elementAttributes/>
|
||||
<pos x="360" y="360"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>VDD</elementName>
|
||||
<elementAttributes/>
|
||||
<pos x="360" y="300"/>
|
||||
</visualElement>
|
||||
</visualElements>
|
||||
<wires>
|
||||
<wire>
|
||||
<p1 x="360" y="320"/>
|
||||
<p2 x="400" y="320"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="360" y="340"/>
|
||||
<p2 x="400" y="340"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="360" y="300"/>
|
||||
<p2 x="360" y="320"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="360" y="340"/>
|
||||
<p2 x="360" y="360"/>
|
||||
</wire>
|
||||
</wires>
|
||||
</circuit>
|
35
src/test/resources/dig/test/power/power1Error.dig
Normal file
35
src/test/resources/dig/test/power/power1Error.dig
Normal file
@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<circuit>
|
||||
<version>1</version>
|
||||
<attributes/>
|
||||
<visualElements>
|
||||
<visualElement>
|
||||
<elementName>PowerSupply</elementName>
|
||||
<elementAttributes/>
|
||||
<pos x="400" y="320"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>VDD</elementName>
|
||||
<elementAttributes/>
|
||||
<pos x="360" y="300"/>
|
||||
</visualElement>
|
||||
</visualElements>
|
||||
<wires>
|
||||
<wire>
|
||||
<p1 x="360" y="320"/>
|
||||
<p2 x="400" y="320"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="360" y="340"/>
|
||||
<p2 x="400" y="340"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="360" y="300"/>
|
||||
<p2 x="360" y="320"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="360" y="320"/>
|
||||
<p2 x="360" y="340"/>
|
||||
</wire>
|
||||
</wires>
|
||||
</circuit>
|
35
src/test/resources/dig/test/power/power2Error.dig
Normal file
35
src/test/resources/dig/test/power/power2Error.dig
Normal file
@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<circuit>
|
||||
<version>1</version>
|
||||
<attributes/>
|
||||
<visualElements>
|
||||
<visualElement>
|
||||
<elementName>PowerSupply</elementName>
|
||||
<elementAttributes/>
|
||||
<pos x="400" y="320"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>Ground</elementName>
|
||||
<elementAttributes/>
|
||||
<pos x="360" y="360"/>
|
||||
</visualElement>
|
||||
</visualElements>
|
||||
<wires>
|
||||
<wire>
|
||||
<p1 x="360" y="320"/>
|
||||
<p2 x="400" y="320"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="360" y="340"/>
|
||||
<p2 x="400" y="340"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="360" y="320"/>
|
||||
<p2 x="360" y="340"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="360" y="340"/>
|
||||
<p2 x="360" y="360"/>
|
||||
</wire>
|
||||
</wires>
|
||||
</circuit>
|
44
src/test/resources/dig/test/power/power3Error.dig
Normal file
44
src/test/resources/dig/test/power/power3Error.dig
Normal file
@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<circuit>
|
||||
<version>1</version>
|
||||
<attributes/>
|
||||
<visualElements>
|
||||
<visualElement>
|
||||
<elementName>PowerSupply</elementName>
|
||||
<elementAttributes/>
|
||||
<pos x="400" y="320"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>Ground</elementName>
|
||||
<elementAttributes/>
|
||||
<pos x="320" y="360"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>Not</elementName>
|
||||
<elementAttributes/>
|
||||
<pos x="340" y="320"/>
|
||||
</visualElement>
|
||||
</visualElements>
|
||||
<wires>
|
||||
<wire>
|
||||
<p1 x="320" y="320"/>
|
||||
<p2 x="340" y="320"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="380" y="320"/>
|
||||
<p2 x="400" y="320"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="320" y="340"/>
|
||||
<p2 x="400" y="340"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="320" y="320"/>
|
||||
<p2 x="320" y="340"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="320" y="340"/>
|
||||
<p2 x="320" y="360"/>
|
||||
</wire>
|
||||
</wires>
|
||||
</circuit>
|
49
src/test/resources/dig/test/power/power4Error.dig
Normal file
49
src/test/resources/dig/test/power/power4Error.dig
Normal file
@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<circuit>
|
||||
<version>1</version>
|
||||
<attributes/>
|
||||
<visualElements>
|
||||
<visualElement>
|
||||
<elementName>PowerSupply</elementName>
|
||||
<elementAttributes/>
|
||||
<pos x="400" y="320"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>Ground</elementName>
|
||||
<elementAttributes/>
|
||||
<pos x="320" y="360"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>VDD</elementName>
|
||||
<elementAttributes/>
|
||||
<pos x="380" y="300"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>Delay</elementName>
|
||||
<elementAttributes/>
|
||||
<pos x="340" y="340"/>
|
||||
</visualElement>
|
||||
</visualElements>
|
||||
<wires>
|
||||
<wire>
|
||||
<p1 x="380" y="320"/>
|
||||
<p2 x="400" y="320"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="320" y="340"/>
|
||||
<p2 x="340" y="340"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="380" y="340"/>
|
||||
<p2 x="400" y="340"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="320" y="340"/>
|
||||
<p2 x="320" y="360"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="380" y="300"/>
|
||||
<p2 x="380" y="320"/>
|
||||
</wire>
|
||||
</wires>
|
||||
</circuit>
|
Loading…
x
Reference in New Issue
Block a user