Initial commit
This commit is contained in:
commit
64a227437d
1920 files changed
+3428556
No files matched your search
+290
@@ -0,0 +1,290 @@
|
||||
#define LGFX_AUTODETECT
|
||||
#include <LovyanGFX.hpp>
|
||||
|
||||
LGFX tft;
|
||||
|
||||
/*\
|
||||
*
|
||||
* ⚠️ Some of those features use a lot of maths, don't expect FTL performances :-)
|
||||
*
|
||||
* Features:
|
||||
*
|
||||
* - Antialiased thick lines, filled with plain color or gradient
|
||||
* - Antialiased circles, filled with plain color or gradient
|
||||
* - Rectangular fill with linear or radial gradient
|
||||
*
|
||||
* LGFX Methods:
|
||||
*
|
||||
* NOTE: COLOR can be any of uint8_t, uint16_t, uint32_t, RGBColor, rgb888_t, rgb565_t, rgb888_t, etc
|
||||
*
|
||||
* - Draw thick+smooth lines:
|
||||
* void drawWideLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, float thick, COLOR color)
|
||||
*
|
||||
* - Draw thick+smooth lines (gradient fill):
|
||||
* void drawWideLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, float thick, const colors_t gradient)
|
||||
*
|
||||
* - Draw wedge line:
|
||||
* void drawWedgeLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, float thick0, float thick1, COLOR color)
|
||||
*
|
||||
* - Draw wedge line (gradient fill):
|
||||
* void drawWedgeLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, float thick0, float thick1, const colors_t gradient)
|
||||
*
|
||||
* - Fill smooth circle with single color (redundant with fillSmoothCircle(), kept for benchmark):
|
||||
* void drawSpot(int32_t x, int32_t y, float radius, COLOR fg_color)
|
||||
*
|
||||
* - Fill smooth circle, like fillSmoothCircle() but with gradient fill:
|
||||
* void drawGradientSpot(int32_t x, int32_t y, float radius, const colors_t gradient)
|
||||
*
|
||||
* - Draw antialiased line:
|
||||
* void drawSmoothLine( LovyanGFX* gfx, int32_t x0, int32_t y0, int32_t x1, int32_t y1, COLOR color )
|
||||
*
|
||||
* - Draw gradient line (not smoothed, used for filling):
|
||||
* void drawGradientLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, const colors_t gradient )
|
||||
* void drawGradientHLine(int32_t x, int32_t y, uint32_t w, const colors_t gradient )
|
||||
* void drawGradientVLine(int32_t x, int32_t y, uint32_t h, const colors_t gradient )
|
||||
*
|
||||
* - Fill rect with radial/linear gradient (fill_style_t can be any of RADIAL, HLINEAR or VLINEAR):
|
||||
* void fillGradientRect(int32_t x, int32_t y, uint32_t w, uint32_t h, COLOR start, COLOR end, fill_style_t style=RADIAL )
|
||||
* void fillGradientRect(int32_t x, int32_t y, uint32_t w, uint32_t h, const colors_t gradient, fill_style_t style=RADIAL )
|
||||
*
|
||||
* - Create a gradient item from a sized array of colors or from a pointer to an array of colors:
|
||||
* colors_t createGradient( rgb888_t[] colors )
|
||||
* colors_t createGradient( rgb888_t* colors, uint32_t count )
|
||||
*
|
||||
* - Example:
|
||||
* lgfx::rgb888_t colors[] = { {0x00,0xff,0x00}, {0xff,0xff,0x00}, {0xff,0x80,0x00}, {0xff,0x00,0x00} };
|
||||
* auto gradient = tft.createGradient( colors ); // create a gradient item
|
||||
* tft.fillGradientRect( 10, 10, 200, 200, gradient, HLINEAR );
|
||||
*
|
||||
*
|
||||
\*/
|
||||
|
||||
// a couple of colors array for the gradient examples
|
||||
static constexpr const lgfx::rgb888_t heatMap[] = { {0, 0xff, 0}, {0xff, 0xff, 0}, {0xff, 0x80, 0}, {0xff, 0, 0}, {0x80, 0, 0} }; // green => yellow => orange => red => dark red
|
||||
static constexpr const lgfx::rgb888_t greyscale[] = { {0,0,0}, {0xff,0xff,0xff} }; // black => white
|
||||
// a couple of gradient examples based on colors arrays
|
||||
static constexpr const lgfx::colors_t heatMapGradient = { heatMap, sizeof(heatMap)/sizeof(lgfx::rgb888_t) };
|
||||
static constexpr const lgfx::colors_t greyScaleGradient = { greyscale, sizeof(greyscale)/sizeof(lgfx::rgb888_t) };
|
||||
// for degrees to radians conversions
|
||||
static constexpr double deg2rad = M_PI/180.0;
|
||||
|
||||
|
||||
// some constant values based on display width/height
|
||||
struct constValues_t
|
||||
{
|
||||
const uint32_t middleX = (tft.width()/2)-1;
|
||||
const uint32_t middleY = (tft.height()/2)-1;
|
||||
const uint32_t r1 = std::min(tft.width(),tft.height()) *.39;
|
||||
const uint32_t r2 = r1/5;
|
||||
const uint32_t r3 = std::min(tft.width(),tft.height()) *.45;
|
||||
const uint32_t r4 = std::min(tft.width(),tft.height()) *.37;
|
||||
const uint32_t thick1 = std::min(tft.width(),tft.height())/35;
|
||||
const uint32_t thick2 = std::min(tft.width(),tft.height())/75;
|
||||
const uint32_t thick3 = std::min(tft.width(),tft.height())/150;
|
||||
const uint32_t bw0 = std::max(tft.width(),tft.height())/4;
|
||||
const uint32_t bw1 = std::max(tft.width(),tft.height())/8;
|
||||
const uint32_t max_thickness = std::min(tft.width(),tft.height())/25;
|
||||
const lgfx::rgb888_t colors888[4] = { {0x00,0xff,0x00}, {0xff,0xff,0x00}, {0xff,0x80,0x00}, {0xff,0x00,0x00} };
|
||||
const lgfx::colors_t gradient888 = tft.createGradient( colors888 );
|
||||
};
|
||||
|
||||
|
||||
// some random values based on display width/height
|
||||
struct randomValues_t
|
||||
{
|
||||
constValues_t constValues;
|
||||
const uint32_t x0 = random()%tft.width();
|
||||
const uint32_t y0 = random()%tft.height();
|
||||
const uint32_t x1 = random()%tft.width();
|
||||
const uint32_t y1 = random()%tft.height();
|
||||
const uint32_t thickness0 = (random()%constValues.max_thickness)+2;
|
||||
const uint32_t thickness1 = (random()%constValues.max_thickness)+2;
|
||||
const RGBColor colorstart = RGBColor( uint8_t(rand() % 0xff), uint8_t(rand() % 0xff), uint8_t(rand() % 0xff) );
|
||||
const RGBColor colorend = RGBColor( uint8_t(rand() % 0xff), uint8_t(rand() % 0xff), uint8_t(rand() % 0xff) );
|
||||
const lgfx::rgb888_t color24start = rand()%0x1000000u;
|
||||
const lgfx::rgb888_t color24end = rand()%0x1000000u;
|
||||
const lgfx::rgb565_t color16start = rand()%0x10000;
|
||||
const lgfx::rgb565_t color16end = rand()%0x10000;
|
||||
const lgfx::rgb332_t color8start = rand()%256;
|
||||
const lgfx::rgb332_t color8end = rand()%256;
|
||||
const lgfx::rgb888_t colors888[2] = { color24start, color24end };
|
||||
const lgfx::colors_t gradient888 = tft.createGradient( colors888 );
|
||||
};
|
||||
|
||||
|
||||
|
||||
void drawGrid()
|
||||
{
|
||||
randomValues_t v;
|
||||
auto cv = v.constValues;
|
||||
|
||||
float theta = ( M_PI / 180.0f ) * 22.5; // angle
|
||||
float sin0 = sinf(theta);
|
||||
float cos0 = cosf(theta);
|
||||
float sin1 = sinf(M_PI-theta);
|
||||
float cos1 = cosf(M_PI-theta);
|
||||
|
||||
for( int32_t y=-tft.height()*2; y<tft.height()*2; y+=8 ) {
|
||||
int32_t x0Pos = -tft.width();
|
||||
int32_t y0Pos = tft.height()-y;
|
||||
int32_t x1Pos = tft.width();
|
||||
int32_t y1Pos = tft.height()-y;
|
||||
float x0 = (x0Pos * cos0 - y0Pos * sin0)+cv.middleX;
|
||||
float y0 = (y0Pos * cos0 + x0Pos * sin0)+cv.middleY;
|
||||
float x1 = (x1Pos * cos0 - y1Pos * sin0)+cv.middleX;
|
||||
float y1 = (y1Pos * cos0 + x1Pos * sin0)+cv.middleY;
|
||||
tft.drawWideLine( x0, y0, x1, y1, 0.5f, heatMapGradient ); // gradient antialiased
|
||||
}
|
||||
|
||||
for( int32_t x=-tft.width()*2; x<tft.width()*2; x+=8 ) {
|
||||
int32_t x0Pos = tft.width()-x;
|
||||
int32_t y0Pos = -tft.height();
|
||||
int32_t x1Pos = tft.width()-x;
|
||||
int32_t y1Pos = tft.height();
|
||||
float x0 = (x0Pos * cos0 - y0Pos * sin0)+cv.middleX;
|
||||
float y0 = (y0Pos * cos0 + x0Pos * sin0)+cv.middleY;
|
||||
float x1 = (x1Pos * cos0 - y1Pos * sin0)+cv.middleX;
|
||||
float y1 = (y1Pos * cos0 + x1Pos * sin0)+cv.middleY;
|
||||
tft.drawWideLine( x0, y0, x1, y1, 0.5f, heatMapGradient ); // gradient antialiased
|
||||
}
|
||||
|
||||
for( int32_t y=-tft.height()*2; y<tft.height()*2; y+=20 ) {
|
||||
uint32_t color = y%100==0? 0xaaaaaau : 0xccccccu;
|
||||
int32_t x0Pos = -tft.width();
|
||||
int32_t y0Pos = tft.height()-y;
|
||||
int32_t x1Pos = tft.width();
|
||||
int32_t y1Pos = tft.height()-y;
|
||||
float x0 = (x0Pos * cos1 - y0Pos * sin1)+cv.middleX;
|
||||
float y0 = (y0Pos * cos1 + x0Pos * sin1)+cv.middleY;
|
||||
float x1 = (x1Pos * cos1 - y1Pos * sin1)+cv.middleX;
|
||||
float y1 = (y1Pos * cos1 + x1Pos * sin1)+cv.middleY;
|
||||
y%100==0
|
||||
? tft.drawWideLine( x0, y0, x1, y1, 1.0f, color ) // slow but with thickness
|
||||
: tft.drawSmoothLine( x0, y0, x1, y1, color ) // just antialiased
|
||||
;
|
||||
}
|
||||
|
||||
for( int32_t x=-tft.width()*2; x<tft.width()*2; x+=20 ) {
|
||||
uint32_t color = x%100==0? 0xaaaaaau : 0xccccccu;
|
||||
int32_t x0Pos = tft.width()-x;
|
||||
int32_t y0Pos = -tft.height();
|
||||
int32_t x1Pos = tft.width()-x;
|
||||
int32_t y1Pos = tft.height();
|
||||
float x0 = (x0Pos * cos1 - y0Pos * sin1)+cv.middleX;
|
||||
float y0 = (y0Pos * cos1 + x0Pos * sin1)+cv.middleY;
|
||||
float x1 = (x1Pos * cos1 - y1Pos * sin1)+cv.middleX;
|
||||
float y1 = (y1Pos * cos1 + x1Pos * sin1)+cv.middleY;
|
||||
x%100==0
|
||||
? tft.drawWideLine( x0, y0, x1, y1, 1.0f, color ) // slow but with thickness
|
||||
: tft.drawSmoothLine( x0, y0, x1, y1, color ) // just antialiased
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void runRandomLinesDemo()
|
||||
{
|
||||
for( int i=0;i<256;i++) {
|
||||
randomValues_t v;
|
||||
switch( i++%5 ) {
|
||||
case 0: tft.drawWedgeLine( v.x0, v.y0, v.x1, v.y1, v.thickness0, v.thickness1, v.gradient888 ); break;
|
||||
case 1: tft.drawWedgeLine( v.x0, v.y0, v.x1, v.y1, v.thickness0, v.thickness1, v.colorstart ); break;
|
||||
case 2: tft.drawWedgeLine( v.x0, v.y0, v.x1, v.y1, v.thickness0, v.thickness1, v.color24start ); break;
|
||||
case 3: tft.drawWedgeLine( v.x0, v.y0, v.x1, v.y1, v.thickness0, v.thickness1, v.color16start ); break;
|
||||
case 4: tft.drawWedgeLine( v.x0, v.y0, v.x1, v.y1, v.thickness0, v.thickness1, v.color8start ); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void runGradientDemo()
|
||||
{
|
||||
|
||||
drawGrid();
|
||||
|
||||
randomValues_t v;
|
||||
auto cv = v.constValues;
|
||||
|
||||
const lgfx::rgb888_t colors888[] = { {0x00,0xff,0x00}, {0xff,0xff,0x00}, {0xff,0x80,0x00}, {0xff,0x00,0x00} };
|
||||
auto gradient888 = tft.createGradient( colors888 );
|
||||
|
||||
// horizontal linear gradient in landscape mode (top left)
|
||||
tft.fillGradientRect( cv.thick2, cv.thick2, cv.bw0, cv.bw1, heatMapGradient, lgfx::HLINEAR );
|
||||
// vertical linear gradient in portrait mode (top right)
|
||||
tft.fillGradientRect( tft.width()-(cv.bw1+cv.thick2+1), cv.thick2, cv.bw1, cv.bw0, heatMapGradient, lgfx::VLINEAR );
|
||||
|
||||
// horizontal linear grayscale gradient (top center)
|
||||
tft.fillGradientRect( cv.middleX-(cv.bw0/2), cv.thick2, cv.bw0, cv.bw1/2, 0x000000u, 0xffffffu, lgfx::HLINEAR );
|
||||
// horizontal linear inverted grayscale gradient (bottom center)
|
||||
tft.fillGradientRect( cv.middleX-(cv.bw0/2), tft.height()-(1+cv.thick2+cv.bw1/2), cv.bw0, cv.bw1/2, 0xffffffu, 0x000000u, lgfx::HLINEAR );
|
||||
|
||||
// radial gradient in landscape mode (bottom left)
|
||||
tft.fillGradientRect( cv.thick2, tft.height()-(1+cv.bw1+cv.thick2), cv.bw0, cv.bw1, heatMapGradient, lgfx::RADIAL );
|
||||
// radial gradient in portrait mode (bottom right)
|
||||
tft.fillGradientRect( tft.width()-(cv.bw1+cv.thick2+1), tft.height()-(1+cv.bw0+cv.thick2), cv.bw1, cv.bw0, heatMapGradient, lgfx::RADIAL );
|
||||
|
||||
// draw a big circle filled with default (rgb888) colored gradient
|
||||
tft.drawGradientSpot( cv.middleX, cv.middleY, cv.r4, gradient888 );
|
||||
|
||||
int32_t last_x=-1, last_y=-1;
|
||||
lgfx::rgb888_t last_color;
|
||||
|
||||
for( int i=0; i<360; i+=15 ) {
|
||||
float a = i*deg2rad;
|
||||
|
||||
float s = sin(a);
|
||||
float c = cos(a);
|
||||
|
||||
int32_t x0 = s*cv.r1 + cv.middleX;
|
||||
int32_t y0 = c*cv.r1 + cv.middleY;
|
||||
int32_t x1 = s*cv.r2 + cv.middleX;
|
||||
int32_t y1 = c*cv.r2 + cv.middleY;
|
||||
|
||||
int32_t x2 = s*cv.r3 + cv.middleX;
|
||||
int32_t y2 = c*cv.r3 + cv.middleY;
|
||||
|
||||
switch( (i/15)%8 ) {
|
||||
case 0: tft.drawWedgeLine( x0, y0, x1, y1, cv.thick1, cv.thick3, heatMapGradient ); break;
|
||||
case 1: tft.drawWedgeLine( x0, y0, x1, y1, cv.thick1, cv.thick3, gradient888 ); break;
|
||||
case 2: tft.drawWedgeLine( x1, y1, x0, y0, cv.thick3, cv.thick1, gradient888 ); break;
|
||||
case 3: tft.drawWedgeLine( x1, y1, x0, y0, cv.thick3, cv.thick1, heatMapGradient ); break;
|
||||
case 4: tft.drawWedgeLine( x0, y0, x1, y1, cv.thick2, cv.thick3, 0xff0000u ); break; // red 24bits
|
||||
case 5: tft.drawWedgeLine( x0, y0, x1, y1, cv.thick2, cv.thick3, (lgfx::rgb332_t)0x82 ); break; // purple 8bits
|
||||
case 6: tft.drawWedgeLine( x0, y0, x1, y1, cv.thick2, cv.thick3, TFT_ORANGE ); break; // named colors default to 16bits rgb565_t
|
||||
case 7: tft.drawWedgeLine( x0, y0, x1, y1, cv.thick2, cv.thick3, RGBColor{0x00,0xff,0x00} ); break; // green
|
||||
}
|
||||
|
||||
auto _color = tft.mapGradient( i, 0, 359, heatMapGradient );
|
||||
lgfx::rgb888_t color( _color.R8(), _color.G8(), _color.B8() );
|
||||
|
||||
if( last_x>=0 && last_y>=0 && (i/15)%2==1 ) {
|
||||
lgfx::rgb888_t colorsRGB[] = { last_color, color };
|
||||
auto gradientRGB = tft.createGradient( colorsRGB );
|
||||
tft.drawWedgeLine( last_x, last_y, x2, y2, cv.thick1, cv.thick3, gradientRGB );
|
||||
}
|
||||
last_color = color;
|
||||
last_x = x2;
|
||||
last_y = y2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
tft.init();
|
||||
tft.fillScreen(TFT_WHITE);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
static bool toggler = true;
|
||||
toggler = !toggler;
|
||||
if( toggler ) {
|
||||
runRandomLinesDemo();
|
||||
vTaskDelay(1000);
|
||||
} else {
|
||||
runGradientDemo();
|
||||
vTaskDelay(5000);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
#include <LovyanGFX.hpp>
|
||||
|
||||
#include <vector>
|
||||
|
||||
#define LINE_COUNT 6
|
||||
|
||||
static LGFX lcd;
|
||||
|
||||
static std::vector<int> points[LINE_COUNT];
|
||||
static int colors[] = { TFT_RED, TFT_GREEN, TFT_BLUE, TFT_CYAN, TFT_MAGENTA, TFT_YELLOW };
|
||||
static int xoffset, yoffset, point_count;
|
||||
|
||||
int getBaseColor(int x, int y)
|
||||
{
|
||||
return ((x^y)&3 || ((x-xoffset)&31 && y&31) ? TFT_BLACK : ((!y || x == xoffset) ? TFT_WHITE : TFT_DARKGREEN));
|
||||
}
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
lcd.init();
|
||||
|
||||
if (lcd.width() < lcd.height()) lcd.setRotation(lcd.getRotation() ^ 1);
|
||||
|
||||
yoffset = lcd.height() >> 1;
|
||||
xoffset = lcd.width() >> 1;
|
||||
point_count = lcd.width() + 1;
|
||||
|
||||
for (int i = 0; i < LINE_COUNT; i++)
|
||||
{
|
||||
points[i].resize(point_count);
|
||||
}
|
||||
|
||||
lcd.startWrite();
|
||||
lcd.setAddrWindow(0, 0, lcd.width(), lcd.height());
|
||||
for (int y = 0; y < lcd.height(); y++)
|
||||
{
|
||||
for (int x = 0; x < lcd.width(); x++)
|
||||
{
|
||||
lcd.writeColor(getBaseColor(x, y - yoffset), 1);
|
||||
}
|
||||
}
|
||||
lcd.endWrite();
|
||||
}
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
static int prev_sec;
|
||||
static int fps;
|
||||
++fps;
|
||||
int sec = millis() / 1000;
|
||||
if (prev_sec != sec)
|
||||
{
|
||||
prev_sec = sec;
|
||||
lcd.setCursor(0,0);
|
||||
lcd.printf("fps:%03d", fps);
|
||||
fps = 0;
|
||||
}
|
||||
|
||||
static int count;
|
||||
|
||||
for (int i = 0; i < LINE_COUNT; i++)
|
||||
{
|
||||
points[i][count % point_count] = (sinf((float)count / (10 + 30 * i))+sinf((float)count / (13 + 37 * i))) * (lcd.height() >> 2);
|
||||
}
|
||||
|
||||
++count;
|
||||
|
||||
lcd.startWrite();
|
||||
int index1 = count % point_count;
|
||||
for (int x = 0; x < point_count-1; x++)
|
||||
{
|
||||
int index0 = index1;
|
||||
index1 = (index0 +1) % point_count;
|
||||
for (int i = 0; i < LINE_COUNT; i++)
|
||||
{
|
||||
int y = points[i][index0];
|
||||
if (y != points[i][index1])
|
||||
{
|
||||
lcd.writePixel(x, y + yoffset, getBaseColor(x, y));
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < LINE_COUNT; i++)
|
||||
{
|
||||
int y = points[i][index1];
|
||||
lcd.writePixel(x, y + yoffset, colors[i]);
|
||||
}
|
||||
}
|
||||
lcd.endWrite();
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
#define LGFX_AUTODETECT
|
||||
#include <LovyanGFX.hpp>
|
||||
|
||||
LGFX lcd;
|
||||
LGFX_Sprite canvas;
|
||||
|
||||
static constexpr char text[] = "Hello world ! こんにちは世界! this is long long string sample. 寿限無、寿限無、五劫の擦り切れ、海砂利水魚の、水行末・雲来末・風来末、喰う寝る処に住む処、藪ら柑子の藪柑子、パイポ・パイポ・パイポのシューリンガン、シューリンガンのグーリンダイ、グーリンダイのポンポコピーのポンポコナの、長久命の長助";
|
||||
static constexpr size_t textlen = sizeof(text) / sizeof(text[0]);
|
||||
size_t textpos = 0;
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
lcd.init();
|
||||
|
||||
// 画面が横長になるように回転
|
||||
if (lcd.width() < lcd.height()) lcd.setRotation(lcd.getRotation() ^ 1);
|
||||
|
||||
canvas.setColorDepth(8);
|
||||
canvas.setFont(&fonts::lgfxJapanMinchoP_32);
|
||||
canvas.setTextWrap(false); // 右端到達時のカーソル折り返しを禁止
|
||||
canvas.createSprite(lcd.width() + 36, 36); // 画面幅+1文字分の横幅を用意
|
||||
}
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
int32_t cursor_x = canvas.getCursorX() - 1; // 現在のカーソル位置を取得し、1ドット左に移動
|
||||
if (cursor_x <= 0) // カーソル位置が左端に到達している場合は一周したと判断
|
||||
{
|
||||
textpos = 0; // 文字列の読取り位置をリセット
|
||||
cursor_x = lcd.width(); // 新たな文字が画面右端に描画されるようにカーソル位置を変更
|
||||
}
|
||||
|
||||
canvas.setCursor(cursor_x, 0); // カーソル位置を更新
|
||||
canvas.scroll(-1, 0); // キャンバスの内容を1ドット左にスクロール
|
||||
while (textpos < textlen && cursor_x <= lcd.width()) // 画面右端に文字が書けるか判定
|
||||
{
|
||||
canvas.print(text[textpos++]); // 1バイトずつ出力 (マルチバイト文字でもこの処理で動作します)
|
||||
cursor_x = canvas.getCursorX(); // 出力後のカーソル位置を取得
|
||||
}
|
||||
|
||||
canvas.pushSprite(&lcd, 0, 0);
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
#if defined (ARDUINO_WIO_TERMINAL)
|
||||
#include <Seeed_FS.h>
|
||||
#include <SD/Seeed_SD.h>
|
||||
#else
|
||||
#include <SD.h>
|
||||
#include <SPIFFS.h>
|
||||
#endif
|
||||
|
||||
#include <LovyanGFX.hpp>
|
||||
|
||||
static LGFX lcd;
|
||||
|
||||
static constexpr char filename[] = "/lovyangfx_test.bmp";
|
||||
|
||||
#ifndef SDCARD_SS_PIN
|
||||
#define SDCARD_SS_PIN 4
|
||||
#endif
|
||||
|
||||
#ifndef SDCARD_SPI
|
||||
#define SDCARD_SPI SPI
|
||||
#endif
|
||||
|
||||
|
||||
bool saveToSD_16bit(void)
|
||||
{
|
||||
bool result = false;
|
||||
File file = SD.open(filename, "w");
|
||||
if (file)
|
||||
{
|
||||
int width = lcd.width();
|
||||
int height = lcd.height();
|
||||
|
||||
int rowSize = (2 * width + 3) & ~ 3;
|
||||
|
||||
lgfx::bitmap_header_t bmpheader;
|
||||
bmpheader.bfType = 0x4D42;
|
||||
bmpheader.bfSize = rowSize * height + sizeof(bmpheader);
|
||||
bmpheader.bfOffBits = sizeof(bmpheader);
|
||||
|
||||
bmpheader.biSize = 40;
|
||||
bmpheader.biWidth = width;
|
||||
bmpheader.biHeight = height;
|
||||
bmpheader.biPlanes = 1;
|
||||
bmpheader.biBitCount = 16;
|
||||
bmpheader.biCompression = 3;
|
||||
|
||||
file.write((std::uint8_t*)&bmpheader, sizeof(bmpheader));
|
||||
std::uint8_t buffer[rowSize];
|
||||
memset(&buffer[rowSize - 4], 0, 4);
|
||||
for (int y = lcd.height() - 1; y >= 0; y--)
|
||||
{
|
||||
lcd.readRect(0, y, lcd.width(), 1, (lgfx::rgb565_t*)buffer);
|
||||
file.write(buffer, rowSize);
|
||||
}
|
||||
file.close();
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.print("error:file open failure\n");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool saveToSD_24bit(void)
|
||||
{
|
||||
bool result = false;
|
||||
File file = SD.open(filename, "w");
|
||||
if (file)
|
||||
{
|
||||
int width = lcd.width();
|
||||
int height = lcd.height();
|
||||
|
||||
int rowSize = (3 * width + 3) & ~ 3;
|
||||
|
||||
lgfx::bitmap_header_t bmpheader;
|
||||
bmpheader.bfType = 0x4D42;
|
||||
bmpheader.bfSize = rowSize * height + sizeof(bmpheader);
|
||||
bmpheader.bfOffBits = sizeof(bmpheader);
|
||||
|
||||
bmpheader.biSize = 40;
|
||||
bmpheader.biWidth = width;
|
||||
bmpheader.biHeight = height;
|
||||
bmpheader.biPlanes = 1;
|
||||
bmpheader.biBitCount = 24;
|
||||
bmpheader.biCompression = 0;
|
||||
|
||||
file.write((std::uint8_t*)&bmpheader, sizeof(bmpheader));
|
||||
std::uint8_t buffer[rowSize];
|
||||
memset(&buffer[rowSize - 4], 0, 4);
|
||||
for (int y = lcd.height() - 1; y >= 0; y--)
|
||||
{
|
||||
lcd.readRect(0, y, lcd.width(), 1, (lgfx::rgb888_t*)buffer);
|
||||
file.write(buffer, rowSize);
|
||||
}
|
||||
file.close();
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.print("error:file open failure\n");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
lcd.init();
|
||||
|
||||
Serial.begin(115200);
|
||||
|
||||
lcd.setColorDepth(16);
|
||||
|
||||
lcd.setColor(TFT_WHITE);
|
||||
lcd.startWrite();
|
||||
lcd.setAddrWindow(0, 0, lcd.width(), lcd.height());
|
||||
for (int y = 0; y < lcd.height(); ++y)
|
||||
{
|
||||
for (int x = 0; x < lcd.width(); ++x)
|
||||
{
|
||||
lcd.writeColor( lcd.color888(x << 1, x + y, y << 1), 1);
|
||||
}
|
||||
}
|
||||
lcd.print("BMP save test\n");
|
||||
lcd.endWrite();
|
||||
|
||||
do {
|
||||
SD.end();
|
||||
delay(1000);
|
||||
|
||||
SD.begin(SDCARD_SS_PIN, SDCARD_SPI, 25000000);
|
||||
|
||||
} while (!saveToSD_16bit());
|
||||
|
||||
|
||||
lcd.print("BMP save success.");
|
||||
}
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
lcd.drawBmpFile(SD, filename, random(-20,20), random(-20, 20));
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
#if defined (ARDUINO_WIO_TERMINAL)
|
||||
#include <Seeed_FS.h>
|
||||
#include <SD/Seeed_SD.h>
|
||||
#else
|
||||
#include <SD.h>
|
||||
#include <SPIFFS.h>
|
||||
#endif
|
||||
|
||||
#include <LovyanGFX.hpp>
|
||||
|
||||
static LGFX lcd;
|
||||
|
||||
static constexpr char filename[] = "/lovyangfx_test.png";
|
||||
|
||||
#ifndef SDCARD_SS_PIN
|
||||
#define SDCARD_SS_PIN 4
|
||||
#endif
|
||||
|
||||
#ifndef SDCARD_SPI
|
||||
#define SDCARD_SPI SPI
|
||||
#endif
|
||||
|
||||
|
||||
bool saveToSD(void)
|
||||
{
|
||||
// createPng関数で指定範囲の画像からPNG形式のデータを生成します。
|
||||
// SAMD51の場合 172x172程度が上限です。
|
||||
// ESP32の場合 192x192程度が上限です。
|
||||
// メモリ使用状況によってさらに縮みます。
|
||||
// ESP32でPSRAMが有効な場合は大きなサイズでも保存できる可能性があります。
|
||||
std::size_t dlen;
|
||||
std::uint8_t* png = (std::uint8_t*)lcd.createPng(&dlen, 0, 0, 128, 128);
|
||||
if (!png)
|
||||
{
|
||||
Serial.print("error:createPng\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
Serial.print("success:createPng\n");
|
||||
|
||||
bool result = false;
|
||||
File file = SD.open(filename, "w");
|
||||
if (file)
|
||||
{
|
||||
file.write((std::uint8_t*)png, dlen);
|
||||
file.close();
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.print("error:file open failure\n");
|
||||
}
|
||||
|
||||
free(png);
|
||||
return result;
|
||||
}
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
lcd.init();
|
||||
|
||||
Serial.begin(115200);
|
||||
|
||||
lcd.setColorDepth(24);
|
||||
|
||||
lcd.setColor(TFT_WHITE);
|
||||
lcd.startWrite();
|
||||
lcd.setAddrWindow(0, 0, lcd.width(), lcd.height());
|
||||
for (int y = 0; y < lcd.height(); ++y)
|
||||
{
|
||||
for (int x = 0; x < lcd.width(); ++x)
|
||||
{
|
||||
lcd.writeColor( lcd.color888(x << 1, x + y, y << 1), 1);
|
||||
}
|
||||
}
|
||||
lcd.print("PNG save test\n");
|
||||
lcd.endWrite();
|
||||
|
||||
do {
|
||||
SD.end();
|
||||
delay(1000);
|
||||
|
||||
SD.begin(SDCARD_SS_PIN, SDCARD_SPI, 25000000);
|
||||
|
||||
} while (!saveToSD());
|
||||
|
||||
|
||||
lcd.print("PNG save success.");
|
||||
}
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
lcd.drawPngFile(SD, filename, random(-20,20), random(-20, 20));
|
||||
}
|
||||
Reference in new issue
Block a user