25 #ifndef ACE_SEGMENT_RENDERER_H 26 #define ACE_SEGMENT_RENDERER_H 30 #include "TimingStats.h" 50 static const uint8_t kBlinkStateOff = 0;
51 static const uint8_t kBlinkStateOn = 1;
56 uint8_t framesPerSecond,
57 uint16_t statsResetInterval,
58 uint16_t blinkSlowDurationMillis,
59 uint16_t blinkFastDurationMillis,
60 uint16_t pulseSlowDurationMillis,
61 uint16_t pulseFastDurationMillis):
64 mStyledDigits(styledDigits),
65 mNumDigits(numDigits),
66 mFramesPerSecond(framesPerSecond),
67 mStatsResetInterval(statsResetInterval),
68 mBlinkSlowDurationMillis(blinkSlowDurationMillis),
69 mBlinkFastDurationMillis(blinkFastDurationMillis),
70 mPulseSlowDurationMillis(pulseSlowDurationMillis),
71 mPulseFastDurationMillis(pulseFastDurationMillis),
73 mIsPulseEnabled(false),
74 mBlinkSlowState(kBlinkStateOn),
75 mBlinkFastState(kBlinkStateOn)
106 mBrightness = brightness;
110 void writePatternAt(uint8_t digit, uint8_t pattern, uint8_t style);
162 return mStyledDigits[i];
167 uint16_t& currentFrame, uint8_t& blinkState);
171 uint16_t& currentFrame, uint8_t& pulseFraction);
179 uint16_t framesPerPulseInverse, uint16_t framesPerPulse,
180 uint16_t& currentFrame, uint8_t& pulseFraction);
198 uint8_t blinkSlowState, uint8_t blinkFastState,
bool isPulseEnabled,
199 uint8_t pulseSlowFraction, uint8_t pulseFastFraction);
218 const uint8_t mNumDigits;
219 const uint8_t mFramesPerSecond;
222 const uint16_t mStatsResetInterval;
226 const uint16_t mBlinkSlowDurationMillis;
227 const uint16_t mBlinkFastDurationMillis;
228 const uint16_t mPulseSlowDurationMillis;
229 const uint16_t mPulseFastDurationMillis;
235 bool mIsPulseEnabled;
238 uint16_t mMicrosPerField;
239 uint16_t mLastRenderFieldMicros;
243 uint16_t mFieldsPerFrame;
244 uint16_t mCurrentField;
249 uint16_t mFramesPerBlinkSlow;
250 uint16_t mCurrentBlinkSlowFrame;
251 uint8_t mBlinkSlowState;
253 uint16_t mFramesPerBlinkFast;
254 uint16_t mCurrentBlinkFastFrame;
255 uint8_t mBlinkFastState;
257 uint16_t mFramesPerPulseSlow;
258 uint16_t mFramesPerPulseSlowInverse;
259 uint16_t mCurrentPulseSlowFrame;
260 uint8_t mPulseSlowFraction;
262 uint16_t mFramesPerPulseFast;
263 uint16_t mFramesPerPulseFastInverse;
264 uint16_t mCurrentPulseFastFrame;
265 uint8_t mPulseFastFraction;
uint16_t getFramesPerSecond()
Return the frames per second.
void renderFieldWhenReady()
Display one field of a frame when the time is right.
TimingStats getTimingStats()
Return stats.
Data structure that keeps track of the state of each digit (its segment bit pattern and its style)...
void writePatternAt(uint8_t digit, uint8_t pattern, uint8_t style)
Write the pattern and style for a given digit.
void renderField()
Render the current field immediately.
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...
void writeStyleAt(uint8_t digit, uint8_t style)
Write the style for a given digit, leaving pattern unchanged.
virtual void configure()
Configure the driver with the parameters given by the various setXxx() methods.
void writeBrightness(uint8_t brightness)
Set brightness expressed as a fraction of 256.
StyledDigit & getStyledDigit(uint8_t i)
Return a reference the styled digit.
A class that knows how to translate an array of led segement bit patterns with style attributes to a ...
void updateFrame()
Perform things that need to be done each frame.
void calcBlinkAndPulseForFrame()
Calculate the blink and pulse states for current frame.
void renderStyledDigits()
Translate the StyledDigits to DimmingDigits for the Driver.
static void calcPulseFractionForFrame(uint16_t framesPerPulse, uint16_t ¤tFrame, uint8_t &pulseFraction)
Calculate the pulse fraction.
uint16_t getFieldsPerSecond()
Return the fields per second.
void writeDecimalPointAt(uint8_t digit, bool state=true)
Write the decimal point for the digit.
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.
Base class of drivers which knows how to transfer the bit patterns stored in the array of DimmingDigi...
virtual ~Renderer()
Destructor.
uint8_t getNumDigits()
Get the number of digits.
static void calcBlinkStateForFrame(uint16_t framesPerBlink, uint16_t ¤tFrame, uint8_t &blinkState)
Calculate the blink state.
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.
virtual uint16_t getFieldsPerFrame()=0
Return number of fields per frame.