AceSegment  0.3.0
An adjustable, configurable, and extensible framework for rendering seven segment LED displays.
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
ace_segment::Driver Class Referenceabstract

Base class of drivers which knows how to transfer the bit patterns stored in the array of DimmablePattern objects to the actual LED display. More...

#include <Driver.h>

Inheritance diagram for ace_segment::Driver:
Inheritance graph
[legend]
Collaboration diagram for ace_segment::Driver:
Collaboration graph
[legend]

Public Types

typedef uint8_t SegmentPatternType
 Integer type used to store the segment bit patterns of a single digit. More...
 
typedef uint8_t DigitPatternType
 Integer type used to store the digit bit patterns of a single segment. More...
 

Public Member Functions

virtual ~Driver ()
 Virtual destructor needed to clean up LedMatrix that was created on the heap by DriverBuilder. More...
 
virtual void configure ()
 Configure the driver. More...
 
virtual void finish ()
 Turn off the LEDs by doing the opposite of configure(). More...
 
virtual void displayCurrentField ()=0
 Display the current field of the frame. More...
 
virtual void prepareToSleep ()
 Prepare to go to sleep by clearing the frame, and setting a flag so that it doesn't turn itself back on through an interrupt.
 
virtual void wakeFromSleep ()
 Wake up from sleep. More...
 
virtual uint16_t getFieldsPerFrame ()=0
 Return number of fields per frame. More...
 
virtual bool isBrightnessSupported ()=0
 Returns true if the driver supports brightness. More...
 
void setPattern (uint8_t digit, SegmentPatternType pattern, uint8_t brightness=DimmablePattern::kOn)
 Set the pattern for a given digit. More...
 
void setBrightness (uint8_t digit, uint8_t brightness)
 Set the brightness of the given digit. More...
 

Protected Member Functions

 Driver (const Driver &)=delete
 
Driveroperator= (const Driver &)=delete
 
 Driver (LedMatrix *ledMatrix, DimmablePattern *dimmablePatterns, uint8_t numDigits, bool ownsLedMatrix=false)
 Constructor. More...
 

Protected Attributes

LedMatrix *const mLedMatrix
 
DimmablePattern *const mDimmablePatterns
 
const uint8_t mNumDigits
 
const bool mOwnsLedMatrix
 
volatile bool mPreparedToSleep
 

Static Protected Attributes

static const uint8_t kNumSegments = 8
 Number of segments on a single digit. More...
 

Detailed Description

Base class of drivers which knows how to transfer the bit patterns stored in the array of DimmablePattern objects to the actual LED display.

Different wiring configuration will require different drivers.

Each call to displayCurrentField() displays one field of a frame. The object is expected to keep internal state so that the next call to displayCurrentField() displays the next field.

Definition at line 44 of file Driver.h.

Member Typedef Documentation

◆ DigitPatternType

Integer type used to store the digit bit patterns of a single segment.

In the current implementations Driver, this must be able to hold 'mNumDigits' number of bits.

Definition at line 58 of file Driver.h.

◆ SegmentPatternType

Integer type used to store the segment bit patterns of a single digit.

For an 7-segment LED, this is a uint8_t because we need 8 bits including the decimal point.

Definition at line 51 of file Driver.h.

Constructor & Destructor Documentation

◆ ~Driver()

ace_segment::Driver::~Driver ( )
virtual

Virtual destructor needed to clean up LedMatrix that was created on the heap by DriverBuilder.

Normally, the Driver will be created once and never deleted, however unit tests will create multiple versions of Driver and will call the destructor to clean up after each test.

Definition at line 31 of file Driver.cpp.

◆ Driver()

ace_segment::Driver::Driver ( LedMatrix ledMatrix,
DimmablePattern dimmablePatterns,
uint8_t  numDigits,
bool  ownsLedMatrix = false 
)
inlineexplicitprotected

Constructor.

The driver takes ownership of the ledMatrix and will delete it in the destructor.

Parameters
ledMatrixThe ledMatrix can be null for a FakeDriver but normally it is expected to be non-null.
dimmablePatternsAn array of DimmablePattern objects that represents each digit.
numDigits
ownsLedMatrixIf true, the Driver object owns the ledMatrix and will delete it in the destructor. Default is false, but set to true by DriverBuidler.

Definition at line 148 of file Driver.h.

Member Function Documentation

◆ configure()

void ace_segment::Driver::configure ( )
virtual

Configure the driver.

Usually called only once in a program. Sometimes unit tests may call it twice.

Reimplemented in ace_segment::DigitDriver, ace_segment::SegmentDriver, and ace_segment::ModulatingDigitDriver.

Definition at line 37 of file Driver.cpp.

◆ displayCurrentField()

virtual void ace_segment::Driver::displayCurrentField ( )
pure virtual

Display the current field of the frame.

Automatically advances to the next field for the next call. A frame is one complete rendering of all the digits. A field is a slice of that frame. If the digits are multiplexed, then a field is a rendering of a single digit with all its segments. If the segments are multiplexed, then a field is a rendering of a single segment across multiple digits.

Implemented in ace_segment::DigitDriver, ace_segment::SegmentDriver, and ace_segment::ModulatingDigitDriver.

◆ finish()

void ace_segment::Driver::finish ( )
virtual

Turn off the LEDs by doing the opposite of configure().

Definition at line 43 of file Driver.cpp.

◆ getFieldsPerFrame()

virtual uint16_t ace_segment::Driver::getFieldsPerFrame ( )
pure virtual

Return number of fields per frame.

Implemented in ace_segment::DigitDriver, ace_segment::SegmentDriver, and ace_segment::ModulatingDigitDriver.

◆ isBrightnessSupported()

virtual bool ace_segment::Driver::isBrightnessSupported ( )
pure virtual

Returns true if the driver supports brightness.

If not, any brightness greater than 0 will be considered ON, and 0 will be OFF.

Implemented in ace_segment::DigitDriver, ace_segment::SegmentDriver, and ace_segment::ModulatingDigitDriver.

◆ setBrightness()

void ace_segment::Driver::setBrightness ( uint8_t  digit,
uint8_t  brightness 
)

Set the brightness of the given digit.

Definition at line 57 of file Driver.cpp.

◆ setPattern()

void ace_segment::Driver::setPattern ( uint8_t  digit,
SegmentPatternType  pattern,
uint8_t  brightness = DimmablePattern::kOn 
)

Set the pattern for a given digit.

Parameters
digitthe digit index, 0 is the left most digit
patternthe segment bit pattern
brightnessoptional brightness fraction of the digit in units of 1/256, set to 255 if not specified

Definition at line 49 of file Driver.cpp.

◆ wakeFromSleep()

virtual void ace_segment::Driver::wakeFromSleep ( )
inlinevirtual

Wake up from sleep.

Definition at line 96 of file Driver.h.

Member Data Documentation

◆ kNumSegments

const uint8_t ace_segment::Driver::kNumSegments = 8
staticprotected

Number of segments on a single digit.

To support a 14-segment LED display or a 16-segment LED display, we would need to change various bit fields from uint8_t to uint16_t. It's a bit of work but doable.

Definition at line 129 of file Driver.h.


The documentation for this class was generated from the following files: