Our second plug-in extends the first by demonstrating 2 new functionalities: pin-bundling and LED use.
package plugins.tutorial;
import dlsim.document.DLPlugIn;
/**
* Plugin01: sample plugin using default view
* 5 inputs, 5 outputs
* copies input to corresponding output
* bundles pins and uses leds
*
* @author rms
*
*/
public class Plugin01 extends DLPlugIn {
public static PluginInfo info =
new PluginInfo("My Second PlugIn", "Writes input to output", "5 bits",
"Illustrates in/out maps and led use");
/**
* Constructor must specify input and output size (default is 0)
* Constructor may specify pin bundling with inMap and outMap
*/
public Plugin01() {
super();
setInputSize(5);
setOutputSize(5);
setInMap(2,1,2);
setOutMap(1,2,2);
setLedSize(5);
}
/**
* evalState is called when an input state changes
* Parameters:
* source - pin number of input source that changed
* val - new state value (0 or 1)
*
* Output changes are propagated using putState(dest, val),
* where dest is the output pin number and val is the new state.
*
* Leds show current pin state
*/
public void evalState(int source, int val) {
putState(source+getInputSize(), val);
setLed(source, val);
}
}
Bundling patterns are specified using void setInMap(int... inMap) and void setOutMap(int... outMap). These methods must be called during object construction. In our example we create 3 input and 3 output pins. The first and last input pin is a 2-pin multipin, as are the second and third output pins.
Each LED will display a single digit from the set defined by the current led radix (default 16); use void setLedRadix(int radix) to change the led radix. The method void setLed(int ledno, long value) sets the specified LED with value % ledRadix. There are other methods to set a range of LEDs with numerical values.
Run DLSim 3 (using "ant run") and build the circuit shown below using Plugin01.
The circuit shows the pin bundling specified by setInMap and setOutMap, and the LED displays.![]()
Exercise