hades.models.io
Class SevenSegmentMultiplexed

java.lang.Object
  extended byhades.simulator.SimObject
      extended byhades.models.io.SevenSegmentMultiplexed
All Implemented Interfaces:
java.lang.Cloneable, ContextToolTip, java.io.Serializable, Simulatable, Wakeable

public class SevenSegmentMultiplexed
extends SimObject
implements Simulatable, Wakeable

SevenSegmentMultiplexed - model a multiplexed seven-segment display

This component allows to visualize the behaviour of a multiplexed 7-segment LED display. To this end, it maintains an internal data structure that keeps track of the 'on period' of each LED segment during a predefined time interval (specified by the t_sample variable). Typically, this time interval will be the as the repaint interval of the GUI (e.g. one second or 1/10th second).

The simulation model is driven by two threads. The first, simulation thread is responsible to set the LED input values and to update the 'on period' statistics of each LED segment. After t_sample has elapsed, the statistics is evaluated and the LED colors are calculated. Note that this implies that the display shows the values 'late', namely corresponding to the previous t_sample time interval.

The second, 'repaint' thread evaluates the 'on period' statistics and decides whether to paint a segment as active (red color) or inactive (dark gray color).

See Also:
Serialized Form

Nested Class Summary
(package private)  class SevenSegmentMultiplexed.DynSymbol
           
 
Field Summary
static int CATHODE_ACTIVE
           
static int CATHODE_INACTIVE
           
static int CATHODE_UX
           
(package private)  java.awt.Color COLOR_OFF
           
(package private)  java.awt.Color COLOR_ON
           
(package private)  java.awt.Color COLOR_UX
           
protected  java.awt.Color dark_gray
           
protected  FigCompound display
           
protected  boolean hasNewEvents
           
static int LED_OFF
           
static int LED_ON
           
static int LED_UX
           
protected  int[] ledValues
           
protected  java.awt.Color medium_gray
           
protected  int n_cycles
           
(package private) static char[] names
           
protected  int[] portValues
           
protected  ColoredPolyline[] segments
           
protected  double t_delta
           
protected  double[] t_lastUpdate
           
protected  double[] t_off
           
protected  double[] t_on
           
protected  double t_sample
           
protected  double t_threshold
           
protected  double[] t_total
           
protected  double[] t_ux
           
protected  StdLogic1164 value_U
           
 
Fields inherited from class hades.simulator.SimObject
classloader, console, debug, editor, name, parent, ports, propertySheet, simulator, symbol, versionId, visible
 
Constructor Summary
SevenSegmentMultiplexed()
          SevenSegmentMultiplexed(): simple constructor
 
Method Summary
 void configure()
          create and display a 'ConfigDialog' to set the parameters for a SimObject.
 void constructDynamicSymbol()
           
 void elaborate(java.lang.Object arg)
          elaborate(): This method is called by the simulation engine to initialize the simulation object.
(package private)  void evalStatistics()
          evaluate the statistics of one t_sample period, calculate the corresponding LED on/off/X states, and store these int ledValues[i].
 void evaluate(java.lang.Object arg)
          evaluate(): called by the simulation engine on all events that concern this object.
 double getT_sample()
           
 double getT_threshold()
           
 java.lang.String getToolTip(java.awt.Point position, long millis)
          construct a tool tip message (with the timing parameters)
 boolean initialize(java.lang.String s)
          initialize a SevenSegmentMultiplexed display from a String, which contains its integer version id, and the double values for sample period and on-threshold (in seconds), e.g.
(package private)  void initLedValues()
           
(package private)  void initPortValues()
           
(package private)  void initStatistics()
           
 boolean needsDynamicSymbol()
          we want to construct our own Symbol!
(package private)  void repaint()
           
(package private)  void resetStatistics()
           
 void setSymbol(Symbol s)
           
 void setT_sample(java.lang.String s)
           
 void setT_threshold(java.lang.String s)
           
 java.lang.String toString()
          toString() - the usual info method
(package private)  void updateAllSegmentStatistics(double time)
          called whenever the common cathode port (port[8]) changes.
(package private)  void updateSegmentStatistics(double time, int i)
          update the on/off/x statistics for segment i (A=0, B=1, ..P=7) from the current value in portValues[i], portValues[cathode=8], and the current simulation time.
 void wakeup(java.lang.Object arg)
          one sample period has elapsed.
 void write(java.io.PrintWriter ps)
           
 
Methods inherited from class hades.simulator.SimObject
copy, getBindkey, getClassLoader, getDebug, getEditor, getExternalResources, getFullName, getName, getParent, getPort, getPorts, getPropertySheet, getResourceAsStream, getSimulator, getSymbol, getSymbolResourceName, getVersionId, isVisible, keyPressed, message, mousePressed, needsExternalResources, setClassLoader, setConsole, setDebug, setEditor, setName, setParent, setPorts, setSimulator, setVersionId, setVisible, tearDown
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface hades.simulator.Simulatable
message
 

