Skip to content

Commit 7f51777

Browse files
Updated to use GFX v1.9.0 (#13)
* transitioned pixel management to GFX lib Moved getting of raw pixel color values from something this library handles to something the underlying AdaFruit GFX library handles. Depends on this pull request in the AdaFruit GFX repository: adafruit/Adafruit-GFX-Library#237 * transitioned pixel management to GFX lib Moved getting of raw pixel color values from something this library handles to something the underlying AdaFruit GFX library handles. Depends on this pull request in the AdaFruit GFX repository: adafruit/Adafruit-GFX-Library#237 * improved monochrome exmaple * fixed CHANGELOG
1 parent 1fccb84 commit 7f51777

File tree

6 files changed

+23
-73
lines changed

6 files changed

+23
-73
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
88
### Added
99
- Specify library dependencies in library.properties
1010

11+
### Changed
12+
- Moved methods for accessing raw pixel color values to the AdaFruit GFX library. This has no net change to the user, but improves the architecture of the code. Depends on [pull request #237 in the AdaFruit GFX repository](https://github.com/adafruit/Adafruit-GFX-Library/pull/237), which was incorporated in v1.9.0 of the GFX library.
13+
1114
## [2.0.0]
1215
### Changed
1316
- Transition library to use [Adafruit's GFX Library](https://github.com/adafruit/Adafruit-GFX-Library) to handle the graphics API. The befit of this is that it immediately brings a wealth of functionality pertaining to the programatic construction of the image, especially fonts and text drawing. The Adafruit GFX library is only used for the primary image buffer. The backend operations of the driver (i.e., the secondary buffer for the shift register bits) is still the same. This is a significant change to the library, likely requiring you to change your code. In the process, dropped support for simulating gray scale on monochrome LED matrices. This might be brought back later.

examples/other/monochrome-32x16/monochrome-32x16.ino

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ LEDMatrix leds(16,32, HIGH, HIGH, 3);
1313

1414
uint16_t loopCounter;
1515
int16_t xpos = leds.columns() + 1;
16+
int16_t lineCounter = 0;
17+
int16_t lineCounterIncrement = 1;
1618
uint16_t textWidth;
1719
uint16_t textHeight;
1820
const char* str = "Hello World!";
@@ -42,8 +44,15 @@ void loop() {
4244
loopCounter++;
4345
if (loopCounter >= 2000) {
4446
loopCounter = 0;
47+
lineCounter += lineCounterIncrement;
48+
if (lineCounter == 0) {
49+
lineCounterIncrement = 1;
50+
} else if ( lineCounter == leds.rows()/2 - 1) {
51+
lineCounterIncrement = -1;
52+
}
4553
leds.startDrawing();
46-
leds.fillRect(0, leds.rows()/2, leds.columns(), leds.rows()/2, LED_BLACK);
54+
leds.fillRect(0, 0, leds.columns(), leds.rows(), LED_BLACK);
55+
leds.drawLine(0, lineCounter, leds.columns(), leds.rows()/2-1-lineCounter, LED_WHITE);
4756
xpos--;
4857
if (xpos < -((int16_t)textWidth)) {
4958
xpos = leds.columns() + 1;

src/LEDMatrix.cpp

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void LEDMatrix::setRowBitsForFrame(
7676
bool rowNeedsPower = false;
7777
size_t colBitIdx = 0;
7878
for (uint16_t col = 0; col < this->columns(); col++) {
79-
uint16_t pixel = this->rawPixel(col, row);
79+
uint16_t pixel = this->getRawPixel(col, row);
8080

8181
if (pixel > 0) {
8282
frameBits.setColumnControlBit(row,colBitIdx,true);
@@ -95,38 +95,6 @@ ICACHE_RAM_ATTR unsigned int LEDMatrix::baseIntervalMultiplier( size_t frame ) c
9595

9696
#pragma mark - Adafruit GFX Support
9797

98-
uint16_t LEDMatrix::rawPixel( int16_t x, int16_t y ) const {
99-
if((x < 0) || (y < 0) || (x >= _width) || (y >= _height)) return 0;
100-
if(this->getBuffer()) {
101-
uint8_t *buffer = this->getBuffer();
102-
uint8_t *ptr = &buffer[(x / 8) + y * ((WIDTH + 7) / 8)];
103-
104-
return ((*ptr) & (0x80 >> (x & 7))) != 0;
105-
}
106-
return 0;
107-
}
108-
109-
uint16_t LEDMatrix::pixel( int16_t x, int16_t y ) const {
110-
int16_t t;
111-
switch(this->getRotation()) {
112-
case 1:
113-
t = x;
114-
x = WIDTH - 1 - y;
115-
y = t;
116-
break;
117-
case 2:
118-
x = WIDTH - 1 - x;
119-
y = HEIGHT - 1 - y;
120-
break;
121-
case 3:
122-
t = x;
123-
x = y;
124-
y = HEIGHT - 1 - t;
125-
break;
126-
}
127-
return this->rawPixel(x, y);
128-
}
129-
13098
void LEDMatrix::drawPixel(int16_t x, int16_t y, uint16_t color) {
13199
this->GFXcanvas1::drawPixel(x, y, color);
132100
_matrixNeedsUpdate = true;

src/LEDMatrix.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ class LEDMatrix : public BaseLEDMatrix, public GFXcanvas1 {
4242
virtual bool matrixNeedsUpdate(void) const;
4343
virtual void matrixHasBeenUpdated(void);
4444
virtual unsigned int baseIntervalMultiplier( size_t frame ) const;
45-
46-
uint16_t rawPixel( int16_t rawX, int16_t rawY ) const;
4745

4846
public:
4947

@@ -92,8 +90,6 @@ class LEDMatrix : public BaseLEDMatrix, public GFXcanvas1 {
9290
//
9391
// Adafruit GFX Support
9492
//
95-
96-
uint16_t pixel( int16_t x, int16_t y ) const;
9793
virtual void drawPixel(int16_t x, int16_t y, uint16_t color);
9894
virtual void fillScreen(uint16_t color);
9995
};

src/RGBLEDMatrix.cpp

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ bool RGBLEDMatrix::setColumnBitsForControlRowAndFrame(
202202
endianCol = this->columns() - (colByte+1)*8 + colBit;
203203
}
204204

205-
RGBColorType rgbValue = this->rawPixel(endianCol, imageRow);
205+
RGBColorType rgbValue = this->getRawPixel(endianCol, imageRow);
206206
// a form of Binary Code Modulation is used to control
207207
// the LED intensity at variou levels.
208208

@@ -239,35 +239,6 @@ unsigned int RGBLEDMatrix::baseIntervalMultiplier( size_t frame ) const {
239239

240240
#pragma mark - Adafruit GFX Support
241241

242-
uint16_t RGBLEDMatrix::rawPixel( int16_t x, int16_t y ) const {
243-
if((x < 0) || (y < 0) || (x >= _width) || (y >= _height)) return 0;
244-
if(this->getBuffer()) {
245-
return this->getBuffer()[x + y * this->WIDTH];
246-
}
247-
return 0;
248-
}
249-
250-
uint16_t RGBLEDMatrix::pixel( int16_t x, int16_t y ) const {
251-
int16_t t;
252-
switch(this->getRotation()) {
253-
case 1:
254-
t = x;
255-
x = WIDTH - 1 - y;
256-
y = t;
257-
break;
258-
case 2:
259-
x = WIDTH - 1 - x;
260-
y = HEIGHT - 1 - y;
261-
break;
262-
case 3:
263-
t = x;
264-
x = y;
265-
y = HEIGHT - 1 - t;
266-
break;
267-
}
268-
return this->rawPixel(x, y);
269-
}
270-
271242
void RGBLEDMatrix::drawPixel(int16_t x, int16_t y, uint16_t color) {
272243
this->GFXcanvas16::drawPixel(x, y, color);
273244
_matrixNeedsUpdate = true;
@@ -287,7 +258,7 @@ void RGBLEDMatrix::debugPrintImageData(void) const {
287258
Serial.print(" ");
288259
for (uint16_t x = 0; x < this->WIDTH; x++) {
289260
Serial.print("0x");
290-
sprintf(c, "%04x", this->rawPixel(x,y));
261+
sprintf(c, "%04x", this->getRawPixel(x,y));
291262
Serial.print(c);
292263
Serial.print(" ");
293264
}

src/RGBLEDMatrix.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ class RGBLEDMatrix : public BaseLEDMatrix, public GFXcanvas16 {
8484
virtual void matrixHasBeenUpdated(void);
8585
virtual unsigned int baseIntervalMultiplier( size_t frame ) const;
8686

87-
uint16_t rawPixel( int16_t rawX, int16_t rawY ) const;
88-
8987
public:
9088

9189
/**
@@ -130,11 +128,16 @@ class RGBLEDMatrix : public BaseLEDMatrix, public GFXcanvas16 {
130128
virtual ~RGBLEDMatrix();
131129

132130
virtual void setup();
133-
134-
uint16_t pixel( int16_t x, int16_t y ) const;
131+
132+
//
133+
// Adafruit GFX Support
134+
//
135135
virtual void drawPixel(int16_t x, int16_t y, uint16_t color);
136136
virtual void fillScreen(uint16_t color);
137137

138+
//
139+
// debug
140+
//
138141
void debugPrintImageData(void) const;
139142
};
140143

0 commit comments

Comments
 (0)