Homepage Demos Overview Downloads Tutorials Reference
Credits

LedEngine Class Reference

#include <LedEngine.h>

Inheritance diagram for LedEngine:

Inheritance graph
[legend]
List of all members.

Detailed Description

Provides basic LED effects to anything that inherits from (recommended method for MotionCommands) or instantiates it (just in case you have reason to).

Provides a collection of special effects so that the code can be reused various places as feedback to to the user.

Cycling ("pulsing") and single-value setting are mutually exclusive; one will cut off the other

A flash will invert and override the current setting, so that it will "reset" after the flash. Flashes change mid-range values to extremes to make the flash visible (ie not just (1-current)) Normal invert will do simple inverses (just (1-current))

getSetting() returns value of last set(); getValue() returns what's actually being returned to Motion at the moment

There's some nice functions for using the LEDs to display numbers. This is handy for when you want to be free of the terminal.

NumberLEDs.jpg

The ERS-220 and ERS-7 have enough LEDs that they just use a "count the lights" style of display instead of this pseudo-arabic display. (look close to see that green bar LED at the top of the 210, which doesn't show up well in the camera image for some reason. )

Definition at line 38 of file LedEngine.h.

Public Types

enum  numStyle_t { onedigit, twodigit }
 Use these to specify a style for displaying numbers using displayNumber(). More...
enum  percentStyle_t { major, minor, none }
 Use these to specify a style for displaying a percentage value [0-1] using displayPercent(). More...

Public Member Functions

 LedEngine ()
 constructor - don't forget to call if you inherit
virtual ~LedEngine ()
 destructor
int updateLEDs (const MotionCommand *caller, LEDBitMask_t mask=AllLEDMask)
 call this from a MotionCommand's updateOutputs() - makes calls to MotionManager to update LED values
int updateLEDs (OutputCmd cmds[NumLEDs])
 call this from a MotionCommand's updateOutputs() - performs the calculations to update LEDs' values
int updateLEDFrames (OutputCmd cmds[NumLEDs][NumFrames])
 call this from a MotionCommand's updateOutputs() - performs the calculations to update LEDs' values
void recalcFlashEnd ()
 recalculates nextFlashEnd so we can tell when a flash has completed
int isDirty ()
 returns true if there are changes since the last updateLEDs()
void invert (LEDBitMask_t leds)
 sets the leds specified by leds to the inverse of their current value
void cset (LEDBitMask_t leds, float value)
 sets the leds specified by leds to value, clears all the rest
void set (LEDBitMask_t leds, float value)
 sets the leds specified by leds to value
void cflash (LEDBitMask_t leds, float value, unsigned int ms)
 sets the leds specified by leds to value for ms milliseconds, then sets back. Clears ~leds
void flash (LEDBitMask_t leds, float value, unsigned int ms)
 sets the leds specified by leds to value for ms milliseconds, then sets back.
void flash (LEDBitMask_t leds, unsigned int ms)
 sets the leds specified by leds to either a much higher or much lower value for ms milliseconds, then sets back.
void ccycle (LEDBitMask_t leds, unsigned int period, float amp, float offset=0, int phase=0)
 causes the leds specified by leds to cycle between low and high, clears others. See cycle() for parameter documentation.
void cycle (LEDBitMask_t leds, unsigned int period, float amp, float offset=0, int phase=0)
 causes the leds specified by leds to cycle between low and high
void clear ()
 sets all leds to 0.
float getSetting (LEDOffset_t led_id)
 returns the current setting of the LED specified by led_id (the value you passed in set())
float getValue (LEDOffset_t led_id, unsigned int planahead=0)
 returns the current value of the LED specified by led_id (the value being expressed - may change if cycling for instance)
void displayNumber (int x, numStyle_t style)
 Allows convenient display of numerical information to the LEDs on the face.
void displayPercent (float x, percentStyle_t left_style, percentStyle_t right_style)
 Allows convenient display of percentage information to the LEDs on the face.

Static Public Attributes

const LEDBitMask_t ERS210numMasks [11]
 holds a series of bit masks for the onedigit style of numerical display (0-10 and '.')
const LEDBitMask_t ERS220numMasks [11]
 bit masks for the ondigit style of numberical display - just count the LEDs on the head
const LEDBitMask_t ERS7numMasks [11]

Protected Member Functions

float calcValue (unsigned int i, unsigned int t)
 Calculates the current value of led i for current time t.
void setOneOfTwo (unsigned int x, unsigned int low, unsigned int mid, unsigned int high)
 used by displayNumber() to determine settings of LEDs when using #numStyle_t::twodigit
void setColumn (float x, unsigned int low, unsigned int mid, unsigned int high, unsigned int top)
 used by displayPercent() to determine settings of LEDs

Static Protected Member Functions

float calcInvert (float value)
 Performs the 'invert' calculation based on current value (returns 1-value).
float calcFlash (float value)
 Performs the 'flash' calculation based on current value (uses calcInvert() if value upper or lower third, 0 or 1 otherwise).
float calcCycle (unsigned int period, float amp, float offset, unsigned int t)
 Performs the 'cycle' calculation based on desired period, amplituted, amplitude offset, and time since start. See cycle().

Protected Attributes

LEDInfo infos [NumLEDs]
 the information regarding each of the LEDs
bool dirty
 true if changes since last updateLEDs: either at least one LED is cycling or a flash has begun/ended
unsigned int numCycling
 the number of LEDs currently cycling (if non-zero, always dirty)
unsigned int nextFlashEnd
 the soonest time a flash will end (and we'll become dirty)


Member Enumeration Documentation

enum LedEngine::numStyle_t
 

Use these to specify a style for displaying numbers using displayNumber().

Enumeration values:
onedigit  can display a number -9 thru 9, using #numMask. For negative numbers, blinks the top bar - fast if it's supposed to be on, slow if it would otherwise be off
twodigit  can display a number -99 thru 99, using setOneOfTwo(). For negative numbers, sets the top bar to 1 (off otherwise).

Definition at line 95 of file LedEngine.h.

enum LedEngine::percentStyle_t
 

Use these to specify a style for displaying a percentage value [0-1] using displayPercent().

Enumeration values:
major  shows overall value
minor  shows value within major tick
none  if you want to leave blank

Definition at line 100 of file LedEngine.h.


Constructor & Destructor Documentation

LedEngine::LedEngine  ) 
 

constructor - don't forget to call if you inherit

Definition at line 119 of file LedEngine.cc.

virtual LedEngine::~LedEngine  )  [inline, virtual]
 

