This repository was archived by the owner on Nov 18, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtouch.cpp
More file actions
87 lines (74 loc) · 1.92 KB
/
Copy pathtouch.cpp
File metadata and controls
87 lines (74 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <vector>
#include <cstdint>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include "touch.h"
#include "config.h"
bool touchReady = false;
void initTouch() {
touchReady = false;
}
int8_t touchBuffer[5];
uint8_t touchOk[3] = { 0x01, 0x30, 0x0d };
bool touchPressed = false;
bool lastTouchPressed = false;
int touchX, touchY;
int touchOkResponse = 0;
void writeTouch(void* packet, int size) {
uint8_t* data = (uint8_t*)packet;
if (data[0] == 1) {
if (data[1] == 68) {
printf("touch should be ready\n");
touchReady = true;
touchPressed = false;
lastTouchPressed = false;
}
if (data[1] == 82) {
printf("reset touch\n");
touchReady = false;
}
}
touchOkResponse++;
}
void update_touch(bool state, int x, int y) {
touchPressed = state;
touchBuffer[1] = x & 0x7f;
touchBuffer[2] = (x / 0x80) & 0x7f;
touchBuffer[3] = y & 0x7f;
touchBuffer[4] = ( y / 0x80) & 0x7f;
}
bool readTouch(void* packet, int* size) {
if (isMt4) {
if (touchReady) {
bool sendTouch = false;
if (!touchPressed) {
if (lastTouchPressed) {
touchBuffer[0] = -128;
sendTouch = true;
lastTouchPressed = false;
}
} else {
touchBuffer[0] = -64;
lastTouchPressed = true;
sendTouch = true;
}
if (sendTouch) {
memcpy(packet, touchBuffer, 5);
*size = 5;
return true;
}
}
if (isMt4) {
// not sure how to deal with this yet
memcpy(packet, touchOk, 3);
*size = 3;
return true;
}
return false;
}
touchOkResponse--;
memcpy(packet, touchOk, 3);
*size = 3;
return true;
}