AceSegment  0.2.0
An adjustable, configurable, and extensible framework for rendering seven segment LED displays.
RendererBuilder.h
1 /*
2 MIT License
3 
4 Copyright (c) 2018 Brian T. Park
5 
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12 
13 The above copyright notice and this permission notice shall be included in all
14 copies or substantial portions of the Software.
15 
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 SOFTWARE.
23 */
24 
25 #ifndef ACE_SEGMENT_RENDERER_BUILDER_H
26 #define ACE_SEGMENT_RENDERER_BUILDER_H
27 
28 #include <stdint.h>
29 #include "Renderer.h"
30 
31 namespace ace_segment {
32 
33 class StyledDigit;
34 class Hardware;
35 
42  public:
44  explicit RendererBuilder(Hardware* hardware, Driver* driver,
45  StyledDigit* styledDigits, uint8_t numDigits):
46  mHardware(hardware),
47  mDriver(driver),
48  mStyledDigits(styledDigits),
49  mNumDigits(numDigits),
50  mFramesPerSecond(kFramesPerSecondDefault),
51  mStatsResetInterval(kStatsResetIntervalDefault),
52  mBlinkSlowDurationMillis(kBlinkSlowDurationMillisDefault),
53  mBlinkFastDurationMillis(kBlinkFastDurationMillisDefault),
54  mPulseSlowDurationMillis(kPulseSlowDurationMillisDefault),
55  mPulseFastDurationMillis(kPulseFastDurationMillisDefault)
56  {}
57 
70  RendererBuilder& setFramesPerSecond(uint8_t framesPerSecond) {
71  mFramesPerSecond = framesPerSecond;
72  return *this;
73  }
74 
82  RendererBuilder& setStatsResetInterval(uint16_t statsResetInterval) {
83  mStatsResetInterval = statsResetInterval;
84  return *this;
85  }
86 
88  RendererBuilder& setBlinkSlowDuration(uint16_t durationMillis) {
89  mBlinkSlowDurationMillis = durationMillis;
90  return *this;
91  }
92 
94  RendererBuilder& setBlinkFastDuration(uint16_t durationMillis) {
95  mBlinkFastDurationMillis = durationMillis;
96  return *this;
97  }
98 
100  RendererBuilder& setPulseSlowDuration(uint16_t durationMillis) {
101  mPulseSlowDurationMillis = durationMillis;
102  return *this;
103  }
104 
106  RendererBuilder& setPulseFastDuration(uint16_t durationMillis) {
107  mPulseFastDurationMillis = durationMillis;
108  return *this;
109  }
110 
116  return new Renderer(mHardware, mDriver, mStyledDigits, mNumDigits,
117  mFramesPerSecond, mStatsResetInterval,
118  mBlinkSlowDurationMillis, mBlinkFastDurationMillis,
119  mPulseSlowDurationMillis, mPulseFastDurationMillis);
120  }
121 
122  private:
123  static const uint8_t kFramesPerSecondDefault = 60;
124 
125  static const uint16_t kStatsResetIntervalDefault = 1200;
126 
127  static const uint16_t kBlinkSlowDurationMillisDefault = 800;
128 
129  static const uint16_t kBlinkFastDurationMillisDefault = 400;
130 
131  static const uint16_t kPulseSlowDurationMillisDefault = 3000;
132 
133  static const uint16_t kPulseFastDurationMillisDefault = 1000;
134 
135  Hardware* const mHardware;
136  Driver* const mDriver;
137  StyledDigit* const mStyledDigits;
138  uint8_t const mNumDigits;
139  uint8_t mFramesPerSecond;
140  uint16_t mStatsResetInterval;
141  uint16_t mBlinkSlowDurationMillis;
142  uint16_t mBlinkFastDurationMillis;
143  uint16_t mPulseSlowDurationMillis;
144  uint16_t mPulseFastDurationMillis;
145 };
146 
147 }
148 
149 #endif
RendererBuilder & setFramesPerSecond(uint8_t framesPerSecond)
Set the desired frame rate.
RendererBuilder & setStatsResetInterval(uint16_t statsResetInterval)
Set the maximum number of stats updates after which it is periodicallly reset.
Data structure that keeps track of the state of each digit (its segment bit pattern and its style)...
Definition: StyledDigit.h:36
A class that knows how to translate an array of led segement bit patterns with style attributes to a ...
Definition: Renderer.h:47
RendererBuilder & setBlinkFastDuration(uint16_t durationMillis)
Set blink fast duration millis.
RendererBuilder(Hardware *hardware, Driver *driver, StyledDigit *styledDigits, uint8_t numDigits)
Constructor.
RendererBuilder & setBlinkSlowDuration(uint16_t durationMillis)
Set blink slow duration millis.
Renderer * build()
Return a new instance of Renderer with the various configurable parameters.
A builder for the Renderer.
Base class of drivers which knows how to transfer the bit patterns stored in the array of DimmingDigi...
Definition: Driver.h:44
RendererBuilder & setPulseSlowDuration(uint16_t durationMillis)
Set pulse slow duration millis.
RendererBuilder & setPulseFastDuration(uint16_t durationMillis)
Set pulse fast duration millis.