AceSegment  0.3.0
An adjustable, configurable, and extensible framework for rendering seven segment LED displays.
DriverBuilder.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_DRIVER_BUILDER_H
26 #define ACE_SEGMENT_DRIVER_BUILDER_H
27 
28 #include "Hardware.h"
29 #include "LedMatrix.h"
30 #include "Driver.h"
31 
32 namespace ace_segment {
33 
34 class Hardware;
35 class LedMatrix;
36 class Driver;
37 
39  public:
40  DriverBuilder(Hardware* hardware):
41  mHardware(hardware)
42  {}
43 
44  DriverBuilder& setNumDigits(uint8_t numDigits) {
45  mNumDigits = numDigits;
46  return *this;
47  }
48 
49  DriverBuilder& setNumSegments(uint8_t numSegments) {
50  mNumSegments = numSegments;
51  return *this;
52  }
53 
54  DriverBuilder& setCommonAnode() {
55  mCommonCathode = false;
56  return *this;
57  }
58 
59  DriverBuilder& setCommonCathode() {
60  mCommonCathode = true;
61  return *this;
62  }
63 
64  DriverBuilder& useTransistors() {
65  mUseTransistors = true;
66  return *this;
67  }
68 
69  DriverBuilder& setResistorsOnDigits() {
70  mResistorsOnSegments = false;
71  return *this;
72  }
73 
74  DriverBuilder& setResistorsOnSegments() {
75  mResistorsOnSegments = true;
76  return *this;
77  }
78 
79  DriverBuilder& setDigitPins(const uint8_t* digitPins) {
80  mDigitPins = digitPins;
81  return *this;
82  }
83 
84  DriverBuilder& setSegmentDirectPins(const uint8_t* segmentPins) {
85  mLedMatrixType = kTypeLedMatrixDirect;
86  mSegmentPins = segmentPins;
87  return *this;
88  }
89 
90  DriverBuilder& setSegmentSerialPins(uint8_t latchPin, uint8_t dataPin,
91  uint8_t clockPin) {
92  mLedMatrixType = kTypeLedMatrixSerial;
93 
94  // We support only resistors on segments in this configuration.
95  mResistorsOnSegments = true;
96  mSegmentPins = nullptr;
97 
98  mLatchPin = latchPin;
99  mDataPin = dataPin;
100  mClockPin = clockPin;
101  return *this;
102  }
103 
104  DriverBuilder& setSegmentSpiPins(uint8_t latchPin, uint8_t dataPin,
105  uint8_t clockPin) {
106  mLedMatrixType = kTypeLedMatrixSpi;
107 
108  // We support only resistors on segments in this configuration.
109  mResistorsOnSegments = true;
110  mSegmentPins = nullptr;
111 
112  mLatchPin = latchPin;
113  mDataPin = dataPin;
114  mClockPin = clockPin;
115  return *this;
116  }
117 
118  DriverBuilder& setDimmablePatterns(DimmablePattern* dimmablePatterns) {
119  mDimmablePatterns = dimmablePatterns;
120  return *this;
121  }
122 
129  DriverBuilder& useModulatingDriver(uint8_t numSubFields) {
130  mUseModulatingDriver = true;
131  mNumSubFields = (numSubFields > 0) ? numSubFields : 1;
132  return *this;
133  }
134 
135  Driver* build();
136 
137  private:
138  static const uint8_t kTypeLedMatrixDirect = 0;
139  static const uint8_t kTypeLedMatrixSerial = 1;
140  static const uint8_t kTypeLedMatrixSpi = 2;
141 
142  LedMatrix* buildLedMatrix();
143 
144  // parameters for LedMatrix
145  Hardware* const mHardware;
146  uint8_t mNumDigits = 2;
147  uint8_t mNumSegments = 8;
148  bool mResistorsOnSegments = true;
149  bool mCommonCathode = true;
150  bool mUseTransistors = false;
151  uint8_t mLedMatrixType = kTypeLedMatrixDirect;
152  const uint8_t* mDigitPins = nullptr;
153  const uint8_t* mSegmentPins = nullptr;
154  uint8_t mLatchPin = 0;
155  uint8_t mDataPin = 0;
156  uint8_t mClockPin = 0;
157 
158  // parameters for Driver
159  DimmablePattern* mDimmablePatterns = nullptr;
160  bool mUseModulatingDriver = false;
161  uint8_t mNumSubFields = 16;
162 };
163 
164 }
165 
166 #endif
Class that represents the abstraction of a particular LED display wiring.
Definition: LedMatrix.h:49
DriverBuilder & useModulatingDriver(uint8_t numSubFields)
Use a driver that provides pulse width modulation.
Base class of drivers which knows how to transfer the bit patterns stored in the array of DimmablePat...
Definition: Driver.h:44