mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-24 11:46:34 +00:00
Touch redesign
This commit is contained in:
parent
fd5dec8f8b
commit
9413d822e6
@ -125,7 +125,7 @@ typedef int16_t lv_coord_t;
|
||||
|
||||
/* Input device read period in milliseconds */
|
||||
#ifndef LV_INDEV_DEF_READ_PERIOD
|
||||
#define LV_INDEV_DEF_READ_PERIOD 20 /*[ms]*/
|
||||
#define LV_INDEV_DEF_READ_PERIOD 25 /*[ms]*/
|
||||
#endif
|
||||
|
||||
/* Drag threshold in pixels */
|
||||
|
@ -74,8 +74,9 @@ lib_deps =
|
||||
git+https://github.com/fvanroie/ConsoleInput.git
|
||||
;git+https://github.com/andrethomas/TasmotaSlave.git
|
||||
;git+https://github.com/lvgl/lvgl.git
|
||||
lvgl/lvgl@^7.11.0 ; from PIO library
|
||||
bodmer/TFT_eSPI@^2.3.69
|
||||
git+https://github.com/lvgl/lvgl.git#b16e7f1076963f123b36dec9ce1dd5950057ca1a
|
||||
;lvgl/lvgl@^7.11.0 ; from PIO library
|
||||
bodmer/TFT_eSPI@^2.3.70
|
||||
;git+https://github.com/Bodmer/TFT_eSPI.git
|
||||
; ------ Unused / Test libraries
|
||||
;https://github.com/netwizeBE/TFT_eSPI.git
|
||||
|
78
src/drv/touch/touch_driver.h
Normal file
78
src/drv/touch/touch_driver.h
Normal file
@ -0,0 +1,78 @@
|
||||
/* MIT License - Copyright (c) 2019-2021 Francis Van Roie
|
||||
For full license information read the LICENSE file in the project folder */
|
||||
|
||||
#ifndef HASP_BASE_TOUCH_DRIVER_H
|
||||
#define HASP_BASE_TOUCH_DRIVER_H
|
||||
|
||||
#ifdef ARDUINO
|
||||
#include "Arduino.h"
|
||||
#endif
|
||||
|
||||
#include "hasplib.h"
|
||||
#include "lvgl.h"
|
||||
|
||||
namespace dev {
|
||||
|
||||
class BaseTouch {
|
||||
public:
|
||||
void init(int w, int h)
|
||||
{}
|
||||
void loop()
|
||||
{}
|
||||
void show_info()
|
||||
{}
|
||||
void set_rotation(uint8_t rotation)
|
||||
{}
|
||||
void set_invert(bool invert_display)
|
||||
{}
|
||||
IRAM_ATTR bool read(lv_indev_drv_t* indev_driver, lv_indev_data_t* data)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
void calibrate(uint16_t* calData)
|
||||
{}
|
||||
bool is_driver_pin(uint8_t)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
const char* get_touch_model()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace dev
|
||||
|
||||
#ifndef TOUCH_DRIVER
|
||||
#define TOUCH_DRIVER -1 // No Touch
|
||||
#endif
|
||||
|
||||
#if TOUCH_DRIVER == 2046
|
||||
#warning Building for XPT2046
|
||||
//#include "touch_driver_xpt2046.h"
|
||||
#include "touch_driver_tftespi.h"
|
||||
#elif TOUCH_DRIVER == 6336
|
||||
#warning Building for FT6336
|
||||
#include "touch_driver_ft6336u.h"
|
||||
#elif TOUCH_DRIVER == 610
|
||||
#warning Building for STMPE610
|
||||
#include "touch_driver_stmpe610.h"
|
||||
#elif TOUCH_DRIVER == 5206
|
||||
#warning Building for FT5206
|
||||
#include "touch_driver_ft5206.h"
|
||||
#else
|
||||
#warning Building for Generic Touch
|
||||
using dev::BaseTouch;
|
||||
extern dev::BaseTouch haspTouch;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
// #elif TOUCH_DRIVER == 0x2046B
|
||||
// touched = XPT2046_getXY(&normal_x, &normal_y, true);
|
||||
|
||||
// #elif TOUCH_DRIVER == 911
|
||||
// touched = GT911_getXY(&normal_x, &normal_y, true);
|
||||
|
||||
// #elif TOUCH_DRIVER == 0xADC // Analog Digital Touch Conroller
|
||||
// touched = Touch_getXY(&normal_x, &normal_y, false);
|
123
src/drv/touch/touch_driver_ft6336u.h
Normal file
123
src/drv/touch/touch_driver_ft6336u.h
Normal file
@ -0,0 +1,123 @@
|
||||
/* MIT License - Copyright (c) 2019-2021 Francis Van Roie
|
||||
For full license information read the LICENSE file in the project folder */
|
||||
|
||||
#ifndef HASP_FT6336T_TOUCH_DRIVER_H
|
||||
#define HASP_FT6336T_TOUCH_DRIVER_H
|
||||
|
||||
#ifdef ARDUINO
|
||||
#include "Arduino.h"
|
||||
#include "lvgl.h"
|
||||
|
||||
#include <Wire.h>
|
||||
#include "FT6336U.h"
|
||||
|
||||
#include "touch_driver.h" // base class
|
||||
#include "touch_helper.h" // i2c scanner
|
||||
|
||||
#include "../../hasp/hasp.h" // for hasp_sleep_state
|
||||
extern uint8_t hasp_sleep_state;
|
||||
|
||||
#define RST_PIN (TOUCH_RST) // -1 if pin is connected to VCC else set pin number
|
||||
|
||||
FT6336U* ft6336u_touch;
|
||||
|
||||
// Read touch points
|
||||
HASP_ATTRIBUTE_FAST_MEM bool FT6336U_getXY(int16_t* touchX, int16_t* touchY)
|
||||
{
|
||||
if(ft6336u_touch->read_touch_number() == 1) {
|
||||
*touchX = ft6336u_touch->read_touch1_x();
|
||||
*touchY = ft6336u_touch->read_touch1_y();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
IRAM_ATTR bool touch_read(lv_indev_drv_t* indev_driver, lv_indev_data_t* data)
|
||||
{
|
||||
|
||||
if(ft6336u_touch->read_touch_number() == 1) {
|
||||
if(hasp_sleep_state != HASP_SLEEP_OFF) hasp_update_sleep_state(); // update Idle
|
||||
|
||||
data->point.x = ft6336u_touch->read_touch1_x();
|
||||
data->point.y = ft6336u_touch->read_touch1_y();
|
||||
data->state = LV_INDEV_STATE_PR;
|
||||
|
||||
} else {
|
||||
data->state = LV_INDEV_STATE_REL;
|
||||
}
|
||||
|
||||
/*Return `false` because we are not buffering and no more data to read*/
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline void FT6336U_drv_init()
|
||||
{
|
||||
LOG_INFO(TAG_DRVR, F("Touch SDA : %d"), TOUCH_SDA);
|
||||
LOG_INFO(TAG_DRVR, F("Touch SCL : %d"), TOUCH_SCL);
|
||||
LOG_INFO(TAG_DRVR, F("Touch freq. : %d"), TOUCH_FREQUENCY);
|
||||
LOG_INFO(TAG_DRVR, F("Touch address : %x"), I2C_ADDR_FT6336U);
|
||||
|
||||
ft6336u_touch = new FT6336U(TOUCH_SDA, TOUCH_SCL, TOUCH_RST, TOUCH_IRQ);
|
||||
ft6336u_touch->begin();
|
||||
|
||||
// From: M5Core2/src/M5Touch.cpp
|
||||
// By default, the FT6336 will pulse the INT line for every touch
|
||||
// event. But because it shares the Wire1 TwoWire/I2C with other
|
||||
// devices, we cannot easily create an interrupt service routine to
|
||||
// handle these events. So instead, we set the INT wire to polled mode,
|
||||
// so it simply goes low as long as there is at least one valid touch.
|
||||
// ft6336u_touch->writeByte(0xA4, 0x00);
|
||||
Wire1.beginTransmission(I2C_ADDR_FT6336U);
|
||||
Wire1.write(0xA4); // address
|
||||
Wire1.write(0x00); // data
|
||||
Wire1.endTransmission();
|
||||
|
||||
touch_scan(Wire1);
|
||||
|
||||
if(ft6336u_touch->read_chip_id() != 0) {
|
||||
LOG_INFO(TAG_DRVR, F("FT6336U touch driver started chipid: %d"), ft6336u_touch->read_chip_id());
|
||||
} else {
|
||||
LOG_ERROR(TAG_DRVR, F("FT6336U touch driver failed to start"));
|
||||
}
|
||||
}
|
||||
|
||||
namespace dev {
|
||||
|
||||
class TouchFt6336u : public BaseTouch {
|
||||
|
||||
public:
|
||||
void init(int w, int h)
|
||||
{
|
||||
FT6336U_drv_init();
|
||||
}
|
||||
|
||||
IRAM_ATTR bool read(lv_indev_drv_t* indev_driver, lv_indev_data_t* data)
|
||||
{
|
||||
int16_t touchX;
|
||||
int16_t touchY;
|
||||
if(FT6336U_getXY(&touchX, &touchY)) {
|
||||
if(hasp_sleep_state != HASP_SLEEP_OFF) hasp_update_sleep_state(); // update Idle
|
||||
|
||||
data->point.x = touchX;
|
||||
data->point.y = touchY;
|
||||
data->state = LV_INDEV_STATE_PR;
|
||||
|
||||
} else {
|
||||
data->state = LV_INDEV_STATE_REL;
|
||||
}
|
||||
|
||||
/*Return `false` because we are not buffering and no more data to read*/
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace dev
|
||||
|
||||
#warning Using FT6336
|
||||
using dev::TouchFt6336u;
|
||||
extern dev::TouchFt6336u haspTouch;
|
||||
|
||||
#endif // ARDUINO
|
||||
|
||||
#endif // HASP_FT6336T_TOUCH_DRIVER_H
|
84
src/drv/touch/touch_driver_stmpe610.h
Normal file
84
src/drv/touch/touch_driver_stmpe610.h
Normal file
@ -0,0 +1,84 @@
|
||||
/* MIT License - Copyright (c) 2019-2021 Francis Van Roie
|
||||
For full license information read the LICENSE file in the project folder */
|
||||
|
||||
#ifndef HASP_STMPE610_TOUCH_DRIVER_H
|
||||
#define HASP_STMPE610_TOUCH_DRIVER_H
|
||||
|
||||
#ifdef ARDUINO
|
||||
#include "Arduino.h"
|
||||
#include <SPI.h>
|
||||
#include "Adafruit_STMPE610.h"
|
||||
#include "ArduinoLog.h"
|
||||
|
||||
#include "touch_driver.h" // base class
|
||||
|
||||
#include "hasp_conf.h"
|
||||
|
||||
#include "../../hasp/hasp.h" // for hasp_sleep_state
|
||||
extern uint8_t hasp_sleep_state;
|
||||
|
||||
// This is calibration data for the raw touch data to the screen coordinates
|
||||
#define TS_MINX 3800
|
||||
#define TS_MAXX 100
|
||||
#define TS_MINY 100
|
||||
#define TS_MAXY 3750
|
||||
|
||||
static Adafruit_STMPE610 stmpe610_touchpanel = Adafruit_STMPE610(TOUCH_CS);
|
||||
|
||||
bool touch_read(lv_indev_drv_t* indev_driver, lv_indev_data_t* data)
|
||||
{
|
||||
data->state = LV_INDEV_STATE_REL;
|
||||
|
||||
// while touched, but the state is released => read next point
|
||||
while(data->state == LV_INDEV_STATE_REL && stmpe610_touchpanel.touched()) {
|
||||
|
||||
TS_Point point = stmpe610_touchpanel.getPoint();
|
||||
Log.trace(TAG_DRVR, F("STMPE610: x=%i y=%i z=%i"), point.x, point.y, point.z);
|
||||
|
||||
if(point.z && point.x < 4096 && point.y < 4096) { // valid reading
|
||||
if(hasp_sleep_state != HASP_SLEEP_OFF) hasp_update_sleep_state(); // update Idle
|
||||
data->state = LV_INDEV_STATE_PR;
|
||||
|
||||
#if HX8357D_DRIVER == 1
|
||||
data->point.x = map(point.x, TS_MINX, TS_MAXX, TFT_WIDTH, 0);
|
||||
data->point.y = map(point.y, TS_MINY, TS_MAXY, 0, TFT_HEIGHT);
|
||||
#else
|
||||
data->point.x = map(point.x, TS_MINX, TS_MAXX, 0, TFT_WIDTH);
|
||||
data->point.y = map(point.y, TS_MINY, TS_MAXY, 0, TFT_HEIGHT);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/*Return `false` because we are not buffering and no more data to read*/
|
||||
return false;
|
||||
}
|
||||
|
||||
namespace dev {
|
||||
|
||||
class TouchStmpe610 : public BaseTouch {
|
||||
|
||||
public:
|
||||
IRAM_ATTR bool read(lv_indev_drv_t* indev_driver, lv_indev_data_t* data)
|
||||
{
|
||||
return touch_read(indev_driver, data);
|
||||
}
|
||||
|
||||
void init(int w, int h)
|
||||
{
|
||||
LOG_INFO(TAG_DRVR, F("STMPE610 " D_SERVICE_STARTING));
|
||||
if(!stmpe610_touchpanel.begin()) {
|
||||
LOG_ERROR(TAG_DRVR, F("STMPE610 " D_SERVICE_START_FAILED));
|
||||
} else {
|
||||
LOG_INFO(TAG_DRVR, F("STMPE610 " D_SERVICE_STARTED));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace dev
|
||||
|
||||
using dev::TouchStmpe610;
|
||||
extern dev::TouchStmpe610 haspTouch;
|
||||
|
||||
#endif // ARDUINO
|
||||
|
||||
#endif // HASP_STMPE610_TOUCH_DRIVER_H
|
80
src/drv/touch/touch_driver_tftespi.h
Normal file
80
src/drv/touch/touch_driver_tftespi.h
Normal file
@ -0,0 +1,80 @@
|
||||
/* MIT License - Copyright (c) 2019-2021 Francis Van Roie
|
||||
For full license information read the LICENSE file in the project folder */
|
||||
|
||||
#ifndef HASP_TFTESPI_TOUCH_DRIVER_H
|
||||
#define HASP_TFTESPI_TOUCH_DRIVER_H
|
||||
|
||||
#ifdef ARDUINO
|
||||
#include "Arduino.h"
|
||||
|
||||
#include "touch_driver.h" // base class
|
||||
#include "dev/device.h" // for haspTft
|
||||
#include "drv/tft/tft_driver.h"
|
||||
|
||||
#include "../../hasp/hasp.h" // for hasp_sleep_state
|
||||
extern uint8_t hasp_sleep_state;
|
||||
|
||||
IRAM_ATTR bool touch_read(lv_indev_drv_t* indev_driver, lv_indev_data_t* data)
|
||||
{
|
||||
if(haspTft.tft.getTouch((uint16_t*)&data->point.x, (uint16_t*)&data->point.y, 300)) {
|
||||
if(hasp_sleep_state != HASP_SLEEP_OFF) hasp_update_sleep_state(); // update Idle
|
||||
data->state = LV_INDEV_STATE_PR;
|
||||
|
||||
} else {
|
||||
data->state = LV_INDEV_STATE_REL;
|
||||
}
|
||||
|
||||
/*Return `false` because we are not buffering and no more data to read*/
|
||||
return false;
|
||||
}
|
||||
|
||||
namespace dev {
|
||||
|
||||
class TouchTftEspi : public BaseTouch {
|
||||
|
||||
public:
|
||||
IRAM_ATTR bool read(lv_indev_drv_t* indev_driver, lv_indev_data_t* data)
|
||||
{
|
||||
int16_t touchX = 0;
|
||||
int16_t touchY = 0;
|
||||
|
||||
if(haspTft.tft.getTouch((uint16_t*)&touchX, (uint16_t*)&touchY, 300)) {
|
||||
if(hasp_sleep_state != HASP_SLEEP_OFF) hasp_update_sleep_state(); // update Idle
|
||||
|
||||
data->point.x = touchX;
|
||||
data->point.y = touchY;
|
||||
data->state = LV_INDEV_STATE_PR;
|
||||
|
||||
} else {
|
||||
data->state = LV_INDEV_STATE_REL;
|
||||
}
|
||||
|
||||
/*Return `false` because we are not buffering and no more data to read*/
|
||||
return false;
|
||||
}
|
||||
|
||||
void calibrate(uint16_t* calData)
|
||||
{
|
||||
haspTft.tft.fillScreen(TFT_BLACK);
|
||||
haspTft.tft.setCursor(20, 0);
|
||||
haspTft.tft.setTextFont(1);
|
||||
haspTft.tft.setTextSize(1);
|
||||
haspTft.tft.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||
|
||||
// tft.println(PSTR("Touch corners as indicated"));
|
||||
|
||||
haspTft.tft.setTextFont(1);
|
||||
delay(500);
|
||||
haspTft.tft.calibrateTouch(calData, TFT_MAGENTA, TFT_BLACK, 15);
|
||||
haspTft.tft.setTouch(calData);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace dev
|
||||
|
||||
using dev::TouchTftEspi;
|
||||
extern dev::TouchTftEspi haspTouch;
|
||||
|
||||
#endif // ARDUINO
|
||||
|
||||
#endif // HASP_TFTESPI_TOUCH_DRIVER_H
|
46
src/drv/touch/touch_helper.h
Normal file
46
src/drv/touch/touch_helper.h
Normal file
@ -0,0 +1,46 @@
|
||||
/* MIT License - Copyright (c) 2019-2021 Francis Van Roie
|
||||
For full license information read the LICENSE file in the project folder */
|
||||
|
||||
#ifndef HASP_TOUCH_HELPER_H
|
||||
#define HASP_TOUCH_HELPER_H
|
||||
|
||||
#ifdef ARDUINO
|
||||
#include "Arduino.h"
|
||||
#include <Wire.h>
|
||||
#include "ArduinoLog.h"
|
||||
#include "hasp_debug.h"
|
||||
|
||||
void touch_scan(TwoWire& i2c)
|
||||
{
|
||||
char buffer[64];
|
||||
byte error, address;
|
||||
int nDevices;
|
||||
|
||||
LOG_VERBOSE(TAG_DRVR, F("Scanning..."));
|
||||
|
||||
nDevices = 0;
|
||||
for(address = 1; address < 127; address++) {
|
||||
// The i2c_scanner uses the return value of
|
||||
// the Write.endTransmisstion to see if
|
||||
// a device did acknowledge to the address.
|
||||
i2c.beginTransmission(address);
|
||||
error = i2c.endTransmission();
|
||||
|
||||
if(error == 0) {
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("I2C device found at address 0x%02x"), address);
|
||||
LOG_VERBOSE(TAG_DRVR, buffer, address);
|
||||
nDevices++;
|
||||
} else if(error == 4) {
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("Unknown error at address 0x%02x"), address);
|
||||
LOG_VERBOSE(TAG_DRVR, buffer, address);
|
||||
}
|
||||
}
|
||||
if(nDevices == 0)
|
||||
LOG_WARNING(TAG_DRVR, F("No I2C devices found"));
|
||||
else
|
||||
LOG_VERBOSE(TAG_DRVR, F("Scan complete"));
|
||||
}
|
||||
|
||||
#endif // ARDUINO
|
||||
|
||||
#endif // HASP_TOUCH_HELPER_H
|
121
src/hasp_gui.cpp
121
src/hasp_gui.cpp
@ -10,12 +10,13 @@
|
||||
#include "lv_fs_if.h"
|
||||
|
||||
// Device Drivers
|
||||
#include "drv/tft/tft_driver.h"
|
||||
#include "dev/device.h"
|
||||
#include "drv/tft/tft_driver.h"
|
||||
#include "drv/touch/touch_driver.h"
|
||||
|
||||
//#include "drv/hasp_drv_display.h"
|
||||
#include "drv/hasp_drv_touch.h"
|
||||
#include "drv/old/hasp_drv_tft_espi.h"
|
||||
// #include "drv/hasp_drv_touch.h"
|
||||
// #include "drv/old/hasp_drv_tft_espi.h"
|
||||
|
||||
#include "hasp_debug.h"
|
||||
#include "hasp_config.h"
|
||||
@ -78,11 +79,16 @@ IRAM_ATTR void gui_flush_cb(lv_disp_drv_t* disp, const lv_area_t* area, lv_color
|
||||
haspTft.flush_pixels(disp, area, color_p);
|
||||
}
|
||||
|
||||
// IRAM_ATTR bool touch_read(lv_indev_drv_t* indev_driver, lv_indev_data_t* data)
|
||||
// {
|
||||
// return haspTouch.read(indev_driver, data);
|
||||
// }
|
||||
|
||||
void guiCalibrate(void)
|
||||
{
|
||||
#if TOUCH_DRIVER == 2046 && USE_TFT_ESPI > 0
|
||||
#ifdef TOUCH_CS
|
||||
tft_espi_calibrate(gui_settings.cal_data);
|
||||
haspTouch.calibrate(gui_settings.cal_data);
|
||||
#endif
|
||||
|
||||
for(int i = 0; i < 5; i++) {
|
||||
@ -97,7 +103,6 @@ void guiCalibrate(void)
|
||||
|
||||
void guiSetup()
|
||||
{
|
||||
// Register logger to capture lvgl_init output
|
||||
LOG_TRACE(TAG_TFT, F(D_SERVICE_STARTING));
|
||||
|
||||
// Initialize the TFT
|
||||
@ -107,11 +112,6 @@ void guiSetup()
|
||||
haspTft.show_info();
|
||||
|
||||
LOG_INFO(TAG_TFT, F(D_SERVICE_STARTED));
|
||||
LOG_TRACE(TAG_LVGL, F(D_SERVICE_STARTING));
|
||||
|
||||
#if LV_USE_LOG != 0
|
||||
lv_log_register_print_cb(debugLvglLogEvent);
|
||||
#endif
|
||||
|
||||
/* Create the Virtual Device Buffers */
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
@ -159,6 +159,13 @@ void guiSetup()
|
||||
// lv_disp_buf_init(&disp_buf, guiVdbBuffer1, guiVdbBuffer2, guiVDBsize);
|
||||
#endif
|
||||
|
||||
LOG_TRACE(TAG_LVGL, F(D_SERVICE_STARTING));
|
||||
|
||||
#if LV_USE_LOG != 0
|
||||
// Register logger to capture lvgl_init output
|
||||
lv_log_register_print_cb(debugLvglLogEvent);
|
||||
#endif
|
||||
|
||||
/* Initialize lvgl */
|
||||
static lv_disp_buf_t disp_buf;
|
||||
if(guiVdbBuffer1 && guiVDBsize > 0) {
|
||||
@ -171,30 +178,72 @@ void guiSetup()
|
||||
LOG_VERBOSE(TAG_LVGL, F("Version : %u.%u.%u %s"), LVGL_VERSION_MAJOR, LVGL_VERSION_MINOR, LVGL_VERSION_PATCH,
|
||||
PSTR(LVGL_VERSION_INFO));
|
||||
|
||||
/* Initialize the display driver */
|
||||
/* Initialize the LVGL display driver with correct orientation */
|
||||
#if TOUCH_DRIVER == 2046
|
||||
|
||||
static lv_disp_drv_t disp_drv;
|
||||
lv_disp_drv_init(&disp_drv);
|
||||
disp_drv.buffer = &disp_buf;
|
||||
disp_drv.flush_cb = gui_flush_cb;
|
||||
disp_drv.hor_res = tft_width;
|
||||
disp_drv.ver_res = tft_height;
|
||||
|
||||
switch(gui_settings.rotation) {
|
||||
case 1:
|
||||
case 3:
|
||||
case 5:
|
||||
case 7:
|
||||
// lv_disp_set_rotation(display, LV_DISP_ROT_90);
|
||||
disp_drv.hor_res = tft_height;
|
||||
disp_drv.ver_res = tft_width;
|
||||
break;
|
||||
default:
|
||||
// lv_disp_set_rotation(display, LV_DISP_ROT_NONE);
|
||||
disp_drv.hor_res = tft_width;
|
||||
disp_drv.ver_res = tft_height;
|
||||
if(gui_settings.rotation % 2) {
|
||||
disp_drv.hor_res = tft_height;
|
||||
disp_drv.ver_res = tft_width;
|
||||
} else {
|
||||
disp_drv.hor_res = tft_width;
|
||||
disp_drv.ver_res = tft_height;
|
||||
}
|
||||
|
||||
lv_disp_t* display = lv_disp_drv_register(&disp_drv);
|
||||
(void)display; // unused
|
||||
lv_disp_set_rotation(display, LV_DISP_ROT_NONE);
|
||||
|
||||
#else
|
||||
|
||||
#if defined(LANBONL8)
|
||||
|
||||
static lv_disp_drv_t disp_drv;
|
||||
lv_disp_drv_init(&disp_drv);
|
||||
disp_drv.buffer = &disp_buf;
|
||||
disp_drv.flush_cb = gui_flush_cb;
|
||||
|
||||
disp_drv.hor_res = tft_width;
|
||||
disp_drv.ver_res = tft_height;
|
||||
|
||||
lv_disp_rot_t rotation[] = {LV_DISP_ROT_NONE, LV_DISP_ROT_270, LV_DISP_ROT_180, LV_DISP_ROT_90};
|
||||
lv_disp_t* display = lv_disp_drv_register(&disp_drv);
|
||||
lv_disp_set_rotation(display, rotation[(4 + gui_settings.rotation - TFT_ROTATION) % 4]);
|
||||
|
||||
#elif defined(M5STACK)
|
||||
|
||||
static lv_disp_drv_t disp_drv;
|
||||
lv_disp_drv_init(&disp_drv);
|
||||
disp_drv.buffer = &disp_buf;
|
||||
disp_drv.flush_cb = gui_flush_cb;
|
||||
|
||||
disp_drv.hor_res = tft_height;
|
||||
disp_drv.ver_res = tft_width;
|
||||
|
||||
lv_disp_rot_t rotation[] = {LV_DISP_ROT_NONE, LV_DISP_ROT_270, LV_DISP_ROT_180, LV_DISP_ROT_90};
|
||||
lv_disp_t* display = lv_disp_drv_register(&disp_drv);
|
||||
lv_disp_set_rotation(display, rotation[(4 + gui_settings.rotation - TFT_ROTATION) % 4]);
|
||||
|
||||
#else
|
||||
|
||||
static lv_disp_drv_t disp_drv;
|
||||
lv_disp_drv_init(&disp_drv);
|
||||
disp_drv.buffer = &disp_buf;
|
||||
disp_drv.flush_cb = gui_flush_cb;
|
||||
|
||||
disp_drv.hor_res = tft_width;
|
||||
disp_drv.ver_res = tft_height;
|
||||
|
||||
lv_disp_rot_t rotation[] = {LV_DISP_ROT_NONE, LV_DISP_ROT_270, LV_DISP_ROT_180, LV_DISP_ROT_90};
|
||||
lv_disp_t* display = lv_disp_drv_register(&disp_drv);
|
||||
lv_disp_set_rotation(display, rotation[(4 + gui_settings.rotation - TFT_ROTATION) % 4]);
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* Initialize Filesystems */
|
||||
#if LV_USE_FS_IF != 0
|
||||
@ -243,7 +292,7 @@ void guiSetup()
|
||||
#if defined(WINDOWS) || defined(POSIX)
|
||||
indev_drv.read_cb = mouse_read;
|
||||
#else
|
||||
indev_drv.read_cb = drv_touch_read;
|
||||
indev_drv.read_cb = touch_read;
|
||||
#endif
|
||||
lv_indev_t* mouse_indev = lv_indev_drv_register(&indev_drv);
|
||||
mouse_indev->driver.type = LV_INDEV_TYPE_POINTER;
|
||||
@ -273,7 +322,9 @@ void guiSetup()
|
||||
}
|
||||
|
||||
#if !(defined(WINDOWS) || defined(POSIX))
|
||||
drv_touch_init(gui_settings.rotation); // Touch driver
|
||||
// drv_touch_init(gui_settings.rotation); // Touch driver
|
||||
haspTouch.init(tft_width, tft_height);
|
||||
haspTouch.set_rotation(gui_settings.rotation);
|
||||
#endif
|
||||
|
||||
/* Initialize Global progress bar*/
|
||||
@ -305,7 +356,8 @@ IRAM_ATTR void guiLoop(void)
|
||||
#endif
|
||||
|
||||
#if !(defined(WINDOWS) || defined(POSIX))
|
||||
drv_touch_loop(); // update touch
|
||||
// drv_touch_loop(); // update touch
|
||||
haspTouch.loop();
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -376,7 +428,8 @@ bool guiGetConfig(const JsonObject& settings)
|
||||
changed = true;
|
||||
|
||||
#if TOUCH_DRIVER == 2046 && USE_TFT_ESPI > 0 && defined(TOUCH_CS)
|
||||
tft_espi_set_touch(gui_settings.cal_data);
|
||||
// tft_espi_set_touch(gui_settings.cal_data);
|
||||
haspTft.tft.setTouch(gui_settings.cal_data);
|
||||
#endif
|
||||
}
|
||||
i++;
|
||||
@ -391,7 +444,8 @@ bool guiGetConfig(const JsonObject& settings)
|
||||
changed = true;
|
||||
|
||||
#if TOUCH_DRIVER == 2046 && USE_TFT_ESPI > 0 && defined(TOUCH_CS)
|
||||
tft_espi_set_touch(gui_settings.cal_data);
|
||||
// tft_espi_set_touch(gui_settings.cal_data);
|
||||
haspTft.tft.setTouch(gui_settings.cal_data);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -459,7 +513,8 @@ bool guiSetConfig(const JsonObject& settings)
|
||||
}
|
||||
|
||||
#if TOUCH_DRIVER == 2046 && USE_TFT_ESPI > 0 && defined(TOUCH_CS)
|
||||
if(status) tft_espi_set_touch(gui_settings.cal_data);
|
||||
if(status) // tft_espi_set_touch(gui_settings.cal_data);
|
||||
haspTft.tft.setTouch(gui_settings.cal_data);
|
||||
#endif
|
||||
changed |= status;
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include "hasp_oobe.h"
|
||||
#include "sys/net/hasp_network.h"
|
||||
#include "dev/device.h"
|
||||
#include "drv/hasp_drv_touch.h"
|
||||
// #include "drv/hasp_drv_touch.h"
|
||||
#include "ArduinoLog.h"
|
||||
|
||||
#if HASP_USE_CONFIG > 0
|
||||
@ -22,7 +22,10 @@
|
||||
bool isConnected;
|
||||
uint8_t mainLoopCounter = 0;
|
||||
unsigned long mainLastLoopTime = 0;
|
||||
uint8_t statLoopCounter = 0;
|
||||
|
||||
#ifdef HASP_USE_STAT_COUNTER
|
||||
uint8_t statLoopCounter = 0; // measures the average looptime
|
||||
#endif
|
||||
|
||||
void setup()
|
||||
{
|
||||
@ -115,12 +118,16 @@ IRAM_ATTR void loop()
|
||||
networkLoop();
|
||||
|
||||
#if HASP_USE_GPIO > 0
|
||||
gpioLoop();
|
||||
// gpioLoop();
|
||||
// Should be called every 4-5ms or faster, for the default debouncing time of ~20ms.
|
||||
for(uint8_t i = 0; i < HASP_NUM_GPIO_CONFIG; i++) {
|
||||
if(gpioConfig[i].btn) gpioConfig[i].btn->check();
|
||||
}
|
||||
#endif // GPIO
|
||||
|
||||
#if HASP_USE_MQTT > 0
|
||||
mqttLoop();
|
||||
#endif // MQTT
|
||||
mqttClient.loop(); // mqttLoop();
|
||||
#endif
|
||||
|
||||
// haspDevice.loop();
|
||||
|
||||
@ -129,7 +136,10 @@ IRAM_ATTR void loop()
|
||||
consoleLoop();
|
||||
#endif
|
||||
|
||||
statLoopCounter++;
|
||||
#ifdef HASP_USE_STAT_COUNTER
|
||||
statLoopCounter++; // measures the average looptime
|
||||
#endif
|
||||
|
||||
/* Timer Loop */
|
||||
if(millis() - mainLastLoopTime >= 1000) {
|
||||
mainLastLoopTime += 1000;
|
||||
@ -170,10 +180,11 @@ IRAM_ATTR void loop()
|
||||
|
||||
case 5:
|
||||
mainLoopCounter = 0;
|
||||
// if(statLoopCounter)
|
||||
// LOG_VERBOSE(TAG_MAIN, F("%d millis per loop, %d counted"), 5000 / statLoopCounter,
|
||||
// statLoopCounter);
|
||||
// statLoopCounter = 0;
|
||||
#ifdef HASP_USE_STAT_COUNTER
|
||||
if(statLoopCounter)
|
||||
LOG_VERBOSE(TAG_MAIN, F("%d millis per loop, %d counted"), 5000 / statLoopCounter, statLoopCounter);
|
||||
statLoopCounter = 0;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -31,8 +31,8 @@ build_flags =
|
||||
-D TOUCH_IRQ=27
|
||||
-D TOUCH_RST=-1 ; not used
|
||||
-D TOUCH_FREQUENCY=400000
|
||||
-D SPI_FREQUENCY=27000000
|
||||
-D SPI_READ_FREQUENCY=16000000
|
||||
-D SPI_FREQUENCY=40000000
|
||||
-D SPI_READ_FREQUENCY=20000000
|
||||
;endregion
|
||||
|
||||
; -- Debugging options -----------------------------
|
||||
|
@ -33,7 +33,7 @@ m5stack =
|
||||
-D INVERT_COLORS=1 ;-D TFT_INVERSION_ON ; for inverted colors
|
||||
-D TFT_WIDTH=240
|
||||
-D TFT_HEIGHT=320
|
||||
-D TFT_ROTATION=0 ; Use default, see TFT_ROTATION values
|
||||
-D TFT_ROTATION=1 ; Use default, see TFT_ROTATION values
|
||||
-D SPI_FREQUENCY=60000000 ; can't handle 80 Mhz
|
||||
-D SPI_READ_FREQUENCY=16000000
|
||||
-D USER_SETUP_LOADED=1
|
||||
|
Loading…
x
Reference in New Issue
Block a user