From: Christian Femers Date: Mon, 2 Sep 2019 04:53:18 +0000 (+0200) Subject: Introduced new adapter class for testing tristate pins easily X-Git-Url: https://mograsim.net/gitweb/?p=Mograsim.git;a=commitdiff_plain;h=ff8f3e75025958484dd10ebd380d1b62eb393396 Introduced new adapter class for testing tristate pins easily --- diff --git a/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/SwitchWithDisplay.java b/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/SwitchWithDisplay.java new file mode 100644 index 00000000..c5c3ab79 --- /dev/null +++ b/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/SwitchWithDisplay.java @@ -0,0 +1,65 @@ +package net.mograsim.logic.model.am2900; + +import net.mograsim.logic.core.components.BitDisplay; +import net.mograsim.logic.core.components.ManualSwitch; +import net.mograsim.logic.core.types.BitVector; +import net.mograsim.logic.model.model.ViewModelModifiable; +import net.mograsim.logic.model.model.components.atomic.GUIBitDisplay; +import net.mograsim.logic.model.model.components.atomic.GUIManualSwitch; +import net.mograsim.logic.model.model.wires.Pin; +import net.mograsim.logic.model.model.wires.WireCrossPoint; +import net.mograsim.logic.model.util.ModellingTool; + +public class SwitchWithDisplay +{ + private final Pin pin; + private final GUIBitDisplay guiBitDisplay; + private final GUIManualSwitch guiManualSwitch; + + public SwitchWithDisplay(ViewModelModifiable model, Pin target) + { + pin = target; + guiBitDisplay = new GUIBitDisplay(model, pin.logicWidth); + guiManualSwitch = new GUIManualSwitch(model, pin.logicWidth); + + ModellingTool tool = ModellingTool.createFor(model); + WireCrossPoint crossPoint = new WireCrossPoint(model, pin.logicWidth); + tool.connect(guiBitDisplay.getInputPin(), crossPoint); + tool.connect(guiManualSwitch.getOutputPin(), crossPoint); + } + + public final BitVector getDisplayedValue() + { + return guiBitDisplay.getBitDisplay().getDisplayedValue(); + } + + public final void setState(BitVector bits) + { + guiManualSwitch.getManualSwitch().setState(bits); + } + + public final Pin getPin() + { + return pin; + } + + public final BitDisplay getBitDisplay() + { + return guiBitDisplay.getBitDisplay(); + } + + public final ManualSwitch getManualSwitch() + { + return guiManualSwitch.getManualSwitch(); + } + + final GUIBitDisplay getGuiBitDisplay() + { + return guiBitDisplay; + } + + final GUIManualSwitch getGuiManualSwitch() + { + return guiManualSwitch; + } +} diff --git a/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/TestEnvironmentHelper.java b/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/TestEnvironmentHelper.java index 0a4838f3..9ac40307 100644 --- a/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/TestEnvironmentHelper.java +++ b/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/TestEnvironmentHelper.java @@ -116,6 +116,10 @@ public class TestEnvironmentHelper GUIBitDisplay gbd = new GUIBitDisplay(viewModel, p.logicWidth); modellingTool.connect(p, gbd.getInputPin()); idDisplayMap.put(p.name, gbd); + } else if (SwitchWithDisplay.class.isAssignableFrom(type)) + { + SwitchWithDisplay swd = new SwitchWithDisplay(viewModel, p); + setField(f, swd); } else { fail("unkown field type " + type);