-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathLRAS1130Picture24x5.h
129 lines (108 loc) · 3.65 KB
/
LRAS1130Picture24x5.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//
// 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/>
//
#pragma once
#ifdef ARDUINO_ARCH_AVR
#include <inttypes.h>
#else
#include <cinttypes>
#endif
namespace lr {
/// @brief One single bitmap in 24x5 layout for manual modification or storage.
///
class AS1130Picture24x5
{
public:
/// @brief Create a empty bitmap.
///
AS1130Picture24x5();
/// @brief Create a bitmap using an existing bitmask.
///
/// The bits from the data are copied to the local structure.
/// All bits in this bitmask has to be in high to low order.
///
/// Bits: 01234567 89ABCDEF GHIJKLMN 01234567 89ABCDEF ...
///
/// @param data A bitmask with 15 bytes.
///
AS1130Picture24x5(const uint8_t *data);
public:
/// @brief Set a pixel in this bitmap.
///
/// The coordinates are bounds checked.
///
/// @param x The X coordinate of the pixel.
/// @param y The Y coordinate of the pixel.
/// @param enabled `true` to set the pixel and `false` to clear it.
///
void setPixel(uint8_t x, uint8_t y, bool enabled);
/// @brief Get the state of a single pixel.
///
/// @param x The X coordinate of the pixel.
/// @param y The Y coordinate of the pixel.
///
bool getPixel(uint8_t x, uint8_t y);
/// @brief Get the width of this bitmap.
///
/// @return The width of the bitmap in pixels.
///
inline static uint8_t getWidth() { return 24; }
/// @brief Get the height of this bitmap.
///
/// @return The height of the bitmap in pixels.
///
inline static uint8_t getHeight() { return 5; }
/// @brief Get the number of raw byte for this bitmap.
///
/// @return The number of raw bytes used to store this bitmap.
///
inline static uint8_t getDataByteCount() { return 15; }
/// @brief Access the raw bit data.
///
/// @return A pointer to the raw bit data.
///
inline const uint8_t* getData() const { return _data; }
/// @brief Get the bitmask for a given coordinate.
///
/// @param x The X coordinate of the pixel.
/// @param y The Y coordinate of the pixel.
/// @return A bitmask with the addressed bit for the given coordinate.
///
inline static uint8_t getDataBit(uint8_t x, uint8_t y) {
return (1<<(7-(x&7)));
}
/// @brief Get the byte for a given coordinate.
///
/// @param x The X coordinate of the pixel.
/// @param y The Y coordinate of the pixel.
/// @return The index of the byte for a given coordinate.
///
inline static uint8_t getDataIndex(uint8_t x, uint8_t y) {
return (y*3)+(x/8);
}
/// @brief Write the registers for this bitmap data.
///
/// @param registerData A pointer to an array of 24 bytes for all frame registers.
/// @param rawData A pointer to the raw bit data.
/// @param pwmSetIndex The PWM index to write to the register data.
///
static void writeRegisters(uint8_t *registerData, const uint8_t *rawData, uint8_t pwmSetIndex);
private:
uint8_t _data[15]; ///< The raw bit data.
};
}