AceSegmentWriter  0.5
Write decimal numbers, hex numbers, temperature, clock digits, characters, and strings to seven segment LED modules
ClockWriter.h
1 /*
2 MIT License
3 
4 Copyright (c) 2021 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_WRITER_CLOCK_WRITER_H
26 #define ACE_SEGMENT_WRITER_CLOCK_WRITER_H
27 
28 #include <stdint.h>
29 #include "PatternWriter.h"
30 #include "NumberWriter.h"
31 
32 namespace ace_segment {
33 
38 template <typename T_LED_MODULE>
39 class ClockWriter {
40  public:
50  explicit ClockWriter(
52  uint8_t colonDigit = 1
53  ) :
54  mNumberWriter(numberWriter),
55  mColonDigit(colonDigit)
56  {}
57 
59  T_LED_MODULE& ledModule() { return mNumberWriter.ledModule(); }
60 
63  return mNumberWriter.patternWriter();
64  }
65 
67  NumberWriter<T_LED_MODULE>& numberWriter() { return mNumberWriter; }
68 
70  void home() { mNumberWriter.home(); }
71 
77  void writeHourMinute24(uint8_t hh, uint8_t mm) {
78  mNumberWriter.writeDec2(hh);
79  mNumberWriter.writeDec2(mm);
80  writeColon();
81  }
82 
88  void writeHourMinute12(uint8_t hh, uint8_t mm) {
89  mNumberWriter.writeDec2(hh, kPatternSpace);
90  mNumberWriter.writeDec2(mm);
91  writeColon();
92  }
93 
99  void writeColon(bool state = true) {
100  mNumberWriter.patternWriter().setDecimalPointAt(mColonDigit, state);
101  }
102 
104  void clear() { mNumberWriter.clear(); }
105 
107  void clearToEnd() { mNumberWriter.clearToEnd(); }
108 
109  private:
110  // disable copy-constructor and assignment operator
111  ClockWriter(const ClockWriter&) = delete;
112  ClockWriter& operator=(const ClockWriter&) = delete;
113 
114  NumberWriter<T_LED_MODULE>& mNumberWriter;
115  uint8_t const mColonDigit;
116 };
117 
118 } // ace_segment
119 
120 #endif
The ClockWriter writes "hh:mm" and "yyyy" to the LedModule.
Definition: ClockWriter.h:39
void clear()
Clear the entire display.
Definition: ClockWriter.h:104
NumberWriter< T_LED_MODULE > & numberWriter()
Get the underlying NumberWriter.
Definition: ClockWriter.h:67
void clearToEnd()
Clear the display from pos to the end.
Definition: ClockWriter.h:107
ClockWriter(NumberWriter< T_LED_MODULE > &numberWriter, uint8_t colonDigit=1)
Constructor.
Definition: ClockWriter.h:50
void writeHourMinute12(uint8_t hh, uint8_t mm)
Write the hour and minute in 12-hour format (i.e.
Definition: ClockWriter.h:88
PatternWriter< T_LED_MODULE > & patternWriter()
Get the underlying PatternWriter.
Definition: ClockWriter.h:62
void writeHourMinute24(uint8_t hh, uint8_t mm)
Write the hour and minute in 24-hour format (i.e.
Definition: ClockWriter.h:77
void writeColon(bool state=true)
Write the colon symbol between 'hh' and 'mm'.
Definition: ClockWriter.h:99
void home()
Reset cursor to home.
Definition: ClockWriter.h:70
T_LED_MODULE & ledModule()
Get the underlying LedModule.
Definition: ClockWriter.h:59
The NumberWriter supports converting decimal and hexadecimal numbers to segment patterns expected by ...
Definition: NumberWriter.h:72
Write LED segment patterns to the underlying LedModule.