mirror of
https://github.com/meshtastic/firmware.git
synced 2025-08-05 13:14:45 +00:00
using the original touchscreen implementation
This commit is contained in:
parent
b761dcb1a6
commit
273e480ebe
12
.vscode/settings.json
vendored
12
.vscode/settings.json
vendored
@ -10,5 +10,17 @@
|
|||||||
},
|
},
|
||||||
"[powershell]": {
|
"[powershell]": {
|
||||||
"editor.defaultFormatter": "ms-vscode.powershell"
|
"editor.defaultFormatter": "ms-vscode.powershell"
|
||||||
|
},
|
||||||
|
"files.associations": {
|
||||||
|
"array": "cpp",
|
||||||
|
"deque": "cpp",
|
||||||
|
"list": "cpp",
|
||||||
|
"string": "cpp",
|
||||||
|
"unordered_map": "cpp",
|
||||||
|
"unordered_set": "cpp",
|
||||||
|
"vector": "cpp",
|
||||||
|
"string_view": "cpp",
|
||||||
|
"initializer_list": "cpp",
|
||||||
|
"*.tpp": "cpp"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1837,9 +1837,6 @@ void Screen::setup()
|
|||||||
touchScreenImpl1 =
|
touchScreenImpl1 =
|
||||||
new TouchScreenImpl1(dispdev->getWidth(), dispdev->getHeight(), static_cast<TFTDisplay *>(dispdev)->getTouch);
|
new TouchScreenImpl1(dispdev->getWidth(), dispdev->getHeight(), static_cast<TFTDisplay *>(dispdev)->getTouch);
|
||||||
touchScreenImpl1->init();
|
touchScreenImpl1->init();
|
||||||
#elif HAS_TOUCHSCREEN && HAS_CST226SE
|
|
||||||
touchScreenCST226SE = new TouchScreenCST226SE(TFT_HEIGHT, TFT_WIDTH);
|
|
||||||
touchScreenCST226SE->init();
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Subscribe to status updates
|
// Subscribe to status updates
|
||||||
|
@ -1,104 +0,0 @@
|
|||||||
#include "TouchScreenCST226SE.h"
|
|
||||||
#include "variant.h"
|
|
||||||
|
|
||||||
#ifdef HAS_CST226SE
|
|
||||||
|
|
||||||
#ifndef TOUCH_IRQ
|
|
||||||
#define TOUCH_IRQ -1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "PowerFSM.h"
|
|
||||||
#include "Wire.h"
|
|
||||||
#include "configuration.h"
|
|
||||||
#include "modules/ExternalNotificationModule.h"
|
|
||||||
|
|
||||||
volatile bool isPressed = false;
|
|
||||||
|
|
||||||
TouchScreenCST226SE *touchScreenCST226SE;
|
|
||||||
|
|
||||||
TouchScreenCST226SE::TouchScreenCST226SE(uint16_t width, uint16_t height) : TouchScreenBase("CST226", width, height) {}
|
|
||||||
|
|
||||||
void TouchScreenCST226SE::init()
|
|
||||||
{
|
|
||||||
touch.setPins(-1, TOUCH_IRQ);
|
|
||||||
touch.setTouchDrvModel(TouchDrv_CST226);
|
|
||||||
for (uint8_t addr : PossibleAddresses) {
|
|
||||||
if (touch.begin(Wire, addr, I2C_SDA, I2C_SCL)) {
|
|
||||||
i2cAddress = addr;
|
|
||||||
if (TOUCH_IRQ != -1) {
|
|
||||||
pinMode(TOUCH_IRQ, INPUT_PULLUP);
|
|
||||||
attachInterrupt(
|
|
||||||
TOUCH_IRQ, []() { isPressed = true; }, FALLING);
|
|
||||||
}
|
|
||||||
LOG_DEBUG("CST226SE init OK at address 0x%02X", addr);
|
|
||||||
inputBroker->registerSource(this);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
LOG_ERROR("CST226SE init failed at all known addresses");
|
|
||||||
}
|
|
||||||
|
|
||||||
bool TouchScreenCST226SE::getTouch(int16_t &x, int16_t &y)
|
|
||||||
{
|
|
||||||
int16_t x_array[1], y_array[1];
|
|
||||||
uint8_t touched = touch.getPoint(x_array, y_array, 1);
|
|
||||||
if (touched > 0) {
|
|
||||||
y = x_array[0];
|
|
||||||
x = (TFT_WIDTH - y_array[0]);
|
|
||||||
// Check bounds
|
|
||||||
if (x < 0 || x >= TFT_WIDTH || y < 0 || y >= TFT_HEIGHT) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true; // Valid touch detected
|
|
||||||
}
|
|
||||||
return false; // No valid touch data
|
|
||||||
}
|
|
||||||
|
|
||||||
void TouchScreenCST226SE::onEvent(const TouchEvent &event)
|
|
||||||
{
|
|
||||||
InputEvent e;
|
|
||||||
e.source = event.source;
|
|
||||||
|
|
||||||
e.touchX = event.x;
|
|
||||||
e.touchY = event.y;
|
|
||||||
|
|
||||||
switch (event.touchEvent) {
|
|
||||||
case TOUCH_ACTION_LEFT: {
|
|
||||||
e.inputEvent = static_cast<char>(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_RIGHT);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case TOUCH_ACTION_RIGHT: {
|
|
||||||
e.inputEvent = static_cast<char>(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_LEFT);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case TOUCH_ACTION_UP: {
|
|
||||||
e.inputEvent = static_cast<char>(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_UP);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case TOUCH_ACTION_DOWN: {
|
|
||||||
e.inputEvent = static_cast<char>(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_DOWN);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case TOUCH_ACTION_DOUBLE_TAP: {
|
|
||||||
e.inputEvent = static_cast<char>(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_SELECT);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case TOUCH_ACTION_LONG_PRESS: {
|
|
||||||
e.inputEvent = static_cast<char>(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_CANCEL);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case TOUCH_ACTION_TAP: {
|
|
||||||
if (moduleConfig.external_notification.enabled && (externalNotificationModule->nagCycleCutoff != UINT32_MAX)) {
|
|
||||||
externalNotificationModule->stopNow();
|
|
||||||
} else {
|
|
||||||
powerFSM.trigger(EVENT_INPUT);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this->notifyObservers(&e);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,30 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "variant.h"
|
|
||||||
|
|
||||||
#ifdef HAS_CST226SE
|
|
||||||
|
|
||||||
#include "modules/CannedMessageModule.h"
|
|
||||||
|
|
||||||
#include "TouchDrvCSTXXX.hpp"
|
|
||||||
#include "TouchScreenBase.h"
|
|
||||||
|
|
||||||
class TouchScreenCST226SE : public TouchScreenBase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
TouchScreenCST226SE(uint16_t width, uint16_t height);
|
|
||||||
void init(void);
|
|
||||||
virtual bool getTouch(int16_t &x, int16_t &y);
|
|
||||||
virtual void onEvent(const TouchEvent &event);
|
|
||||||
|
|
||||||
private:
|
|
||||||
static TouchScreenCST226SE *instance;
|
|
||||||
TouchDrvCSTXXX touch;
|
|
||||||
uint8_t i2cAddress = 0;
|
|
||||||
static constexpr uint8_t PossibleAddresses[2] = {CST226SE_ADDR, CST226SE_ADDR_ALT};
|
|
||||||
};
|
|
||||||
|
|
||||||
// For global reference in other code
|
|
||||||
extern TouchScreenCST226SE *touchScreenCST226SE;
|
|
||||||
|
|
||||||
#endif
|
|
51
src/platform/extra_variants/tbeam_displayshield/variant.cpp
Normal file
51
src/platform/extra_variants/tbeam_displayshield/variant.cpp
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
#include "configuration.h"
|
||||||
|
|
||||||
|
#ifdef HAS_CST226SE
|
||||||
|
|
||||||
|
#include "TouchDrvCSTXXX.hpp"
|
||||||
|
#include "input/TouchScreenImpl1.h"
|
||||||
|
#include <Wire.h>
|
||||||
|
|
||||||
|
TouchDrvCSTXXX tsPanel;
|
||||||
|
static constexpr uint8_t PossibleAddresses[2] = {CST226SE_ADDR, CST226SE_ADDR_ALT};
|
||||||
|
volatile bool isPressed = false;
|
||||||
|
uint8_t i2cAddress = 0;
|
||||||
|
|
||||||
|
bool readTouch(int16_t *x, int16_t *y)
|
||||||
|
{
|
||||||
|
int16_t x_array[1], y_array[1];
|
||||||
|
uint8_t touched = tsPanel.getPoint(x_array, y_array, 1);
|
||||||
|
if (touched > 0) {
|
||||||
|
*y = x_array[0];
|
||||||
|
*x = (TFT_WIDTH - y_array[0]);
|
||||||
|
|
||||||
|
// Check bounds
|
||||||
|
if (*x < 0 || *x >= TFT_WIDTH || *y < 0 || *y >= TFT_HEIGHT) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true; // Valid touch detected
|
||||||
|
}
|
||||||
|
return false; // No valid touch data
|
||||||
|
}
|
||||||
|
|
||||||
|
void lateInitVariant()
|
||||||
|
{
|
||||||
|
tsPanel.setPins(-1, TOUCH_IRQ);
|
||||||
|
tsPanel.setTouchDrvModel(TouchDrv_CST226);
|
||||||
|
for (uint8_t addr : PossibleAddresses) {
|
||||||
|
if (tsPanel.begin(Wire, addr, I2C_SDA, I2C_SCL)) {
|
||||||
|
i2cAddress = addr;
|
||||||
|
if (TOUCH_IRQ != -1) {
|
||||||
|
pinMode(TOUCH_IRQ, INPUT_PULLUP);
|
||||||
|
attachInterrupt(
|
||||||
|
TOUCH_IRQ, []() { isPressed = true; }, FALLING);
|
||||||
|
}
|
||||||
|
LOG_DEBUG("CST226SE init OK at address 0x%02X", addr);
|
||||||
|
touchScreenImpl1 = new TouchScreenImpl1(TFT_WIDTH, TFT_HEIGHT, readTouch);
|
||||||
|
touchScreenImpl1->init();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LOG_ERROR("CST226SE init failed at all known addresses");
|
||||||
|
}
|
||||||
|
#endif
|
@ -54,6 +54,9 @@
|
|||||||
#define HAS_CST226SE 1
|
#define HAS_CST226SE 1
|
||||||
#define HAS_TOUCHSCREEN 1
|
#define HAS_TOUCHSCREEN 1
|
||||||
// #define TOUCH_IRQ 35 // broken in this version of the lib 0.3.1
|
// #define TOUCH_IRQ 35 // broken in this version of the lib 0.3.1
|
||||||
|
#ifndef TOUCH_IRQ
|
||||||
|
#define TOUCH_IRQ -1
|
||||||
|
#endif
|
||||||
#define CANNED_MESSAGE_MODULE_ENABLE 1
|
#define CANNED_MESSAGE_MODULE_ENABLE 1
|
||||||
#define USE_VIRTUAL_KEYBOARD 1
|
#define USE_VIRTUAL_KEYBOARD 1
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user