25 #ifndef ACE_SEGMENT_SCANNING_MODULE_H
26 #define ACE_SEGMENT_SCANNING_MODULE_H
29 #include <AceCommon.h>
30 #include "../hw/ClockInterface.h"
31 #include "../LedModule.h"
33 class ScanningModuleTest_displayCurrentField;
35 namespace ace_segment {
78 uint8_t T_SUBFIELDS = 1,
79 typename T_CI = ClockInterface>
94 const T_LM& ledMatrix,
95 uint8_t framesPerSecond
98 mLedMatrix(ledMatrix),
99 mFramesPerSecond(framesPerSecond)
111 mLastRenderFieldMicros = T_CI::micros();
115 mPrevDigit = T_DIGITS - 1;
116 mCurrentSubField = 0;
121 if (T_SUBFIELDS > 1) {
138 mPatterns[pos] = pattern;
142 return mPatterns[pos];
152 for (uint8_t i = 0; i < T_DIGITS; i++) {
186 if (pos >= T_DIGITS)
return;
187 mBrightnesses[pos] = (brightness >= T_SUBFIELDS)
188 ? T_SUBFIELDS : brightness;
221 uint16_t now = T_CI::micros();
222 uint16_t elapsedMicros = now - mLastRenderFieldMicros;
223 if (elapsedMicros >= mMicrosPerField) {
225 mLastRenderFieldMicros = now;
242 if (T_SUBFIELDS > 1) {
243 displayCurrentFieldModulated();
245 displayCurrentFieldPlain();
250 friend class ::ScanningModuleTest_displayCurrentField;
257 void displayCurrentFieldPlain() {
258 const uint8_t pattern = mPatterns[mCurrentDigit];
259 mLedMatrix.draw(mCurrentDigit, pattern);
260 mPrevDigit = mCurrentDigit;
261 ace_common::incrementMod(mCurrentDigit, T_DIGITS);
265 void displayCurrentFieldModulated() {
267 const uint8_t brightness = mBrightnesses[mCurrentDigit];
279 const uint8_t pattern = (mCurrentSubField < brightness)
280 ? mPatterns[mCurrentDigit]
283 if (pattern != mPattern || mCurrentDigit != mPrevDigit) {
284 mLedMatrix.draw(mCurrentDigit, pattern);
289 mPrevDigit = mCurrentDigit;
290 if (mCurrentSubField >= T_SUBFIELDS) {
291 ace_common::incrementMod(mCurrentDigit, T_DIGITS);
292 mCurrentSubField = 0;
301 const T_LM& mLedMatrix;
304 volatile uint8_t mPatterns[T_DIGITS];
307 volatile uint8_t mBrightnesses[T_DIGITS];
315 uint16_t mMicrosPerField;
318 uint16_t mLastRenderFieldMicros;
321 uint8_t
const mFramesPerSecond;
333 uint8_t mCurrentDigit;
348 uint8_t mCurrentSubField;