jAER project on SourceForge

net.sf.jaer.biasgen
Class Biasgen

java.lang.Object
  extended by net.sf.jaer.biasgen.Biasgen
All Implemented Interfaces:
java.util.Observer, BiasgenHardwareInterface, BiasgenPreferences, HardwareInterface
Direct Known Subclasses:
CochleaAMS1b.Biasgen, CochleaAMSWithBiasgen.Biasgen, Dollbrain1.DollBrainBiasgen, DVS128.Biasgen, DVS320.DVS320Biasgen, Motion18.Motion18Biasgen, TestchipARCsPixelTestArray.Biasgen, Tmpdiff128.Biasgen

public class Biasgen
extends java.lang.Object
implements BiasgenPreferences, java.util.Observer, BiasgenHardwareInterface

Describes a complete bias generator, with a masterbias. a bunch of IPots, and a hardware interface. This class handles the USB commands for the masterbias and ipots.

When using this class in conjunction with another use of the HardwareInterface, it is much better to share the same interface if possible. Do this by constructing the Biasgen using an existing HardwareInterface.

Users of this class should also check for unitialized bias values and warn the user that bias settings should be loaded.

Biasgen can implement the formatting of the raw bytes that are sent, although for historical reasons the default implementation is that it asks the BiasgenHardwareInterface to do this formatting. A particular system can override formatConfigurationBytes to implement a particular low level format.

Biasgen also implements a default method getControlPanel for building it's own user GUI interface, but subclasses can override this method to build their own arbitrarily-complex JPanel for control.

Author:
tobi

Nested Class Summary
protected static interface Biasgen.HasPreference
          Marks a class (for example, some object in a subclass of Biasgen) as having a preference that can be loaded and stored.
 
Field Summary
protected  javax.swing.JPanel controlPanel
          The built-in control panel that is built by getControlPanel on first call
protected  BiasgenHardwareInterface hardwareInterface
          The hardware interface for this Biasgen object
protected  PotArray potArray
           
 
Constructor Summary
Biasgen(Chip chip)
          Constructs a new biasgen.
 
