AceSegment  0.3.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 StyledPattern;
34 class Hardware;
35 
42  public:
44  explicit RendererBuilder(Hardware* hardware, Driver* driver,
45  StyledPattern* styledPatterns, uint8_t numDigits):
46  mHardware(hardware),
47  mDriver(driver),
48  mStyledPatterns(styledPatterns),
49  mNumDigits(numDigits),
50  mFramesPerSecond(kFramesPerSecondDefault),
51  mStatsResetInterval(kStatsResetIntervalDefault)
52  {
53  for (uint8_t i = 0; i < Renderer::kNumStyles; i++) {
54  mStylers[i] = nullptr;
55  }
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 
91  RendererBuilder& setStyler(uint8_t styleIndex, Styler* styler) {
92  if (styleIndex > 0 && styleIndex < Renderer::kNumStyles) {
93  mStylers[styleIndex] = styler;
94  }
95  return *this;
96  }
97 
103  return new Renderer(mHardware, mDriver, mStyledPatterns, mNumDigits,
104  mFramesPerSecond, mStatsResetInterval, mStylers);
105  }
106 
107  private:
108  static const uint8_t kFramesPerSecondDefault = 60;
109  static const uint16_t kStatsResetIntervalDefault = 1200;
110 
111  Hardware* const mHardware;
112  Driver* const mDriver;
113  StyledPattern* const mStyledPatterns;
114  uint8_t const mNumDigits;
115  uint8_t mFramesPerSecond;
116  uint16_t mStatsResetInterval;
117  Styler* mStylers[Renderer::kNumStyles];
118 
119 };
120 
121 }
122 
123 #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.
static const uint8_t kNumStyles
Maximum number of styles.
Definition: Renderer.h:55
RendererBuilder & setStyler(uint8_t styleIndex, Styler *styler)
Set the Styler for the given styleIndex.
A class that knows how to translate an array of led segement bit patterns with style attributes to a ...
Definition: Renderer.h:48
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 DimmablePat...
Definition: Driver.h:44
Data structure that keeps track of the state of each digit (its segment bit pattern and its style)...
Definition: StyledPattern.h:36
Interface for classes which apply a style to the given bit pattern and brightness.
Definition: Styler.h:34
RendererBuilder(Hardware *hardware, Driver *driver, StyledPattern *styledPatterns, uint8_t numDigits)
Constructor.