AceSegment  0.2.0
An adjustable, configurable, and extensible framework for rendering seven segment LED displays.
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
ace_segment::Renderer Class Reference

A class that knows how to translate an array of led segement bit patterns with style attributes to a displayable frame for the Driver class. More...

#include <Renderer.h>

Collaboration diagram for ace_segment::Renderer:
Collaboration graph
[legend]

Public Member Functions

 Renderer (Hardware *hardware, Driver *driver, StyledDigit *styledDigits, uint8_t numDigits, uint8_t framesPerSecond, uint16_t statsResetInterval, uint16_t blinkSlowDurationMillis, uint16_t blinkFastDurationMillis, uint16_t pulseSlowDurationMillis, uint16_t pulseFastDurationMillis)
 Constructor. More...
 
virtual ~Renderer ()
 Destructor. More...
 
virtual void configure ()
 Configure the driver with the parameters given by the various setXxx() methods.
 
uint8_t getNumDigits ()
 Get the number of digits. More...
 
uint16_t getFramesPerSecond ()
 Return the frames per second. More...
 
uint16_t getFieldsPerSecond ()
 Return the fields per second. More...
 
void writeBrightness (uint8_t brightness)
 Set brightness expressed as a fraction of 256. More...
 
void writePatternAt (uint8_t digit, uint8_t pattern, uint8_t style)
 Write the pattern and style for a given digit. More...
 
void writePatternAt (uint8_t digit, uint8_t pattern)
 Write the pattern for a given digit, leaving style unchanged. More...
 
void writeStyleAt (uint8_t digit, uint8_t style)
 Write the style for a given digit, leaving pattern unchanged. More...
 
void writeDecimalPointAt (uint8_t digit, bool state=true)
 Write the decimal point for the digit. More...
 
void renderFieldWhenReady ()
 Display one field of a frame when the time is right. More...
 
void renderField ()
 Render the current field immediately. More...
 
TimingStats getTimingStats ()
 Return stats. More...
 
StyledDigitgetStyledDigit (uint8_t i)
 Return a reference the styled digit. More...
 

Static Public Member Functions

static void calcBlinkStateForFrame (uint16_t framesPerBlink, uint16_t &currentFrame, uint8_t &blinkState)
 Calculate the blink state. More...
 
static void calcPulseFractionForFrame (uint16_t framesPerPulse, uint16_t &currentFrame, uint8_t &pulseFraction)
 Calculate the pulse fraction. More...
 
static void calcPulseFractionForFrameUsingInverse (uint16_t framesPerPulseInverse, uint16_t framesPerPulse, uint16_t &currentFrame, uint8_t &pulseFraction)
 Calculate the pulse fraction using the reciprocal of the framesPerPulse, which avoid a long division, which is very slow in 8-bit processors. More...
 
static uint8_t calcBrightness (uint8_t style, uint8_t brightness, uint8_t blinkSlowState, uint8_t blinkFastState, bool isPulseEnabled, uint8_t pulseSlowFraction, uint8_t pulseFastFraction)
 Calculate the effective brightness of a digit with the given style. More...
 

Static Public Attributes

static const uint8_t kBlinkStateOff = 0
 
static const uint8_t kBlinkStateOn = 1
 

Protected Member Functions

 Renderer (const Renderer &)=delete
 
Rendereroperator= (const Renderer &)=delete
 
void updateFrame ()
 Perform things that need to be done each frame. More...
 
void calcBlinkAndPulseForFrame ()
 Calculate the blink and pulse states for current frame. More...
 
void renderStyledDigits ()
 Translate the StyledDigits to DimmingDigits for the Driver. More...
 

Protected Attributes

Hardware *const mHardware
 
Driver *const mDriver
 
StyledDigit *const mStyledDigits
 
const uint8_t mNumDigits
 
const uint8_t mFramesPerSecond
 
const uint16_t mStatsResetInterval
 
TimingStats mStats
 
const uint16_t mBlinkSlowDurationMillis
 
const uint16_t mBlinkFastDurationMillis
 
const uint16_t mPulseSlowDurationMillis
 
const uint16_t mPulseFastDurationMillis
 
uint8_t mBrightness
 
bool mIsPulseEnabled
 
uint16_t mMicrosPerField
 
uint16_t mLastRenderFieldMicros
 
