1
0
mirror of https://github.com/whowechina/aic_pico.git synced 2024-09-23 18:48:24 +02:00

Touch keypad working

This commit is contained in:
whowechina 2024-06-07 15:10:32 +08:00
parent c520b5a169
commit 6119b58fb4
6 changed files with 57 additions and 11 deletions

Binary file not shown.

View File

@ -4,6 +4,8 @@
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
@ -141,10 +143,13 @@ cst816t_report_t cst816t_read()
cst816t_report_t report = ctx.old_report;
report.updated = false;
if (report.gesture != GESTURE_NONE) {
report.gesture = GESTURE_NONE;
report.updated = true;
}
if (raw.updated) {
/* touch related changes */
report.gesture = GESTURE_NONE;
report.x = raw.x;
report.y = raw.y;
report.touched = raw.touched;
@ -154,9 +159,13 @@ cst816t_report_t cst816t_read()
} else if (ctx.old_report.touched && !report.touched) {
report.release_x = report.x;
report.release_y = report.y;
if (report.release_x - report.touch_x > 30) {
int dx = report.release_x - report.touch_x;
int dy = report.release_y - report.touch_y;
if ((abs(dx) < 10) && (abs(dy) < 10)) {
report.gesture = GESTURE_TAP;
} else if (dx > 30) {
report.gesture = GESTURE_SLIDE_RIGHT;
} else if (report.release_x - report.touch_x < -30) {
} else if (dx < -30) {
report.gesture = GESTURE_SLIDE_LEFT;
}
}
@ -169,5 +178,6 @@ cst816t_report_t cst816t_read()
}
ctx.old_report = report;
return report;
}

View File

@ -25,9 +25,7 @@ typedef struct {
typedef enum {
GESTURE_NONE = 0,
GESTURE_CLICK,
GESTURE_DOUBLE_CLICK,
GESTURE_LONG_PRESS,
GESTURE_TAP,
GESTURE_SLIDE_UP,
GESTURE_SLIDE_DOWN,
GESTURE_SLIDE_LEFT,

View File

@ -42,7 +42,7 @@ void gui_level(uint8_t level)
st7789_dimmer(255 - level);
}
static void gui_numpad()
static void gui_keypad()
{
static struct {
uint16_t x;
@ -70,6 +70,43 @@ static void gui_numpad()
}
}
static int tapped_key = -1;
uint16_t gui_keypad_read()
{
static int last_tapped = -1;
static uint64_t last_active;
uint64_t now = time_us_32();
const uint8_t map[] = { 6, 7, 8, 3, 4, 5, 0, 1, 2, 9, 10, 11 };
if ((last_tapped >= 0) && (now - last_active < 10000)) {
return 1 << map[last_tapped];
}
if (tapped_key >= 0) {
last_tapped = tapped_key;
last_active = now;
return 1 << map[tapped_key];
}
return 0;
}
static bool proc_keypad(cst816t_report_t touch)
{
switch (touch.gesture) {
case GESTURE_NONE:
tapped_key = -1;
break;
case GESTURE_TAP:
tapped_key = touch.y / 70 * 3 + touch.x / 80;
break;
default:
return false;
}
return true;
}
static void status_title(int x, int y, const char *title, uint16_t color)
{
st7789_text(x + 1, y + 1, title, &lv_lts16, 0x0000, ALIGN_CENTER);
@ -165,7 +202,7 @@ typedef struct {
} gui_page_t;
static gui_page_t pages[] = {
{gui_numpad, NULL},
{gui_keypad, proc_keypad},
{gui_status, NULL},
{gui_credits, NULL},
};
@ -237,7 +274,7 @@ static void event_proc()
return;
}
if ((curr_page > 0) && pages[curr_page].proc) {
if ((curr_page >= 0) && pages[curr_page].proc) {
if (pages[curr_page].proc(touch)) {
return;
}

View File

@ -14,6 +14,6 @@
void gui_init();
void gui_level(uint8_t level);
void gui_loop();
uint16_t gui_keypad_read();
#endif

View File

@ -75,7 +75,8 @@ void report_hid_key()
return;
}
uint16_t keys = aic_runtime.touch ? 0 : keypad_read();
uint16_t keys = aic_runtime.touch ? gui_keypad_read() : keypad_read();
for (int i = 0; i < keypad_key_num(); i++) {
uint8_t code = keymap[i];
uint8_t byte = code / 8;