@@ -26,29 +26,24 @@ void HT16K33AlphaDisplay::setup() {
26
26
display->write_bytes (DISPLAY_COMMAND_DISPLAY_ON, nullptr , 0 );
27
27
}
28
28
this ->set_brightness (1 );
29
- memset (this ->buffer_ , 0 , 64 );
30
29
}
31
30
32
31
void HT16K33AlphaDisplay::loop () {
33
32
unsigned long now = millis ();
34
33
int numc = this ->displays_ .size () * 8 ;
35
- // check if the buffer has shrunk past the current position since last update
36
- if (this ->offset_ + numc > this ->buffer_fill_ ) {
37
- this ->offset_ = std::max (this ->buffer_fill_ - numc, 0 );
38
- this ->display_ ();
39
- }
40
- if (!this ->scroll_ || (this ->buffer_fill_ <= numc))
34
+ int len = this ->buffer_ .size ();
35
+ if (!this ->scroll_ || (len <= numc))
41
36
return ;
42
37
if ((this ->offset_ == 0 ) && (now - this ->last_scroll_ < this ->scroll_delay_ ))
43
38
return ;
44
- if (this ->offset_ + numc >= this ->buffer_fill_ ) {
45
- if (now - this ->last_scroll_ >= this ->scroll_dwell_ ) {
39
+ if ((!this ->continuous_ && (this ->offset_ + numc >= len)) ||
40
+ (this ->continuous_ && (this ->offset_ > len - 2 ))) {
41
+ if (this ->continuous_ || (now - this ->last_scroll_ >= this ->scroll_dwell_ )) {
46
42
this ->offset_ = 0 ;
47
43
this ->last_scroll_ = now;
48
44
this ->display_ ();
49
45
}
50
- } else
51
- if (now - this ->last_scroll_ >= this ->scroll_speed_ ) {
46
+ } else if (now - this ->last_scroll_ >= this ->scroll_speed_ ) {
52
47
this ->offset_ += 2 ;
53
48
this ->last_scroll_ = now;
54
49
this ->display_ ();
@@ -58,19 +53,33 @@ void HT16K33AlphaDisplay::loop() {
58
53
float HT16K33AlphaDisplay::get_setup_priority () const { return setup_priority::PROCESSOR; }
59
54
60
55
void HT16K33AlphaDisplay::display_ () {
61
- int offset = this ->offset_ ;
56
+ int numc = this ->displays_ .size () * 8 ;
57
+ int len = this ->buffer_ .size ();
58
+ uint8_t data[numc];
59
+ memset (data, 0 , numc);
60
+ int pos = this ->offset_ ;
61
+ for (int i = 0 ; i < numc; i++, pos++) {
62
+ if (pos >= len) {
63
+ if (!this ->continuous_ )
64
+ break ;
65
+ pos %= len;
66
+ }
67
+ data[i] = this ->buffer_ [pos];
68
+ }
69
+ pos = 0 ;
62
70
for (auto *display : this ->displays_ ) {
63
- display->write_bytes (DISPLAY_COMMAND_SET_DDRAM_ADDR, this -> buffer_ + offset , 8 );
64
- offset += 8 ;
71
+ display->write_bytes (DISPLAY_COMMAND_SET_DDRAM_ADDR, data + pos , 8 );
72
+ pos += 8 ;
65
73
}
66
74
}
67
75
68
76
void HT16K33AlphaDisplay::update () {
69
- memset (this ->buffer_ , 0 , 64 );
70
- int prev_fill = this ->buffer_fill_ ;
71
- this ->buffer_fill_ = 0 ;
77
+ int prev_fill = this ->buffer_ .size ();
78
+ this ->buffer_ .clear ();
72
79
this ->call_writer ();
73
- if (this ->scroll_ && (prev_fill != this ->buffer_fill_ )) {
80
+ int numc = this ->displays_ .size () * 8 ;
81
+ int len = this ->buffer_ .size ();
82
+ if ((this ->scroll_ && (prev_fill != len) && !this ->continuous_ ) || (len <= numc)) {
74
83
this ->last_scroll_ = millis ();
75
84
this ->offset_ = 0 ;
76
85
}
@@ -99,14 +108,8 @@ float HT16K33AlphaDisplay::get_brightness() {
99
108
}
100
109
101
110
void HT16K33AlphaDisplay::print (const char *str) {
102
- uint8_t pos = this ->buffer_fill_ ;
103
111
uint16_t fontc = 0 ;
104
112
while (*str != ' \0 ' ) {
105
- if (pos >= 64 ) {
106
- ESP_LOGW (TAG, " output buffer full!" );
107
- break ;
108
- }
109
-
110
113
uint8_t c = *reinterpret_cast <const uint8_t *>(str++);
111
114
if (c > 127 )
112
115
fontc = 0 ;
@@ -117,10 +120,9 @@ void HT16K33AlphaDisplay::print(const char *str) {
117
120
fontc |= 0x4000 ;
118
121
str++;
119
122
}
120
- this ->buffer_ [pos++] = fontc & 0xff ;
121
- this ->buffer_ [pos++] = fontc >> 8 ;
123
+ this ->buffer_ . push_back ( fontc & 0xff ) ;
124
+ this ->buffer_ . push_back ( fontc >> 8 ) ;
122
125
}
123
- this ->buffer_fill_ = pos;
124
126
}
125
127
126
128
void HT16K33AlphaDisplay::print (const std::string &str) { this ->print (str.c_str ()); }
0 commit comments