uint16_t mFieldsPerFrame
 
uint16_t mCurrentField
 
uint16_t mFramesPerBlinkSlow
 
uint16_t mCurrentBlinkSlowFrame
 
uint8_t mBlinkSlowState
 
uint16_t mFramesPerBlinkFast
 
uint16_t mCurrentBlinkFastFrame
 
uint8_t mBlinkFastState
 
uint16_t mFramesPerPulseSlow
 
uint16_t mFramesPerPulseSlowInverse
 
uint16_t mCurrentPulseSlowFrame
 
uint8_t mPulseSlowFraction
 
uint16_t mFramesPerPulseFast
 
uint16_t mFramesPerPulseFastInverse
 
uint16_t mCurrentPulseFastFrame
 
uint8_t mPulseFastFraction
 

Detailed Description

A class that knows how to translate an array of led segement bit patterns with style attributes to a displayable frame for the Driver class.

The supported style for each digit are (blinkSlow, blinkFast, pulseSlow, pulseFast).

A frame is divided into fields, which is a partial rendering of a frame. The renderField() (or renderFieldWhenReady()) method should be called to successively render each field of a frame.

Definition at line 47 of file Renderer.h.

Constructor & Destructor Documentation

◆ Renderer()

ace_segment::Renderer::Renderer ( Hardware hardware,
Driver driver,
StyledDigit styledDigits,
uint8_t  numDigits,
uint8_t  framesPerSecond,
uint16_t  statsResetInterval,
uint16_t  blinkSlowDurationMillis,
uint16_t  blinkFastDurationMillis,
uint16_t  pulseSlowDurationMillis,
uint16_t  pulseFastDurationMillis 
)
inlineexplicit

Constructor.

Definition at line 54 of file Renderer.h.

◆ ~Renderer()

virtual ace_segment::Renderer::~Renderer ( )
inlinevirtual

Destructor.

Definition at line 79 of file Renderer.h.

Member Function Documentation

◆ calcBlinkAndPulseForFrame()

void ace_segment::Renderer::calcBlinkAndPulseForFrame ( )
protected

Calculate the blink and pulse states for current frame.

Definition at line 184 of file Renderer.cpp.

◆ calcBlinkStateForFrame()

void ace_segment::Renderer::calcBlinkStateForFrame ( uint16_t  framesPerBlink,
uint16_t &  currentFrame,
uint8_t &  blinkState 
)
static

Calculate the blink state.

VisibleForTesting.

Definition at line 205 of file Renderer.cpp.

◆ calcBrightness()

uint8_t ace_segment::Renderer::calcBrightness ( uint8_t  style,
uint8_t  brightness,
uint8_t  blinkSlowState,
uint8_t  blinkFastState,
bool  isPulseEnabled,
uint8_t  pulseSlowFraction,
uint8_t  pulseFastFraction 
)
static

Calculate the effective brightness of a digit with the given style.

VisibleForTesting.

Parameters
brightnessglobal brightness
stylethe style of the digit
blinkSlowStatestate of the blinkSlow cycle (on or off)
blinkFastStatestate of the blinkFast cycle (on or off)
isPulseEnabledtrue if the driver supports greyscale brightness, probably using PWM
pulseSlowFractioncurrent brightness of the pulseSlow cycle
pulseFastFractioncurrent brightness of the pulseSlow cycle
Returns
the effective brightness of a digit with the given style

Definition at line 156 of file Renderer.cpp.

◆ calcPulseFractionForFrame()

void ace_segment::Renderer::calcPulseFractionForFrame ( uint16_t  framesPerPulse,
uint16_t &  currentFrame,
uint8_t &  pulseFraction 
)
static

Calculate the pulse fraction.

VisibleForTesting.

Definition at line 216 of file Renderer.cpp.

◆ calcPulseFractionForFrameUsingInverse()

void ace_segment::Renderer::calcPulseFractionForFrameUsingInverse ( uint16_t  framesPerPulseInverse,
uint16_t  framesPerPulse,
uint16_t &  currentFrame,
uint8_t &  pulseFraction 
)
static

Calculate the pulse fraction using the reciprocal of the framesPerPulse, which avoid a long division, which is very slow in 8-bit processors.

VisibleForTesting.

Definition at line 235 of file Renderer.cpp.

