Skip to content

Commit 9980d83

Browse files
committed
upd
1 parent 4c04c8f commit 9980d83

5 files changed

Lines changed: 26 additions & 18 deletions

File tree

‎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.13
2+
version=1.4.14
33
author=AlexGyver <alex@alexgyver.ru>
44
maintainer=AlexGyver <alex@alexgyver.ru>
55
sentence=Powerful library for controlling 7-segment indicators

‎src/core/utils/SegAnimationExt.h‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ class SegAnimationExt : public SegBuffer {
3232
uint8_t from,
3333
bool dec = 1) : SegBuffer(buffer, size, dec),
3434
buffer(buffer),
35-
_size(size),
3635
_disp(disp),
37-
_from(min(from, size)) {}
36+
_from(min(from, disp->getSize())),
37+
_size(min(size, (uint8_t)(disp->getSize() - _from))) {}
3838

3939
// установить эффект и время его выполнения в мс
4040
void setEffect(SegEffect eff, uint16_t duration = 300) {
@@ -68,7 +68,7 @@ class SegAnimationExt : public SegBuffer {
6868

6969
// true - эффект воспроизводится
7070
bool running() {
71-
return _count;
71+
return _state && (_count || _differ());
7272
}
7373

7474
// ждать окончания воспроизведения эффекта
@@ -91,7 +91,13 @@ class SegAnimationExt : public SegBuffer {
9191

9292
// ручной тикер. Вернёт 0 в холостом, 1 при новом шаге, 2 при завершении анимации
9393
uint8_t tickManual() {
94-
if (_eff == SegEffect::None) return 0;
94+
if (_eff == SegEffect::None) {
95+
if (_differ()) {
96+
refresh();
97+
return GS_ANIMATION_END;
98+
}
99+
return GS_ANIMATION_IDLE;
100+
}
95101

96102
if (_count) {
97103
if (_maskall) {
@@ -112,7 +118,7 @@ class SegAnimationExt : public SegBuffer {
112118
if (!_maskall) {
113119
_mask = 0;
114120
for (uint8_t i = 0; i < min(_size, (uint8_t)32); i++) {
115-
if ((_disp->buffer[_from + i] & 0x7F) != (buffer[i] & 0x7F)) _mask |= (1ul << i);
121+
if (_disp->buffer[_from + i] != buffer[i]) _mask |= (1ul << i);
116122
}
117123
}
118124
}
@@ -124,9 +130,9 @@ class SegAnimationExt : public SegBuffer {
124130
uint8_t* buffer = nullptr;
125131

126132
private:
127-
uint8_t _size;
128133
SegBuffer* _disp;
129134
uint8_t _from;
135+
uint8_t _size;
130136

131137
uint16_t _tmr = 0, _prd = 100;
132138
SegEffect _eff = SegEffect::None;
@@ -137,7 +143,7 @@ class SegAnimationExt : public SegBuffer {
137143

138144
bool _differ() {
139145
for (uint8_t i = 0; i < _size; i++) {
140-
if ((_disp->buffer[_from + i] & 0x7F) != (buffer[i] & 0x7F)) return 1;
146+
if (_disp->buffer[_from + i] != buffer[i]) return 1;
141147
}
142148
return 0;
143149
// return memcmp(_disp->buffer + _from, buffer, _size);
@@ -201,4 +207,4 @@ class SegAnimationExt : public SegBuffer {
201207
_bitcpy(dst, 6, src, 3);
202208
}
203209
}
204-
};
210+
};

‎src/core/utils/SegDuty.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,5 @@ class SegDuty {
7575
private:
7676
// _top == 0 - макс яркость
7777
uint8_t _count = 0, _top = 0;
78-
uint16_t _tmr;
79-
};
78+
uint16_t _tmr = 0;
79+
};

‎src/core/utils/SegRunner.h‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class SegRunner {
1313
public:
1414
SegRunner(SegBuffer* disp) : _disp(disp) {
1515
_x0 = 0;
16-
_x1 = _disp->getSize() - 1;
16+
_x1 = _disp->getSize() ? (_disp->getSize() - 1) : 0;
1717
}
1818

1919
// установить текст const char*
@@ -37,8 +37,10 @@ class SegRunner {
3737

3838
// установить окно вывода (x0, x1)
3939
void setWindow(uint8_t x0, uint8_t x1) {
40-
_x0 = min(x0, _disp->getSize());
41-
_x1 = min(x1, _disp->getSize());
40+
if (!_disp->getSize()) return;
41+
uint8_t last = _disp->getSize() - 1;
42+
_x0 = min(x0, last);
43+
_x1 = min(x1, last);
4244
if (_x0 > _x1) {
4345
uint8_t b = _x0;
4446
_x0 = _x1;
@@ -102,7 +104,7 @@ class SegRunner {
102104

103105
// сдвинуть строку на 1 символ. Можно передать false, чтобы дисплей не обновлялся сам
104106
uint8_t tickManual(bool update = true) {
105-
if (!_str) return 0;
107+
if (!_str || !_disp->getSize()) return 0;
106108
memset(_disp->buffer + _x0, 0, _x1 - _x0 + 1);
107109

108110
int16_t cpos = 0;
@@ -149,4 +151,4 @@ class SegRunner {
149151
bool _pgm;
150152
uint16_t _tmr = 0, _prd = 400;
151153
bool _state = 0;
152-
};
154+
};

‎src/core/utils/SegUtils.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ uint8_t intLen(int32_t val) {
101101
return intLen(uint32_t(val < 0 ? -val : val)) + (val < 0);
102102
}
103103

104-
uint8_t floatLen(float val, uint8_t dec) {
104+
uint8_t floatLen(double val, uint8_t dec) {
105105
return (val < 0) + intLen(uint32_t(val < 0 ? -val : val)) + (dec ? dec + 1 : 0);
106106
}
107107

108-
} // namespace sseg
108+
} // namespace sseg

0 commit comments

Comments
 (0)