Skip to content

Commit bf0637b

Browse files
Added getPixel() method;
1 parent f1be49c commit bf0637b

3 files changed

Lines changed: 31 additions & 9 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=LEDMatrixDriver
2-
version=0.1.1
2+
version=0.1.2
33
author=Bartosz Bielawski
44
maintainer=Bartosz Bielawski, bartosz.bielawski@gmail.com
55
sentence=A replacement for Arduino's LedControl library for MAX7219

src/LEDMatrixDriver.cpp

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,27 @@ LEDMatrixDriver::~LEDMatrixDriver()
4242

4343
void LEDMatrixDriver::setPixel(uint16_t x, uint16_t y, bool enabled)
4444
{
45-
if (y >= 8)
46-
return;
47-
if (x >= (8*N))
45+
uint8_t* p = _getBufferPtr(x,y);
46+
if (!p)
4847
return;
4948

50-
uint16_t B = x >> 3; //byte
5149
uint16_t b = 7 - (x & 7); //bit
5250

53-
uint8_t& v = frameBuffer[y*N + B];
54-
5551
if (enabled)
56-
v |= (1<<b);
52+
*p |= (1<<b);
5753
else
58-
v &= ~(1<<b);
54+
*p &= ~(1<<b);
55+
}
56+
57+
bool LEDMatrixDriver::getPixel(uint16_t x, uint16_t y) const
58+
{
59+
uint8_t* p = _getBufferPtr(x,y);
60+
if (!p)
61+
return false;
62+
63+
uint16_t b = 7 - (x & 7); //bit
64+
65+
return *p & (1 << b);
5966
}
6067

6168
void LEDMatrixDriver::setColumn(uint16_t x, uint8_t value)
@@ -160,6 +167,19 @@ void LEDMatrixDriver::_displayRow(uint8_t row)
160167
SPI.endTransaction();
161168
}
162169

170+
uint8_t* LEDMatrixDriver::_getBufferPtr(uint16_t x, uint16_t y) const
171+
{
172+
if (y >= 8)
173+
return nullptr;
174+
if (x >= (8*N))
175+
return nullptr;
176+
177+
uint16_t B = x >> 3; //byte
178+
uint16_t b = 7 - (x & 7); //bit
179+
180+
return frameBuffer + y*N + B;
181+
}
182+
163183
void LEDMatrixDriver::display()
164184
{
165185
for (uint8_t y = 0; y < 8; y++)

src/LEDMatrixDriver.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class LEDMatrixDriver
4646
void setEnabled(bool enabled);
4747
void setIntensity(uint8_t level);
4848
void setPixel(uint16_t x, uint16_t y, bool enabled);
49+
bool getPixel(uint16_t x, uint16_t y) const;
4950
void setColumn(uint16_t x, uint8_t value);
5051
uint8_t getSegments() const {return N;}
5152
uint8_t* getFrameBuffer() const {return frameBuffer;}
@@ -82,6 +83,7 @@ class LEDMatrixDriver
8283
const static uint8_t BCD_BLANK = 0x0F;
8384

8485
private:
86+
uint8_t* _getBufferPtr(uint16_t x, uint16_t y) const;
8587
void _sendCommand(uint16_t command);
8688
void _displayRow(uint8_t row);
8789

0 commit comments

Comments
 (0)