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,19 @@ 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
+ uint16_t HT16K33AlphaDisplay::read_character_ (uint8_t c) const {
122
+ return pgm_read_word (&alphafonttable[c]);
123
+ }
124
+
125
+ uint16_t HT16K337SegmentDisplay::read_character_ (uint8_t c) const {
126
+ return pgm_read_word (&sevensegfonttable[c - 32 ]);
127
+ }
128
+
129
+ void HT16K33BaseDisplay::print (const char *str) {
102
130
uint8_t pos = this ->buffer_fill_ ;
103
131
uint16_t fontc = 0 ;
104
132
while (*str != ' \0 ' ) {
@@ -111,10 +139,10 @@ void HT16K33AlphaDisplay::print(const char *str) {
111
139
if (c > 127 )
112
140
fontc = 0 ;
113
141
else
114
- fontc = pgm_read_word (&alphafonttable[c] );
142
+ fontc = read_character_ (c );
115
143
c = *reinterpret_cast <const uint8_t *>(str);
116
144
if (c == ' .' ) {
117
- fontc |= 0x4000 ;
145
+ fontc |= decimal_point_mask_ () ;
118
146
str++;
119
147
}
120
148
this ->buffer_ [pos++] = fontc & 0xff ;
@@ -123,9 +151,9 @@ void HT16K33AlphaDisplay::print(const char *str) {
123
151
this ->buffer_fill_ = pos;
124
152
}
125
153
126
- void HT16K33AlphaDisplay ::print (const std::string &str) { this ->print (str.c_str ()); }
154
+ void HT16K33BaseDisplay ::print (const std::string &str) { this ->print (str.c_str ()); }
127
155
128
- void HT16K33AlphaDisplay ::printf (const char *format, ...) {
156
+ void HT16K33BaseDisplay ::printf (const char *format, ...) {
129
157
va_list arg;
130
158
va_start (arg, format);
131
159
char buffer[64 ];
@@ -136,14 +164,14 @@ void HT16K33AlphaDisplay::printf(const char *format, ...) {
136
164
}
137
165
138
166
#ifdef USE_TIME
139
- void HT16K33AlphaDisplay ::strftime (const char *format, ESPTime time) {
167
+ void HT16K33BaseDisplay ::strftime (const char *format, ESPTime time) {
140
168
char buffer[64 ];
141
169
size_t ret = time .strftime (buffer, sizeof (buffer), format);
142
170
if (ret > 0 )
143
171
this ->print (buffer);
144
172
}
145
173
#endif
146
174
147
- } // namespace ht16k33_alpha
175
+ } // namespace ht16k33
148
176
} // namespace esphome
149
177
0 commit comments