destructor

Definition at line 43 of file LedEngine.h.


Member Function Documentation

float LedEngine::calcCycle unsigned int  period,
float  amp,
float  offset,
unsigned int  t
[inline, static, protected]
 

Performs the 'cycle' calculation based on desired period, amplituted, amplitude offset, and time since start. See cycle().

Definition at line 134 of file LedEngine.h.

float LedEngine::calcFlash float  value  )  [inline, static, protected]
 

Performs the 'flash' calculation based on current value (uses calcInvert() if value upper or lower third, 0 or 1 otherwise).

Definition at line 127 of file LedEngine.h.

Referenced by flash().

float LedEngine::calcInvert float  value  )  [inline, static, protected]
 

Performs the 'invert' calculation based on current value (returns 1-value).

Definition at line 123 of file LedEngine.h.

float LedEngine::calcValue unsigned int  i,
unsigned int  t
[inline, protected]
 

Calculates the current value of led i for current time t.

Definition at line 140 of file LedEngine.h.

Referenced by flash(), updateLEDFrames(), and updateLEDs().

void LedEngine::ccycle LEDBitMask_t  leds,
unsigned int  period,
float  amp,
float  offset = 0,
int  phase = 0
[inline]
 

causes the leds specified by leds to cycle between low and high, clears others. See cycle() for parameter documentation.

Definition at line 77 of file LedEngine.h.

Referenced by displayNumber().

void LedEngine::cflash LEDBitMask_t  leds,
float  value,
unsigned int  ms
 

sets the leds specified by leds to value for ms milliseconds, then sets back. Clears ~leds

Definition at line 201 of file LedEngine.cc.

Referenced by ControlBase::doSelect().

void LedEngine::clear  ) 
 

sets all leds to 0.

Definition at line 270 of file LedEngine.cc.

Referenced by ControlBase::deactivate(), displayNumber(), displayPercent(), ControlBase::doSelect(), and LedEngine().

void LedEngine::cset LEDBitMask_t  leds,
float  value
[inline]
 

sets the leds specified by leds to value, clears all the rest

Definition at line 67 of file LedEngine.h.

Referenced by ControlBase::doReadStdIn().

void LedEngine::cycle LEDBitMask_t  leds,
unsigned int  period,
float  amp,
float  offset = 0,
int  phase = 0
 

causes the leds specified by leds to cycle between low and high

Parameters:
leds the bitmask of leds to apply this to
period the period of the cycle (milliseconds), includes an on and off
amp the amplitude of the cycle - note that this is clipped at 0 and 1.
offset the vertical offset of the cycle - simply shifts the baseline of the cycle up or down
phase the phase within the cycle to start at (specify in milliseconds)
When this function is called, the starting time is stored as current time + phase.

