mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-16 16:34:47 -04:00
Added multiple poles to the single-pole relay in line with the double-pole relay.
(cherry picked from commit 8c1687b)
This commit is contained in:
parent
50d4bed3cb
commit
a6822c16ab
@ -25,11 +25,11 @@ public class Relay extends Node implements Element {
|
|||||||
.addAttribute(Keys.ROTATE)
|
.addAttribute(Keys.ROTATE)
|
||||||
.addAttribute(Keys.BITS)
|
.addAttribute(Keys.BITS)
|
||||||
.addAttribute(Keys.LABEL)
|
.addAttribute(Keys.LABEL)
|
||||||
|
.addAttribute(Keys.POLES)
|
||||||
.addAttribute(Keys.RELAY_NORMALLY_CLOSED);
|
.addAttribute(Keys.RELAY_NORMALLY_CLOSED);
|
||||||
|
|
||||||
|
private final Pole[] poles;
|
||||||
private final boolean invers;
|
private final boolean invers;
|
||||||
private final Switch s;
|
|
||||||
private ObservableValue input1;
|
private ObservableValue input1;
|
||||||
private ObservableValue input2;
|
private ObservableValue input2;
|
||||||
private boolean isClosed;
|
private boolean isClosed;
|
||||||
@ -40,30 +40,31 @@ public class Relay extends Node implements Element {
|
|||||||
* @param attr the attributes
|
* @param attr the attributes
|
||||||
*/
|
*/
|
||||||
public Relay(ElementAttributes attr) {
|
public Relay(ElementAttributes attr) {
|
||||||
this(attr, attr.get(Keys.RELAY_NORMALLY_CLOSED));
|
this.invers = attr.get(Keys.RELAY_NORMALLY_CLOSED);
|
||||||
}
|
int bits = attr.getBits();
|
||||||
|
int poleCount = attr.get(Keys.POLES);
|
||||||
/**
|
poles = new Pole[poleCount];
|
||||||
* Create a new instance
|
for (int i = 0; i < poleCount; i++)
|
||||||
*
|
poles[i] = new Pole(bits, i + 1);
|
||||||
* @param attr the attributes
|
|
||||||
* @param invers true if relay is closed on zero in.
|
|
||||||
*/
|
|
||||||
public Relay(ElementAttributes attr, boolean invers) {
|
|
||||||
this.invers = invers;
|
|
||||||
s = new Switch(attr, invers, "out1", "out2");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ObservableValues getOutputs() {
|
public ObservableValues getOutputs() {
|
||||||
return s.getOutputs();
|
ObservableValues.Builder ov = new ObservableValues.Builder();
|
||||||
|
for (Pole p : poles)
|
||||||
|
p.addOutputs(ov);
|
||||||
|
return ov.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setInputs(ObservableValues inputs) throws NodeException {
|
public void setInputs(ObservableValues inputs) throws NodeException {
|
||||||
input1 = inputs.get(0).checkBits(1, this).addObserverToValue(this);
|
input1 = inputs.get(0).checkBits(1, this).addObserverToValue(this);
|
||||||
input2 = inputs.get(1).checkBits(1, this).addObserverToValue(this);
|
input2 = inputs.get(1).checkBits(1, this).addObserverToValue(this);
|
||||||
s.setInputs(new ObservableValues(inputs.get(2), inputs.get(3)));
|
int i = 2;
|
||||||
|
for (Pole p : poles) {
|
||||||
|
p.setInputs(inputs.get(i), inputs.get(i + 1));
|
||||||
|
i += 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -76,12 +77,14 @@ public class Relay extends Node implements Element {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeOutputs() {
|
public void writeOutputs() {
|
||||||
s.setClosed(isClosed);
|
for (Pole p : poles)
|
||||||
|
p.setClosed(isClosed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(Model model) {
|
public void init(Model model) {
|
||||||
s.init(model);
|
for (Pole p : poles)
|
||||||
|
p.init(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -90,4 +93,32 @@ public class Relay extends Node implements Element {
|
|||||||
public boolean isClosed() {
|
public boolean isClosed() {
|
||||||
return isClosed;
|
return isClosed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final class Pole {
|
||||||
|
private final Switch s;
|
||||||
|
private final ObservableValue outputA;
|
||||||
|
private final ObservableValue outputB;
|
||||||
|
|
||||||
|
private Pole(int bits, int num) {
|
||||||
|
outputA = new ObservableValue("A" + num, bits).setBidirectional().setToHighZ();
|
||||||
|
outputB = new ObservableValue("B" + num, bits).setBidirectional().setToHighZ();
|
||||||
|
s = new Switch(outputA, outputB, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addOutputs(ObservableValues.Builder ov) {
|
||||||
|
ov.add(outputA, outputB);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInputs(ObservableValue inA, ObservableValue inB) throws NodeException {
|
||||||
|
s.setInputs(new ObservableValues(inA, inB));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init(Model model) {
|
||||||
|
s.init(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClosed(boolean isClosed) {
|
||||||
|
s.setClosed(isClosed);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,9 +26,10 @@ public class RelayShape implements Shape {
|
|||||||
private final PinDescriptions inputs;
|
private final PinDescriptions inputs;
|
||||||
private final PinDescriptions outputs;
|
private final PinDescriptions outputs;
|
||||||
private final String label;
|
private final String label;
|
||||||
private boolean invers;
|
private final int poles;
|
||||||
private Relay relay;
|
private Relay relay;
|
||||||
private boolean relayIsClosed;
|
private boolean relayIsClosed;
|
||||||
|
private Pins pins;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance
|
* Creates a new instance
|
||||||
@ -43,15 +44,25 @@ public class RelayShape implements Shape {
|
|||||||
invers = attributes.get(Keys.RELAY_NORMALLY_CLOSED);
|
invers = attributes.get(Keys.RELAY_NORMALLY_CLOSED);
|
||||||
relayIsClosed = invers;
|
relayIsClosed = invers;
|
||||||
label = attributes.getCleanLabel();
|
label = attributes.getCleanLabel();
|
||||||
|
poles = attributes.get(Keys.POLES);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Pins getPins() {
|
public Pins getPins() {
|
||||||
return new Pins()
|
if (pins == null) {
|
||||||
|
pins = new Pins()
|
||||||
.add(new Pin(new Vector(0, -SIZE * 2), inputs.get(0)))
|
.add(new Pin(new Vector(0, -SIZE * 2), inputs.get(0)))
|
||||||
.add(new Pin(new Vector(SIZE * 2, -SIZE * 2), inputs.get(1)))
|
.add(new Pin(new Vector(SIZE * 2, -SIZE * 2), inputs.get(1)));
|
||||||
.add(new Pin(new Vector(0, 0), outputs.get(0)))
|
final int relayStepY = 2 * SIZE;
|
||||||
.add(new Pin(new Vector(SIZE * 2, 0), outputs.get(1)));
|
int relayBaseY = 0;
|
||||||
|
for (int p = 0; p < poles; p++) {
|
||||||
|
pins
|
||||||
|
.add(new Pin(new Vector(0, relayBaseY), outputs.get(p * 2)))
|
||||||
|
.add(new Pin(new Vector(SIZE * 2, relayBaseY), outputs.get(p * 2 + 1)));
|
||||||
|
relayBaseY += relayStepY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return pins;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -70,16 +81,28 @@ public class RelayShape implements Shape {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawTo(Graphic graphic, Style highLight) {
|
public void drawTo(Graphic graphic, Style highLight) {
|
||||||
int yOffs = 0;
|
final int relayTipY;
|
||||||
|
final int relayTipX;
|
||||||
if (relayIsClosed) {
|
if (relayIsClosed) {
|
||||||
graphic.drawLine(new Vector(0, 0), new Vector(SIZE * 2, 0), Style.NORMAL);
|
relayTipX = SIZE * 2;
|
||||||
|
relayTipY = 0;
|
||||||
} else {
|
} else {
|
||||||
yOffs = SIZE2 / 2;
|
relayTipX = (SIZE * 2) - 4;
|
||||||
graphic.drawLine(new Vector(0, 0), new Vector(SIZE * 2 - 4, -yOffs * 2), Style.NORMAL);
|
relayTipY = SIZE2;
|
||||||
}
|
}
|
||||||
graphic.drawLine(new Vector(SIZE, -yOffs), new Vector(SIZE, 1 - SIZE), Style.DASH);
|
|
||||||
|
|
||||||
|
final int relayStepY = 2 * SIZE;
|
||||||
|
int relayBaseY = 0;
|
||||||
|
for (int p = 0; p < poles; p++) {
|
||||||
|
graphic.drawLine(new Vector(0, relayBaseY), new Vector(relayTipX, relayBaseY - relayTipY), Style.NORMAL);
|
||||||
|
relayBaseY += relayStepY;
|
||||||
|
}
|
||||||
|
|
||||||
|
final int yOffs = (SIZE / 4) + (relayTipY / 2);
|
||||||
|
graphic.drawLine(new Vector(SIZE, (poles - 1) * SIZE * 2 - yOffs), new Vector(SIZE, 1 - SIZE), Style.DASH);
|
||||||
|
|
||||||
|
|
||||||
|
// the coil
|
||||||
graphic.drawPolygon(new Polygon(true)
|
graphic.drawPolygon(new Polygon(true)
|
||||||
.add(SIZE2, -SIZE)
|
.add(SIZE2, -SIZE)
|
||||||
.add(SIZE2, -SIZE * 3)
|
.add(SIZE2, -SIZE * 3)
|
||||||
|
@ -670,8 +670,6 @@
|
|||||||
Das Relais verhält sich damit ähnlich wie ein XOr Gatter.</string>
|
Das Relais verhält sich damit ähnlich wie ein XOr Gatter.</string>
|
||||||
<string name="elem_Relay_pin_in1">Ein Steuereingang des Relais.</string>
|
<string name="elem_Relay_pin_in1">Ein Steuereingang des Relais.</string>
|
||||||
<string name="elem_Relay_pin_in2">Ein Steuereingang des Relais.</string>
|
<string name="elem_Relay_pin_in2">Ein Steuereingang des Relais.</string>
|
||||||
<string name="elem_Relay_pin_out1">Einer der Ausgänge des gesteuerten Schalters.</string>
|
|
||||||
<string name="elem_Relay_pin_out2">Einer der Ausgänge des gesteuerten Schalters.</string>
|
|
||||||
<string name="elem_RelayDT">Relais mit Wechselkontakt</string>
|
<string name="elem_RelayDT">Relais mit Wechselkontakt</string>
|
||||||
<string name="elem_RelayDT_tt">Ein Relais ist ein Schalter, welcher über eine Spule umgeschaltet werden kann.
|
<string name="elem_RelayDT_tt">Ein Relais ist ein Schalter, welcher über eine Spule umgeschaltet werden kann.
|
||||||
Wenn ein Strom durch das Relais fließt, wird der Schalter geöffnet bzw. geschlossen.
|
Wenn ein Strom durch das Relais fließt, wird der Schalter geöffnet bzw. geschlossen.
|
||||||
|
@ -668,8 +668,6 @@
|
|||||||
The relay behaves similar to an XOr gate.</string>
|
The relay behaves similar to an XOr gate.</string>
|
||||||
<string name="elem_Relay_pin_in1">On of the inputs to control the relay.</string>
|
<string name="elem_Relay_pin_in1">On of the inputs to control the relay.</string>
|
||||||
<string name="elem_Relay_pin_in2">On of the inputs to control the relay.</string>
|
<string name="elem_Relay_pin_in2">On of the inputs to control the relay.</string>
|
||||||
<string name="elem_Relay_pin_out1">One of the switch outputs.</string>
|
|
||||||
<string name="elem_Relay_pin_out2">One of the switch outputs.</string>
|
|
||||||
<string name="elem_RelayDT">Double Throw Relay</string>
|
<string name="elem_RelayDT">Double Throw Relay</string>
|
||||||
<string name="elem_RelayDT_tt">A relay is a switch which can be controlled by a coil.
|
<string name="elem_RelayDT_tt">A relay is a switch which can be controlled by a coil.
|
||||||
If a current flows through the coil, the switch is closed or opened.
|
If a current flows through the coil, the switch is closed or opened.
|
||||||
|
@ -11,6 +11,7 @@ import de.neemann.digital.core.element.*;
|
|||||||
import de.neemann.digital.core.extern.External;
|
import de.neemann.digital.core.extern.External;
|
||||||
import de.neemann.digital.core.memory.LookUpTable;
|
import de.neemann.digital.core.memory.LookUpTable;
|
||||||
import de.neemann.digital.core.switching.RelayDT;
|
import de.neemann.digital.core.switching.RelayDT;
|
||||||
|
import de.neemann.digital.core.switching.Relay;
|
||||||
import de.neemann.digital.core.wiring.*;
|
import de.neemann.digital.core.wiring.*;
|
||||||
import de.neemann.digital.draw.elements.PinException;
|
import de.neemann.digital.draw.elements.PinException;
|
||||||
import de.neemann.digital.draw.graphics.GraphicSVG;
|
import de.neemann.digital.draw.graphics.GraphicSVG;
|
||||||
@ -70,6 +71,7 @@ public class TestElemConsistence extends TestCase {
|
|||||||
|| e instanceof BusSplitter
|
|| e instanceof BusSplitter
|
||||||
|| e instanceof External
|
|| e instanceof External
|
||||||
|| e instanceof LookUpTable
|
|| e instanceof LookUpTable
|
||||||
|
|| e instanceof Relay
|
||||||
|| e instanceof RelayDT);
|
|| e instanceof RelayDT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user