Merge pull request #4685 from mourix/master
Microtouch: fix compilation warnings, optimize command handling and liftoffs
This commit is contained in:
@@ -56,6 +56,7 @@ const char* mtouch_identity[] = {
|
|||||||
|
|
||||||
typedef struct mouse_microtouch_t {
|
typedef struct mouse_microtouch_t {
|
||||||
double baud_rate;
|
double baud_rate;
|
||||||
|
unsigned int abs_x_int, abs_y_int;
|
||||||
int b;
|
int b;
|
||||||
char cmd[256];
|
char cmd[256];
|
||||||
int cmd_pos;
|
int cmd_pos;
|
||||||
@@ -72,21 +73,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 +89,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 +148,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);
|
||||||
}
|
|
||||||
if (fifo8_num_used(&mtouch->resp) != fifo_used || mtouch->in_reset) {
|
|
||||||
pclog("Command handled: %s\n", mtouch->cmd);
|
|
||||||
} else {
|
} else {
|
||||||
pclog("Command ignored: %s\n", mtouch->cmd);
|
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); /* <SOH>0<CR> */
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -243,8 +209,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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -325,7 +297,7 @@ mtouch_poll(void *priv)
|
|||||||
snprintf(buffer, sizeof(buffer), "\x1c%03d,%03d\r", abs_x_int, abs_y_int);
|
snprintf(buffer, sizeof(buffer), "\x1c%03d,%03d\r", abs_x_int, abs_y_int);
|
||||||
}
|
}
|
||||||
} else if (dev->b) { /* Liftoff Status */
|
} 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));
|
fifo8_push_all(&dev->resp, (uint8_t *)buffer, strlen(buffer));
|
||||||
}
|
}
|
||||||
@@ -349,7 +321,7 @@ mtouch_poll(void *priv)
|
|||||||
snprintf(buffer, sizeof(buffer), "\x1c%03X,%03X\r", abs_x_int, abs_y_int);
|
snprintf(buffer, sizeof(buffer), "\x1c%03X,%03X\r", abs_x_int, abs_y_int);
|
||||||
}
|
}
|
||||||
} else if (dev->b) { /* Liftoff Status */
|
} 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));
|
fifo8_push_all(&dev->resp, (uint8_t *)buffer, strlen(buffer));
|
||||||
}
|
}
|
||||||
@@ -367,14 +339,17 @@ mtouch_poll(void *priv)
|
|||||||
fifo8_push(&dev->resp, (abs_y_int >> 7) & 0b1111111);
|
fifo8_push(&dev->resp, (abs_y_int >> 7) & 0b1111111);
|
||||||
} else if (dev->b) { /* Liftoff */
|
} else if (dev->b) { /* Liftoff */
|
||||||
fifo8_push(&dev->resp, 0b10000000 | ((dev->pen_mode == 2) ? ((1 << 5)) : 0));
|
fifo8_push(&dev->resp, 0b10000000 | ((dev->pen_mode == 2) ? ((1 << 5)) : 0));
|
||||||
fifo8_push(&dev->resp, abs_x_int & 0b1111111);
|
fifo8_push(&dev->resp, dev->abs_x_int & 0b1111111);
|
||||||
fifo8_push(&dev->resp, (abs_x_int >> 7) & 0b1111111);
|
fifo8_push(&dev->resp, (dev->abs_x_int >> 7) & 0b1111111);
|
||||||
fifo8_push(&dev->resp, abs_y_int & 0b1111111);
|
fifo8_push(&dev->resp, dev->abs_y_int & 0b1111111);
|
||||||
fifo8_push(&dev->resp, (abs_y_int >> 7) & 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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user