The equation used is

\[\cos(\frac{2\pi(t-starttime)}{period})*(\frac{-amp}{2})+.5+offset\]

The idea is that with a amplitude=1 and offset=0, it will start at 0, ramp up to 1, and then ramp down again. The arguments to this function will let you control all parameters of the cycle.

You can get a blink-on/off instead of cycle on/off by using a very large amplitude.

Definition at line 253 of file LedEngine.cc.

Referenced by EmergencyStopMC::EmergencyStopMC().

void LedEngine::displayNumber int  x,
numStyle_t  style
 

Allows convenient display of numerical information to the LEDs on the face.

If overflow occurs, the face LEDs are set to flash on and off 3 every 333 milliseconds

Definition at line 279 of file LedEngine.cc.

Referenced by ControlBase::refresh().

void LedEngine::displayPercent float  x,
percentStyle_t  left_style,
percentStyle_t  right_style
 

Allows convenient display of percentage information to the LEDs on the face.

Besides allowing a two-digit display, the 'edge' bar for each type is blinked to denote how full it is. So you can get up to a two-digit, base 5 display, with an extra digit of estimated value.

If overflow (>1) occurs, sets everything to .75.
If underflow (<0) occurs, sets everything to .25.

The left and right columns are combined with an OR operation. (they overlap on the top bar) Left and right designations are dog centric!

Definition at line 339 of file LedEngine.cc.

void LedEngine::flash LEDBitMask_t  leds,
unsigned int  ms
 

sets the leds specified by leds to either a much higher or much lower value for ms milliseconds, then sets back.

Definition at line 224 of file LedEngine.cc.

void LedEngine::flash LEDBitMask_t  leds,
float  value,
unsigned int  ms
 

sets the leds specified by leds to value for ms milliseconds, then sets back.

Definition at line 211 of file LedEngine.cc.

Referenced by BehaviorSwitchActivatorControl::activate(), and ControlBase::doSelect().

float LedEngine::getSetting LEDOffset_t  led_id  )  [inline]
 

returns the current setting of the LED specified by led_id (the value you passed in set())

Definition at line 84 of file LedEngine.h.

float LedEngine::getValue LEDOffset_t  led_id,
unsigned int  planahead = 0
[inline]
 

returns the current value of the LED specified by led_id (the value being expressed - may change if cycling for instance)

Definition at line 86 of file LedEngine.h.

void LedEngine::invert LEDBitMask_t  leds  ) 
 

sets the leds specified by leds to the inverse of their current value

Definition at line 177 of file LedEngine.cc.

int LedEngine::isDirty  ) 
 

returns true if there are changes since the last updateLEDs()

Reimplemented in LedMC.

Definition at line 135 of file LedEngine.cc.

Referenced by LedMC::isAlive(), and LedMC::isDirty().

void LedEngine::recalcFlashEnd  ) 
 

recalculates nextFlashEnd so we can tell when a flash has completed

Definition at line 127 of file LedEngine.cc.

Referenced by isDirty(), updateLEDFrames(), and updateLEDs().

void LedEngine::set LEDBitMask_t  leds,
float  value
 

sets the leds specified by leds to value

Definition at line 188 of file LedEngine.cc.

Referenced by displayNumber(), displayPercent(), and setColumn().

void LedEngine::setColumn float  x,
unsigned int  low,
unsigned int  mid,
unsigned int  high,
unsigned int  top
[protected]
 

used by displayPercent() to determine settings of LEDs

Definition at line 361 of file LedEngine.cc.

Referenced by displayPercent().

void LedEngine::setOneOfTwo unsigned int  x,
unsigned int  low,
unsigned int  mid,
unsigned int  high
[protected]
 

used by displayNumber() to determine settings of LEDs when using #numStyle_t::twodigit

Definition at line 315 of file LedEngine.cc.

Referenced by displayNumber().

int LedEngine::updateLEDFrames OutputCmd  cmds[NumLEDs][NumFrames]  ) 
 

call this from a MotionCommand's updateOutputs() - performs the calculations to update LEDs' values

Parameters:
cmds on input, used for weight values - on return, holds the resulting OutputCmd's

Definition at line 166 of file LedEngine.cc.

Referenced by LedMC::updateOutputs().

int LedEngine::updateLEDs OutputCmd  cmds[NumLEDs]  ) 
 

call this from a MotionCommand's updateOutputs() - performs the calculations to update LEDs' values