Method Summary
 javax.swing.JPanel buildControlPanel()
          Builds the default control panel and returns it.
 void close()
          Closes the device and frees the internal device handle.
 void endBatchEdit()
          call this to end the edit and send the values over the hardware interface.
 void exportPreferences(java.io.OutputStream os)
          exports preference values for this subtree of all Preferences (the biasgen package subtreee).
 void flashConfiguration(Biasgen biasgen)
          flashes the the ipot values onto the hardware interface.
 byte[] formatConfigurationBytes(Biasgen biasgen)
          This method formats and returns a byte array of configuration information (e.g.
 Chip getChip()
          Returns chip associated with this biasgen.
 javax.swing.JPanel getControlPanel()
          Returns the graphical control panel for this Biasgen.
 BiasgenHardwareInterface getHardwareInterface()
           
 java.util.ArrayList<IPotGroup> getIPotGroups()
           
 Masterbias getMasterbias()
           
 java.lang.String getName()
           
 int getNumPots()
           
 PotArray getPotArray()
          A Biasgen has a single PotArray of biases.
 Pot getPotByName(java.lang.String name)
          Get an IPot by name.
 Pot getPotByNumber(int number)
          Get an IPot by number in IPotArray.
 java.lang.String getTypeName()
          get text name of interface, e.g.
 void importPreferences(java.io.InputStream is)
          Imports preference values for this subtree of all Preferences (the biasgen package subtreee).
 boolean isBatchEditOccurring()
          boolean that flags that a batch edit is occurring
 boolean isInitialized()
          Checks for unitialized biases (no non-zero preference values).
 boolean isOpen()
           
 void loadPreferences()
          Loads preferences for the potArray and masterbias.
 void open()
          opens the first available hardware interface found
 void putPref(java.lang.String key, boolean value)
          Use this method to put a value only if the value is different than the stored Preference value.
 void putPref(java.lang.String key, double value)
          Use this method to put a value to the preferences only if the value is different than the stored Preference value.
 void putPref(java.lang.String key, float value)
          Use this method to put a value to the preferences only if the value is different than the stored Preference value.
 void putPref(java.lang.String key, int value)
          Use this method to put a value to the preferences only if the value is different than the stored Preference value.
 void putPref(java.lang.String key, java.lang.String value)
          Use this method to put a value only if the value is different than the stored Preference value.
 void resume()
          restores biases after suspend
 void sendConfiguration(Biasgen biasgen)
          sends the ipot values over the hardware interface if there is not a batch edit occuring.
 void setBatchEditOccurring(boolean batchEditOccurring)
          sets boolean to flag batch edit occuring
 void setChip(Chip chip)
          Sets chip associated with this biasgen
 void setControlPanel(javax.swing.JPanel panel)
          Sets the control panel but doesn't do anything to rebuild the GUI interface.
 void setHardwareInterface(BiasgenHardwareInterface hardwareInterface)
          Assigns the HardwareInterface to this Biasgen.
 void setIPotGroups(java.util.ArrayList<IPotGroup> iPotGroups)
           
 void setMasterbias(Masterbias masterbias)
           
 void setName(java.lang.String name)
           
 void setPotArray(PotArray PotArray)
           
 void setPowerDown(boolean powerDown)
          sends the powerdown vendor request to power down the chip.
 void showUnitializedBiasesWarningDialog(java.awt.Frame container)
          Shows a dialog centered on the screen warning user to load bias settings
 void startBatchEdit()
          call this when starting a set of related pot value changes.
 void storePreferences()
          Stores preferences to the Preferences node for the potArray and masterbias.
 void suspend()
          sets all the biases to zero current
 java.lang.String toString()
           
 void update(java.util.Observable observable, java.lang.Object object)
          called when observable (masterbias) calls notifyObservers.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

potArray

protected transient PotArray potArray

hardwareInterface

protected BiasgenHardwareInterface hardwareInterface
The hardware interface for this Biasgen object


controlPanel

protected javax.swing.JPanel controlPanel
The built-in control panel that is built by getControlPanel on first call

Constructor Detail

Biasgen

public Biasgen(Chip chip)
Constructs a new biasgen. A BiasgenHardwareInterface is constructed when needed. This biasgen adds itself as a PropertyChangeListener to the IPotArray. It also adds itself as an Observer for the Masterbias.

See Also:
HardwareInterfaceException
Method Detail

getControlPanel

public javax.swing.JPanel getControlPanel()
Returns the graphical control panel for this Biasgen. The control panel must be first built using, e.g. the default buildControlPanel.

Returns:
the control panel

buildControlPanel

public javax.swing.JPanel buildControlPanel()
Builds the default control panel and returns it. This method builds a BiasgenPanel that encloses the PotArray in a PotPanel and the Masterbias in a MasterbiasPanel and returns a tabbed pane for these two components. Subclasses can override buildControlPanel to build their own control panel.

Returns:
the default control panel

setControlPanel

public void setControlPanel(javax.swing.JPanel panel)
Sets the control panel but doesn't do anything to rebuild the GUI interface. To rebuild the control panel, set the control panel to null and call getControlPanel.

Parameters:
panel - the new panel

getPotArray

public PotArray getPotArray()
A Biasgen has a single PotArray of biases.

Returns:
the PotArray

setPotArray

public void setPotArray(PotArray PotArray)

getMasterbias

public Masterbias getMasterbias()

setMasterbias

public void setMasterbias(Masterbias masterbias)

getName

public java.lang.String getName()

setName

public void setName(java.lang.String name)

exportPreferences

public void exportPreferences(java.io.OutputStream os)
                       throws java.io.IOException
exports preference values for this subtree of all Preferences (the biasgen package subtreee). Biases and other settings (e.g. master bias resistor) are written to the output stream as an XML file

Specified by:
exportPreferences in interface BiasgenPreferences
Parameters:
os - an output stream, typically constructed for a FileOutputStream
Throws:
java.io.IOException - if the output stream cannot be written

importPreferences

public void importPreferences(java.io.InputStream is)
                       throws java.io.IOException,
                              java.util.prefs.InvalidPreferencesFormatException,
                              HardwareInterfaceException
Imports preference values for this subtree of all Preferences (the biasgen package subtreee). Biases and other settings (e.g. master bias resistor) are read in from an XML file. Bias values are sent as a batch to the device after values are imported.

Specified by:
importPreferences in interface BiasgenPreferences
Parameters:
is - an input stream, typically constructed for a FileInputStream
Throws:
java.io.IOException - if the output stream cannot be read
java.util.prefs.InvalidPreferencesFormatException
HardwareInterfaceException

loadPreferences

public void loadPreferences()
Loads preferences for the potArray and masterbias. Subclasses should override this method to load additional information.

Specified by:
loadPreferences in interface BiasgenPreferences

storePreferences

public void storePreferences()
Stores preferences to the Preferences node for the potArray and masterbias. Subclasses must override this method to store additional information!!! For example, a subclass that defines additional configuration information should call storePreferences explicitly for additional configuration.

Specified by:
storePreferences in interface BiasgenPreferences

putPref

public void putPref(java.lang.String key,
                    java.lang.String value)
Use this method to put a value only if the value is different than the stored Preference value. If the value has never been put to the Preferences then it will be put. If the stored Preference value is different than the value being put it will be put.

Parameters:
key - your key.
value - your value.

putPref

public void putPref(java.lang.String key,
                    boolean value)
Use this method to put a value only if the value is different than the stored Preference value.

Parameters:
key - your key.
value - your value.

putPref

public void putPref(java.lang.String key,
                    int value)
Use this method to put a value to the preferences only if the value is different than the stored Preference value. Using this method will thus not call preference change listeners unless the value has changed. If the value has never been put to the Preferences then it will be put and listeners will be called. If the stored Preference value is different than the value being put it will be put and listeners will be called. Listeners will not be called if the value has previously been stored and is the same as the value being put.

Parameters:
key - your key.
value - your value.

putPref

public void putPref(java.lang.String key,
                    float value)
Use this method to put a value to the preferences only if the value is different than the stored Preference value. Using this method will thus not call preference change listeners unless the value has changed.

Parameters:
key - your key.
value - your value.

putPref

public void putPref(java.lang.String key,
                    double value)
Use this method to put a value to the preferences only if the value is different than the stored Preference value. Using this method will thus not call preference change listeners unless the value has changed.

Parameters:
key - your key.
value - your value.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

startBatchEdit

public void startBatchEdit()
call this when starting a set of related pot value changes.

See Also:
endBatchEdit()

endBatchEdit

public void endBatchEdit()
                  throws HardwareInterfaceException
call this to end the edit and send the values over the hardware interface.

Throws:
HardwareInterfaceException
See Also:
startBatchEdit()

update

public void update(java.util.Observable observable,
                   java.lang.Object object)
called when observable (masterbias) calls notifyObservers. Sets the powerDown state. If there is not a batch edit occuring, opens device if not open and calls sendConfiguration.

Specified by:
update in interface java.util.Observer

getPotByName

public Pot getPotByName(java.lang.String name)
Get an IPot by name.

Parameters:
name - name of pot as assigned in IPot
Returns:
the IPot, or null if there isn't one named that

getPotByNumber

public Pot getPotByNumber(int number)
Get an IPot by number in IPotArray. Note that first entry is last one in shift register.

Parameters:
number - name of pot as assigned in IPot
Returns:
the IPot, or null if there isn't one named that

getHardwareInterface

public BiasgenHardwareInterface getHardwareInterface()
Returns:
interface, or null if none has been sucessfully opened

setHardwareInterface

public void setHardwareInterface(BiasgenHardwareInterface hardwareInterface)
Assigns the HardwareInterface to this Biasgen. If non-null, the configuration information (e.g. biases) are also sent to the device.

Parameters:
hardwareInterface - the hardware interface.

getNumPots

public int getNumPots()

close

public void close()
Description copied from interface: HardwareInterface
Closes the device and frees the internal device handle. Never throws an exception.

Specified by:
close in interface HardwareInterface

flashConfiguration

public void flashConfiguration(Biasgen biasgen)
                        throws HardwareInterfaceException
flashes the the ipot values onto the hardware interface.

Specified by:
flashConfiguration in interface BiasgenHardwareInterface
Parameters:
biasgen - the bias generator object. This parameter is necessary because the same method is used in the hardware interface, which doesn't know about the particular bias generator instance.
Throws:
HardwareInterfaceException - if there is a hardware error. If there is no interface, prints a message and just returns.

open

public void open()
          throws HardwareInterfaceException
opens the first available hardware interface found

Specified by:
open in interface HardwareInterface
Throws:
HardwareInterfaceException - if there is a problem. Diagnostics are printeds.

sendConfiguration

public void sendConfiguration(Biasgen biasgen)
                       throws HardwareInterfaceException
sends the ipot values over the hardware interface if there is not a batch edit occuring.

Specified by:
sendConfiguration in interface BiasgenHardwareInterface
Parameters:
biasgen - the bias generator object. This parameter is necessary because the same method is used in the hardware interface, which doesn't know about the particular bias generator instance.
Throws:
HardwareInterfaceException - if there is a hardware error. If there is a null HardwareInterface, just returns.
See Also:
startBatchEdit(), endBatchEdit()

formatConfigurationBytes

public byte[] formatConfigurationBytes(Biasgen biasgen)
This method formats and returns a byte array of configuration information (e.g. biases, scanner or diagnostic bits) that can be sent over the hardware interface using sendConfiguration(net.sf.jaer.biasgen.Biasgen). This method delegates the task of formatting these bytes to the Biasgen object rather than the more generic HardwareInterface.

A Biasgen can override this method to customize the bytes that are sent. The default implementation asks the BiasgenHardwareInterface for the bytes.

Specified by:
formatConfigurationBytes in interface BiasgenHardwareInterface
Parameters:
biasgen - source of the configuration
Returns:
array of bytes to be sent.

setPowerDown

public void setPowerDown(boolean powerDown)
                  throws HardwareInterfaceException
Description copied from interface: BiasgenHardwareInterface
sends the powerdown vendor request to power down the chip.

Typically this method toggles the powerDown pin correctly to ensure on-chip biasgen is powered up. Chip may have been plugged in without being powered up. If powerdown is true, simply sets powerdown high. If powerdown is false, powerdown is toggled high and then low, to make sure a nagative transistion occurs. This transistion is necessary to ensure the startup circuit starts up the masterbias again.

Specified by:
setPowerDown in interface BiasgenHardwareInterface
Parameters:
powerDown - true to power OFF the biasgen, false to power on
Throws:
HardwareInterfaceException

getTypeName

public java.lang.String getTypeName()
Description copied from interface: HardwareInterface
get text name of interface, e.g. "CypressFX2" or "SiLabsC8051F320"

Specified by:
getTypeName in interface HardwareInterface

isOpen

public boolean isOpen()
Specified by:
isOpen in interface HardwareInterface
Returns:
true if interface is open, false otherwise

suspend

public void suspend()
sets all the biases to zero current

See Also:
resume()

resume

public void resume()
restores biases after suspend

See Also:
suspend()

isBatchEditOccurring

public boolean isBatchEditOccurring()
boolean that flags that a batch edit is occurring

Returns:
true if there is a batch edit occuring
See Also:
startBatchEdit(), endBatchEdit()

setBatchEditOccurring

public void setBatchEditOccurring(boolean batchEditOccurring)
sets boolean to flag batch edit occuring

Parameters:
batchEditOccurring - true to signal that it is occuring
See Also:
startBatchEdit(), endBatchEdit()

getIPotGroups

public java.util.ArrayList<IPotGroup> getIPotGroups()
Returns:
the list of IPotGroup lists for this Biasgen

setIPotGroups

public void setIPotGroups(java.util.ArrayList<IPotGroup> iPotGroups)

getChip

public Chip getChip()
Returns chip associated with this biasgen. Used, e.g. for preference keys.

Returns:
chip

setChip

public void setChip(Chip chip)
Sets chip associated with this biasgen

Parameters:
chip - the chip

isInitialized

public boolean isInitialized()
Checks for unitialized biases (no non-zero preference values).

Returns:
true if any Pot value is non-zero.

showUnitializedBiasesWarningDialog

public void showUnitializedBiasesWarningDialog(java.awt.Frame container)
Shows a dialog centered on the screen warning user to load bias settings

Parameters:
container - the window or panel that should contain the dialog

jAER project on SourceForge