AceSegment  0.3.0
An adjustable, configurable, and extensible framework for rendering seven segment LED displays.
Driver.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_H
26 #define ACE_SEGMENT_DRIVER_H
27 
28 #include <stdint.h>
29 #include "DimmablePattern.h"
30 
31 namespace ace_segment {
32 
33 class LedMatrix;
34 
44 class Driver {
45  public:
51  typedef uint8_t SegmentPatternType;
52 
58  typedef uint8_t DigitPatternType;
59 
66  virtual ~Driver();
67 
72  virtual void configure();
73 
75  virtual void finish();
76 
85  virtual void displayCurrentField() = 0;
86 
91  virtual void prepareToSleep() {
92  mPreparedToSleep = true;
93  }
94 
96  virtual void wakeFromSleep() {
97  mPreparedToSleep = false;
98  }
99 
101  virtual uint16_t getFieldsPerFrame() = 0;
102 
107  virtual bool isBrightnessSupported() = 0;
108 
117  void setPattern(uint8_t digit, SegmentPatternType pattern,
118  uint8_t brightness = DimmablePattern::kOn);
119 
121  void setBrightness(uint8_t digit, uint8_t brightness);
122 
123  protected:
129  static const uint8_t kNumSegments = 8;
130 
131  // disable copy-constructor and assignment operator
132  Driver(const Driver&) = delete;
133  Driver& operator=(const Driver&) = delete;
134 
148  explicit Driver(LedMatrix* ledMatrix, DimmablePattern* dimmablePatterns,
149  uint8_t numDigits, bool ownsLedMatrix = false):
150  mLedMatrix(ledMatrix),
151  mDimmablePatterns(dimmablePatterns),
152  mNumDigits(numDigits),
153  mOwnsLedMatrix(ownsLedMatrix),
154  mPreparedToSleep(false)
155  {}
156 
157  LedMatrix* const mLedMatrix;
158  DimmablePattern* const mDimmablePatterns;
159  const uint8_t mNumDigits;
160  const bool mOwnsLedMatrix;
161 
162  volatile bool mPreparedToSleep;
163 };
164 
165 }
166 
167 #endif
uint8_t SegmentPatternType
Integer type used to store the segment bit patterns of a single digit.
Definition: Driver.h:51
virtual void displayCurrentField()=0
Display the current field of the frame.
virtual void wakeFromSleep()
Wake up from sleep.
Definition: Driver.h:96
virtual bool isBrightnessSupported()=0
Returns true if the driver supports brightness.
virtual void configure()
Configure the driver.
Definition: Driver.cpp:37
Driver(LedMatrix *ledMatrix, DimmablePattern *dimmablePatterns, uint8_t numDigits, bool ownsLedMatrix=false)
Constructor.
Definition: Driver.h:148
virtual void prepareToSleep()
Prepare to go to sleep by clearing the frame, and setting a flag so that it doesn&#39;t turn itself back ...
Definition: Driver.h:91
virtual void finish()
Turn off the LEDs by doing the opposite of configure().
Definition: Driver.cpp:43
Class that represents the abstraction of a particular LED display wiring.
Definition: LedMatrix.h:49
void setPattern(uint8_t digit, SegmentPatternType pattern, uint8_t brightness=DimmablePattern::kOn)
Set the pattern for a given digit.
Definition: Driver.cpp:49
virtual ~Driver()
Virtual destructor needed to clean up LedMatrix that was created on the heap by DriverBuilder.
Definition: Driver.cpp:31
void setBrightness(uint8_t digit, uint8_t brightness)
Set the brightness of the given digit.
Definition: Driver.cpp:57
Base class of drivers which knows how to transfer the bit patterns stored in the array of DimmablePat...
Definition: Driver.h:44
virtual uint16_t getFieldsPerFrame()=0
Return number of fields per frame.
static const uint8_t kNumSegments
Number of segments on a single digit.
Definition: Driver.h:129
uint8_t DigitPatternType
Integer type used to store the digit bit patterns of a single segment.
Definition: Driver.h:58