AceSegmentWriter  0.4
Write decimal numbers, hex numbers, temperature, clock digits, characters, and strings to seven segment LED modules
TemperatureWriter.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_TEMPERATURE_WRITER_H
26 #define ACE_SEGMENT_WRITER_TEMPERATURE_WRITER_H
27 
28 #include <stdint.h>
29 #include "PatternWriter.h"
30 #include "NumberWriter.h"
31 
32 namespace ace_segment {
33 
41 template <typename T_LED_MODULE>
43  public:
50  mNumberWriter(numberWriter)
51  {}
52 
54  T_LED_MODULE& ledModule() { return mNumberWriter.ledModule(); }
55 
58  return mNumberWriter.patternWriter();
59  }
60 
62  NumberWriter<T_LED_MODULE>& numberWriter() { return mNumberWriter; }
63 
65  void home() { mNumberWriter.home(); }
66 
70  uint8_t writeTemp(int16_t temp, int8_t boxSize = 0) {
71  return mNumberWriter.writeSignedDecimal(temp, boxSize);
72  }
73 
84  uint8_t writeTempDeg(int16_t temp, int8_t boxSize = 0) {
85  uint8_t written = mNumberWriter.writeSignedDecimal(
86  temp, boxSize >= 1 ? boxSize - 1 : 0);
87  patternWriter().writePattern(kPatternDeg);
88  return written + 1;
89  }
90 
94  uint8_t writeTempDegC(int16_t temp, int8_t boxSize = 0) {
95  uint8_t written = mNumberWriter.writeSignedDecimal(
96  temp, boxSize >= 2 ? boxSize - 2 : 0);
97  patternWriter().writePattern(kPatternDeg);
98  patternWriter().writePattern(kPatternC);
99  return written + 2;
100  }
101 
105  uint8_t writeTempDegF(int16_t temp, int8_t boxSize = 0) {
106  uint8_t written = mNumberWriter.writeSignedDecimal(
107  temp, boxSize >= 2 ? boxSize - 2 : 0);
108  patternWriter().writePattern(kPatternDeg);
109  patternWriter().writePattern(kPatternF);
110  return written + 2;
111  }
112 
114  void clear() { mNumberWriter.clear(); }
115 
117  void clearToEnd() { mNumberWriter.clearToEnd(); }
118 
119  private:
120  // disable copy-constructor and assignment operator
121  TemperatureWriter(const TemperatureWriter&) = delete;
122  TemperatureWriter& operator=(const TemperatureWriter&) = delete;
123 
124  NumberWriter<T_LED_MODULE>& mNumberWriter;
125 };
126 
127 } // ace_segment
128 
129 #endif
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.
The TemperatureWriter supports writing integer temperature values in Celcius or Farenheit.
PatternWriter< T_LED_MODULE > & patternWriter()
Get the underlying PatternWriter.
TemperatureWriter(NumberWriter< T_LED_MODULE > &numberWriter)
Constructor.
void clear()
Clear the entire display.
T_LED_MODULE & ledModule()
Get the underlying LedModule.
uint8_t writeTempDegF(int16_t temp, int8_t boxSize=0)
Write integer temperature with degree symbol and 'F' symbol.
uint8_t writeTempDegC(int16_t temp, int8_t boxSize=0)
Write integer temperature with degree symbol and 'C' symbol.
uint8_t writeTempDeg(int16_t temp, int8_t boxSize=0)
Write integer temperature with degree symbol.
void home()
Reset cursor to home.
NumberWriter< T_LED_MODULE > & numberWriter()
Get the underlying NumberWriter.
void clearToEnd()
Clear the display from pos to the end.
uint8_t writeTemp(int16_t temp, int8_t boxSize=0)
Write signed integer temperature without deg or unit within the boxSize.