-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathLRAS1130Picture24x5.cpp
92 lines (73 loc) · 2.37 KB
/
LRAS1130Picture24x5.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//
// Lucky Resistor's AS1130 Library
// ---------------------------------------------------------------------------
// (c)2017 by Lucky Resistor. See LICENSE for details.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>
//
#include "LRAS1130.h"
#include <Arduino.h>
#ifdef ARDUINO_ARCH_AVR
// Make it compatible with the standart
#include <string.h>
namespace std { using ::memset; }
namespace std { using ::memcpy; }
#else
#include <cstring>
#endif
namespace lr {
AS1130Picture24x5::AS1130Picture24x5()
{
std::memset(_data, 0, getDataByteCount());
}
AS1130Picture24x5::AS1130Picture24x5(const uint8_t *data)
{
std::memcpy(_data, data, getDataByteCount());
}
void AS1130Picture24x5::setPixel(uint8_t x, uint8_t y, bool enabled)
{
if (x < getWidth() && y < getHeight()) {
const uint8_t bitMask = getDataBit(x, y);
if (enabled) {
_data[getDataIndex(x,y)] |= bitMask;
} else {
_data[getDataIndex(x,y)] &= ~bitMask;
}
}
}
bool AS1130Picture24x5::getPixel(uint8_t x, uint8_t y)
{
if (x < getWidth() && y < getHeight()) {
const uint8_t bitMask = getDataBit(x, y);
return (_data[getDataIndex(x,y)]&bitMask)!=0;
} else {
return false;
}
}
void AS1130Picture24x5::writeRegisters(uint8_t *registerData, const uint8_t *rawData, uint8_t pwmSetIndex)
{
std::memset(registerData, 0, 0x18);
for (uint8_t x = 0; x < getWidth(); ++x) {
for (uint8_t y = 0; y < getHeight(); ++y) {
if ((rawData[getDataIndex(x, y)] & getDataBit(x,y)) != 0) {
const uint8_t ledIndex = (x*5+y);
const uint8_t registerBitIndex = ledIndex%10;
uint8_t registerIndex = (ledIndex/10)*2+(registerBitIndex/8);
registerData[registerIndex] |= (1<<(registerBitIndex&7));
}
}
}
registerData[1] |= (pwmSetIndex<<5);
}
}