mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-08 22:22:05 +00:00
changed to sensorlib 0.3.1
This commit is contained in:
parent
0f1e528b20
commit
f5c3e77a60
@ -3,35 +3,38 @@
|
|||||||
|
|
||||||
#ifdef HAS_CST226SE
|
#ifdef HAS_CST226SE
|
||||||
|
|
||||||
|
#ifndef TOUCH_IRQ
|
||||||
|
#define TOUCH_IRQ -1
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "PowerFSM.h"
|
#include "PowerFSM.h"
|
||||||
#include "Wire.h"
|
#include "Wire.h"
|
||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
#include "modules/ExternalNotificationModule.h"
|
#include "modules/ExternalNotificationModule.h"
|
||||||
|
|
||||||
volatile bool CST_IRQ = false;
|
volatile bool isPressed = false;
|
||||||
|
|
||||||
TouchScreenCST226SE *TouchScreenCST226SE::instance = nullptr;
|
TouchScreenCST226SE *TouchScreenCST226SE::instance = nullptr;
|
||||||
TouchScreenCST226SE *touchScreenCST226SE;
|
TouchScreenCST226SE *touchScreenCST226SE;
|
||||||
|
|
||||||
TouchScreenCST226SE::TouchScreenCST226SE(uint16_t width, uint16_t height, bool (*getTouch)(int16_t *, int16_t *))
|
TouchScreenCST226SE::TouchScreenCST226SE(uint16_t width, uint16_t height, bool (*getTouch)(int16_t *, int16_t *))
|
||||||
: TouchScreenBase("touchscreen1", width, height), _getTouch(getTouch)
|
: TouchScreenBase("CST226", width, height), _getTouch(getTouch)
|
||||||
{
|
{
|
||||||
instance = this;
|
instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TouchScreenCST226SE::init()
|
void TouchScreenCST226SE::init()
|
||||||
{
|
{
|
||||||
|
touch.setPins(-1, TOUCH_IRQ);
|
||||||
|
touch.setTouchDrvModel(TouchDrv_CST226);
|
||||||
for (uint8_t addr : PossibleAddresses) {
|
for (uint8_t addr : PossibleAddresses) {
|
||||||
if (touch.begin(Wire, addr, I2C_SDA, I2C_SCL)) {
|
if (touch.begin(Wire, addr, I2C_SDA, I2C_SCL)) {
|
||||||
i2cAddress = addr;
|
i2cAddress = addr;
|
||||||
|
attachInterrupt(
|
||||||
// #ifdef TOUCHSCREEN_INT
|
TOUCH_IRQ, []() { isPressed = true; }, FALLING);
|
||||||
// pinMode(TOUCHSCREEN_INT, INPUT);
|
|
||||||
// attachInterrupt(
|
|
||||||
// TOUCHSCREEN_INT, [] { CST_IRQ = true; }, RISING);
|
|
||||||
// #endif
|
|
||||||
|
|
||||||
LOG_DEBUG("CST226SE init OK at address 0x%02X", addr);
|
LOG_DEBUG("CST226SE init OK at address 0x%02X", addr);
|
||||||
|
touch.setMaxCoordinates(TFT_WIDTH + 5, TFT_HEIGHT + 5);
|
||||||
|
touch.setMirrorXY(true, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -41,17 +44,18 @@ void TouchScreenCST226SE::init()
|
|||||||
|
|
||||||
bool TouchScreenCST226SE::getTouch(int16_t &x, int16_t &y)
|
bool TouchScreenCST226SE::getTouch(int16_t &x, int16_t &y)
|
||||||
{
|
{
|
||||||
if (!touch.isPressed())
|
if (!touch.isPressed()) {
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
int16_t x_array[1], y_array[1];
|
int16_t x_array[1], y_array[1];
|
||||||
uint8_t count = touch.getPoint(x_array, y_array, 1);
|
uint8_t touched = touch.getPoint(x_array, y_array, 1);
|
||||||
if (count > 0) {
|
if (touched > 0) {
|
||||||
x = x_array[0];
|
x = x_array[0];
|
||||||
y = y_array[0];
|
y = y_array[0];
|
||||||
return true;
|
LOG_DEBUG("TouchScreen touched %dx %dy", x, y);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,10 +63,10 @@ bool TouchScreenCST226SE::forwardGetTouch(int16_t *x, int16_t *y)
|
|||||||
{
|
{
|
||||||
if (instance) {
|
if (instance) {
|
||||||
return instance->getTouch(*x, *y);
|
return instance->getTouch(*x, *y);
|
||||||
LOG_DEBUG("TouchScreen touched %dx %dy", x, y);
|
LOG_DEBUG("TouchScreen parsed %dx %dy", x, y);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TouchScreenCST226SE::onEvent(const TouchEvent &event)
|
void TouchScreenCST226SE::onEvent(const TouchEvent &event)
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
|
|
||||||
#include "modules/CannedMessageModule.h"
|
#include "modules/CannedMessageModule.h"
|
||||||
|
|
||||||
|
#include "TouchDrvCSTXXX.hpp"
|
||||||
#include "TouchScreenBase.h"
|
#include "TouchScreenBase.h"
|
||||||
#include "touch/TouchClassCST226.h"
|
|
||||||
|
|
||||||
class TouchScreenCST226SE : public TouchScreenBase
|
class TouchScreenCST226SE : public TouchScreenBase
|
||||||
{
|
{
|
||||||
@ -17,14 +17,12 @@ class TouchScreenCST226SE : public TouchScreenBase
|
|||||||
|
|
||||||
static bool forwardGetTouch(int16_t *x, int16_t *y);
|
static bool forwardGetTouch(int16_t *x, int16_t *y);
|
||||||
bool (*_getTouch)(int16_t *, int16_t *);
|
bool (*_getTouch)(int16_t *, int16_t *);
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual bool getTouch(int16_t &x, int16_t &y);
|
virtual bool getTouch(int16_t &x, int16_t &y);
|
||||||
virtual void onEvent(const TouchEvent &event);
|
virtual void onEvent(const TouchEvent &event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static TouchScreenCST226SE *instance;
|
static TouchScreenCST226SE *instance;
|
||||||
TouchClassCST226 touch;
|
TouchDrvCSTXXX touch;
|
||||||
uint8_t i2cAddress = 0;
|
uint8_t i2cAddress = 0;
|
||||||
|
|
||||||
static constexpr uint8_t PossibleAddresses[2] = {CST226SE_ADDR, CST226SE_ADDR_ALT};
|
static constexpr uint8_t PossibleAddresses[2] = {CST226SE_ADDR, CST226SE_ADDR_ALT};
|
||||||
|
@ -22,4 +22,4 @@ build_flags =
|
|||||||
lib_deps =
|
lib_deps =
|
||||||
${env:tbeam.lib_deps}
|
${env:tbeam.lib_deps}
|
||||||
https://github.com/Nasimovy/st7796/archive/refs/tags/1.0.5.zip ; display addon
|
https://github.com/Nasimovy/st7796/archive/refs/tags/1.0.5.zip ; display addon
|
||||||
lewisxhe/SensorLib@0.2.0 ; touchscreen addon
|
lewisxhe/SensorLib@0.3.1 ; touchscreen addon
|
||||||
|
@ -53,7 +53,7 @@
|
|||||||
|
|
||||||
#define HAS_CST226SE 1
|
#define HAS_CST226SE 1
|
||||||
#define HAS_TOUCHSCREEN 1
|
#define HAS_TOUCHSCREEN 1
|
||||||
#define TOUCHSCREEN_INT 35
|
#define TOUCH_IRQ 35
|
||||||
|
|
||||||
#define ST7796_NSS 25
|
#define ST7796_NSS 25
|
||||||
#define ST7796_RS 13 // DC
|
#define ST7796_RS 13 // DC
|
||||||
|
Loading…
Reference in New Issue
Block a user