Search in sources :

Example 26 with ObservableValue

use of de.neemann.digital.core.ObservableValue in project Digital by hneemann.

the class DipSwitchShape method applyStateMonitor.

@Override
public Interactor applyStateMonitor(IOState ioState, Observer guiObserver) {
    this.ioState = ioState;
    ioState.getOutput(0).addObserverToValue(guiObserver);
    return new Interactor() {

        @Override
        public boolean clicked(CircuitComponent cc, Point pos, IOState ioState, Element element, Sync modelSync) {
            ObservableValue value = ioState.getOutput(0);
            modelSync.access(() -> value.setValue(1 - value.getValue()));
            return true;
        }
    };
}
Also used : CircuitComponent(de.neemann.digital.gui.components.CircuitComponent) IOState(de.neemann.digital.draw.elements.IOState) Element(de.neemann.digital.core.element.Element) ObservableValue(de.neemann.digital.core.ObservableValue) Sync(de.neemann.digital.gui.sync.Sync)

Example 27 with ObservableValue

use of de.neemann.digital.core.ObservableValue in project Digital by hneemann.

the class AddTest method testAdd32.

public void testAdd32() throws Exception {
    ObservableValue a = new ObservableValue("a", 32);
    ObservableValue b = new ObservableValue("b", 32);
    ObservableValue c = new ObservableValue("c", 1);
    Model model = new Model();
    Add node = new Add(new ElementAttributes().setBits(32));
    node.setInputs(ovs(a, b, c));
    model.add(node);
    TestExecuter sc = new TestExecuter(model).setInputs(a, b, c).setOutputs(node.getOutputs());
    sc.check(-1, 0, 1, 0, 1);
    sc.check(-1, 1, 0, 0, 1);
}
Also used : ObservableValue(de.neemann.digital.core.ObservableValue) Model(de.neemann.digital.core.Model) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) TestExecuter(de.neemann.digital.TestExecuter)

Example 28 with ObservableValue

use of de.neemann.digital.core.ObservableValue in project Digital by hneemann.

the class AddTest method testAdd64.

public void testAdd64() throws Exception {
    ObservableValue a = new ObservableValue("a", 64);
    ObservableValue b = new ObservableValue("b", 64);
    ObservableValue c = new ObservableValue("c", 1);
    Model model = new Model();
    Add node = new Add(new ElementAttributes().setBits(64));
    node.setInputs(ovs(a, b, c));
    model.add(node);
    TestExecuter sc = new TestExecuter(model).setInputs(a, b, c).setOutputs(node.getOutputs());
    sc.check(-1, 0, 1, 0, 1);
    sc.check(-1, 1, 0, 0, 1);
}
Also used : ObservableValue(de.neemann.digital.core.ObservableValue) Model(de.neemann.digital.core.Model) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) TestExecuter(de.neemann.digital.TestExecuter)

Example 29 with ObservableValue

use of de.neemann.digital.core.ObservableValue in project Digital by hneemann.

the class BitCountTest method testBitCount64.

public void testBitCount64() throws Exception {
    ObservableValue a = new ObservableValue("a", 64);
    Model model = new Model();
    BitCount node = new BitCount(new ElementAttributes().setBits(64));
    node.setInputs(a.asList());
    model.add(node);
    TestExecuter sc = new TestExecuter(model).setInputs(a).setOutputs(node.getOutputs());
    sc.check(0, 0);
    sc.check(-1, 64);
    sc.check(1, 1);
}
Also used : ObservableValue(de.neemann.digital.core.ObservableValue) Model(de.neemann.digital.core.Model) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) TestExecuter(de.neemann.digital.TestExecuter)

Example 30 with ObservableValue

use of de.neemann.digital.core.ObservableValue in project Digital by hneemann.

the class BitExtenderTest method testSignExtendError2.

public void testSignExtendError2() throws Exception {
    try {
        ObservableValue in = new ObservableValue("in", 5);
        new BitExtender(new ElementAttributes().set(Keys.OUTPUT_BITS, 4)).setInputs(in.asList());
        fail();
    } catch (NodeException e) {
    }
}
Also used : ObservableValue(de.neemann.digital.core.ObservableValue) NodeException(de.neemann.digital.core.NodeException) ElementAttributes(de.neemann.digital.core.element.ElementAttributes)

Aggregations

ObservableValue (de.neemann.digital.core.ObservableValue)88 ElementAttributes (de.neemann.digital.core.element.ElementAttributes)73 TestExecuter (de.neemann.digital.TestExecuter)61 Model (de.neemann.digital.core.Model)56 ObservableValues (de.neemann.digital.core.ObservableValues)17 NodeException (de.neemann.digital.core.NodeException)5 ArrayList (java.util.ArrayList)4 BitsException (de.neemann.digital.core.BitsException)3 FanIn (de.neemann.digital.core.basic.FanIn)3 Signal (de.neemann.digital.core.Signal)2 Element (de.neemann.digital.core.element.Element)2 Clock (de.neemann.digital.core.wiring.Clock)2 Delay (de.neemann.digital.core.wiring.Delay)2 DataBus (de.neemann.digital.core.wiring.bus.DataBus)2 IOState (de.neemann.digital.draw.elements.IOState)2 CircuitComponent (de.neemann.digital.gui.components.CircuitComponent)2 Sync (de.neemann.digital.gui.sync.Sync)2 BurnException (de.neemann.digital.core.BurnException)1 Node (de.neemann.digital.core.Node)1 NodeWithoutDelay (de.neemann.digital.core.NodeWithoutDelay)1