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;
}
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);
}
}
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();
}
}
}
});
}
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);
}
}
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);
}
Aggregations