AceSegment
0.2.0
An adjustable, configurable, and extensible framework for rendering seven segment LED displays.
|
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>
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... | |
StyledDigit & | getStyledDigit (uint8_t i) |
Return a reference the styled digit. More... | |
Static Public Member Functions | |
static void | calcBlinkStateForFrame (uint16_t framesPerBlink, uint16_t ¤tFrame, uint8_t &blinkState) |
Calculate the blink state. More... | |
static void | calcPulseFractionForFrame (uint16_t framesPerPulse, uint16_t ¤tFrame, uint8_t &pulseFraction) |
Calculate the pulse fraction. More... | |
static void | calcPulseFractionForFrameUsingInverse (uint16_t framesPerPulseInverse, uint16_t framesPerPulse, uint16_t ¤tFrame, 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 | |
Renderer & | operator= (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 |
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.
|
inlineexplicit |
Constructor.
Definition at line 54 of file Renderer.h.
|
inlinevirtual |
Destructor.
Definition at line 79 of file Renderer.h.
|
protected |
Calculate the blink and pulse states for current frame.
Definition at line 184 of file Renderer.cpp.
|
static |
|
static |
Calculate the effective brightness of a digit with the given style.
VisibleForTesting.
brightness | global brightness |
style | the style of the digit |
blinkSlowState | state of the blinkSlow cycle (on or off) |
blinkFastState | state of the blinkFast cycle (on or off) |
isPulseEnabled | true if the driver supports greyscale brightness, probably using PWM |
pulseSlowFraction | current brightness of the pulseSlow cycle |
pulseFastFraction | current brightness of the pulseSlow cycle |
Definition at line 156 of file Renderer.cpp.
|
static |
|
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.
|
inline |
Return the fields per second.
Definition at line 94 of file Renderer.h.
|
inline |
Return the frames per second.
Definition at line 91 of file Renderer.h.
|
inline |
Get the number of digits.
Definition at line 88 of file Renderer.h.
|
inline |
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.
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.
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.
|
protected |
Translate the StyledDigits to DimmingDigits for the Driver.
Definition at line 145 of file Renderer.cpp.
|
protected |
Perform things that need to be done each frame.
Definition at line 129 of file Renderer.cpp.
|
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.
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.
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.
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.
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.