AceSegment  0.8.0
A framework for rendering seven segment LED displays using the TM1637, MAX7219, HT16K33, or 74HC595 controller chips
CharWriter.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_CHAR_WRITER_H
26 #define ACE_SEGMENT_CHAR_WRITER_H
27 
28 #include <stdint.h>
29 #include "PatternWriter.h"
30 
31 namespace ace_segment {
32 
38 class CharWriter {
39  public:
40  // Segment patterns for the ASCII character set.
41  static const uint8_t kCharPatterns[];
42 
43  // Number of characters in the default ASCII character set
44  static const uint8_t kNumChars = 128;
45 
54  explicit CharWriter(
56  const uint8_t charPatterns[] = kCharPatterns,
57  uint8_t numChars = kNumChars
58  ) :
59  mPatternWriter(ledModule),
60  mCharPatterns(charPatterns),
61  mNumChars(numChars)
62  {}
63 
65  LedModule& ledModule() const { return mPatternWriter.ledModule(); }
66 
68  uint8_t getNumDigits() const { return mPatternWriter.getNumDigits(); }
69 
71  uint8_t getNumChars() const { return mNumChars; }
72 
74  void writeCharAt(uint8_t pos, char c);
75 
77  uint8_t getPattern(char c) const;
78 
80  void writeDecimalPointAt(uint8_t pos, bool state = true) {
81  mPatternWriter.writeDecimalPointAt(pos, state);
82  }
83 
85  void clear() { clearToEnd(0); }
86 
88  void clearToEnd(uint8_t pos) { mPatternWriter.clearToEnd(pos); }
89 
90  private:
91  // disable copy-constructor and assignment operator
92  CharWriter(const CharWriter&) = delete;
93  CharWriter& operator=(const CharWriter&) = delete;
94 
95  private:
96  PatternWriter mPatternWriter;
97  const uint8_t* const mCharPatterns;
98  uint8_t const mNumChars;
99 };
100 
101 }
102 
103 #endif
ace_segment::PatternWriter::ledModule
LedModule & ledModule() const
Return the underlying LedModule.
Definition: PatternWriter.h:52
ace_segment::CharWriter::writeDecimalPointAt
void writeDecimalPointAt(uint8_t pos, bool state=true)
Write the decimal point for the pos.
Definition: CharWriter.h:80
ace_segment::CharWriter::clear
void clear()
Clear the entire display.
Definition: CharWriter.h:85
ace_segment::LedModule
General interface that represents a generic seven-segment LED module with multiple digits.
Definition: LedModule.h:44
ace_segment::CharWriter::getNumChars
uint8_t getNumChars() const
Get number of characters in current character set.
Definition: CharWriter.h:71
ace_segment::CharWriter
The CharWriter supports mapping of an 8-bit character set to segment patterns supported by LedModule.
Definition: CharWriter.h:38
ace_segment::CharWriter::ledModule
LedModule & ledModule() const
Get the underlying LedModule.
Definition: CharWriter.h:65
ace_segment::CharWriter::clearToEnd
void clearToEnd(uint8_t pos)
Clear the display from pos to the end.
Definition: CharWriter.h:88
ace_segment::CharWriter::writeCharAt
void writeCharAt(uint8_t pos, char c)
Write the character at the specified position.
Definition: CharWriter.cpp:191
ace_segment::PatternWriter::clearToEnd
void clearToEnd(uint8_t pos)
Clear the display from pos to the end.
Definition: PatternWriter.h:117
ace_segment::CharWriter::getPattern
uint8_t getPattern(char c) const
Get segment pattern for character 'c'.
Definition: CharWriter.cpp:184
ace_segment::CharWriter::getNumDigits
uint8_t getNumDigits() const
Return the number of digits supported by this display instance.
Definition: CharWriter.h:68
ace_segment::CharWriter::CharWriter
CharWriter(LedModule &ledModule, const uint8_t charPatterns[]=kCharPatterns, uint8_t numChars=kNumChars)
Constructor.
Definition: CharWriter.h:54
ace_segment::PatternWriter::getNumDigits
uint8_t getNumDigits() const
Return the number of digits supported by this display instance.
Definition: PatternWriter.h:55
ace_segment::PatternWriter::writeDecimalPointAt
void writeDecimalPointAt(uint8_t pos, bool state=true)
Write the decimal point for the pos.
Definition: PatternWriter.h:102
ace_segment::PatternWriter
Write LED segment patterns to the underlying LedModule.
Definition: PatternWriter.h:43