-
Notifications
You must be signed in to change notification settings - Fork 0
/
FakeLedControl.h
112 lines (92 loc) · 2.76 KB
/
FakeLedControl.h
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#pragma once
#include <vector>
#include <bitset>
#include <stdint.h>
#include <array>
#include <stdexcept>
#include <cassert>
//This class pretends to be the LcdControl class available on Arduino.
//Some methods haven't been implemented
class FakeLedControl
{
public:
FakeLedControl(uint32_t displays, uint32_t displayLen = 8):
displays(displays),
displayLen(displayLen),
displayEnabled(displays, false),
columns(displays * displayLen, 0)
{
}
void shutdown(uint32_t addr, bool disabled)
{
assert(addr < displays);
displayEnabled[addr] = !disabled;
}
int getDeviceCount() const {return displays;}
void setScanLimit(int addr, int limit)
{
throw std::runtime_error("Not implemented");
}
void setIntensity(int addr, int intensity) const
{
}
void clearDisplay(int addr)
{
assert(addr < displays);
for (int i = addr*displayLen; i <(addr+1)*displayLen; ++i)
{
columns[i] = 0;
}
}
void setLed(int addr, int row, int col, bool state)
{
assert(addr < displays);
uint32_t linearAddress = addr * displayLen + col;
uint8_t& v = columns[linearAddress];
if (state)
{
v |= 1<<col;
}
else
{
v &= ~(1<<col);
}
}
void setRow(int addr, int row, uint8_t value)
{
throw std::runtime_error("Not implemented!");
}
void setColumn(int addr, int col, uint8_t value)
{
assert(addr < displays);
uint32_t linearAddress = addr * displayLen + col;
columns[linearAddress] = value;
}
void setDigit(int addr, int digit)
{
throw std::runtime_error("Not implemented!");
}
void setChar(int addr, int digit, uint8_t value, bool dp)
{
throw std::runtime_error("Not implemented!");
}
void print()
{
for (uint8_t mask = 0x01; mask > 0; mask <<= 1)
{
for (int col = 0; col < displays * displayLen; ++col)
{
uint32_t displayAddress = col / displayLen;
uint8_t toPrint = displayEnabled[displayAddress] ? columns[col] & mask: 0;
toPrint = toPrint ? '#': ' ';
putchar(toPrint);
}
putchar('\n');
}
}
private:
uint32_t displays;
uint32_t displayLen;
std::vector<bool> displayEnabled;
std::vector<uint8_t> columns;
};