Skip to content

Commit 13b1e04

Browse files
authored
Merge pull request chandong83#5 from epikao/master
Touch ID handling fixed
2 parents 263ecdb + 59d0a5f commit 13b1e04

File tree

1 file changed

+74
-15
lines changed

1 file changed

+74
-15
lines changed

usb_touch/Core/Src/touch.c

Lines changed: 74 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ extern USBD_HandleTypeDef hUsbDeviceFS;
1919
extern uint8_t USBD_HID_SendReport (USBD_HandleTypeDef *pdev, uint8_t *report, uint16_t len);
2020

2121
static uint8_t touchIrq = 0;
22-
static uint16_t oldX[max_point_num]={0,};
23-
static uint16_t oldY[max_point_num]={0,};
24-
static uint8_t p_point_num = 0;
22+
//static uint16_t oldX[max_point_num]={0,};
23+
//static uint16_t oldY[max_point_num]={0,};
24+
static uint16_t oldid[max_point_num];
25+
//static uint8_t p_point_num = 0;
26+
2527

2628
//https://docs.microsoft.com/en-us/windows-hardware/design/component-guidelines/touch-and-pen-support
2729
const uint8_t touchQualityKey[] = {
@@ -64,24 +66,26 @@ struct multiTouchHid_t multiTouch;
6466

6567
void tpd_down(uint16_t x, uint16_t y, uint16_t p)
6668
{
67-
multiTouch.touch[p].tip = 0x01;
68-
multiTouch.touch[p].num = p; //contact id
69-
multiTouch.touch[p].x = x;
70-
multiTouch.touch[p].y = y;
71-
multiTouch.touch[p].width = 0x30; //width of contact
72-
multiTouch.touch[p].height = 0x30;
69+
multiTouch.touch[multiTouch.id].tip = 0x01;
70+
multiTouch.touch[multiTouch.id].num = p; //contact id
71+
multiTouch.touch[multiTouch.id].x = x;
72+
multiTouch.touch[multiTouch.id].y = y;
73+
multiTouch.touch[multiTouch.id].width = 0x30; //width of contact
74+
multiTouch.touch[multiTouch.id].height = 0x30;
7375
multiTouch.id++;
7476

7577
}
7678
void tpd_up(uint16_t x, uint16_t y, uint16_t p)
7779
{
7880
multiTouch.touch[multiTouch.id].tip = 0x00;
79-
multiTouch.touch[multiTouch.id].num = multiTouch.id;
80-
multiTouch.touch[multiTouch.id].x = x;
81-
multiTouch.touch[multiTouch.id].y = y;
82-
multiTouch.touch[multiTouch.id].width = 0x30;
83-
multiTouch.touch[multiTouch.id].height = 0x30;
81+
//multiTouch.touch[multiTouch.id].num = multiTouch.id;
82+
multiTouch.touch[multiTouch.id].num = p;
83+
//multiTouch.touch[multiTouch.id].x = x;
84+
//multiTouch.touch[multiTouch.id].y = y;
85+
multiTouch.touch[multiTouch.id].width = 0;
86+
multiTouch.touch[multiTouch.id].height = 0;
8487
multiTouch.id++;
88+
8589
}
8690

8791
void input_sync()
@@ -93,6 +97,7 @@ void input_sync()
9397
{
9498
printf("\n[%d:%d] x : %d, y : %d, %d\n",multiTouch.id, multiTouch.touch[i].tip, multiTouch.touch[i].x,multiTouch.touch[i].y, multiTouch.count);
9599
}*/
100+
//HAL_UART_Transmit_IT(&huart3, (uint8_t*)&multiTouch, sizeof(multiTouch));
96101
USBD_HID_SendReport(&hUsbDeviceFS, (uint8_t*)&multiTouch, sizeof(struct multiTouchHid_t));
97102
multiTouch.id=0;
98103
for(int i=0;i<max_point_num;i++)
@@ -142,19 +147,26 @@ void initTouch()
142147
}
143148
}
144149

150+
//void toucuProc(I2C_HandleTypeDef hi2c1)
145151
void toucuProc()
146152
{
147153
uint8_t point_num;
148154
uint8_t i;
149155
uint16_t x[max_point_num];
150156
uint16_t y[max_point_num];
157+
158+
uint16_t id[max_point_num];
159+
151160
uint8_t dat[100];
161+
152162
if(touchIrq)
153163
{
154164
touchIrq=0;
155165

156-
readI2C(TOUCH_I2C_ID, 0x00, dat, 33);
166+
readI2C(TOUCH_I2C_ID, 0x00, dat, 40);
167+
//HAL_I2C_Mem_Read(&hi2c1, TOUCH_I2C_ID, 0x00, I2C_MEMADD_SIZE_8BIT, (uint8_t *)dat, 40, 200);
157168

169+
//HAL_I2C_Master_Receive_DMA()
158170
//device mode[6:4]
159171
//0 Work Mode
160172
//4 Factory Mode
@@ -184,14 +196,59 @@ void toucuProc()
184196

185197
x[i] = (((uint16_t)dat[3+6*i]&0x0F)<<8)|dat[3+6*i+1];
186198
y[i] = (((uint16_t)dat[3+6*i+2]&0x0F)<<8)|dat[3+6*i+3];
199+
200+
id[i] = dat[5+6*i]>>4;
201+
187202
if(x[i] > 1024)
188203
x[i] = 1024;
189204
if(y[i] > 600)
190205
y[i] = 600;
191206
x[i] = (x[i]*2048)/1024;// touch range ( 0 ~ 1024 ) to USB HID range (0 ~ 2048)
192207
y[i] = (y[i]*2048)/600; // touch range ( 0 ~ 1024 ) to USB HID range (0 ~ 2048)
208+
209+
tpd_down(x[i], y[i], id[i]);
210+
211+
212+
for(uint8_t c = 0; c < point_num; c++)
213+
{
214+
if(id[i] == oldid[c])
215+
{
216+
oldid[c]=255;
217+
}
218+
219+
}
220+
221+
}
222+
//input_sync();
223+
224+
225+
for(i=0; i < point_num; i++)
226+
{
227+
if(oldid[i]!=255)
228+
{
229+
tpd_up(x[i], y[i], oldid[i]);
230+
231+
}
232+
oldid[i] = id[i];
193233
}
234+
input_sync();
194235

236+
/*
237+
input_sync();
238+
for(i = 0; i < point_num; i++)
239+
{
240+
if(id[i]!=oldid[i])
241+
{
242+
tpd_up(x[i], y[i], oldid[i]);
243+
//input_sync();
244+
}
245+
oldid[i] = id[i];
246+
}
247+
input_sync();
248+
*/
249+
250+
251+
/*
195252
if(point_num > 0)
196253
{
197254
// pressed
@@ -225,5 +282,7 @@ void toucuProc()
225282
input_sync();
226283
}
227284
p_point_num = point_num;
285+
*/
286+
228287
}
229288
}

0 commit comments

Comments
 (0)