From ba20dfdf785a4fde6092821d7b8b7ee74ad9cc45 Mon Sep 17 00:00:00 2001 From: rondlh <77279634+rondlh@users.noreply.github.com> Date: Tue, 14 Oct 2025 00:38:03 +0800 Subject: [PATCH 1/2] Improve touchscreen calibration Improve touchscreen calibration --- TFT/src/User/API/Touch_Screen.c | 58 ++++++++++++++------------------- 1 file changed, 24 insertions(+), 34 deletions(-) diff --git a/TFT/src/User/API/Touch_Screen.c b/TFT/src/User/API/Touch_Screen.c index f3e7401857..3b85cfb8b0 100644 --- a/TFT/src/User/API/Touch_Screen.c +++ b/TFT/src/User/API/Touch_Screen.c @@ -81,7 +81,7 @@ uint16_t TS_KeyValue(uint8_t totalRect, const GUI_RECT * menuRect) for (i = 0; i < totalRect; i++) { - if ((x > menuRect[i].x0) && (x < menuRect[i].x1) && (y > menuRect[i].y0) && (y < menuRect[i].y1)) + if ((x >= menuRect[i].x0) && (x <= menuRect[i].x1) && (y >= menuRect[i].y0) && (y <= menuRect[i].y1)) { #ifdef BUZZER_PIN if (TS_Sound == true) @@ -115,7 +115,7 @@ uint16_t KEY_GetValue(uint8_t totalRect, const GUI_RECT * menuRect) } else { - if (firstPress == false) + if (!firstPress) { if (TS_ReDrawIcon) TS_ReDrawIcon(key_num, 0); @@ -136,22 +136,21 @@ uint16_t KEY_GetValue(uint8_t totalRect, const GUI_RECT * menuRect) return key_return; } +void drawTouchTargetCross(uint16_t x, uint16_t y) +{ + GUI_SetColor(RED); + GUI_FillCircle(x, y, 5); + + GUI_HLine(x - 25, y, x + 25); + GUI_VLine(x, y - 25, y + 25); +} + static inline uint8_t TS_CalibrationEnsure(uint16_t x, uint16_t y) { - uint32_t i; uint16_t tp_x, tp_y; int lcd_x, lcd_y; - GUI_SetColor(BLACK); - GUI_FillCircle(x, y, 5); - - for (i = 0; i < 10; i++) - { - GUI_DrawPoint(x + i, y); - GUI_DrawPoint(x - i, y); - GUI_DrawPoint(x, y + i); - GUI_DrawPoint(x, y - i); - } + drawTouchTargetCross(x, y); while (!TS_IsPressed()); @@ -163,19 +162,20 @@ static inline uint8_t TS_CalibrationEnsure(uint16_t x, uint16_t y) if (lcd_x < x + TS_ERR_RANGE && lcd_x > x - TS_ERR_RANGE && lcd_y > y - TS_ERR_RANGE && lcd_y < y + TS_ERR_RANGE) { - GUI_DispStringCenter(LCD_WIDTH / 2, LCD_HEIGHT - 40, LABEL_ADJUST_OK); - Delay_ms(1000); + Buzzer_Play(SOUND_KEYPRESS); + GUI_SetColor(DARKGREEN); + GUI_DispStringCenter(LCD_WIDTH / 2, 62, LABEL_ADJUST_OK); + Delay_ms(2000); } else { while (TS_IsPressed()); GUI_SetColor(RED); - GUI_DispStringCenter(LCD_WIDTH / 2, LCD_HEIGHT - 40, LABEL_ADJUST_FAILED); - GUI_DispDec(0, 0, lcd_x, 3, 0); - GUI_DispDec(0, 20, lcd_y, 3, 0); - Delay_ms(1000); - + GUI_DispStringCenter(LCD_WIDTH / 2, 62, (int32_t)LABEL_ADJUST_FAILED); + Buzzer_AddSound(100, 200); + Delay_ms(2500); + Buzzer_Play(SOUND_KEYPRESS); return 0; } @@ -188,7 +188,6 @@ void TS_Calibrate(void) uint32_t LCD_Y[3] = {40, 40, LCD_HEIGHT - 40}; uint16_t TP_X[3], TP_Y[3]; uint32_t tp_num = 0; - int i; do { @@ -197,26 +196,17 @@ void TS_Calibrate(void) GUI_SetBkColor(WHITE); GUI_DispStringCenter(LCD_WIDTH / 2, 5, LABEL_ADJUST_TITLE); GUI_DispStringCenter(LCD_WIDTH / 2, 25, LABEL_ADJUST_INFO); - GUI_SetColor(RED); for (tp_num = 0; tp_num < 3; tp_num++) { - GUI_FillCircle(LCD_X[tp_num], LCD_Y[tp_num], 3); - - for (i = 0; i < 10; i++) - { - GUI_DrawPoint(LCD_X[tp_num] + i, LCD_Y[tp_num]); - GUI_DrawPoint(LCD_X[tp_num] - i, LCD_Y[tp_num]); - GUI_DrawPoint(LCD_X[tp_num], LCD_Y[tp_num] + i); - GUI_DrawPoint(LCD_X[tp_num], LCD_Y[tp_num] - i); - } - - while (TS_IsPressed() == false); + drawTouchTargetCross(LCD_X[tp_num], LCD_Y[tp_num]); + while (!TS_IsPressed()); + Buzzer_Play(SOUND_KEYPRESS); TP_X[tp_num] = XPT2046_Repeated_Compare_AD(CMD_RDX); TP_Y[tp_num] = XPT2046_Repeated_Compare_AD(CMD_RDY); - while (TS_IsPressed() != false); + while (TS_IsPressed()); } K = (X1 - X3) * (Y2 - Y3) - (X2 - X3) * (Y1 - Y3); From a06f82ee0b600b1a659062adfc917ec59ece462d Mon Sep 17 00:00:00 2001 From: rondlh <77279634+rondlh@users.noreply.github.com> Date: Tue, 14 Oct 2025 01:27:58 +0800 Subject: [PATCH 2/2] Make used click target dot disappear Make used click target dot disappear --- TFT/src/User/API/Touch_Screen.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/TFT/src/User/API/Touch_Screen.c b/TFT/src/User/API/Touch_Screen.c index 3b85cfb8b0..d63a91465d 100644 --- a/TFT/src/User/API/Touch_Screen.c +++ b/TFT/src/User/API/Touch_Screen.c @@ -136,9 +136,13 @@ uint16_t KEY_GetValue(uint8_t totalRect, const GUI_RECT * menuRect) return key_return; } -void drawTouchTargetCross(uint16_t x, uint16_t y) +void drawTouchTargetCross(uint16_t x, uint16_t y, bool red) { - GUI_SetColor(RED); + if (red) + GUI_SetColor(RED); // IRON, WAS BLACK + else + GUI_SetColor(WHITE); + GUI_FillCircle(x, y, 5); GUI_HLine(x - 25, y, x + 25); @@ -150,9 +154,9 @@ static inline uint8_t TS_CalibrationEnsure(uint16_t x, uint16_t y) uint16_t tp_x, tp_y; int lcd_x, lcd_y; - drawTouchTargetCross(x, y); + drawTouchTargetCross(x, y, true); - while (!TS_IsPressed()); + while (!TS_IsPressed()) {}; tp_x = XPT2046_Repeated_Compare_AD(CMD_RDX); tp_y = XPT2046_Repeated_Compare_AD(CMD_RDY); @@ -169,7 +173,7 @@ static inline uint8_t TS_CalibrationEnsure(uint16_t x, uint16_t y) } else { - while (TS_IsPressed()); + while (TS_IsPressed()) {}; GUI_SetColor(RED); GUI_DispStringCenter(LCD_WIDTH / 2, 62, (int32_t)LABEL_ADJUST_FAILED); @@ -199,15 +203,20 @@ void TS_Calibrate(void) for (tp_num = 0; tp_num < 3; tp_num++) { - drawTouchTargetCross(LCD_X[tp_num], LCD_Y[tp_num]); - while (!TS_IsPressed()); + if (tp_num) + drawTouchTargetCross(LCD_X[tp_num - 1], LCD_Y[tp_num - 1], false); + + drawTouchTargetCross(LCD_X[tp_num], LCD_Y[tp_num], true); + + while (!TS_IsPressed()) {}; Buzzer_Play(SOUND_KEYPRESS); TP_X[tp_num] = XPT2046_Repeated_Compare_AD(CMD_RDX); TP_Y[tp_num] = XPT2046_Repeated_Compare_AD(CMD_RDY); - while (TS_IsPressed()); + while (TS_IsPressed()) {}; } + drawTouchTargetCross(LCD_X[tp_num - 1], LCD_Y[tp_num - 1], false); K = (X1 - X3) * (Y2 - Y3) - (X2 - X3) * (Y1 - Y3); A = ((XL1 - XL3) * (Y2 - Y3) - (XL2 - XL3) * (Y1 - Y3));