v0.8.03b
This commit is contained in:
@@ -6,6 +6,10 @@
|
||||
|
||||
Config config;
|
||||
|
||||
#if DSP_HSPI || TS_HSPI || VS_HSPI
|
||||
SPIClass SPI2(HSPI);
|
||||
#endif
|
||||
|
||||
void u8fix(char *src){
|
||||
char last = src[strlen(src)-1];
|
||||
if ((uint8_t)last >= 0xC2) src[strlen(src)-1]='\0';
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define config_h
|
||||
#include "Arduino.h"
|
||||
#include <Ticker.h>
|
||||
#include <SPI.h>
|
||||
#include "options.h"
|
||||
|
||||
#define EEPROM_SIZE 768
|
||||
@@ -184,5 +185,9 @@ class Config {
|
||||
};
|
||||
|
||||
extern Config config;
|
||||
#if DSP_HSPI || TS_HSPI || VS_HSPI
|
||||
extern SPIClass SPI2;
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -42,9 +42,9 @@ yoEncoder encoder2 = yoEncoder(ENC2_BTNL, ENC2_BTNR, ENCODER2_STEPS, ENC2_INTERN
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if TS_CS!=255
|
||||
#include <XPT2046_Touchscreen.h>
|
||||
XPT2046_Touchscreen ts(TS_CS);
|
||||
#if TS_MODEL!=TS_MODEL_UNDEFINED
|
||||
#include "touchscreen.h"
|
||||
TouchScreen touchscreen;
|
||||
#endif
|
||||
|
||||
#if IR_PIN!=255
|
||||
@@ -113,9 +113,8 @@ void initControls() {
|
||||
button[i].setPressTicks(BTN_PRESS_TICKS);
|
||||
}
|
||||
#endif
|
||||
#if TS_CS!=255
|
||||
ts.begin();
|
||||
ts.setRotation(config.store.fliptouch?3:1);
|
||||
#if TS_MODEL!=TS_MODEL_UNDEFINED
|
||||
touchscreen.init();
|
||||
#endif
|
||||
#if IR_PIN!=255
|
||||
pinMode(IR_PIN, INPUT);
|
||||
@@ -145,18 +144,15 @@ void loopControls() {
|
||||
if (lpId >= 0) {
|
||||
if (DSP_MODEL == DSP_DUMMY && (lpId == 4 || lpId == 5)) continue;
|
||||
onBtnDuringLongPress(lpId);
|
||||
yield();
|
||||
}
|
||||
yield();
|
||||
}
|
||||
#endif
|
||||
#if IR_PIN!=255
|
||||
irLoop();
|
||||
#endif
|
||||
#if TS_CS!=255
|
||||
touchLoop();
|
||||
#if TS_MODEL!=TS_MODEL_UNDEFINED
|
||||
touchscreen.loop();
|
||||
#endif
|
||||
yield();
|
||||
}
|
||||
|
||||
#if ENC_BTNL!=255
|
||||
@@ -326,122 +322,6 @@ void irLoop() {
|
||||
}
|
||||
#endif // if IR_PIN!=255
|
||||
|
||||
#if TS_CS!=255
|
||||
#ifndef TS_X_MIN
|
||||
#define TS_X_MIN 400
|
||||
#endif
|
||||
#ifndef TS_X_MAX
|
||||
#define TS_X_MAX 3800
|
||||
#endif
|
||||
#ifndef TS_Y_MIN
|
||||
#define TS_Y_MIN 260
|
||||
#endif
|
||||
#ifndef TS_Y_MAX
|
||||
#define TS_Y_MAX 3800
|
||||
#endif
|
||||
#ifndef TS_STEPS
|
||||
#define TS_STEPS 40
|
||||
#endif
|
||||
|
||||
boolean wastouched = true;
|
||||
unsigned long touchdelay;
|
||||
uint16_t touchVol, touchStation;
|
||||
uint16_t oldTouchP[2];
|
||||
tsDirection_e direct;
|
||||
unsigned long touchLongPress;
|
||||
|
||||
tsDirection_e tsDirection(uint16_t x, uint16_t y) {
|
||||
int16_t dX = x - oldTouchP[0];
|
||||
int16_t dY = y - oldTouchP[1];
|
||||
if (abs(dX) > 20 || abs(dY) > 20) {
|
||||
if (abs(dX) > abs(dY)) {
|
||||
if (dX > 0) {
|
||||
return TSD_RIGHT;
|
||||
} else {
|
||||
return TSD_LEFT;
|
||||
}
|
||||
} else {
|
||||
if (dY > 0) {
|
||||
return TSD_DOWN;
|
||||
} else {
|
||||
return TSD_UP;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return TDS_REQUEST;
|
||||
}
|
||||
}
|
||||
|
||||
void touchLoop() {
|
||||
if (!checklpdelay(100, touchdelay)) return;
|
||||
boolean istouched = ts.touched();
|
||||
if (istouched) {
|
||||
TS_Point p = ts.getPoint();
|
||||
uint16_t touchX = map(p.x, TS_X_MIN, TS_X_MAX, 0, dsp.width());
|
||||
uint16_t touchY = map(p.y, TS_Y_MIN, TS_Y_MAX, 0, dsp.height());
|
||||
if (!wastouched) { /* START TOUCH */
|
||||
oldTouchP[0] = touchX;
|
||||
oldTouchP[1] = touchY;
|
||||
touchVol = touchX;
|
||||
touchStation = touchY;
|
||||
direct = TDS_REQUEST;
|
||||
touchLongPress=millis();
|
||||
} else { /* SWIPE TOUCH */
|
||||
direct = tsDirection(touchX, touchY);
|
||||
switch (direct) {
|
||||
case TSD_LEFT:
|
||||
case TSD_RIGHT: {
|
||||
touchLongPress=millis();
|
||||
if(display.mode()==PLAYER || display.mode()==VOL){
|
||||
int16_t xDelta = map(abs(touchVol - touchX), 0, dsp.width(), 0, TS_STEPS);
|
||||
display.putRequest(NEWMODE, VOL);
|
||||
if (xDelta>1) {
|
||||
controlsEvent((touchVol - touchX)<0);
|
||||
touchVol = touchX;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TSD_UP:
|
||||
case TSD_DOWN: {
|
||||
touchLongPress=millis();
|
||||
if(display.mode()==PLAYER || display.mode()==STATIONS){
|
||||
int16_t yDelta = map(abs(touchStation - touchY), 0, dsp.height(), 0, TS_STEPS);
|
||||
display.putRequest(NEWMODE, STATIONS);
|
||||
if (yDelta>1) {
|
||||
controlsEvent((touchStation - touchY)<0);
|
||||
touchStation = touchY;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (config.store.dbgtouch) {
|
||||
Serial.print(", x = ");
|
||||
Serial.print(p.x);
|
||||
Serial.print(", y = ");
|
||||
Serial.println(p.y);
|
||||
}
|
||||
} else {
|
||||
if (wastouched) {/* END TOUCH */
|
||||
if (direct == TDS_REQUEST) {
|
||||
uint32_t pressTicks = millis()-touchLongPress;
|
||||
if( pressTicks < BTN_PRESS_TICKS*2){
|
||||
if(pressTicks > 50) onBtnClick(EVT_BTNCENTER);
|
||||
}else{
|
||||
display.putRequest(NEWMODE, display.mode() == PLAYER ? STATIONS : PLAYER);
|
||||
}
|
||||
}
|
||||
direct = TSD_STAY;
|
||||
}
|
||||
}
|
||||
wastouched = istouched;
|
||||
}
|
||||
#endif // if TS_CS!=255
|
||||
|
||||
void onBtnLongPressStart(int id) {
|
||||
switch ((controlEvt_e)id) {
|
||||
case EVT_BTNLEFT:
|
||||
@@ -629,7 +509,7 @@ void setEncAcceleration(uint16_t acc){
|
||||
#endif
|
||||
}
|
||||
void flipTS(){
|
||||
#if TS_CS!=255
|
||||
ts.setRotation(config.store.fliptouch?3:1);
|
||||
#if TS_MODEL!=TS_MODEL_UNDEFINED
|
||||
touchscreen.flip();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
enum controlEvt_e { EVT_BTNLEFT, EVT_BTNCENTER, EVT_BTNRIGHT, EVT_ENCBTNB, EVT_BTNUP, EVT_BTNDOWN, EVT_ENC2BTNB };
|
||||
|
||||
enum tsDirection_e { TSD_STAY, TSD_LEFT, TSD_RIGHT, TSD_UP, TSD_DOWN, TDS_REQUEST };
|
||||
//enum tsDirection_e { TSD_STAY, TSD_LEFT, TSD_RIGHT, TSD_UP, TSD_DOWN, TDS_REQUEST };
|
||||
|
||||
#if IR_PIN!=255
|
||||
enum : uint8_t { IR_UP=0, IR_PREV=1, IR_PLAY=2, IR_NEXT=3, IR_DOWN=4, IR_1=5, IR_2=6, IR_3=7, IR_4=8, IR_5=9, IR_6=10, IR_7=11, IR_8=12, IR_9=13, IR_AST=14, IR_0=15, IR_HASH=16 };
|
||||
@@ -17,7 +17,7 @@ void loopControls();
|
||||
void encoderLoop();
|
||||
void encoder2Loop();
|
||||
void irLoop();
|
||||
void touchLoop();
|
||||
//void touchLoop();
|
||||
void irNum(byte num);
|
||||
void irBlink();
|
||||
void controlsEvent(bool toRight, int8_t volDelta = 0);
|
||||
@@ -27,7 +27,7 @@ void onBtnDoubleClick(int id);
|
||||
void onBtnDuringLongPress(int id);
|
||||
void onBtnLongPressStart(int id);
|
||||
void onBtnLongPressStop(int id);
|
||||
tsDirection_e tsDirection(uint16_t x, uint16_t y);
|
||||
//tsDirection_e tsDirection(uint16_t x, uint16_t y);
|
||||
|
||||
void setIRTolerance(uint8_t tl);
|
||||
void setEncAcceleration(uint16_t acc);
|
||||
|
||||
@@ -49,6 +49,9 @@ void loopDspTask(void * pvParameters){
|
||||
void Display::init() {
|
||||
#ifdef USE_NEXTION
|
||||
nextion.begin();
|
||||
#endif
|
||||
#if LIGHT_SENSOR!=255
|
||||
analogSetAttenuation(ADC_0db);
|
||||
#endif
|
||||
_bootStep = 0;
|
||||
dsp.initDisplay();
|
||||
@@ -442,6 +445,10 @@ void Display::_title() {
|
||||
}
|
||||
|
||||
void Display::_time(bool redraw) {
|
||||
#if LIGHT_SENSOR!=255
|
||||
config.store.brightness = AUTOBACKLIGHT(analogRead(LIGHT_SENSOR));
|
||||
config.setBrightness();
|
||||
#endif
|
||||
_clock.draw();
|
||||
/*#ifdef USE_NEXTION
|
||||
nextion.printClock(network.timeinfo);
|
||||
|
||||
@@ -110,4 +110,5 @@ class Display {
|
||||
|
||||
extern Display display;
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -557,7 +557,7 @@ void NetServer::requestOnChange(requestType_e request, uint8_t clientId) {
|
||||
#endif
|
||||
if (BRIGHTNESS_PIN != 255 || nxtn || dbgact) act += F("\"group_brightness\",");
|
||||
if (DSP_CAN_FLIPPED || dbgact) act += F("\"group_tft\",");
|
||||
if (TS_CS != 255 || dbgact) act += F("\"group_touch\",");
|
||||
if (TS_MODEL != TS_MODEL_UNDEFINED || dbgact) act += F("\"group_touch\",");
|
||||
if (DSP_MODEL == DSP_NOKIA5110) act += F("\"group_nokia\",");
|
||||
act += F("\"group_timezone\",");
|
||||
if (SHOW_WEATHER || dbgact) act += F("\"group_weather\",");
|
||||
|
||||
@@ -209,6 +209,7 @@ bool getWeather(char *wstr) {
|
||||
}
|
||||
char *tmpe;
|
||||
char *tmps;
|
||||
char *tmpc;
|
||||
const char* cursor = line.c_str();
|
||||
char desc[120], temp[20], hum[20], press[20], icon[5];
|
||||
|
||||
@@ -251,8 +252,9 @@ bool getWeather(char *wstr) {
|
||||
if (tmps == NULL) { Serial.println("## OPENWEATHERMAP ###: humidity not found !"); return false;}
|
||||
tmps += 10;
|
||||
tmpe = strstr(tmps, ",\"");
|
||||
tmpc = strstr(tmps, "}");
|
||||
if (tmpe == NULL) { Serial.println("## OPENWEATHERMAP ###: humidity not found !"); return false;}
|
||||
strlcpy(hum, tmps, tmpe - tmps + 1);
|
||||
strlcpy(hum, tmps, tmpe - tmps + (tmpc>tmpe?1:0));
|
||||
|
||||
#ifdef USE_NEXTION
|
||||
nextion.putcmdf("press_txt.txt=\"%dmm\"", pressi);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef options_h
|
||||
#define options_h
|
||||
|
||||
#define VERSION "0.8.02b"
|
||||
#define VERSION "0.8.03b"
|
||||
|
||||
/*******************************************************
|
||||
DO NOT EDIT THIS FILE.
|
||||
@@ -41,6 +41,7 @@ The connection tables are located here https://github.com/e2002/yoradio#connecti
|
||||
#define DSP_SSD1305I2C 16 // 128x64 2.4' SSD1305 and SSD1309 I2C https://aliexpress.com/item/32950307344.html
|
||||
#define DSP_ILI9225 17 // 220x176 2.0' https://aliexpress.com/item/32952021835.html
|
||||
#define DSP_ST7789_240 18 // 240x240 1.3' https://aliexpress.com/item/32996979276.html
|
||||
#define DSP_ST7796 19
|
||||
/* !!! DSP_ST7789_240 requires further development when used in conjunction with the VS1053 module !!! See the link https://www.instructables.com/Adding-CS-Pin-to-13-LCD/ */
|
||||
|
||||
#define DSP_CUSTOM 101 // your display
|
||||
@@ -48,6 +49,12 @@ The connection tables are located here https://github.com/e2002/yoradio#connecti
|
||||
#ifndef DSP_MODEL
|
||||
#define DSP_MODEL DSP_DUMMY
|
||||
#endif
|
||||
#ifndef DSP_HSPI
|
||||
#define DSP_HSPI false // use HSPI for displays (miso=12, mosi=13, clk=14) instead of VSPI (by default)
|
||||
#endif
|
||||
#ifndef LED_INVERT
|
||||
#define LED_INVERT false // invert onboard LED?
|
||||
#endif
|
||||
|
||||
/* TFT DISPLAY */
|
||||
#ifndef TFT_CS
|
||||
@@ -92,6 +99,9 @@ The connection tables are located here https://github.com/e2002/yoradio#connecti
|
||||
#ifndef VS1053_RST
|
||||
#define VS1053_RST -1 // set to -1 if connected to Esp EN pin
|
||||
#endif
|
||||
#ifndef VS_HSPI
|
||||
#define VS_HSPI false // use HSPI for VS1053 (miso=12, mosi=13, clk=14) instead of VSPI (by default)
|
||||
#endif
|
||||
|
||||
/* I2S DAC */
|
||||
#ifndef I2S_DOUT
|
||||
@@ -167,8 +177,32 @@ The connection tables are located here https://github.com/e2002/yoradio#connecti
|
||||
#endif
|
||||
|
||||
/* TOUCH SCREEN */
|
||||
#define TS_MODEL_UNDEFINED 0
|
||||
#define TS_MODEL_XPT2046 1
|
||||
#define TS_MODEL_GT911 2
|
||||
|
||||
#ifndef TS_MODEL
|
||||
#define TS_MODEL TS_MODEL_UNDEFINED
|
||||
#endif
|
||||
|
||||
#ifndef TS_CS
|
||||
#define TS_CS 255
|
||||
#define TS_CS 13
|
||||
#endif
|
||||
#ifndef TS_SDA
|
||||
#define TS_SDA 33
|
||||
#endif
|
||||
#ifndef TS_SCL
|
||||
#define TS_SCL 32
|
||||
#endif
|
||||
#ifndef TS_INT
|
||||
#define TS_INT 21
|
||||
#endif
|
||||
#ifndef TS_RST
|
||||
#define TS_RST 25
|
||||
#endif
|
||||
|
||||
#ifndef TS_HSPI
|
||||
#define TS_HSPI false // use HSPI for touchscreen (miso=12, mosi=13, clk=14) instead of VSPI (by default)
|
||||
#endif
|
||||
|
||||
/* LCD DISPLAY */
|
||||
@@ -218,6 +252,18 @@ The connection tables are located here https://github.com/e2002/yoradio#connecti
|
||||
#ifndef WAKE_PIN
|
||||
#define WAKE_PIN 255 // Wake Pin (for manual wakeup from sleep mode. can match with BTN_XXXX, ENC_BTNB, ENC2_BTNB. must be one of: 0,2,4,12,13,14,15,25,26,27,32,33,34,35,36,39)
|
||||
#endif
|
||||
#ifndef LIGHT_SENSOR
|
||||
#define LIGHT_SENSOR 255 // Light sensor
|
||||
#endif
|
||||
#ifndef AUTOBACKLIGHT
|
||||
#ifndef AUTOBACKLIGHT_MAX
|
||||
#define AUTOBACKLIGHT_MAX 2500
|
||||
#endif
|
||||
#ifndef AUTOBACKLIGHT_MIN
|
||||
#define AUTOBACKLIGHT_MIN 12
|
||||
#endif
|
||||
#define AUTOBACKLIGHT(x) ({uint16_t _lh=(x>AUTOBACKLIGHT_MAX?AUTOBACKLIGHT_MAX:x); map(_lh, AUTOBACKLIGHT_MAX, 0, AUTOBACKLIGHT_MIN, 100);}) // autobacklight function
|
||||
#endif
|
||||
/*
|
||||
*** ST7735 display submodel ***
|
||||
INITR_BLACKTAB // 1.8' https://aliexpress.ru/item/1005002822797745.html
|
||||
|
||||
@@ -11,9 +11,11 @@
|
||||
Player player;
|
||||
|
||||
#if VS1053_CS!=255 && !I2S_INTERNAL
|
||||
Player::Player(): Audio(VS1053_CS, VS1053_DCS, VS1053_DREQ) {
|
||||
|
||||
}
|
||||
#if VS_HSPI
|
||||
Player::Player(): Audio(VS1053_CS, VS1053_DCS, VS1053_DREQ, HSPI, 13, 12, 14) {}
|
||||
#else
|
||||
Player::Player(): Audio(VS1053_CS, VS1053_DCS, VS1053_DREQ) {}
|
||||
#endif
|
||||
void ResetChip(){
|
||||
pinMode(VS1053_RST, OUTPUT);
|
||||
digitalWrite(VS1053_RST, LOW);
|
||||
@@ -116,7 +118,7 @@ void Player::zeroRequest() {
|
||||
}
|
||||
|
||||
void Player::setOutputPins(bool isPlaying) {
|
||||
digitalWrite(LED_BUILTIN, isPlaying);
|
||||
digitalWrite(LED_BUILTIN, LED_INVERT?!isPlaying:isPlaying);
|
||||
if(MUTE_PIN!=255) digitalWrite(MUTE_PIN, isPlaying?!MUTE_VAL:MUTE_VAL);
|
||||
}
|
||||
|
||||
|
||||
196
yoRadio/src/core/touchscreen.cpp
Normal file
196
yoRadio/src/core/touchscreen.cpp
Normal file
@@ -0,0 +1,196 @@
|
||||
#include "options.h"
|
||||
#if TS_MODEL!=TS_MODEL_UNDEFINED
|
||||
|
||||
#include "touchscreen.h"
|
||||
#include "config.h"
|
||||
#include "controls.h"
|
||||
#include "display.h"
|
||||
#include "player.h"
|
||||
|
||||
#ifndef TS_X_MIN
|
||||
#define TS_X_MIN 400
|
||||
#endif
|
||||
#ifndef TS_X_MAX
|
||||
#define TS_X_MAX 3800
|
||||
#endif
|
||||
#ifndef TS_Y_MIN
|
||||
#define TS_Y_MIN 260
|
||||
#endif
|
||||
#ifndef TS_Y_MAX
|
||||
#define TS_Y_MAX 3800
|
||||
#endif
|
||||
#ifndef TS_STEPS
|
||||
#define TS_STEPS 40
|
||||
#endif
|
||||
|
||||
#if TS_MODEL==TS_MODEL_XPT2046
|
||||
#ifdef TS_SPIPINS
|
||||
SPIClass TSSPI(HSPI);
|
||||
#endif
|
||||
#include <XPT2046_Touchscreen.h>
|
||||
XPT2046_Touchscreen ts(TS_CS);
|
||||
typedef TS_Point TSPoint;
|
||||
#elif TS_MODEL==TS_MODEL_GT911
|
||||
#include "../GT911_Touchscreen/TAMC_GT911.h"
|
||||
TAMC_GT911 ts = TAMC_GT911(TS_SDA, TS_SCL, TS_INT, TS_RST, 0, 0);
|
||||
typedef TP_Point TSPoint;
|
||||
#endif
|
||||
|
||||
void TouchScreen::init(){
|
||||
|
||||
#if TS_MODEL==TS_MODEL_XPT2046
|
||||
#ifdef TS_SPIPINS
|
||||
TSSPI.begin(TS_SPIPINS);
|
||||
ts.begin(TSSPI);
|
||||
#else
|
||||
#if TS_HSPI
|
||||
ts.begin(SPI2);
|
||||
#else
|
||||
ts.begin();
|
||||
#endif
|
||||
#endif
|
||||
ts.setRotation(config.store.fliptouch?3:1);
|
||||
#endif
|
||||
#if TS_MODEL==TS_MODEL_GT911
|
||||
ts.begin();
|
||||
ts.setRotation(config.store.fliptouch?0:2);
|
||||
#endif
|
||||
_width = dsp.width();
|
||||
_height = dsp.height();
|
||||
#if TS_MODEL==TS_MODEL_GT911
|
||||
ts.setResolution(_width, _height);
|
||||
#endif
|
||||
}
|
||||
|
||||
tsDirection_e TouchScreen::_tsDirection(uint16_t x, uint16_t y) {
|
||||
int16_t dX = x - _oldTouchX;
|
||||
int16_t dY = y - _oldTouchY;
|
||||
if (abs(dX) > 20 || abs(dY) > 20) {
|
||||
if (abs(dX) > abs(dY)) {
|
||||
if (dX > 0) {
|
||||
return TSD_RIGHT;
|
||||
} else {
|
||||
return TSD_LEFT;
|
||||
}
|
||||
} else {
|
||||
if (dY > 0) {
|
||||
return TSD_DOWN;
|
||||
} else {
|
||||
return TSD_UP;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return TDS_REQUEST;
|
||||
}
|
||||
}
|
||||
|
||||
void TouchScreen::flip(){
|
||||
#if TS_MODEL==TS_MODEL_XPT2046
|
||||
ts.setRotation(config.store.fliptouch?3:1);
|
||||
#endif
|
||||
#if TS_MODEL==TS_MODEL_GT911
|
||||
ts.setRotation(config.store.fliptouch?0:2);
|
||||
#endif
|
||||
}
|
||||
|
||||
void TouchScreen::loop(){
|
||||
uint16_t touchX, touchY;
|
||||
static bool wastouched = true;
|
||||
static uint32_t touchLongPress;
|
||||
static tsDirection_e direct;
|
||||
static uint16_t touchVol, touchStation;
|
||||
if (!_checklpdelay(20, _touchdelay)) return;
|
||||
#if TS_MODEL==TS_MODEL_GT911
|
||||
ts.read();
|
||||
#endif
|
||||
bool istouched = _istouched();
|
||||
if(istouched){
|
||||
#if TS_MODEL==TS_MODEL_XPT2046
|
||||
TSPoint p = ts.getPoint();
|
||||
touchX = map(p.x, TS_X_MIN, TS_X_MAX, 0, _width);
|
||||
touchY = map(p.y, TS_Y_MIN, TS_Y_MAX, 0, _height);
|
||||
#elif TS_MODEL==TS_MODEL_GT911
|
||||
TSPoint p = ts.points[0];
|
||||
touchX = p.x;
|
||||
touchY = p.y;
|
||||
#endif
|
||||
if (!wastouched) { /* START TOUCH */
|
||||
_oldTouchX = touchX;
|
||||
_oldTouchY = touchY;
|
||||
touchVol = touchX;
|
||||
touchStation = touchY;
|
||||
direct = TDS_REQUEST;
|
||||
touchLongPress=millis();
|
||||
} else { /* SWIPE TOUCH */
|
||||
direct = _tsDirection(touchX, touchY);
|
||||
switch (direct) {
|
||||
case TSD_LEFT:
|
||||
case TSD_RIGHT: {
|
||||
touchLongPress=millis();
|
||||
if(display.mode()==PLAYER || display.mode()==VOL){
|
||||
int16_t xDelta = map(abs(touchVol - touchX), 0, _width, 0, TS_STEPS);
|
||||
display.putRequest(NEWMODE, VOL);
|
||||
if (xDelta>1) {
|
||||
controlsEvent((touchVol - touchX)<0);
|
||||
touchVol = touchX;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TSD_UP:
|
||||
case TSD_DOWN: {
|
||||
touchLongPress=millis();
|
||||
if(display.mode()==PLAYER || display.mode()==STATIONS){
|
||||
int16_t yDelta = map(abs(touchStation - touchY), 0, _height, 0, TS_STEPS);
|
||||
display.putRequest(NEWMODE, STATIONS);
|
||||
if (yDelta>1) {
|
||||
controlsEvent((touchStation - touchY)<0);
|
||||
touchStation = touchY;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (config.store.dbgtouch) {
|
||||
Serial.print(", x = ");
|
||||
Serial.print(p.x);
|
||||
Serial.print(", y = ");
|
||||
Serial.println(p.y);
|
||||
}
|
||||
}else{
|
||||
if (wastouched) {/* END TOUCH */
|
||||
if (direct == TDS_REQUEST) {
|
||||
uint32_t pressTicks = millis()-touchLongPress;
|
||||
if( pressTicks < BTN_PRESS_TICKS*2){
|
||||
if(pressTicks > 50) onBtnClick(EVT_BTNCENTER);
|
||||
}else{
|
||||
display.putRequest(NEWMODE, display.mode() == PLAYER ? STATIONS : PLAYER);
|
||||
}
|
||||
}
|
||||
direct = TSD_STAY;
|
||||
}
|
||||
}
|
||||
wastouched = istouched;
|
||||
}
|
||||
|
||||
bool TouchScreen::_checklpdelay(int m, uint32_t &tstamp) {
|
||||
if (millis() - tstamp > m) {
|
||||
tstamp = millis();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool TouchScreen::_istouched(){
|
||||
#if TS_MODEL==TS_MODEL_XPT2046
|
||||
return ts.touched();
|
||||
#elif TS_MODEL==TS_MODEL_GT911
|
||||
return ts.isTouched;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // TS_MODEL!=TS_MODEL_UNDEFINED
|
||||
23
yoRadio/src/core/touchscreen.h
Normal file
23
yoRadio/src/core/touchscreen.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef touchscreen_h
|
||||
#define touchscreen_h
|
||||
#include "Arduino.h"
|
||||
|
||||
enum tsDirection_e { TSD_STAY, TSD_LEFT, TSD_RIGHT, TSD_UP, TSD_DOWN, TDS_REQUEST };
|
||||
|
||||
class TouchScreen {
|
||||
public:
|
||||
TouchScreen() {}
|
||||
void init();
|
||||
void loop();
|
||||
void flip();
|
||||
private:
|
||||
uint16_t _oldTouchX, _oldTouchY, _width, _height;
|
||||
uint32_t _touchdelay;
|
||||
bool _checklpdelay(int m, uint32_t &tstamp);
|
||||
tsDirection_e _tsDirection(uint16_t x, uint16_t y);
|
||||
bool _istouched();
|
||||
};
|
||||
|
||||
extern TouchScreen touchscreen;
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user