9
9
#endif
10
10
11
11
namespace esphome {
12
- namespace ht16k33_alpha {
12
+ namespace ht16k33 {
13
13
14
- static const char *TAG = " ht16k33_alpha " ;
14
+ static const char *TAG = " ht16k33 " ;
15
15
16
16
// First set bit determines command, bits after that are the data.
17
17
static const uint8_t DISPLAY_COMMAND_SET_DDRAM_ADDR = 0x00 ;
@@ -20,7 +20,7 @@ static const uint8_t DISPLAY_COMMAND_DISPLAY_OFF = 0x80;
20
20
static const uint8_t DISPLAY_COMMAND_DISPLAY_ON = 0x81 ;
21
21
static const uint8_t DISPLAY_COMMAND_DIMMING = 0xE0 ;
22
22
23
- void HT16K33AlphaDisplay ::setup () {
23
+ void HT16K33BaseDisplay ::setup () {
24
24
for (auto *display : this ->displays_ ) {
25
25
display->write_bytes (DISPLAY_COMMAND_SYSTEM_SETUP, nullptr , 0 );
26
26
display->write_bytes (DISPLAY_COMMAND_DISPLAY_ON, nullptr , 0 );
@@ -29,7 +29,7 @@ void HT16K33AlphaDisplay::setup() {
29
29
memset (this ->buffer_ , 0 , 64 );
30
30
}
31
31
32
- void HT16K33AlphaDisplay ::loop () {
32
+ void HT16K33BaseDisplay ::loop () {
33
33
unsigned long now = millis ();
34
34
int numc = this ->displays_ .size () * 8 ;
35
35
// check if the buffer has shrunk past the current position since last update
@@ -55,7 +55,27 @@ void HT16K33AlphaDisplay::loop() {
55
55
}
56
56
}
57
57
58
- float HT16K33AlphaDisplay::get_setup_priority () const { return setup_priority::PROCESSOR; }
58
+ float HT16K33BaseDisplay::get_setup_priority () const { return setup_priority::PROCESSOR; }
59
+
60
+ void HT16K337SegmentDisplay::display_ () {
61
+ int offset = this ->offset_ ;
62
+ constexpr uint8_t size = 10 ;
63
+ uint8_t buffer[size];
64
+ memcpy (buffer, this ->buffer_ + offset, 4 );
65
+ // TODO: implement method to show/hide colon symbol
66
+ // if (this->show_colon()) {
67
+ // buffer[4] = 0x02;
68
+ // } else {
69
+ buffer[4 ] = 0 ;
70
+ // }
71
+ buffer[5 ] = 0 ;
72
+ memcpy (buffer + 6 , this ->buffer_ + offset + 4 , 4 );
73
+
74
+ for (auto *display : this ->displays_ ) {
75
+ display->write_bytes (DISPLAY_COMMAND_SET_DDRAM_ADDR, buffer, size);
76
+ offset += 8 ;
77
+ }
78
+ }
59
79
60
80
void HT16K33AlphaDisplay::display_ () {
61
81
int offset = this ->offset_ ;
@@ -65,7 +85,7 @@ void HT16K33AlphaDisplay::display_() {
65
85
}
66
86
}
67
87
68
- void HT16K33AlphaDisplay ::update () {
88
+ void HT16K33BaseDisplay ::update () {
69
89
memset (this ->buffer_ , 0 , 64 );
70
90
int prev_fill = this ->buffer_fill_ ;
71
91
this ->buffer_fill_ = 0 ;
@@ -77,7 +97,7 @@ void HT16K33AlphaDisplay::update() {
77
97
this ->display_ ();
78
98
}
79
99
80
- void HT16K33AlphaDisplay ::set_brightness (float level) {
100
+ void HT16K33BaseDisplay ::set_brightness (float level) {
81
101
int val = (int ) round (level * 16 );
82
102
if (val < 0 )
83
103
val = 0 ;
@@ -94,11 +114,11 @@ void HT16K33AlphaDisplay::set_brightness(float level) {
94
114
}
95
115
}
96
116
97
- float HT16K33AlphaDisplay ::get_brightness () {
117
+ float HT16K33BaseDisplay ::get_brightness () {
98
118
return this ->brightness_ / 16.0 ;
99
119
}
100
120
101
- void HT16K33AlphaDisplay ::print (const char *str) {
121
+ void HT16K33BaseDisplay ::print (const char *str) {
102
122
uint8_t pos = this ->buffer_fill_ ;
103
123
uint16_t fontc = 0 ;
104
124
while (*str != ' \0 ' ) {
@@ -111,10 +131,10 @@ void HT16K33AlphaDisplay::print(const char *str) {
111
131
if (c > 127 )
112
132
fontc = 0 ;
113
133
else
114
- fontc = pgm_read_word (&alphafonttable[c] );
134
+ fontc = read_character_ (c );
115
135
c = *reinterpret_cast <const uint8_t *>(str);
116
136
if (c == ' .' ) {
117
- fontc |= 0x4000 ;
137
+ fontc |= decimal_point_mask_ () ;
118
138
str++;
119
139
}
120
140
this ->buffer_ [pos++] = fontc & 0xff ;
@@ -123,9 +143,9 @@ void HT16K33AlphaDisplay::print(const char *str) {
123
143
this ->buffer_fill_ = pos;
124
144
}
125
145
126
- void HT16K33AlphaDisplay ::print (const std::string &str) { this ->print (str.c_str ()); }
146
+ void HT16K33BaseDisplay ::print (const std::string &str) { this ->print (str.c_str ()); }
127
147
128
- void HT16K33AlphaDisplay ::printf (const char *format, ...) {
148
+ void HT16K33BaseDisplay ::printf (const char *format, ...) {
129
149
va_list arg;
130
150
va_start (arg, format);
131
151
char buffer[64 ];
@@ -136,14 +156,22 @@ void HT16K33AlphaDisplay::printf(const char *format, ...) {
136
156
}
137
157
138
158
#ifdef USE_TIME
139
- void HT16K33AlphaDisplay ::strftime (const char *format, ESPTime time) {
159
+ void HT16K33BaseDisplay ::strftime (const char *format, ESPTime time) {
140
160
char buffer[64 ];
141
161
size_t ret = time .strftime (buffer, sizeof (buffer), format);
142
162
if (ret > 0 )
143
163
this ->print (buffer);
144
164
}
145
165
#endif
146
166
147
- } // namespace ht16k33_alpha
167
+ uint16_t HT16K33AlphaDisplay::read_character_ (uint8_t c) const {
168
+ return pgm_read_word (&alphafonttable[c]);
169
+ }
170
+
171
+ uint16_t HT16K337SegmentDisplay::read_character_ (uint8_t c) const {
172
+ return pgm_read_word (&sevensegfonttable[c - 32 ]);
173
+ }
174
+
175
+ } // namespace ht16k33
148
176
} // namespace esphome
149
177
0 commit comments