Parameters:
cmds on input, used for weight values - on return, holds the resulting OutputCmd's

Definition at line 156 of file LedEngine.cc.

int LedEngine::updateLEDs const MotionCommand caller,
LEDBitMask_t  mask = AllLEDMask
 

call this from a MotionCommand's updateOutputs() - makes calls to MotionManager to update LED values

Parameters:
caller pass the "parent" motioncommand's address here (usually will pass 'this')
mask a bitmask of which leds to update (uses weight of 1)

Definition at line 144 of file LedEngine.cc.

Referenced by EmergencyStopMC::updateOutputs().


Member Data Documentation

bool LedEngine::dirty [protected]
 

true if changes since last updateLEDs: either at least one LED is cycling or a flash has begun/ended

Definition at line 166 of file LedEngine.h.

Referenced by cflash(), clear(), cycle(), flash(), invert(), isDirty(), set(), updateLEDFrames(), and updateLEDs().

const LEDBitMask_t LedEngine::ERS210numMasks [static]
 

Initial value:

 {
  ERS210Info::BotRLEDMask|ERS210Info::BotLLEDMask|ERS210Info::TopBrLEDMask, 
  
  ERS210Info::BotLLEDMask|ERS210Info::MidLLEDMask|ERS210Info::TopLLEDMask,  
  
  ERS210Info::BotRLEDMask|ERS210Info::BotLLEDMask|ERS210Info::TopLLEDMask|ERS210Info::TopBrLEDMask, 
  
  ERS210Info::BotRLEDMask|ERS210Info::BotLLEDMask|ERS210Info::MidRLEDMask|ERS210Info::TopLLEDMask
  |ERS210Info::TopBrLEDMask, 
  
  ERS210Info::BotLLEDMask|ERS210Info::MidLLEDMask|ERS210Info::TopRLEDMask|ERS210Info::TopLLEDMask,  

  ERS210Info::BotRLEDMask|ERS210Info::BotLLEDMask|ERS210Info::TopRLEDMask|ERS210Info::TopBrLEDMask, 

  ERS210Info::BotRLEDMask|ERS210Info::BotLLEDMask|ERS210Info::MidRLEDMask|ERS210Info::MidLLEDMask
  |ERS210Info::TopRLEDMask|ERS210Info::TopBrLEDMask, 

  ERS210Info::BotLLEDMask|ERS210Info::MidLLEDMask|ERS210Info::TopLLEDMask|ERS210Info::TopBrLEDMask,  

  ERS210Info::BotRLEDMask|ERS210Info::BotLLEDMask|ERS210Info::MidRLEDMask|ERS210Info::MidLLEDMask
  |ERS210Info::TopRLEDMask|ERS210Info::TopLLEDMask|ERS210Info::TopBrLEDMask, 

  ERS210Info::BotLLEDMask|ERS210Info::MidLLEDMask|ERS210Info::TopRLEDMask|ERS210Info::TopLLEDMask
  |ERS210Info::TopBrLEDMask,  

  ERS210Info::BotLLEDMask 
}
holds a series of bit masks for the onedigit style of numerical display (0-10 and '.')

the hope is that these actually resemble the shapes of the numbers so people can recognize them more easily - without converting base 2 in their heads.

Definition at line 9 of file LedEngine.cc.

const LEDBitMask_t LedEngine::ERS220numMasks [static]
 

bit masks for the ondigit style of numberical display - just count the LEDs on the head

This is "Count the dots" style

Definition at line 37 of file LedEngine.cc.

const LEDBitMask_t LedEngine::ERS7numMasks [static]
 

writes a number on the display

Definition at line 86 of file LedEngine.cc.

LEDInfo LedEngine::infos[NumLEDs] [protected]
 

the information regarding each of the LEDs

Definition at line 165 of file LedEngine.h.

Referenced by cflash(), clear(), cycle(), displayNumber(), flash(), invert(), LedEngine(), recalcFlashEnd(), set(), and setOneOfTwo().

unsigned int LedEngine::nextFlashEnd [protected]
 

the soonest time a flash will end (and we'll become dirty)

Definition at line 168 of file LedEngine.h.

Referenced by cflash(), flash(), and recalcFlashEnd().

unsigned int LedEngine::numCycling [protected]
 

the number of LEDs currently cycling (if non-zero, always dirty)

Definition at line 167 of file LedEngine.h.

Referenced by clear(), cycle(), set(), updateLEDFrames(), and updateLEDs().


The documentation for this class was generated from the following files:

Tekkotsu v2.2
Generated Tue Oct 19 14:20:19 2004 by Doxygen 1.3.9.1