◆ getFieldsPerSecond()

uint16_t ace_segment::Renderer::getFieldsPerSecond ( )
inline

Return the fields per second.

Definition at line 94 of file Renderer.h.

◆ getFramesPerSecond()

uint16_t ace_segment::Renderer::getFramesPerSecond ( )
inline

Return the frames per second.

Definition at line 91 of file Renderer.h.

◆ getNumDigits()

uint8_t ace_segment::Renderer::getNumDigits ( )
inline

Get the number of digits.

Definition at line 88 of file Renderer.h.

◆ getStyledDigit()

StyledDigit& ace_segment::Renderer::getStyledDigit ( uint8_t  i)
inline

Return a reference the styled digit.

VisibleForTesting.

Definition at line 161 of file Renderer.h.

◆ getTimingStats()

TimingStats ace_segment::Renderer::getTimingStats ( )

Return stats.

For debugging only. TimingStats is returned by 'value' to be safe from interrupts.

Definition at line 138 of file Renderer.cpp.

◆ renderField()

void ace_segment::Renderer::renderField ( )

Render the current field immediately.

Designed to be called from a timer interrupt handler. The statistics variables give us the following benchmar on a 16MHz ATmega328P using a 4-digit LED display, at 60 fps, using 8 sub-fields per frame, with 2 digits pulsing, and 2 digits blinking:

DigitDriver w/ LedMatrixDirect min: 16us; avg: 73; max: 120us DigitDriver w/ LedMatrixSerial min: 16us; avg: 128us; max: 200us DigitDriver w/ LedMatrixSpi min: 16us; avg: 30-55us; max: 80us ModulatingDigitDriver w/ LedMatrixDirect min: 8us; avg: 16us; max: 140us ModulatingDigitDriver w/ LedMatrixDirect w/ calcPulseFractionForFrame(): min: 8us; avg: 12-20us; max: 192us ModulatingDigitDriver w/ LedMatrixSerial min: 8us; avg: 19us; max: 212us ModulatingDigitDriver w/ LedMatrixSpi min: 8us; avg: 14us; max: 104us SegmentDriver w/ LedMatrixDirect min: 32us; avg: 57us; max: 96us

Definition at line 117 of file Renderer.cpp.

◆ renderFieldWhenReady()

void ace_segment::Renderer::renderFieldWhenReady ( )

Display one field of a frame when the time is right.

This is a polling method, so call this slightly more frequently than getFieldsPerSecond().

Definition at line 108 of file Renderer.cpp.

◆ renderStyledDigits()

void ace_segment::Renderer::renderStyledDigits ( )
protected

Translate the StyledDigits to DimmingDigits for the Driver.

Definition at line 145 of file Renderer.cpp.

◆ updateFrame()

void ace_segment::Renderer::updateFrame ( )
protected

Perform things that need to be done each frame.

Definition at line 129 of file Renderer.cpp.

◆ writeBrightness()

void ace_segment::Renderer::writeBrightness ( uint8_t  brightness)
inline

Set brightness expressed as a fraction of 256.

In other words, 255 is brightest (default); 1 is 1/256 of full brightness. Requires the support of useModulatingDriver() option in DriverBuilder. If the driver doesn't support brightness, then anything above 0 is full brightness and 0 turns off the digit.

Definition at line 105 of file Renderer.h.

◆ writeDecimalPointAt()

void ace_segment::Renderer::writeDecimalPointAt ( uint8_t  digit,
bool  state = true 
)

Write the decimal point for the digit.

Definition at line 98 of file Renderer.cpp.

◆ writePatternAt() [1/2]

void ace_segment::Renderer::writePatternAt ( uint8_t  digit,
uint8_t  pattern,
uint8_t  style 
)

Write the pattern and style for a given digit.

Definition at line 79 of file Renderer.cpp.

◆ writePatternAt() [2/2]

void ace_segment::Renderer::writePatternAt ( uint8_t  digit,
uint8_t  pattern 
)

Write the pattern for a given digit, leaving style unchanged.

Definition at line 86 of file Renderer.cpp.

◆ writeStyleAt()

void ace_segment::Renderer::writeStyleAt ( uint8_t  digit,
uint8_t  style 
)

Write the style for a given digit, leaving pattern unchanged.

Definition at line 92 of file Renderer.cpp.


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