AceSegment  0.4.0
An adjustable, configurable, and extensible framework for rendering seven segment LED displays.
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 LedDisplay. 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 (LedDisplay &ledDisplay)
 Constructor.
 
LedDisplaydisplay () const
 Get the underlying LedDisplay.
 
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 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 LedDisplay.

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 142 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 82 of file NumberWriter.h.

◆ 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: