-
-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tweak for PlatformIO
platform=native
- Loading branch information
Showing
14 changed files
with
470 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
|
||
## Visual Studio Code + PlatformIO + SDL2 環境で LovyanGFXを使用する手順 | ||
|
||
まず最初にVisual Studio Code をインストールし、PlatformIO を使用できる状態にする。 | ||
この手順に関しては説明を省略。 | ||
|
||
--- | ||
|
||
次に、PlatformIOにて、 `platform = native` のビルドができる状態にする。 | ||
|
||
手順は下記 URL から `Installation` の項目を読んで実施する。 | ||
https://docs.platformio.org/en/latest/platforms/native.html#installation | ||
|
||
--- | ||
|
||
### PlatformIOにて、 SDL2 が使用できる状態にする。 | ||
|
||
手順は下記 URL から `Install SDL2` の項目を読んで実施する。 | ||
https://docs.lvgl.io/latest/en/html/get-started/pc-simulator.html#install-sdl-2 | ||
|
||
|
||
#### Linuxの場合 | ||
|
||
apt-getでlibsdl2をインストールする。 | ||
|
||
``` | ||
sudo apt-get install libsdl2 libsdl2-dev | ||
``` | ||
|
||
#### MacOS OSXの場合 | ||
|
||
Homebrewを使ってsdl2をインストールする。 | ||
``` | ||
brew install sdl2 | ||
``` | ||
|
||
#### Windowsの場合 | ||
|
||
`platform = native` のビルドを可能にする手順において、 msys2をインストール済みのはずなので、 | ||
githubの SDLのリポジトリにアクセスし、SDL2-devel-x.xx.x-mingw のリリースパッケージを入手する。 | ||
https://github.com/libsdl-org/SDL/releases | ||
|
||
本記事作成時点のファイル名は `SDL2-devel-2.28.1-mingw.zip` | ||
これを解凍し、出てきたフォルダの中にある `x86_64-w64-mingw32` フォルダを開き、中に以下の 4つのフォルダがあることを確認。 | ||
- share | ||
- bin | ||
- include | ||
- lib | ||
|
||
C:\msys64\mingw64\ を開き、上記の4つのフォルダと同名のフォルダが存在することを確認したら、C:\msys64\mingw64\ 内に上記フォルダの内容を追加する。(上書きコピー) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
; PlatformIO Project Configuration File | ||
; | ||
; Build options: build flags, source filter | ||
; Upload options: custom upload port, speed and extra flags | ||
; Library options: dependencies, extra library storages | ||
; Advanced options: extra scripting | ||
; | ||
; Please visit documentation for the other options and examples | ||
; https://docs.platformio.org/page/projectconf.html | ||
|
||
[env:native] | ||
platform = native | ||
build_type = debug | ||
build_flags = -lSDL2 | ||
|
||
[esp32_base] | ||
build_type = debug | ||
platform = espressif32 | ||
board = esp32dev | ||
|
||
[env:esp32_arduino] | ||
extends = esp32_base | ||
framework = arduino | ||
|
||
[env:esp32_idf] | ||
extends = esp32_base | ||
framework = espidf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
#include <lgfx/v1/platforms/sdl/Panel_sdl.hpp> | ||
#if defined ( SDL_h_ ) | ||
#include <thread> | ||
|
||
void setup(void); | ||
void loop(void); | ||
|
||
static void loopThread(void) | ||
{ | ||
setup(); | ||
SDL_Delay(5); | ||
for (;;) | ||
{ | ||
std::this_thread::yield(); | ||
loop(); | ||
} | ||
} | ||
|
||
#if __has_include(<windows.h>) | ||
#include <windows.h> | ||
#include <tchar.h> | ||
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) | ||
#else | ||
int main(int, char**) | ||
#endif | ||
{ | ||
std::thread sub_thread(loopThread); | ||
for (;;) | ||
{ | ||
std::this_thread::yield(); | ||
lgfx::Panel_sdl::sdl_event_handler(); | ||
SDL_Delay(5); | ||
} | ||
return 1; | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#define LGFX_AUTODETECT | ||
#include <LGFX_AUTODETECT.hpp> | ||
|
||
#if defined ( SDL_h_ ) | ||
static LGFX lcd ( 320, 240, 3 ); | ||
#else | ||
static LGFX lcd; | ||
#endif | ||
|
||
|
||
static LGFX_Sprite sprite(&lcd); | ||
|
||
struct meter_t | ||
{ | ||
int32_t pivot_x; | ||
int32_t pivot_y; | ||
|
||
float angle = 0; | ||
float add = 0; | ||
|
||
void advance(void) | ||
{ | ||
if ((angle >= 256 && add > 0.0) | ||
|| (angle <= 0 && add < 0.0)) | ||
{ | ||
add = -add; | ||
} | ||
angle += add; | ||
} | ||
|
||
void drawGauge(uint32_t color) | ||
{ | ||
lcd.setPivot(pivot_x, pivot_y); | ||
sprite.setPaletteColor(1, color); | ||
sprite.pushRotated(angle - 127); | ||
advance(); | ||
} | ||
}; | ||
|
||
struct meter_t meter1, meter2, meter3; | ||
|
||
void setup(void) | ||
{ | ||
lcd.init(); | ||
|
||
if (lcd.width() < lcd.height()) { | ||
lcd.setRotation(lcd.getRotation() ^ 1); | ||
} | ||
|
||
sprite.setColorDepth(2); | ||
|
||
sprite.createSprite(3,lcd.height() / 8); | ||
sprite.setPivot(1, lcd.height() / 4); | ||
|
||
sprite.drawFastVLine(1, 0, sprite.height() , 3); | ||
sprite.drawFastVLine(0, 2, sprite.height() - 4, 1); | ||
|
||
meter1.pivot_x = lcd.width() >> 1; | ||
meter1.pivot_y = (lcd.height() >> 2) + 2; | ||
meter1.add = 0.01; | ||
|
||
meter2.pivot_x = lcd.width() >> 2; | ||
meter2.pivot_y = (lcd.height() * 3) >>2; | ||
meter2.add = 0.11; | ||
|
||
meter3.pivot_x = (lcd.width() * 3) >> 2; | ||
meter3.pivot_y = (lcd.height() * 3) >> 2; | ||
meter3.add = 0.57; | ||
|
||
lcd.fillScreen(lcd.color565(0,0,127)); | ||
|
||
for (int i = 0; i < 20; i++) { | ||
lcd.drawFastHLine(0, (i*2+1) * lcd.height() / 40, lcd.width(), 0xFFFF); | ||
lcd.drawFastVLine((i*2+1) * lcd.width() / 40, 0, lcd.height() , 0xFFFF); | ||
} | ||
} | ||
|
||
void loop(void) | ||
{ | ||
meter1.drawGauge(sprite.color888(255, meter1.angle, 127)); | ||
meter2.drawGauge(sprite.color888(255 - meter2.angle, meter2.angle, 127)); | ||
meter3.drawGauge(sprite.color888(0, 127, meter3.angle)); | ||
} | ||
|
||
|
||
|
||
#if defined ( ESP_PLATFORM ) && !defined ( ARDUINO ) | ||
extern "C" { | ||
int app_main(int, char**) | ||
{ | ||
setup(); | ||
for (;;) { | ||
loop(); | ||
} | ||
return 0; | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.