Skip to content

Commit 441d52e

Browse files
committed
upd
1 parent db3b90f commit 441d52e

File tree

2 files changed

+25
-27
lines changed

2 files changed

+25
-27
lines changed

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=GyverSegment
2-
version=1.4.2
2+
version=1.4.3
33
author=AlexGyver <[email protected]>
44
maintainer=AlexGyver <[email protected]>
55
sentence=Powerful library for controlling 7-segment indicators

src/utils/SegBuffer.h

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -85,45 +85,23 @@ class SegBuffer : public Print {
8585
setCursor(from);
8686
if (hour < 10) print(' ');
8787
print(hour);
88-
setCursor(from + 2);
8988
if (minute < 10) print(0);
9089
print(minute);
9190
}
9291

9392
// вывести байт в текущую позицию курсора
9493
void writeByte(uint8_t data) {
95-
_useFont = 0;
96-
write(data);
97-
_useFont = 1;
94+
_write(data, false);
9895
}
9996

10097
// вывести байты в текущую позицию курсора
10198
void writeByte(uint8_t* data, uint8_t len) {
102-
_useFont = 0;
103-
while (len--) write(*data++);
104-
_useFont = 1;
99+
while (len--) writeByte(*data++);
105100
}
106101

107102
// вывести символ в текущую позицию курсора
108103
size_t write(uint8_t data) {
109-
if (_useFont && data == '.') {
110-
if (!_dec) return 1;
111-
if (_rtol) {
112-
if (_pos >= 0 && _pos < _size) bitSet(buffer[_pos], 7);
113-
} else {
114-
if (_pos > 0 && _pos <= _size) bitSet(buffer[_pos - 1], 7);
115-
}
116-
return 1;
117-
}
118-
119-
if (_pos >= 0 && _pos < _size) {
120-
if (_rtol) {
121-
uint8_t from = (_shiftSize && _shiftSize <= _pos) ? (_pos - _shiftSize + 1) : 0;
122-
for (int8_t i = from; i < _pos; i++) buffer[i] = buffer[i + 1];
123-
}
124-
buffer[_pos] = _useFont ? sseg::getCharCode(data) : data;
125-
}
126-
if (!_rtol) _pos++;
104+
_write(data, true);
127105
return 1;
128106
}
129107

@@ -156,5 +134,25 @@ class SegBuffer : public Print {
156134
int16_t _pos = 0;
157135
bool _rtol = 0;
158136
uint8_t _shiftSize = 0;
159-
bool _useFont = 1;
137+
138+
void _write(uint8_t data, bool useFont) {
139+
if (useFont && data == '.') {
140+
if (!_dec) return;
141+
if (_rtol) {
142+
if (_pos >= 0 && _pos < _size) bitSet(buffer[_pos], 7);
143+
} else {
144+
if (_pos > 0 && _pos <= _size) bitSet(buffer[_pos - 1], 7);
145+
}
146+
return;
147+
}
148+
149+
if (_pos >= 0 && _pos < _size) {
150+
if (_rtol) {
151+
uint8_t from = (_shiftSize && _shiftSize <= _pos) ? (_pos - _shiftSize + 1) : 0;
152+
for (int8_t i = from; i < _pos; i++) buffer[i] = buffer[i + 1];
153+
}
154+
buffer[_pos] = useFont ? sseg::getCharCode(data) : data;
155+
}
156+
if (!_rtol) _pos++;
157+
}
160158
};

0 commit comments

Comments
 (0)