Added Software
This commit is contained in:
@ -0,0 +1,113 @@
|
||||
/***
|
||||
This example is intended to demonstrate the use of getPixel() versus
|
||||
getRawPixel() and the fast horizontal and vertical drawing routines
|
||||
in the GFXcanvas family of classes,
|
||||
|
||||
When using the GFXcanvas* classes as the image buffer for a hardware driver,
|
||||
there is a need to get individual pixel color values at given physical
|
||||
coordinates. Rather than subclasses or client classes call getBuffer() and
|
||||
reinterpret the byte layout of the buffer, two methods are added to each of the
|
||||
GFXcanvas* classes that allow fetching of specific pixel values.
|
||||
|
||||
* getPixel(x, y) : Gets the pixel color value at the rotated coordinates in
|
||||
the image.
|
||||
* getRawPixel(x,y) : Gets the pixel color value at the unrotated coordinates
|
||||
in the image. This is useful for getting the pixel value to map to a hardware
|
||||
pixel location. This method was made protected as only the hardware driver
|
||||
should be accessing it.
|
||||
|
||||
The GFXcanvas*SerialDemo classes in this example will print to Serial the
|
||||
contents of the underlying GFXcanvas buffer in both the current rotated layout
|
||||
and the underlying physical layout.
|
||||
***/
|
||||
|
||||
#include "GFXcanvasSerialDemo.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
// first create a rectangular GFXcanvas8SerialDemo object and draw to it
|
||||
GFXcanvas8SerialDemo demo8(21, 11);
|
||||
|
||||
demo8.fillScreen(0x00);
|
||||
demo8.setRotation(1); // now canvas is 11x21
|
||||
demo8.fillCircle(5, 10, 5, 0xAA);
|
||||
demo8.writeFastHLine(0, 0, 11, 0x11);
|
||||
demo8.writeFastHLine(10, 10, -11, 0x22);
|
||||
demo8.writeFastHLine(0, 20, 11, 0x33);
|
||||
demo8.writeFastVLine(0, 0, 21, 0x44);
|
||||
demo8.writeFastVLine(10, 20, -21, 0x55);
|
||||
|
||||
Serial.println("Demonstrating GFXcanvas rotated and raw pixels.\n");
|
||||
|
||||
// print it out rotated
|
||||
|
||||
Serial.println("The canvas's content in the rotation of '0':\n");
|
||||
demo8.setRotation(0);
|
||||
demo8.print(true);
|
||||
Serial.println("\n");
|
||||
|
||||
Serial.println("The canvas's content in the rotation of '1' (which is what "
|
||||
"it was drawn in):\n");
|
||||
demo8.setRotation(1);
|
||||
demo8.print(true);
|
||||
Serial.println("\n");
|
||||
|
||||
Serial.println("The canvas's content in the rotation of '2':\n");
|
||||
demo8.setRotation(2);
|
||||
demo8.print(true);
|
||||
Serial.println("\n");
|
||||
|
||||
Serial.println("The canvas's content in the rotation of '3':\n");
|
||||
demo8.setRotation(3);
|
||||
demo8.print(true);
|
||||
Serial.println("\n");
|
||||
|
||||
// print it out unrotated
|
||||
Serial.println("The canvas's content in it's raw, physical layout:\n");
|
||||
demo8.print(false);
|
||||
Serial.println("\n");
|
||||
|
||||
// Demonstrate GFXcanvas1SerialDemo
|
||||
|
||||
GFXcanvas1SerialDemo demo1(21, 11);
|
||||
demo1.fillScreen(0);
|
||||
demo1.setRotation(0);
|
||||
demo1.writeFastHLine(0, 0, 9, 1);
|
||||
demo1.setRotation(1);
|
||||
demo1.writeFastHLine(0, 0, 9, 1);
|
||||
demo1.setRotation(2);
|
||||
demo1.writeFastHLine(0, 0, 9, 1);
|
||||
demo1.setRotation(3);
|
||||
demo1.writeFastHLine(0, 0, 9, 1);
|
||||
demo1.setRotation(1);
|
||||
demo1.fillRect(3, 8, 5, 5, 1);
|
||||
|
||||
Serial.println("\nThe GFXcanvas1 raw content after drawing a fast horizontal "
|
||||
"line in each rotation:\n");
|
||||
demo1.print(false);
|
||||
Serial.println("\n");
|
||||
|
||||
// Demonstrate GFXcanvas16SerialDemo
|
||||
|
||||
GFXcanvas16SerialDemo demo16(21, 11);
|
||||
demo16.fillScreen(0);
|
||||
demo16.setRotation(0);
|
||||
demo16.writeFastHLine(0, 0, 9, 0x1111);
|
||||
demo16.setRotation(1);
|
||||
demo16.writeFastHLine(0, 0, 9, 0x2222);
|
||||
demo16.setRotation(2);
|
||||
demo16.writeFastHLine(0, 0, 9, 0x3333);
|
||||
demo16.setRotation(3);
|
||||
demo16.writeFastHLine(0, 0, 9, 0x4444);
|
||||
demo16.setRotation(1);
|
||||
demo16.fillRect(3, 8, 5, 5, 0x8888);
|
||||
|
||||
Serial.println("\nThe GFXcanvas16 raw content after drawing a fast "
|
||||
"horizontal line in each rotation:\n");
|
||||
demo16.print(false);
|
||||
Serial.println("\n");
|
||||
}
|
||||
|
||||
void loop() {}
|
@ -0,0 +1,92 @@
|
||||
#include "GFXcanvasSerialDemo.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
GFXcanvas1SerialDemo::GFXcanvas1SerialDemo(uint16_t w, uint16_t h)
|
||||
: GFXcanvas1(w, h) {}
|
||||
|
||||
void GFXcanvas1SerialDemo::print(bool rotated) {
|
||||
char pixel_buffer[8];
|
||||
uint16_t width, height;
|
||||
|
||||
if (rotated) {
|
||||
width = this->width();
|
||||
height = this->height();
|
||||
} else {
|
||||
width = this->WIDTH;
|
||||
height = this->HEIGHT;
|
||||
}
|
||||
|
||||
for (uint16_t y = 0; y < height; y++) {
|
||||
for (uint16_t x = 0; x < width; x++) {
|
||||
bool pixel;
|
||||
if (rotated) {
|
||||
pixel = this->getPixel(x, y);
|
||||
} else {
|
||||
pixel = this->getRawPixel(x, y);
|
||||
}
|
||||
sprintf(pixel_buffer, " %d", pixel);
|
||||
Serial.print(pixel_buffer);
|
||||
}
|
||||
Serial.print("\n");
|
||||
}
|
||||
}
|
||||
|
||||
GFXcanvas8SerialDemo::GFXcanvas8SerialDemo(uint16_t w, uint16_t h)
|
||||
: GFXcanvas8(w, h) {}
|
||||
|
||||
void GFXcanvas8SerialDemo::print(bool rotated) {
|
||||
char pixel_buffer[8];
|
||||
uint16_t width, height;
|
||||
|
||||
if (rotated) {
|
||||
width = this->width();
|
||||
height = this->height();
|
||||
} else {
|
||||
width = this->WIDTH;
|
||||
height = this->HEIGHT;
|
||||
}
|
||||
|
||||
for (uint16_t y = 0; y < height; y++) {
|
||||
for (uint16_t x = 0; x < width; x++) {
|
||||
uint8_t pixel;
|
||||
if (rotated) {
|
||||
pixel = this->getPixel(x, y);
|
||||
} else {
|
||||
pixel = this->getRawPixel(x, y);
|
||||
}
|
||||
sprintf(pixel_buffer, " %02x", pixel);
|
||||
Serial.print(pixel_buffer);
|
||||
}
|
||||
Serial.print("\n");
|
||||
}
|
||||
}
|
||||
|
||||
GFXcanvas16SerialDemo::GFXcanvas16SerialDemo(uint16_t w, uint16_t h)
|
||||
: GFXcanvas16(w, h) {}
|
||||
|
||||
void GFXcanvas16SerialDemo::print(bool rotated) {
|
||||
char pixel_buffer[8];
|
||||
uint16_t width, height;
|
||||
|
||||
if (rotated) {
|
||||
width = this->width();
|
||||
height = this->height();
|
||||
} else {
|
||||
width = this->WIDTH;
|
||||
height = this->HEIGHT;
|
||||
}
|
||||
|
||||
for (uint16_t y = 0; y < height; y++) {
|
||||
for (uint16_t x = 0; x < width; x++) {
|
||||
uint16_t pixel;
|
||||
if (rotated) {
|
||||
pixel = this->getPixel(x, y);
|
||||
} else {
|
||||
pixel = this->getRawPixel(x, y);
|
||||
}
|
||||
sprintf(pixel_buffer, " %04x", pixel);
|
||||
Serial.print(pixel_buffer);
|
||||
}
|
||||
Serial.print("\n");
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
#ifndef __GFXcanvasSerialDemo__
|
||||
#define __GFXcanvasSerialDemo__
|
||||
#include <Adafruit_GFX.h>
|
||||
|
||||
/**********************************************************************/
|
||||
/*!
|
||||
@brief Demonstrates using the GFXconvas classes as the backing store
|
||||
for a device driver.
|
||||
*/
|
||||
/**********************************************************************/
|
||||
class GFXcanvas1SerialDemo : public GFXcanvas1 {
|
||||
public:
|
||||
GFXcanvas1SerialDemo(uint16_t w, uint16_t h);
|
||||
|
||||
/**********************************************************************/
|
||||
/*!
|
||||
@brief Prints the current contents of the canvas to Serial
|
||||
@param rotated true to print according to the current GFX rotation,
|
||||
false to print to the native rotation of the canvas (or unrotated).
|
||||
*/
|
||||
/**********************************************************************/
|
||||
void print(bool rotated);
|
||||
};
|
||||
|
||||
/**********************************************************************/
|
||||
/*!
|
||||
@brief Demonstrates using the GFXconvas classes as the backing store
|
||||
for a device driver.
|
||||
*/
|
||||
/**********************************************************************/
|
||||
class GFXcanvas8SerialDemo : public GFXcanvas8 {
|
||||
public:
|
||||
GFXcanvas8SerialDemo(uint16_t w, uint16_t h);
|
||||
|
||||
/**********************************************************************/
|
||||
/*!
|
||||
@brief Prints the current contents of the canvas to Serial
|
||||
@param rotated true to print according to the current GFX rotation,
|
||||
false to print to the native rotation of the canvas (or unrotated).
|
||||
*/
|
||||
/**********************************************************************/
|
||||
void print(bool rotated);
|
||||
};
|
||||
|
||||
/**********************************************************************/
|
||||
/*!
|
||||
@brief Demonstrates using the GFXconvas classes as the backing store
|
||||
for a device driver.
|
||||
*/
|
||||
/**********************************************************************/
|
||||
class GFXcanvas16SerialDemo : public GFXcanvas16 {
|
||||
public:
|
||||
GFXcanvas16SerialDemo(uint16_t w, uint16_t h);
|
||||
|
||||
/**********************************************************************/
|
||||
/*!
|
||||
@brief Prints the current contents of the canvas to Serial
|
||||
@param rotated true to print according to the current GFX rotation,
|
||||
false to print to the native rotation of the canvas (or unrotated).
|
||||
*/
|
||||
/**********************************************************************/
|
||||
void print(bool rotated);
|
||||
};
|
||||
|
||||
#endif // __GFXcanvasSerialDemo__
|
Reference in New Issue
Block a user