Implement calibration
This commit is contained in:
@@ -37,6 +37,7 @@ typedef struct mouse_microtouch_t {
|
|||||||
int baud_rate_sel;
|
int baud_rate_sel;
|
||||||
int cmd_pos;
|
int cmd_pos;
|
||||||
int mode;
|
int mode;
|
||||||
|
uint8_t cal_cntr;
|
||||||
double rate;
|
double rate;
|
||||||
bool soh;
|
bool soh;
|
||||||
bool in_reset;
|
bool in_reset;
|
||||||
@@ -57,6 +58,17 @@ void microtouch_reset_complete(void *priv)
|
|||||||
fifo8_push_all(&mtouch->resp, (uint8_t*) "0\r", 2);
|
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)
|
void microtouch_process_commands(mouse_microtouch_t* mtouch)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@@ -83,22 +95,16 @@ void microtouch_process_commands(mouse_microtouch_t* mtouch)
|
|||||||
fifo8_push(&mtouch->resp, 1);
|
fifo8_push(&mtouch->resp, 1);
|
||||||
fifo8_push_all(&mtouch->resp, (uint8_t*) "0\r", 2);
|
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') {
|
if (mtouch->cmd[0] == 'M' && mtouch->cmd[1] == 'S') {
|
||||||
fifo8_push(&mtouch->resp, 1);
|
fifo8_push(&mtouch->resp, 1);
|
||||||
fifo8_push_all(&mtouch->resp, (uint8_t*) "0\r", 2);
|
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') {
|
if (mtouch->cmd[0] == 'R') {
|
||||||
mtouch->in_reset = true;
|
mtouch->in_reset = true;
|
||||||
mtouch->mode = MODE_TABLET;
|
mtouch->mode = MODE_TABLET;
|
||||||
@@ -120,6 +126,15 @@ void microtouch_process_commands(mouse_microtouch_t* mtouch)
|
|||||||
fifo8_push(&mtouch->resp, 1);
|
fifo8_push(&mtouch->resp, 1);
|
||||||
fifo8_push_all(&mtouch->resp, (uint8_t*) "1\r", 2);
|
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)
|
void mtouch_write_to_host(void *priv)
|
||||||
@@ -207,6 +222,15 @@ mtouch_poll(void *priv)
|
|||||||
if (abs_y >= 1.0)
|
if (abs_y >= 1.0)
|
||||||
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) {
|
if (b & 1) {
|
||||||
dev->abs_x = abs_x;
|
dev->abs_x = abs_x;
|
||||||
dev->abs_y = abs_y;
|
dev->abs_y = abs_y;
|
||||||
|
Reference in New Issue
Block a user