From 09dad6f6b718df053d796348aacb244e03e688c3 Mon Sep 17 00:00:00 2001 From: Jos van Mourik Date: Sun, 4 Aug 2024 00:19:40 +0200 Subject: [PATCH 1/2] Command handling updates - Always return 0 (success) for commands to greatly increase compatibility with unknown command. - Remove empty commands because of this. - Remove command wrapper function. - Fix compiler warnings. - Fix unit type string for SMT2/3. - Guard for empty commands. --- src/device/mouse_microtouch_touchscreen.c | 93 ++++++++--------------- 1 file changed, 32 insertions(+), 61 deletions(-) diff --git a/src/device/mouse_microtouch_touchscreen.c b/src/device/mouse_microtouch_touchscreen.c index 2f5333121..5b207dfc6 100644 --- a/src/device/mouse_microtouch_touchscreen.c +++ b/src/device/mouse_microtouch_touchscreen.c @@ -72,21 +72,13 @@ typedef struct mouse_microtouch_t { static mouse_microtouch_t *mtouch_inst = NULL; -void -mt_fifo8_puts(Fifo8 *fifo, const uint8_t *data) -{ - fifo8_push(fifo, 1); - fifo8_push_all(fifo, data, strlen(data)); - fifo8_push(fifo, '\r'); -} - void microtouch_reset_complete(void *priv) { mouse_microtouch_t *mtouch = (mouse_microtouch_t *) priv; mtouch->in_reset = false; - mt_fifo8_puts(&mtouch->resp, "0"); + fifo8_push_all(&mtouch->resp, (uint8_t *) "\x01\x30\x0D", 3); /* 0 */ } void @@ -96,85 +88,55 @@ microtouch_calibrate_timer(void *priv) if (!fifo8_num_used(&mtouch->resp)) { mtouch->cal_cntr--; - mt_fifo8_puts(&mtouch->resp, "1"); + fifo8_push_all(&mtouch->resp, (uint8_t *) "\x01\x31\x0D", 3); /* 1 */ } } void microtouch_process_commands(mouse_microtouch_t *mtouch) { - int fifo_used = fifo8_num_used(&mtouch->resp); mtouch->cmd[strcspn(mtouch->cmd, "\r")] = '\0'; - mtouch->cmd_pos = 0; - if (mtouch->cmd[0] == 'A' && (mtouch->cmd[1] == 'D' || mtouch->cmd[1] == 'E')) { /* Autobaud Enable/Disable */ - mt_fifo8_puts(&mtouch->resp, "0"); - } + pclog("MT Command: %s\n", mtouch->cmd); + if (mtouch->cmd[0] == 'C' && (mtouch->cmd[1] == 'N' || mtouch->cmd[1] == 'X')) { /* Calibrate New/Extended */ - mt_fifo8_puts(&mtouch->resp, "0"); mtouch->cal_cntr = 2; } if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'D') { /* Format Decimal */ mouse_set_sample_rate(106); mtouch->format = FORMAT_DEC; - mt_fifo8_puts(&mtouch->resp, "0"); - } - if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'N') { /* Filter Number */ - mt_fifo8_puts(&mtouch->resp, "0"); } if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'O') { /* Finger Only */ mtouch->pen_mode = 1; - mt_fifo8_puts(&mtouch->resp, "0"); } if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'H') { /* Format Hexadecimal */ mouse_set_sample_rate(106); mtouch->format = FORMAT_HEX; - mt_fifo8_puts(&mtouch->resp, "0"); - } - if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'Q') { /* ?? */ - mt_fifo8_puts(&mtouch->resp, "0"); } if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'R') { /* Format Raw */ mouse_set_sample_rate(106); mtouch->format = FORMAT_RAW; mtouch->cal_cntr = 0; - mt_fifo8_puts(&mtouch->resp, "0"); } if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'T') { /* Format Tablet */ mouse_set_sample_rate(192); mtouch->format = FORMAT_TABLET; - mt_fifo8_puts(&mtouch->resp, "0"); - } - if (mtouch->cmd[0] == 'G' && mtouch->cmd[1] == 'F') { /* ?? */ - mt_fifo8_puts(&mtouch->resp, "0"); } if (mtouch->cmd[0] == 'G' && mtouch->cmd[1] == 'P' && mtouch->cmd[2] == '1') { /* Get Parameter Block 1 */ - mt_fifo8_puts(&mtouch->resp, "A"); - fifo8_push_all(&mtouch->resp, (uint8_t *) "0000000000000000000000000\r", sizeof("0000000000000000000000000\r") - 1); - mt_fifo8_puts(&mtouch->resp, "0"); - } - if (mtouch->cmd[0] == 'M' && mtouch->cmd[1] == 'P') { /* ?? */ - mt_fifo8_puts(&mtouch->resp, "0"); - } - if (mtouch->cmd[0] == 'M' && mtouch->cmd[1] == 'S') { /* Mode Stream */ - mt_fifo8_puts(&mtouch->resp, "0"); + fifo8_push_all(&mtouch->resp, (uint8_t *) "\x01\x41\x0D", 3); /* A */ + fifo8_push_all(&mtouch->resp, (uint8_t *) "0000000000000000000000000\r", 26); } if (mtouch->cmd[0] == 'M' && mtouch->cmd[1] == 'T') { /* Mode Status */ mtouch->mode_status = true; - mt_fifo8_puts(&mtouch->resp, "0"); - } - if (mtouch->cmd[0] == 'N' && mtouch->cmd[1] == 'M') { /* ?? */ - mt_fifo8_puts(&mtouch->resp, "0"); } if (mtouch->cmd[0] == 'O' && mtouch->cmd[1] == 'I') { /* Output Identity */ - mt_fifo8_puts(&mtouch->resp, mtouch_identity[mtouch->id]); + fifo8_push(&mtouch->resp, 0x01); + fifo8_push_all(&mtouch->resp, (uint8_t *) mtouch_identity[mtouch->id], 6); + fifo8_push(&mtouch->resp, 0x0D); + return; } if (mtouch->cmd[0] == 'P') { if (mtouch->cmd[1] == 'F') mtouch->pen_mode = 3; /* Pen or Finger */ else if (mtouch->cmd[1] == 'O') mtouch->pen_mode = 2; /* Pen Only */ - mt_fifo8_puts(&mtouch->resp, "0"); /* Also 'PL' Parameter Lock */ - } - if (mtouch->cmd[0] == 'Q' && mtouch->cmd[1] == 'P') { /* ?? */ - mt_fifo8_puts(&mtouch->resp, "0"); } if (mtouch->cmd[0] == 'R') { /* Reset */ mtouch->in_reset = true; @@ -185,28 +147,31 @@ microtouch_process_commands(mouse_microtouch_t *mtouch) if (mtouch->id < 2) { mouse_set_sample_rate(106); mtouch->format = FORMAT_DEC; - } - else { + } else { mouse_set_sample_rate(192); mtouch->format = FORMAT_TABLET; } timer_on_auto(&mtouch->reset_timer, 500. * 1000.); + return; } if (mtouch->cmd[0] == 'S' && mtouch->cmd[1] == 'P' && mtouch->cmd[2] == '1') { /* Set Parameter Block 1 */ - mt_fifo8_puts(&mtouch->resp, "A"); + fifo8_push_all(&mtouch->resp, (uint8_t *) "\x01\x41\x0D", 3); /* A */ + return; } if (mtouch->cmd[0] == 'U' && mtouch->cmd[1] == 'T') { /* Unit Type */ - mt_fifo8_puts(&mtouch->resp, "TP****00"); - } - if (mtouch->cmd[0] == 'Z') { /* Null */ - mt_fifo8_puts(&mtouch->resp, "0"); - } - if (fifo8_num_used(&mtouch->resp) != fifo_used || mtouch->in_reset) { - pclog("Command handled: %s\n", mtouch->cmd); - } else { - pclog("Command ignored: %s\n", mtouch->cmd); + fifo8_push(&mtouch->resp, 0x01); + + if (mtouch->id == 2) { + fifo8_push_all(&mtouch->resp, (uint8_t *) "TP****00", 8); + } else { + fifo8_push_all(&mtouch->resp, (uint8_t *) "QM****00", 8); + } + fifo8_push(&mtouch->resp, 0x0D); + return; } + + fifo8_push_all(&mtouch->resp, (uint8_t *) "\x01\x30\x0D", 3); /* 0 */ } void @@ -243,8 +208,14 @@ mtouch_write(serial_t *serial, void *priv, uint8_t data) if (data != '\r') { dev->cmd[dev->cmd_pos++] = data; } else { - dev->cmd[dev->cmd_pos++] = data; dev->soh = 0; + + if (!dev->cmd_pos) { + return; + } + + dev->cmd[dev->cmd_pos++] = data; + dev->cmd_pos = 0; microtouch_process_commands(dev); } } From 7692abb60c2b755591d133028a79a3f26f305908 Mon Sep 17 00:00:00 2001 From: Jos van Mourik Date: Sun, 4 Aug 2024 01:04:09 +0200 Subject: [PATCH 2/2] A liftoff should keep the old touch location --- src/device/mouse_microtouch_touchscreen.c | 44 ++++++++++++----------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/src/device/mouse_microtouch_touchscreen.c b/src/device/mouse_microtouch_touchscreen.c index 5b207dfc6..9767d5c04 100644 --- a/src/device/mouse_microtouch_touchscreen.c +++ b/src/device/mouse_microtouch_touchscreen.c @@ -55,19 +55,20 @@ const char* mtouch_identity[] = { }; typedef struct mouse_microtouch_t { - double baud_rate; - int b; - char cmd[256]; - int cmd_pos; - uint8_t format; - bool mode_status; - uint8_t id, cal_cntr, pen_mode; - bool soh; - bool in_reset; - serial_t *serial; - Fifo8 resp; - pc_timer_t host_to_serial_timer; - pc_timer_t reset_timer; + double baud_rate; + unsigned int abs_x_int, abs_y_int; + int b; + char cmd[256]; + int cmd_pos; + uint8_t format; + bool mode_status; + uint8_t id, cal_cntr, pen_mode; + bool soh; + bool in_reset; + serial_t *serial; + Fifo8 resp; + pc_timer_t host_to_serial_timer; + pc_timer_t reset_timer; } mouse_microtouch_t; static mouse_microtouch_t *mtouch_inst = NULL; @@ -296,7 +297,7 @@ mtouch_poll(void *priv) snprintf(buffer, sizeof(buffer), "\x1c%03d,%03d\r", abs_x_int, abs_y_int); } } else if (dev->b) { /* Liftoff Status */ - snprintf(buffer, sizeof(buffer), "\x18%03d,%03d\r", abs_x_int, abs_y_int); + snprintf(buffer, sizeof(buffer), "\x18%03d,%03d\r", dev->abs_x_int, dev->abs_y_int); } fifo8_push_all(&dev->resp, (uint8_t *)buffer, strlen(buffer)); } @@ -320,7 +321,7 @@ mtouch_poll(void *priv) snprintf(buffer, sizeof(buffer), "\x1c%03X,%03X\r", abs_x_int, abs_y_int); } } else if (dev->b) { /* Liftoff Status */ - snprintf(buffer, sizeof(buffer), "\x18%03X,%03X\r", abs_x_int, abs_y_int); + snprintf(buffer, sizeof(buffer), "\x18%03X,%03X\r", dev->abs_x_int, dev->abs_y_int); } fifo8_push_all(&dev->resp, (uint8_t *)buffer, strlen(buffer)); } @@ -338,14 +339,17 @@ mtouch_poll(void *priv) fifo8_push(&dev->resp, (abs_y_int >> 7) & 0b1111111); } else if (dev->b) { /* Liftoff */ fifo8_push(&dev->resp, 0b10000000 | ((dev->pen_mode == 2) ? ((1 << 5)) : 0)); - fifo8_push(&dev->resp, abs_x_int & 0b1111111); - fifo8_push(&dev->resp, (abs_x_int >> 7) & 0b1111111); - fifo8_push(&dev->resp, abs_y_int & 0b1111111); - fifo8_push(&dev->resp, (abs_y_int >> 7) & 0b1111111); + fifo8_push(&dev->resp, dev->abs_x_int & 0b1111111); + fifo8_push(&dev->resp, (dev->abs_x_int >> 7) & 0b1111111); + fifo8_push(&dev->resp, dev->abs_y_int & 0b1111111); + fifo8_push(&dev->resp, (dev->abs_y_int >> 7) & 0b1111111); } } - dev->b = b; /* Save buttonpress */ + /* Save old states*/ + dev->abs_x_int = abs_x_int; + dev->abs_y_int = abs_y_int; + dev->b = b; return 0; }