AceSegment  0.2.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  mNumSegments(8),
43  mResistorsOnSegments(true),
44  mCommonCathode(true),
45  mLedMatrixType(kTypeLedMatrixDirect),
46  mDigitPins(nullptr),
47  mSegmentPins(nullptr),
48  mUseModulatingDriver(false),
49  mNumSubFields(1)
50  {}
51 
52  DriverBuilder& setNumDigits(uint8_t numDigits) {
53  mNumDigits = numDigits;
54  return *this;
55  }
56 
57  DriverBuilder& setNumSegments(uint8_t numSegments) {
58  mNumSegments = numSegments;
59  return *this;
60  }
61 
62  DriverBuilder& setCommonAnode() {
63  mCommonCathode = false;
64  return *this;
65  }
66 
67  DriverBuilder& setCommonCathode() {
68  mCommonCathode = true;
69  return *this;
70  }
71 
72  DriverBuilder& setResistorsOnDigits() {
73  mResistorsOnSegments = false;
74  return *this;
75  }
76 
77  DriverBuilder& setResistorsOnSegments() {
78  mResistorsOnSegments = true;
79  return *this;
80  }
81 
82  DriverBuilder& setDigitPins(const uint8_t* digitPins) {
83  mDigitPins = digitPins;
84  return *this;
85  }
86 
87  DriverBuilder& setSegmentDirectPins(const uint8_t* segmentPins) {
88  mLedMatrixType = kTypeLedMatrixDirect;
89  mSegmentPins = segmentPins;
90  return *this;
91  }
92 
93  DriverBuilder& setSegmentSerialPins(uint8_t latchPin, uint8_t dataPin,
94  uint8_t clockPin) {
95  mLedMatrixType = kTypeLedMatrixSerial;
96 
97  // We support only resistors on segments in this configuration.
98  mResistorsOnSegments = true;
99  mSegmentPins = nullptr;
100 
101  mLatchPin = latchPin;
102  mDataPin = dataPin;
103  mClockPin = clockPin;
104  return *this;
105  }
106 
107  DriverBuilder& setSegmentSpiPins(uint8_t latchPin, uint8_t dataPin,
108  uint8_t clockPin) {
109  mLedMatrixType = kTypeLedMatrixSpi;
110 
111  // We support only resistors on segments in this configuration.
112  mResistorsOnSegments = true;
113  mSegmentPins = nullptr;
114 
115  mLatchPin = latchPin;
116  mDataPin = dataPin;
117  mClockPin = clockPin;
118  return *this;
119  }
120 
121  DriverBuilder& setDimmingDigits(DimmingDigit* dimmingDigits) {
122  mDimmingDigits = dimmingDigits;
123  return *this;
124  }
125 
132  DriverBuilder& useModulatingDriver(uint8_t numSubFields) {
133  mUseModulatingDriver = true;
134  mNumSubFields = (numSubFields > 0) ? numSubFields : 1;
135  return *this;
136  }
137 
138  Driver* build();
139 
140  private:
141  static const uint8_t kTypeLedMatrixDirect = 0;
142  static const uint8_t kTypeLedMatrixSerial = 1;
143  static const uint8_t kTypeLedMatrixSpi = 2;
144 
145  LedMatrix* buildLedMatrix();
146 
147  // parameters for LedMatrix
148  Hardware* const mHardware;
149  uint8_t mNumDigits;
150  uint8_t mNumSegments;
151  bool mResistorsOnSegments;
152  bool mCommonCathode;
153  uint8_t mLedMatrixType;
154  const uint8_t* mDigitPins;
155  const uint8_t* mSegmentPins;
156  uint8_t mLatchPin;
157  uint8_t mDataPin;
158  uint8_t mClockPin;
159 
160  // parameters for Driver
161  DimmingDigit* mDimmingDigits;
162  bool mUseModulatingDriver;
163  uint8_t mNumSubFields;
164 };
165 
166 }
167 
168 #endif
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 DimmingDigi...
Definition: Driver.h:44