Search in sources :

Example 1 with ObservableValue

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

the class CircuitComponent method getToolTipText.

@Override
public String getToolTipText(MouseEvent event) {
    Vector pos = getPosVector(event);
    VisualElement ve = circuit.getElementAt(pos);
    if (ve != null) {
        Pin p = circuit.getPinAt(raster(pos), ve);
        if (p != null)
            return createPinToolTip(p);
        try {
            ElementTypeDescription etd = library.getElementType(ve.getElementName());
            String tt = etd.getDescription(ve.getElementAttributes());
            final String pin = ve.getElementAttributes().get(Keys.PINNUMBER);
            if (pin.length() > 0)
                tt += " (" + Lang.get("msg_pin_N", pin) + ")";
            return checkToolTip(tt);
        } catch (ElementNotFoundException e) {
            return null;
        }
    }
    Wire w = circuit.getWireAt(pos, SIZE2);
    if (w != null) {
        ObservableValue v = w.getValue();
        if (v != null)
            return v.getValueString();
    }
    return null;
}
Also used : ObservableValue(de.neemann.digital.core.ObservableValue) ElementNotFoundException(de.neemann.digital.draw.library.ElementNotFoundException) Vector(de.neemann.digital.draw.graphics.Vector)

Example 2 with ObservableValue

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

the class StdIOInterface method writeValues.

@Override
public void writeValues(ObservableValues values) throws IOException {
    try {
        for (ObservableValue v : values) {
            final int bits = v.getBits();
            final long value = v.getValue();
            final long highZ = v.getHighZ();
            long mask = 1;
            for (int i = 0; i < bits; i++) {
                if ((highZ & mask) != 0)
                    writer.write('Z');
                else {
                    if ((value & mask) != 0)
                        writer.write('1');
                    else
                        writer.write('0');
                }
                mask <<= 1;
            }
        }
        writer.write("\n");
        writer.flush();
    } catch (IOException e) {
        throw new IOException(Lang.get("err_writingToStdOut_O", getConsoleOut()), e);
    }
}
Also used : ObservableValue(de.neemann.digital.core.ObservableValue)

Example 3 with ObservableValue

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

the class Monoflop method init.

@Override
public void init(Model model) throws NodeException {
    ArrayList<Clock> clockList = model.getClocks();
    if (clockList.size() != 1)
        throw new NodeException(Lang.get("err_monoflopRequiresOneClock"));
    final ObservableValue clock = clockList.get(0).getClockOutput();
    clock.addObserver(() -> {
        if (clock.getBool()) {
            if (counter > 0) {
                counter--;
                if (counter == 0) {
                    setOut(false);
                    Monoflop.this.hasChanged();
                }
            }
        }
    });
}
Also used : ObservableValue(de.neemann.digital.core.ObservableValue) NodeException(de.neemann.digital.core.NodeException) Clock(de.neemann.digital.core.wiring.Clock)

Example 4 with ObservableValue

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

the class AbstractBusHandler method recalculate.

/**
 * recalculates the state of the net
 * Also calls {@link AbstractBusHandler#set(long, long)} with the new value.
 */
void recalculate() {
    long value = 0;
    burn = State.ok;
    if (getResistor().equals(PinDescription.PullResistor.both)) {
        burn = State.both;
        set(0, -1);
    } else {
        long highz = -1;
        for (ObservableValue input : getInputs()) {
            highz &= input.getHighZ();
            value |= input.getValue();
        }
        // check for a burn condition!
        for (ObservableValue input : getInputs()) {
            long bothDefine = ~(highz | input.getHighZ());
            if ((value & bothDefine) != (input.getValue() & bothDefine))
                burn = State.burn;
        }
        switch(getResistor()) {
            case pullUp:
                set(value | highz, 0);
                break;
            case pullDown:
                set(value, 0);
                break;
            default:
                set(value, highz);
        }
    }
    // if burn condition and not yet added for post step check add for post step check
    if (burn != State.ok && (obs.getVersion() != addedVersion)) {
        addedVersion = obs.getVersion();
        obs.addCheck(this);
    }
}
Also used : ObservableValue(de.neemann.digital.core.ObservableValue)

Example 5 with ObservableValue

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

the class DecoderTest method testDecoder.

public void testDecoder() throws Exception {
    Model model = new Model();
    ObservableValue sel = new ObservableValue("sel", 2);
    Decoder decoder = model.add(new Decoder(new ElementAttributes().set(Keys.SELECTOR_BITS, 2)));
    decoder.setInputs(sel.asList());
    TestExecuter te = new TestExecuter(model).setInputs(sel).setOutputs(decoder.getOutputs());
    te.check(0, 1, 0, 0, 0);
    te.check(1, 0, 1, 0, 0);
    te.check(2, 0, 0, 1, 0);
    te.check(3, 0, 0, 0, 1);
}
Also used : Model(de.neemann.digital.core.Model) ObservableValue(de.neemann.digital.core.ObservableValue) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) TestExecuter(de.neemann.digital.TestExecuter)

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