From d9fa8bbb4a1eab05b04ea536f300c6d4fc8bd056 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Sun, 5 May 2024 14:25:31 +0600 Subject: [PATCH] Implement calibration --- src/device/mouse_microtouch_touchscreen.c | 48 +++++++++++++++++------ 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/src/device/mouse_microtouch_touchscreen.c b/src/device/mouse_microtouch_touchscreen.c index e063260ea..14d400fbc 100644 --- a/src/device/mouse_microtouch_touchscreen.c +++ b/src/device/mouse_microtouch_touchscreen.c @@ -37,6 +37,7 @@ typedef struct mouse_microtouch_t { int baud_rate_sel; int cmd_pos; int mode; + uint8_t cal_cntr; double rate; bool soh; bool in_reset; @@ -57,6 +58,17 @@ void microtouch_reset_complete(void *priv) fifo8_push_all(&mtouch->resp, (uint8_t*) "0\r", 2); } +void microtouch_calibrate_timer(void *priv) +{ + mouse_microtouch_t *mtouch = (mouse_microtouch_t*)priv; + + if (!fifo8_num_used(&mtouch->resp)) { + mtouch->cal_cntr--; + fifo8_push(&mtouch->resp, 1); + fifo8_push_all(&mtouch->resp, (uint8_t*) "1\r", 2); + } +} + void microtouch_process_commands(mouse_microtouch_t* mtouch) { int i = 0; @@ -83,22 +95,16 @@ void microtouch_process_commands(mouse_microtouch_t* mtouch) fifo8_push(&mtouch->resp, 1); fifo8_push_all(&mtouch->resp, (uint8_t*) "0\r", 2); } + if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'R') { + mtouch->mode = MODE_RAW; + mtouch->cal_cntr = 0; + fifo8_push(&mtouch->resp, 1); + fifo8_push_all(&mtouch->resp, (uint8_t*) "0\r", 2); + } if (mtouch->cmd[0] == 'M' && mtouch->cmd[1] == 'S') { fifo8_push(&mtouch->resp, 1); fifo8_push_all(&mtouch->resp, (uint8_t*) "0\r", 2); } - if (mtouch->cmd[0] == 'P' && mtouch->cmd[1] == 'F') { - fifo8_push(&mtouch->resp, 1); - fifo8_push_all(&mtouch->resp, (uint8_t*) "0\r", 2); - } - if (mtouch->cmd[0] == 'P' && mtouch->cmd[1] == 'O') { - fifo8_push(&mtouch->resp, 1); - fifo8_push_all(&mtouch->resp, (uint8_t*) "0\r", 2); - } - if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'O') { - fifo8_push(&mtouch->resp, 1); - fifo8_push_all(&mtouch->resp, (uint8_t*) "0\r", 2); - } if (mtouch->cmd[0] == 'R') { mtouch->in_reset = true; mtouch->mode = MODE_TABLET; @@ -120,6 +126,15 @@ void microtouch_process_commands(mouse_microtouch_t* mtouch) fifo8_push(&mtouch->resp, 1); fifo8_push_all(&mtouch->resp, (uint8_t*) "1\r", 2); } + if (mtouch->cmd[0] == 'P') { + fifo8_push(&mtouch->resp, 1); + fifo8_push_all(&mtouch->resp, (uint8_t*) "0\r", 2); + } + if (mtouch->cmd[0] == 'C' && (mtouch->cmd[1] == 'N' || mtouch->cmd[1] == 'X')) { + fifo8_push(&mtouch->resp, 1); + fifo8_push_all(&mtouch->resp, (uint8_t*) "0\r", 2); + mtouch->cal_cntr = 2; + } } void mtouch_write_to_host(void *priv) @@ -207,6 +222,15 @@ mtouch_poll(void *priv) if (abs_y >= 1.0) abs_y = 1.0; } + if (dev->cal_cntr && (!(dev->b & 1) && (b & 1))) { + dev->b |= 1; + } else if (dev->cal_cntr && ((dev->b & 1) && !(b & 1))) { + dev->b &= ~1; + microtouch_calibrate_timer(dev); + } + if (dev->cal_cntr) { + return 0; + } if (b & 1) { dev->abs_x = abs_x; dev->abs_y = abs_y;