From 3eb5fc8d2bc13871cc459d2d76be7ffb6d75c223 Mon Sep 17 00:00:00 2001 From: lovyan03 <42724151+lovyan03@users.noreply.github.com> Date: Thu, 3 Sep 2020 16:34:58 +0900 Subject: [PATCH 1/2] add: convertRawXY function --- src/config/LGFX_Config_AutoDetectESP32.hpp | 2 +- src/lgfx/LGFX_Device.hpp | 54 ++++++++++++++-------- 2 files changed, 35 insertions(+), 21 deletions(-) diff --git a/src/config/LGFX_Config_AutoDetectESP32.hpp b/src/config/LGFX_Config_AutoDetectESP32.hpp index 73377652..6828089e 100644 --- a/src/config/LGFX_Config_AutoDetectESP32.hpp +++ b/src/config/LGFX_Config_AutoDetectESP32.hpp @@ -232,7 +232,7 @@ class LGFX : public lgfx::LGFX_SPI p_tmp.freq_read = 8000000; board = lgfx::board_t::board_unknown; std::uint32_t id; - + (void)id; // Suppressing Compiler Warnings // TTGO T-Watch 判定 (GPIO33を使う判定を先に行うと振動モーターが作動する事に注意) #if defined ( LGFX_AUTODETECT ) || defined ( LGFX_TTGO_TWATCH ) diff --git a/src/lgfx/LGFX_Device.hpp b/src/lgfx/LGFX_Device.hpp index 866fa36c..45411a8d 100644 --- a/src/lgfx/LGFX_Device.hpp +++ b/src/lgfx/LGFX_Device.hpp @@ -145,42 +145,56 @@ namespace lgfx bool need_transaction = (_touch->bus_shared && _in_transaction); if (need_transaction) { endTransaction(); } - std::uint_fast8_t res = _touch->getTouch(x, y, number); + auto res = _touch->getTouch(x, y, number); if (need_transaction) { beginTransaction(); } return res; } - std::uint_fast8_t getTouch(std::uint16_t *px, std::uint16_t *py, std::uint_fast8_t number = 0) + std::uint_fast8_t getTouch(std::uint16_t *x, std::uint16_t *y, std::uint_fast8_t number = 0) { - std::int32_t x, y; - auto res = getTouch(&x, &y, number); - if (px) *px = x; - if (py) *py = y; + std::int32_t tx, ty; + auto res = getTouch(&tx, &ty, number); + if (x) *x = tx; + if (y) *y = ty; return res; } - std::uint_fast8_t getTouch(std::int32_t *px, std::int32_t *py, std::uint_fast8_t number = 0) + std::uint_fast8_t getTouch(std::int32_t *x, std::int32_t *y, std::uint_fast8_t number = 0) { std::int32_t tx, ty; - std::uint_fast8_t res = getTouchRaw(&tx, &ty, number); + auto res = getTouchRaw(&tx, &ty, number); if (0 == res) return 0; + convertRawXY(&tx, &ty); + if (x) *x = tx; + if (y) *y = ty; + return res; + } - int x = (_touch_affin[0] * (float)tx + _touch_affin[1] * (float)ty) + _touch_affin[2]; - int y = (_touch_affin[3] * (float)tx + _touch_affin[4] * (float)ty) + _touch_affin[5]; + void convertRawXY(std::uint16_t *x, std::uint16_t *y) + { + std::int32_t tx = *x, ty = *y; + convertRawXY(&tx, &ty); + *x = tx; + *y = ty; + } - int r = _panel->rotation & 7; + void convertRawXY(std::int32_t *x, std::int32_t *y) + { + std::int32_t tx = (_touch_affin[0] * (float)*x + _touch_affin[1] * (float)*y) + _touch_affin[2]; + std::int32_t ty = (_touch_affin[3] * (float)*x + _touch_affin[4] * (float)*y) + _touch_affin[5]; + + std::uint_fast8_t r = _panel->rotation & 7; if (r & 1) { - std::swap(x, y); + std::swap(tx, ty); } - if (px) { - if (r & 2) x = (_width-1) - x; - *px = x; + if (x) { + if (r & 2) tx = (_width-1) - tx; + *x = tx; } - if (py) { - if ((0 == ((r + 1) & 2)) != (0 == (r & 4))) y = (_height-1) - y; - *py = y; + if (y) { + if ((0 == ((r + 1) & 2)) != (0 == (r & 4))) ty = (_height-1) - ty; + *y = ty; } - return res; } // This requires a uint16_t array with 8 elements. ( or nullptr ) @@ -374,7 +388,7 @@ namespace lgfx std::int32_t px = (_width - 1) * ((i>>1) & 1); std::int32_t py = (_height - 1) * ( i & 1); draw_calibrate_point( px, py, size, fg_rawcolor, bg_rawcolor); - + delay(500); std::int32_t x_touch = 0, y_touch = 0; static constexpr int _RAWERR = 20; std::int32_t x_tmp, y_tmp, x_tmp2, y_tmp2; From 7ce7d7399dbdb8ca1bf59fe96a72b8d3222ad76d Mon Sep 17 00:00:00 2001 From: lovyan03 <42724151+lovyan03@users.noreply.github.com> Date: Thu, 3 Sep 2020 17:34:48 +0900 Subject: [PATCH 2/2] v0.2.0 --- library.json | 2 +- library.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library.json b/library.json index 7acdc4f6..cb4c3d7c 100644 --- a/library.json +++ b/library.json @@ -11,7 +11,7 @@ "type": "git", "url": "https://github.com/lovyan03/LovyanGFX" }, - "version": "0.1.19", + "version": "0.2.0", "framework": "arduino, espidf", "platforms": "espressif32, atmelsam", "build": { diff --git a/library.properties b/library.properties index cc6a0369..86b70c94 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=LovyanGFX -version=0.1.19 +version=0.2.0 author=lovyan03 maintainer=Lovyan <42724151+lovyan03@users.noreply.github.com> sentence=LCD Graphics driver for ESP32 and SAMD51