AceSegment  0.7.0
A framework for rendering seven segment LED displays using the TM1637, MAX7219, HT16K33, or 74HC595 controller chips
Public Member Functions | Friends | List of all members
ace_segment::Tm1637Module< T_TMII, T_DIGITS > Class Template Reference

An implementation of LedModule using the TM1637 chip. More...

#include <Tm1637Module.h>

Inheritance diagram for ace_segment::Tm1637Module< T_TMII, T_DIGITS >:
Inheritance graph
[legend]
Collaboration diagram for ace_segment::Tm1637Module< T_TMII, T_DIGITS >:
Collaboration graph
[legend]

Public Member Functions

 Tm1637Module (const T_TMII &tmiInterface, const uint8_t *remapArray=nullptr)
 Constructor. More...
 
void begin ()
 Initialize the module. More...
 
void end ()
 Signal end of usage. More...
 
uint8_t getNumDigits () const
 Return the number of digits supported by this display instance.
 
void setPatternAt (uint8_t pos, uint8_t pattern) override
 Set the led digit pattern at position pos.
 
uint8_t getPatternAt (uint8_t pos) override
 Get the led digit pattern at position pos.
 
void setBrightness (uint8_t brightness) override
 Set global brightness of all digits. More...
 
void setDisplayOn (bool on=true)
 Turn off the entire display. More...
 
void flush ()
 Send segment patterns of all digits plus the brightness to the display, if any of the digits or brightness is dirty. More...
 
void flushIncremental ()
 Update only a single digit or the brightness. More...
 
- Public Member Functions inherited from ace_segment::LedModule
 LedModule (uint8_t numDigits)
 Constructor. More...
 
uint8_t getNumDigits () const
 Return the number of digits supported by this display instance. More...
 

Friends

class ::Tm1637ModuleTest_flushIncremental
 
class ::Tm1637ModuleTest_flush
 

Detailed Description

template<typename T_TMII, uint8_t T_DIGITS>
class ace_segment::Tm1637Module< T_TMII, T_DIGITS >

An implementation of LedModule using the TM1637 chip.

The chip communicates using a protocol that is electrically similar to I2C, but does not use an address byte at the beginning of the protocol. We can use a software-based I2C interface.

Template Parameters
T_TMIItwo wire protocol interface for TM1637, either SoftTmiInterface or SoftTmiFastInterface
T_DIGITSnumber of digits in the LED module (usually 4 or 6)

Definition at line 91 of file Tm1637Module.h.

Constructor & Destructor Documentation

◆ Tm1637Module()

template<typename T_TMII , uint8_t T_DIGITS>
ace_segment::Tm1637Module< T_TMII, T_DIGITS >::Tm1637Module ( const T_TMII &  tmiInterface,
const uint8_t *  remapArray = nullptr 
)
inlineexplicit

Constructor.

Parameters
tmiInterfaceinstance of either SoftTmiInterface or SoftTmiFastInterface
remapArray(optional, nullable) a mapping of the logical digit positions to their physical positions, useful for 6-digt LED modules using the TM1637 chip whose digits are wired out of order

Definition at line 102 of file Tm1637Module.h.

Member Function Documentation

◆ begin()

template<typename T_TMII , uint8_t T_DIGITS>
void ace_segment::Tm1637Module< T_TMII, T_DIGITS >::begin ( )
inline

Initialize the module.

The SoftTmiInterface object must be initialized separately.

Parameters
remapArrayoptional array of positions to handle LED modules whose digit ordering is physically different than the logical ordering (where digit 0 is on the left, and digit (T_DIGITS-1) is on the far right).

Definition at line 124 of file Tm1637Module.h.

◆ end()

template<typename T_TMII , uint8_t T_DIGITS>
void ace_segment::Tm1637Module< T_TMII, T_DIGITS >::end ( )
inline

Signal end of usage.

Currently does nothing.

Definition at line 138 of file Tm1637Module.h.

◆ flush()

template<typename T_TMII , uint8_t T_DIGITS>
void ace_segment::Tm1637Module< T_TMII, T_DIGITS >::flush ( )
inline

Send segment patterns of all digits plus the brightness to the display, if any of the digits or brightness is dirty.

Takes about 22 ms using a 100 microsecond delay.

Definition at line 187 of file Tm1637Module.h.

◆ flushIncremental()

template<typename T_TMII , uint8_t T_DIGITS>
void ace_segment::Tm1637Module< T_TMII, T_DIGITS >::flushIncremental ( )
inline

Update only a single digit or the brightness.

This method must be called (T_DIGITS + 1) times to update the digits of entire module, including the brightness which is updated using a separate step. Uses the mFlushStage and the mIsDirty bit array to update only the part that needs updating.

This method should be used if the processor cannot be blocked for the entire duration of the flush() method (e.g. on the ESP8266, which will cause a WDT reset when it is blocked for more than 20-40 ms).

Using 100 micro delay, I see the following durations:

1) If brightness is updated on every iteration, I get 'min/avg/max:4/494/13780', so a maximum of 14 ms, which is still a little bit high.

2) If brightness is updated during its own mFlushStage (== T_DIGITS), then I see min/avg/max:4/492/10152, saving about 3.5ms from the latency. The side effect is a slightly flicker when the display and brightness changes at the same time, because this incrementally updating function makes those changes in 2 steps.

The incremental flushing must use fixed addressing mode to write specific digits, which adds extra commands to the wire protocol to the LED module. If this algorithm is used to send all the digits in one-shot, then this method is about 50% slower (30 ms), compared to flush() (22 ms).

Technical note: The TM1637 datasheet seems to suggest that the brightness must always be sent after a set of digits are sent. However, experimentation shows that the brightness can be sent as an independent transimission, so this method splits out each digit and the brightness as separate iterations.

Definition at line 249 of file Tm1637Module.h.

◆ setBrightness()

template<typename T_TMII , uint8_t T_DIGITS>
void ace_segment::Tm1637Module< T_TMII, T_DIGITS >::setBrightness ( uint8_t  brightness)
inlineoverridevirtual

Set global brightness of all digits.

Different subclasses will interpret the brightness integer value differently.

Implements ace_segment::LedModule.

Definition at line 156 of file Tm1637Module.h.

◆ setDisplayOn()

template<typename T_TMII , uint8_t T_DIGITS>
void ace_segment::Tm1637Module< T_TMII, T_DIGITS >::setDisplayOn ( bool  on = true)
inline

Turn off the entire display.

The brightness is not affected so when it is turned back on, the previous brightness will be used.

Definition at line 169 of file Tm1637Module.h.


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