esp32displaytest/include/demos.cpp
2022-03-12 12:33:52 +01:00

253 lines
9.1 KiB
C++

float p = 3.1415926;
typedef struct {
uint8_t width;
uint8_t height;
const uint8_t *data;
} bitmap_t;
/*const uint8_t PROGMEM dvdlogo_data[] = {
B00001111, B11111111, B11111100, B00000011, B11111111, B11000000,
B00001111, B11111111, B11111100, B00000011, B11111111, B11111000,
B00000000, B00111111, B11111100, B00000111, B11100001, B11111110,
B00000000, B00000111, B11011110, B00001111, B00000000, B00111110,
B00011110, B00000011, B11011110, B00011110, B01111000, B00011111,
B00011110, B00000011, B11011110, B00111100, B01111000, B00011111,
B00011110, B00000011, B11001111, B00111100, B11111000, B00011110,
B00011110, B00000111, B11001111, B01111000, B11110000, B00011110,
B00111110, B00001111, B10000111, B11110000, B11110000, B00111100,
B00111110, B00111111, B00000111, B11100000, B11110000, B11111000,
B00111111, B11111100, B00000111, B11000000, B11111111, B11110000,
B00111111, B11110000, B00000011, B10000001, B11111111, B10000000,
B00000000, B00000000, B00000011, B10000000, B00000000, B00000000,
B00000000, B00000000, B00000011, B00000000, B00000000, B00000000,
B00000000, B00000000, B00000000, B00000000, B00000000, B00000000,
B00000000, B00000000, B00000000, B00000000, B00000000, B00000000,
B00000001, B11111111, B11111111, B11111111, B11111100, B00000000,
B00111111, B11111111, B11100000, B01111111, B11111111, B11100000,
B11111111, B11111111, B10000000, B00011111, B11111111, B11111000,
B01111111, B11111111, B10000000, B00111111, B11111111, B11110000,
B00000111, B11111111, B11111111, B11111111, B11111111, B00000000,
B00000000, B00000011, B11111111, B11111110, B00000000, B00000000 };*/
/* DVD logo */
static PROGMEM bitmap_t dvdlogo = {
.width = 48,
.height = 22,
.data = (PROGMEM uint8_t[]) {
B00001111, B11111111, B11111100, B00000011, B11111111, B11000000,
B00001111, B11111111, B11111100, B00000011, B11111111, B11111000,
B00000000, B00111111, B11111100, B00000111, B11100001, B11111110,
B00000000, B00000111, B11011110, B00001111, B00000000, B00111110,
B00011110, B00000011, B11011110, B00011110, B01111000, B00011111,
B00011110, B00000011, B11011110, B00111100, B01111000, B00011111,
B00011110, B00000011, B11001111, B00111100, B11111000, B00011110,
B00011110, B00000111, B11001111, B01111000, B11110000, B00011110,
B00111110, B00001111, B10000111, B11110000, B11110000, B00111100,
B00111110, B00111111, B00000111, B11100000, B11110000, B11111000,
B00111111, B11111100, B00000111, B11000000, B11111111, B11110000,
B00111111, B11110000, B00000011, B10000001, B11111111, B10000000,
B00000000, B00000000, B00000011, B10000000, B00000000, B00000000,
B00000000, B00000000, B00000011, B00000000, B00000000, B00000000,
B00000000, B00000000, B00000000, B00000000, B00000000, B00000000,
B00000000, B00000000, B00000000, B00000000, B00000000, B00000000,
B00000001, B11111111, B11111111, B11111111, B11111100, B00000000,
B00111111, B11111111, B11100000, B01111111, B11111111, B11100000,
B11111111, B11111111, B10000000, B00011111, B11111111, B11111000,
B01111111, B11111111, B10000000, B00111111, B11111111, B11110000,
B00000111, B11111111, B11111111, B11111111, B11111111, B00000000,
B00000000, B00000011, B11111111, B11111110, B00000000, B00000000
}
};
void testlines(uint16_t color) {
screen.fillScreen(BLACK);
for (uint16_t x = 0; x < screen.width() - 1; x += 6) {
screen.drawLine(0, 0, x, screen.height() - 1, color);
}
for (uint16_t y = 0; y < screen.height() - 1; y += 6) {
screen.drawLine(0, 0, screen.width() - 1, y, color);
}
screen.fillScreen(BLACK);
for (uint16_t x = 0; x < screen.width() - 1; x += 6) {
screen.drawLine(screen.width() - 1, 0, x, screen.height() - 1, color);
}
for (uint16_t y = 0; y < screen.height() - 1; y += 6) {
screen.drawLine(screen.width() - 1, 0, 0, y, color);
}
screen.fillScreen(BLACK);
for (uint16_t x = 0; x < screen.width() - 1; x += 6) {
screen.drawLine(0, screen.height() - 1, x, 0, color);
}
for (uint16_t y = 0; y < screen.height() - 1; y += 6) {
screen.drawLine(0, screen.height() - 1, screen.width() - 1, y, color);
}
screen.fillScreen(BLACK);
for (uint16_t x = 0; x < screen.width() - 1; x += 6) {
screen.drawLine(screen.width() - 1, screen.height() - 1, x, 0, color);
}
for (uint16_t y = 0; y < screen.height() - 1; y += 6) {
screen.drawLine(screen.width() - 1, screen.height() - 1, 0, y, color);
}
}
void testdrawtext(const char *text, uint16_t color) {
screen.setCursor(0, 0);
screen.setTextColor(color);
screen.print(text);
}
void testfastlines(uint16_t color1, uint16_t color2) {
screen.fillScreen(BLACK);
for (uint16_t y = 0; y < screen.height() - 1; y += 5) {
screen.drawFastHLine(0, y, screen.width() - 1, color1);
}
for (uint16_t x = 0; x < screen.width() - 1; x += 5) {
screen.drawFastVLine(x, 0, screen.height() - 1, color2);
}
}
void testdrawrects(uint16_t color) {
screen.fillScreen(BLACK);
for (uint16_t x = 0; x < screen.height() - 1; x += 6) {
screen.drawRect((screen.width() - 1) / 2 - x / 2, (screen.height() - 1) / 2 - x / 2, x, x, color);
}
}
void testfillrects(uint16_t color1, uint16_t color2) {
screen.fillScreen(BLACK);
for (uint16_t x = screen.height() - 1; x > 6; x -= 6) {
screen.fillRect((screen.width() - 1) / 2 - x / 2, (screen.height() - 1) / 2 - x / 2, x, x, color1);
screen.drawRect((screen.width() - 1) / 2 - x / 2, (screen.height() - 1) / 2 - x / 2, x, x, color2);
}
}
void testfillcircles(uint8_t radius, uint16_t color) {
for (uint8_t x = radius; x < screen.width() - 1; x += radius * 2) {
for (uint8_t y = radius; y < screen.height() - 1; y += radius * 2) {
screen.fillCircle(x, y, radius, color);
}
}
}
void testdrawcircles(uint8_t radius, uint16_t color) {
for (uint8_t x = 0; x < screen.width() - 1 + radius; x += radius * 2) {
for (uint8_t y = 0; y < screen.height() - 1 + radius; y += radius * 2) {
screen.drawCircle(x, y, radius, color);
}
}
}
void testtriangles() {
screen.fillScreen(BLACK);
int color = 0xF800;
int t;
int w = screen.width() / 2;
int x = screen.height();
int y = 0;
int z = screen.width();
for (t = 0; t <= 15; t += 1) {
screen.drawTriangle(w, y, y, x, z, x, color);
x -= 4;
y += 4;
z -= 4;
color += 100;
}
}
void testroundrects() {
screen.fillScreen(BLACK);
int color = 100;
int x = 0;
int y = 0;
int w = screen.width();
int h = screen.height();
for (int i = 0; i <= 24; i++) {
screen.drawRoundRect(x, y, w, h, 5, color);
x += 2;
y += 3;
w -= 4;
h -= 6;
color += 1100;
Serial.println(i);
}
}
void oledPrintTest() {
screen.fillScreen(BLACK);
screen.setCursor(0, 5);
screen.setTextColor(RED);
screen.setTextSize(1);
screen.println("Hello World!");
screen.setTextColor(YELLOW);
screen.setTextSize(2);
screen.println("Hello World!");
screen.setTextColor(BLUE);
screen.setTextSize(3);
screen.print(1234.567);
delay(1500);
screen.setCursor(0, 5);
screen.fillScreen(BLACK);
screen.setTextColor(WHITE);
screen.setTextSize(0);
screen.println("Hello World!");
screen.setTextSize(1);
screen.setTextColor(GREEN);
screen.print(p, 6);
screen.println(" Want pi?");
screen.println(" ");
screen.print(8675309, HEX); // print 8,675,309 out in HEX!
screen.println(" Print HEX!");
screen.println(" ");
screen.setTextColor(WHITE);
screen.println("Sketch has been");
screen.println("running for: ");
screen.setTextColor(MAGENTA);
screen.print(millis() / 1000);
screen.setTextColor(WHITE);
screen.print(" seconds.");
}
void mediabuttons() {
// play
screen.fillScreen(BLACK);
screen.fillRoundRect(25, 10, 78, 60, 8, WHITE);
screen.fillTriangle(42, 20, 42, 60, 90, 40, RED);
delay(500);
// pause
screen.fillRoundRect(25, 90, 78, 60, 8, WHITE);
screen.fillRoundRect(39, 98, 20, 45, 5, GREEN);
screen.fillRoundRect(69, 98, 20, 45, 5, GREEN);
delay(500);
// play color
screen.fillTriangle(42, 20, 42, 60, 90, 40, BLUE);
delay(50);
// pause color
screen.fillRoundRect(39, 98, 20, 45, 5, RED);
screen.fillRoundRect(69, 98, 20, 45, 5, RED);
// play color
screen.fillTriangle(42, 20, 42, 60, 90, 40, GREEN);
}
/**************************************************************************/
/*!
@brief Renders a simple test pattern on the screen
*/
/**************************************************************************/
void lcdTestPattern(void) {
static const uint16_t PROGMEM colors[] =
{RED, YELLOW, GREEN, CYAN, BLUE, MAGENTA, BLACK, WHITE};
for (uint8_t c = 0; c < 8; c++) {
screen.fillRect(0, screen.height() * c / 8, screen.width(), screen.height() / 8,
pgm_read_word(&colors[c]));
}
}