first commit
This commit is contained in:
commit
e6a42e28e9
4355 changed files with 4626605 additions and 0 deletions
90
libraries/LovyanGFX/examples/Standard/Graph/Graph.ino
Normal file
90
libraries/LovyanGFX/examples/Standard/Graph/Graph.ino
Normal file
|
|
@ -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);
|
||||
}
|
||||
144
libraries/LovyanGFX/examples/Standard/SaveBMP/SaveBMP.ino
Normal file
144
libraries/LovyanGFX/examples/Standard/SaveBMP/SaveBMP.ino
Normal file
|
|
@ -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));
|
||||
}
|
||||
94
libraries/LovyanGFX/examples/Standard/SavePNG/SavePNG.ino
Normal file
94
libraries/LovyanGFX/examples/Standard/SavePNG/SavePNG.ino
Normal file
|
|
@ -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));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue