Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relax OS_Time IRQHandler #2833

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion TFT/src/User/API/Printing.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ uint32_t getPrintExpectedTime(void)
return infoPrinting.expectedTime;
}

void updatePrintTime(void)
void updatePrintTime(void) // Handle in interrupt
{
if (infoPrinting.printing && !infoPrinting.paused)
{
Expand Down
209 changes: 10 additions & 199 deletions TFT/src/User/API/UI/TouchProcess.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
#define F TSC_Para[5]
#define K TSC_Para[6]

#define TOUCH_DEBOUNCE_MS 20 // 20ms

int32_t TSC_Para[7];
static volatile bool touchScreenIsPress = false;
static volatile uint8_t touchCountdown = TOUCH_DEBOUNCE_MS;
bool touchSound = true;

void TS_Get_Coordinates(uint16_t *x, uint16_t *y)
Expand Down Expand Up @@ -142,30 +144,17 @@ uint16_t Key_value(uint8_t total_rect, const GUI_RECT *menuRect)
return IDLE_TOUCH;
}

void loopTouchScreen(void) // Handle in interrupt
void checkTouchScreen(void) // Handle in interrupt
{
static uint8_t touch;
if (!XPT2046_Read_Pen())
{
if (touch >= 20) // 20ms
{
touchScreenIsPress = true;
}
else
{
touch++;
}
}
if (XPT2046_Read_Pen() == LOW)
touchCountdown -= !!touchCountdown;
else
{
touchScreenIsPress = false;
touch = 0;
}
touchCountdown = TOUCH_DEBOUNCE_MS;
}

uint8_t isPress(void)
bool isPress(void)
{
return touchScreenIsPress;
return (touchCountdown == 0);
}

void (*TSC_ReDrawIcon)(uint8_t position, uint8_t is_press) = NULL;
Expand All @@ -177,7 +166,7 @@ uint16_t KEY_GetValue(uint8_t total_rect, const GUI_RECT* menuRect)

uint16_t key_return = IDLE_TOUCH;

if (touchScreenIsPress)
if (isPress())
{
if (firstPress)
{
Expand Down Expand Up @@ -207,181 +196,3 @@ uint16_t KEY_GetValue(uint8_t total_rect, const GUI_RECT* menuRect)
}
return key_return;
}

typedef enum
{
NO_CLICK,
FIRST_CLICK,
FIRST_RELEASE,
SECOND_CLICK,
LONG_PRESS,
} KEY_STATUS;

#define KEY_DOUOBLE_SPACE 15 //锟洁长时锟斤拷锟节碉拷锟斤拷锟斤拷锟斤拷卸锟轿?双锟斤拷
#define KEY_LONG_PRESS_START 200 //锟斤拷锟斤拷锟斤拷锟斤拷每锟绞硷拷卸锟轿? 锟斤拷锟斤拷 锟斤拷值

#define KEY_LONG_PRESS_SPACE_MAX 10 //锟斤拷锟斤拷时 锟筋长锟斤拷梅锟斤拷锟揭伙拷渭锟街?
#define KEY_LONG_PRESS_SPACE_MIN 2 //����ʱ ��̶�÷���һ�μ�ֵ

//uint16_t KEY_GetValue(uint8_t total_rect, const GUI_RECT *menuRect)
//{
// uint16_t key_return = NO_TOUCH;

// static uint16_t first_key = NO_TOUCH;
// static uint32_t first_time = 0;
// static uint8_t long_press_space = KEY_LONG_PRESS_SPACE_MAX;

// static KEY_STATUS nowStatus = NO_CLICK; //������ǰ��״̬

// if (touchScreenIsPress)
// {
// switch (nowStatus)
// {
// case NO_CLICK:
// nowStatus = FIRST_CLICK;
// first_key = Key_value(total_rect, menuRect);
// first_time = OS_GetTime();
// break;

// case FIRST_CLICK:
// if (OS_GetTime() - first_time > KEY_LONG_PRESS_START)
// {
// nowStatus = LONG_PRESS;
// first_key |= KEY_LONG_CLICK;
// }
// break;

// case FIRST_RELEASE:
// if (first_key == Key_value(total_rect, menuRect))
// {
// nowStatus = SECOND_CLICK;
// first_key |= KEY_DOUBLE_CLICK;
// }
// else
// {
// nowStatus = NO_CLICK;
// }
// break;

// case SECOND_CLICK:
// if (OS_GetTime() - first_time > KEY_LONG_PRESS_START)
// {
// nowStatus = LONG_PRESS;
// first_key |= KEY_LONG_CLICK;
// }
// break;

// case LONG_PRESS:
// if (OS_GetTime() - first_time > long_press_space)
// {
// if (long_press_space > KEY_LONG_PRESS_SPACE_MIN)
// long_press_space--;
// first_time = OS_GetTime();
// key_return = first_key;
// }
// break;

// default:
// break;
// }
// }
// else
// {
// switch (nowStatus)
// {
// case FIRST_CLICK:
// nowStatus = FIRST_RELEASE;
// break;

// case FIRST_RELEASE:
// if (OS_GetTime() - first_time > KEY_DOUOBLE_SPACE)
// {
// nowStatus = NO_CLICK;
// key_return = first_key;
// }
// break;

// case SECOND_CLICK:
// nowStatus = NO_CLICK;
// key_return = first_key;
// break;

// case LONG_PRESS:
// nowStatus = NO_CLICK;
// key_return = first_key | KEY_LONG_RELEASE;
// break;

// default:
// break;
// }
// }
// return key_return;
//}

uint16_t KNOB_GetRV(GUI_RECT *knob)
{
uint16_t key_return = IDLE_TOUCH;
uint16_t x = 0, y = 0;

static uint16_t oldx = 0, oldy = 0;
static uint32_t mytime;

if (touchScreenIsPress && OS_GetTimeMs() > mytime)
{
mytime = OS_GetTimeMs() + 10;
TS_Get_Coordinates(&x, &y);
if (x > knob->x0 && x < knob->x1 && y > knob->y0 && y < knob->y1)
{
if (x > oldx + 5)
{
if (oldy > (knob->y0 + knob->y1) / 2)
{
key_return = KNOB_DEC;
}
else
{
key_return = KNOB_INC;
}
}
else if (x < oldx - 5)
{
if (oldy > (knob->y0 + knob->y1) / 2)
{
key_return = KNOB_INC;
}
else
{
key_return = KNOB_DEC;
}
}
if (y > oldy + 5)
{
if (x > (knob->x0 + knob->x1) / 2)
{
key_return = KNOB_INC;
}
else
{
key_return = KNOB_DEC;
}
}
else if (y < oldy - 5)
{
if (x > (knob->x0 + knob->x1) / 2)
{
key_return = KNOB_DEC;
}
else
{
key_return = KNOB_INC;
}
}
}
}
if (key_return != IDLE_TOUCH)
{
oldx = x;
oldy = y;
}
return key_return;
}
10 changes: 2 additions & 8 deletions TFT/src/User/API/UI/TouchProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,14 @@ enum
KNOB_DEC,
};

#define KEY_CLICK 0x0000 // The key is defined as uint16_t , 16 (uint16_t 16bit)-3 (3 bits flag) = 13 bit, so uint16_t supports a maximum of 2 ^ 13 = 8192 key values
#define KEY_DOUBLE_CLICK 0x2000 // The third bit is used to identify the double-click action
#define KEY_LONG_RELEASE 0x4000 // The second bit is used to identify the release action after a long press
#define KEY_LONG_CLICK 0x8000 // The first bit is used to identify the long press action

extern bool touchSound;

void TSC_Calibration(void);
uint8_t isPress(void);
bool isPress(void);
uint16_t KEY_GetValue(uint8_t total_rect, const GUI_RECT *menuRect);
uint16_t Key_value(uint8_t total_rect, const GUI_RECT *menuRect);
uint16_t KNOB_GetRV(GUI_RECT *knob);

void loopTouchScreen(void);
void checkTouchScreen(void); // WARNING, TIMER INTERRUPT ROUTINE CALLED ONCE A MILLISECOND

extern void (*TSC_ReDrawIcon)(uint8_t position, uint8_t is_press);
extern void TS_Get_Coordinates(uint16_t *x, uint16_t *y);
Expand Down
4 changes: 2 additions & 2 deletions TFT/src/User/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@
* Monitoring Debug
* Uncomment/Enable to monitor/show system resources usage in Monitoring menu.
*/
#define DEBUG_MONITORING // Default: commented (disabled)
//#define DEBUG_MONITORING // Default: commented (disabled)

/**
* Generic Debug
Expand Down Expand Up @@ -1431,7 +1431,7 @@
* Uncomment to enable a progress bar with 10% markers.
* Comment to enable a standard progress bar.
*/
#define MARKED_PROGRESS_BAR // Default: commented (disabled)
//#define MARKED_PROGRESS_BAR // Default: commented (disabled)

/**
* Live Text Common Color Layout (Status Screen menu)
Expand Down
Loading