Field Detail

LED_UX

public static final int LED_UX
See Also:
Constant Field Values

LED_OFF

public static final int LED_OFF
See Also:
Constant Field Values

LED_ON

public static final int LED_ON
See Also:
Constant Field Values

CATHODE_UX

public static final int CATHODE_UX
See Also:
Constant Field Values

CATHODE_ACTIVE

public static final int CATHODE_ACTIVE
See Also:
Constant Field Values

CATHODE_INACTIVE

public static final int CATHODE_INACTIVE
See Also:
Constant Field Values

segments

protected ColoredPolyline[] segments

display

protected FigCompound display

dark_gray

protected java.awt.Color dark_gray

medium_gray

protected java.awt.Color medium_gray

value_U

protected StdLogic1164 value_U

portValues

protected int[] portValues

ledValues

protected int[] ledValues

t_on

protected double[] t_on

t_off

protected double[] t_off

t_ux

protected double[] t_ux

t_lastUpdate

protected double[] t_lastUpdate

t_total

protected double[] t_total

t_delta

protected double t_delta

t_sample

protected double t_sample

t_threshold

protected double t_threshold

n_cycles

protected int n_cycles

hasNewEvents

protected boolean hasNewEvents

COLOR_UX

java.awt.Color COLOR_UX

COLOR_ON

java.awt.Color COLOR_ON

COLOR_OFF

java.awt.Color COLOR_OFF

names

static char[] names
Constructor Detail

SevenSegmentMultiplexed

public SevenSegmentMultiplexed()
SevenSegmentMultiplexed(): simple constructor

Method Detail

setSymbol

public void setSymbol(Symbol s)
Overrides:
setSymbol in class SimObject

needsDynamicSymbol

public boolean needsDynamicSymbol()
we want to construct our own Symbol!

Overrides:
needsDynamicSymbol in class SimObject

constructDynamicSymbol

public void constructDynamicSymbol()
Overrides:
constructDynamicSymbol in class SimObject

elaborate

public void elaborate(java.lang.Object arg)
elaborate(): This method is called by the simulation engine to initialize the simulation object.

Specified by:
elaborate in interface Simulatable
Overrides:
elaborate in class SimObject
Parameters:
arg - This parameter is ignored by SevenSegmentMultiplexed

wakeup

public void wakeup(java.lang.Object arg)
one sample period has elapsed. Update and evaluate the segments on/off/X statistics.

Specified by:
wakeup in interface Wakeable
Parameters:
arg - a WakeupEvent whose details are not used

evaluate

public void evaluate(java.lang.Object arg)
evaluate(): called by the simulation engine on all events that concern this object. The object is responsible for updating its internal state and for scheduling all pending output events.

Specified by:
evaluate in interface Simulatable
Overrides:
evaluate in class SimObject
Parameters:
arg - An arbitrary and unused object

repaint

void repaint()

updateSegmentStatistics

void updateSegmentStatistics(double time,
                             int i)
update the on/off/x statistics for segment i (A=0, B=1, ..P=7) from the current value in portValues[i], portValues[cathode=8], and the current simulation time.


updateAllSegmentStatistics

void updateAllSegmentStatistics(double time)
called whenever the common cathode port (port[8]) changes. Update all segment statistics from the segments value and the current cathode value (which is about to change next).


initPortValues

void initPortValues()

initLedValues

void initLedValues()

initStatistics

void initStatistics()

resetStatistics

void resetStatistics()

evalStatistics

void evalStatistics()
evaluate the statistics of one t_sample period, calculate the corresponding LED on/off/X states, and store these int ledValues[i]. Note that this method is called from the simulation thread only, so there is no need to synchronize anything.


initialize

public boolean initialize(java.lang.String s)
initialize a SevenSegmentMultiplexed display from a String, which contains its integer version id, and the double values for sample period and on-threshold (in seconds), e.g. 1001 0.01 0.0001 for 0.01 sec sampling and 1/100 duty cycle (1/100 * 0.01 = 0.0001)

Overrides:
initialize in class SimObject

write

public void write(java.io.PrintWriter ps)
Overrides:
write in class SimObject

configure

public void configure()
Description copied from class: SimObject
create and display a 'ConfigDialog' to set the parameters for a SimObject. The default ConfigDialog for the base class (SimObject) itself is empty except for the 'instance name' of the SimObject.

Overrides:
configure in class SimObject

getT_sample

public double getT_sample()

getT_threshold

public double getT_threshold()

setT_sample

public void setT_sample(java.lang.String s)

setT_threshold

public void setT_threshold(java.lang.String s)

getToolTip

public java.lang.String getToolTip(java.awt.Point position,
                                   long millis)
construct a tool tip message (with the timing parameters)

Specified by:
getToolTip in interface ContextToolTip
Overrides:
getToolTip in class SimObject

toString

public java.lang.String toString()
toString() - the usual info method

Overrides:
toString in class SimObject