Command handling updates

- Always return <SOH>0<CR> (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.
This commit is contained in:
Jos van Mourik
2024-08-04 00:19:40 +02:00
parent 1b3b612837
commit 09dad6f6b7

View File

@@ -72,21 +72,13 @@ typedef struct mouse_microtouch_t {
static mouse_microtouch_t *mtouch_inst = NULL; 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 void
microtouch_reset_complete(void *priv) microtouch_reset_complete(void *priv)
{ {
mouse_microtouch_t *mtouch = (mouse_microtouch_t *) priv; mouse_microtouch_t *mtouch = (mouse_microtouch_t *) priv;
mtouch->in_reset = false; mtouch->in_reset = false;
mt_fifo8_puts(&mtouch->resp, "0"); fifo8_push_all(&mtouch->resp, (uint8_t *) "\x01\x30\x0D", 3); /* <SOH>0<CR> */
} }
void void
@@ -96,85 +88,55 @@ microtouch_calibrate_timer(void *priv)
if (!fifo8_num_used(&mtouch->resp)) { if (!fifo8_num_used(&mtouch->resp)) {
mtouch->cal_cntr--; mtouch->cal_cntr--;
mt_fifo8_puts(&mtouch->resp, "1"); fifo8_push_all(&mtouch->resp, (uint8_t *) "\x01\x31\x0D", 3); /* <SOH>1<CR> */
} }
} }
void void
microtouch_process_commands(mouse_microtouch_t *mtouch) microtouch_process_commands(mouse_microtouch_t *mtouch)
{ {
int fifo_used = fifo8_num_used(&mtouch->resp);
mtouch->cmd[strcspn(mtouch->cmd, "\r")] = '\0'; mtouch->cmd[strcspn(mtouch->cmd, "\r")] = '\0';
mtouch->cmd_pos = 0; pclog("MT Command: %s\n", mtouch->cmd);
if (mtouch->cmd[0] == 'A' && (mtouch->cmd[1] == 'D' || mtouch->cmd[1] == 'E')) { /* Autobaud Enable/Disable */
mt_fifo8_puts(&mtouch->resp, "0");
}
if (mtouch->cmd[0] == 'C' && (mtouch->cmd[1] == 'N' || mtouch->cmd[1] == 'X')) { /* Calibrate New/Extended */ 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; mtouch->cal_cntr = 2;
} }
if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'D') { /* Format Decimal */ if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'D') { /* Format Decimal */
mouse_set_sample_rate(106); mouse_set_sample_rate(106);
mtouch->format = FORMAT_DEC; 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 */ if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'O') { /* Finger Only */
mtouch->pen_mode = 1; mtouch->pen_mode = 1;
mt_fifo8_puts(&mtouch->resp, "0");
} }
if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'H') { /* Format Hexadecimal */ if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'H') { /* Format Hexadecimal */
mouse_set_sample_rate(106); mouse_set_sample_rate(106);
mtouch->format = FORMAT_HEX; 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 */ if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'R') { /* Format Raw */
mouse_set_sample_rate(106); mouse_set_sample_rate(106);
mtouch->format = FORMAT_RAW; mtouch->format = FORMAT_RAW;
mtouch->cal_cntr = 0; mtouch->cal_cntr = 0;
mt_fifo8_puts(&mtouch->resp, "0");
} }
if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'T') { /* Format Tablet */ if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'T') { /* Format Tablet */
mouse_set_sample_rate(192); mouse_set_sample_rate(192);
mtouch->format = FORMAT_TABLET; 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 */ 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 *) "\x01\x41\x0D", 3); /* <SOH>A<CR> */
fifo8_push_all(&mtouch->resp, (uint8_t *) "0000000000000000000000000\r", sizeof("0000000000000000000000000\r") - 1); fifo8_push_all(&mtouch->resp, (uint8_t *) "0000000000000000000000000\r", 26);
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");
} }
if (mtouch->cmd[0] == 'M' && mtouch->cmd[1] == 'T') { /* Mode Status */ if (mtouch->cmd[0] == 'M' && mtouch->cmd[1] == 'T') { /* Mode Status */
mtouch->mode_status = true; 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 */ 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[0] == 'P') {
if (mtouch->cmd[1] == 'F') mtouch->pen_mode = 3; /* Pen or Finger */ if (mtouch->cmd[1] == 'F') mtouch->pen_mode = 3; /* Pen or Finger */
else if (mtouch->cmd[1] == 'O') mtouch->pen_mode = 2; /* Pen Only */ 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 */ if (mtouch->cmd[0] == 'R') { /* Reset */
mtouch->in_reset = true; mtouch->in_reset = true;
@@ -185,28 +147,31 @@ microtouch_process_commands(mouse_microtouch_t *mtouch)
if (mtouch->id < 2) { if (mtouch->id < 2) {
mouse_set_sample_rate(106); mouse_set_sample_rate(106);
mtouch->format = FORMAT_DEC; mtouch->format = FORMAT_DEC;
} } else {
else {
mouse_set_sample_rate(192); mouse_set_sample_rate(192);
mtouch->format = FORMAT_TABLET; mtouch->format = FORMAT_TABLET;
} }
timer_on_auto(&mtouch->reset_timer, 500. * 1000.); 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 */ 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); /* <SOH>A<CR> */
return;
} }
if (mtouch->cmd[0] == 'U' && mtouch->cmd[1] == 'T') { /* Unit Type */ if (mtouch->cmd[0] == 'U' && mtouch->cmd[1] == 'T') { /* Unit Type */
mt_fifo8_puts(&mtouch->resp, "TP****00"); fifo8_push(&mtouch->resp, 0x01);
}
if (mtouch->cmd[0] == 'Z') { /* Null */ if (mtouch->id == 2) {
mt_fifo8_puts(&mtouch->resp, "0"); fifo8_push_all(&mtouch->resp, (uint8_t *) "TP****00", 8);
} } else {
if (fifo8_num_used(&mtouch->resp) != fifo_used || mtouch->in_reset) { fifo8_push_all(&mtouch->resp, (uint8_t *) "QM****00", 8);
pclog("Command handled: %s\n", mtouch->cmd); }
} else { fifo8_push(&mtouch->resp, 0x0D);
pclog("Command ignored: %s\n", mtouch->cmd); return;
} }
fifo8_push_all(&mtouch->resp, (uint8_t *) "\x01\x30\x0D", 3); /* <SOH>0<CR> */
} }
void void
@@ -243,8 +208,14 @@ mtouch_write(serial_t *serial, void *priv, uint8_t data)
if (data != '\r') { if (data != '\r') {
dev->cmd[dev->cmd_pos++] = data; dev->cmd[dev->cmd_pos++] = data;
} else { } else {
dev->cmd[dev->cmd_pos++] = data;
dev->soh = 0; dev->soh = 0;
if (!dev->cmd_pos) {
return;
}
dev->cmd[dev->cmd_pos++] = data;
dev->cmd_pos = 0;
microtouch_process_commands(dev); microtouch_process_commands(dev);
} }
} }