forked from saul-rodriguez/Qtraspberrylib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ada7seg.cpp
68 lines (55 loc) · 1.02 KB
/
ada7seg.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "ada7seg.h"
const quint8 Ada7Seg::numbertable[] = {
0x3F, /* 0 */
0x06, /* 1 */
0x5B, /* 2 */
0x4F, /* 3 */
0x66, /* 4 */
0x6D, /* 5 */
0x7D, /* 6 */
0x07, /* 7 */
0x7F, /* 8 */
0x6F, /* 9 */
0x77, /* a */
0x7C, /* b */
0x39, /* C */
0x5E, /* d */
0x79, /* E */
0x71, /* F */
};
Ada7Seg::Ada7Seg(QObject *parent) :
Ht16k33(parent)
{
}
void Ada7Seg::writeint(qint16 num)
{
quint16 res, absol;
qint16 aux[4];
qint8 sign;
int i;
for (i = 0; i<4; i++)
aux[i] = 0;
if (num < 0) {
absol = -num;
sign = 1;
} else {
absol = num;
sign = 0;
}
for (i=0;i<4;i++) {
res = absol % 10;
absol /= 10;
aux[i] = numbertable[res];
if (!absol) break;
}
if (sign && i<3) {
i++;
aux[i] = 0x40; // minus sign
}
displaybuffer[0] = aux[3];
displaybuffer[1] = aux[2];
displaybuffer[3] = aux[1];
displaybuffer[4] = aux[0];
displaybuffer[2] = 0; //semi dot (:) off
writeDisplay(4);
}