File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11name =LEDMatrixDriver
2- version =0.1.1
2+ version =0.1.2
33author =Bartosz Bielawski
44maintainer =Bartosz Bielawski, bartosz.bielawski@gmail.com
55sentence =A replacement for Arduino' s LedControl library for MAX7219
Original file line number Diff line number Diff line change @@ -42,20 +42,27 @@ LEDMatrixDriver::~LEDMatrixDriver()
4242
4343void 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
6168void 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+
163183void LEDMatrixDriver::display ()
164184{
165185 for (uint8_t y = 0 ; y < 8 ; y++)
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments