AceSegment  0.7.0
A framework for rendering seven segment LED displays using the TM1637, MAX7219, HT16K33, or 74HC595 controller chips
Public Types | Public Member Functions | Static Public Attributes | List of all members
ace_segment::NumberWriter Class Reference

The NumberWriter supports converting decimal and hexadecimal numbers to segment patterns expected by LedModule. More...

#include <NumberWriter.h>

Public Types

typedef uint8_t hexchar_t
 The type of the character set supported by many methods in this class, usually containing the string "HexChar" in its name. More...
 

Public Member Functions

 NumberWriter (LedModule &ledModule)
 Constructor.
 
LedModuleledModule ()
 Get the underlying LedModule.
 
PatternWriterpatternWriter ()
 Get the underlying LedModule.
 
void writeHexCharAt (uint8_t pos, hexchar_t c)
 Write the hex character c at position pos. More...
 
void writeHexCharsAt (uint8_t pos, const hexchar_t s[], uint8_t len)
 Write the len hex characters given by s starting at pos.
 
void writeHexByteAt (uint8_t pos, uint8_t b)
 Write the 2-digit (8-bit) hexadecimal byte 'b' at pos.
 
void writeHexWordAt (uint8_t pos, uint16_t w)
 Write the 4 digit (16-bit) hexadecimal word at pos.
 
uint8_t writeUnsignedDecimalAt (uint8_t pos, uint16_t num, int8_t boxSize=0)
 Write the 16-bit unsigned number num as a decimal number at pos. More...
 
uint8_t writeSignedDecimalAt (uint8_t pos, int16_t num, int8_t boxSize=0)
 Same as writeUnsignedDecimalAt() but prepends a '-' sign if negative.
 
void writeUnsignedDecimal2At (uint8_t pos, uint8_t num)
 Write the 2 digit decimal number at pos. More...
 
void writeDecimalPointAt (uint8_t pos, bool state=true)
 Write the decimal point for the pos. More...
 
void clear ()
 Clear the entire display.
 
void clearToEnd (uint8_t pos)
 Clear the display from pos to the end. More...
 

Static Public Attributes

static const uint8_t kNumHexChars = 18
 Total number of characters in the HexCharacter set.
 
static const hexchar_t kCharSpace = 0x10
 A space character.
 
static const hexchar_t kCharMinus = 0x11
 A minus character.
 

Detailed Description

The NumberWriter supports converting decimal and hexadecimal numbers to segment patterns expected by LedModule.

The character set includes 0 to F, and a few other characters which should be self-explanatory: kCharSpace and kCharMinus.

Definition at line 39 of file NumberWriter.h.

Member Typedef Documentation

◆ hexchar_t

The type of the character set supported by many methods in this class, usually containing the string "HexChar" in its name.

This custom character set is not ASCII to save flash memory. It is a restricted set that starts with 0 and goes up to 0xF to support hexadecimal digits. In addition, the character set adds few more characters for convenience:

  • kCharSpace = 0x10 = space character
  • kCharMinus = 0x11 = minus character

The hexchar_t typedef is an alias for uint8_t and unfortunately, C++ will not prevent mixing a normal char or uint8_t with a hexchar_t. However, it does make the documentation of the various methods more self-explanatory.

Definition at line 56 of file NumberWriter.h.

Member Function Documentation

◆ clearToEnd()

void ace_segment::NumberWriter::clearToEnd ( uint8_t  pos)
inline

Clear the display from pos to the end.

Useful after calling writeSignedDecimalAt() and writeUnsignedDecimalAt() which prints a variable number of digits.

Definition at line 164 of file NumberWriter.h.

◆ writeDecimalPointAt()

void ace_segment::NumberWriter::writeDecimalPointAt ( uint8_t  pos,
bool  state = true 
)
inline

Write the decimal point for the pos.

Clock LED modules will attach the colon segment to one of the decimal points.

Definition at line 152 of file NumberWriter.h.

◆ writeHexCharAt()

void ace_segment::NumberWriter::writeHexCharAt ( uint8_t  pos,
hexchar_t  c 
)
inline

Write the hex character c at position pos.

If c falls outside the valid range of the kHexCharPatterns set, a kCharSpace character is printed instead.

Definition at line 83 of file NumberWriter.h.

◆ writeUnsignedDecimal2At()

void ace_segment::NumberWriter::writeUnsignedDecimal2At ( uint8_t  pos,
uint8_t  num 
)

Write the 2 digit decimal number at pos.

This method always writes 2 characters. The padding is always a space, so 9 is printed as " 9" not "09". If num >= 100, then this prints "99".

This method is meant to be a lighter version of writeUnsignedDecimalAt() when only 2 digits are needed. Seems to save about 110 bytes of flash.

Definition at line 134 of file NumberWriter.cpp.

◆ writeUnsignedDecimalAt()

uint8_t ace_segment::NumberWriter::writeUnsignedDecimalAt ( uint8_t  pos,
uint16_t  num,
int8_t  boxSize = 0 
)

Write the 16-bit unsigned number num as a decimal number at pos.

Parameters
posstart position of the number
numunsigned decimal number, 0-65535
boxSizesize of box. This is meant to be similar to the "%-5d" or "%5d" specifier to the printf() function
  • 0 means no boxing, printing from left
  • > 0 means right justified inside box
  • < 0 means left justified inside box
Returns
number of characters actually written, even if the characters bled over the end of the LED segments

Definition at line 71 of file NumberWriter.cpp.


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