Commit 8b194ee761699aab97c4994bd41d63e289d1dfc6
1 parent
e912f423
Getting touch information from screen
Showing
3 changed files
with
42 additions
and
6 deletions
Show diff stats
... | ... | @@ -57,6 +57,8 @@ void setDebit(unsigned int d) |
57 | 57 | |
58 | 58 | void processScreen() |
59 | 59 | { |
60 | + int x = -1; | |
61 | + int y = -1; | |
60 | 62 | if(actScreen == SC_HOME) |
61 | 63 | { |
62 | 64 | if(uid[0] == '\0') |
... | ... | @@ -67,6 +69,12 @@ void processScreen() |
67 | 69 | displayPicture("img/main.boz"); |
68 | 70 | } |
69 | 71 | } |
72 | + else if(actScreen == SC_MAIN) | |
73 | + { | |
74 | + if(screenTouched(&x, &y)) | |
75 | + displayPicture("img/home.boz"); | |
76 | + //displayPicture = calculateInteraction(displayPicture, x, y); | |
77 | + } | |
70 | 78 | } |
71 | 79 | |
72 | 80 | void* drawUI(void* we) | ... | ... |
... | ... | @@ -2,14 +2,17 @@ |
2 | 2 | #include <stdlib.h> |
3 | 3 | #include <stdbool.h> |
4 | 4 | #include <libusb-1.0/libusb.h> |
5 | +#include "printx.h" | |
5 | 6 | #include "usb.h" |
6 | 7 | |
7 | -#define VENDOR_ID 0xfccf | |
8 | -#define PRODUCT_ID 0xa001 | |
9 | -#define ENDPOINT_OUT 0x01 | |
10 | -#define MAX_SIZE_OUT 64 | |
11 | -#define HEIGHT 240 | |
12 | -#define WIDTH 320 | |
8 | +#define VENDOR_ID 0xfccf | |
9 | +#define PRODUCT_ID 0xa001 | |
10 | +#define ENDPOINT_OUT 0x01 | |
11 | +#define ENDPOINT_IN 0x82 | |
12 | +#define MAX_SIZE_OUT 64 | |
13 | +#define HEIGHT 240 | |
14 | +#define WIDTH 320 | |
15 | +#define STATUS_QUERY_LENGTH 11 | |
13 | 16 | |
14 | 17 | libusb_device_handle* screenHandle; |
15 | 18 | unsigned char data[MAX_SIZE_OUT]; |
... | ... | @@ -183,3 +186,27 @@ bool initUSB(void) |
183 | 186 | |
184 | 187 | return true; |
185 | 188 | } |
189 | + | |
190 | +bool screenTouched(int* x, int* y) | |
191 | +{ | |
192 | + unsigned char data[STATUS_QUERY_LENGTH]; | |
193 | + int transfered; | |
194 | + libusb_interrupt_transfer(screenHandle, ENDPOINT_IN, data, STATUS_QUERY_LENGTH, &transfered, 0); | |
195 | + if(transfered != STATUS_QUERY_LENGTH) | |
196 | + { | |
197 | + printx(ERROR, UI, "Status recieved is %d bytes long, and expected %d\n", transfered, STATUS_QUERY_LENGTH); | |
198 | + return false; | |
199 | + } | |
200 | + | |
201 | + //printx(DEBUG, UI, "%02X %02X %02X %02X", data[0], data[1], data[2], data[3]); | |
202 | + //printx(DEBUG, UI, "%02X %02X %02X %02X", data[4], data[5], data[6], data[7]); | |
203 | + //printx(DEBUG, UI, "%02X %02X %02X\n", data[8], data[9], data[10]); | |
204 | + | |
205 | + *x = data[3] + (256 * (int)data[4]); | |
206 | + | |
207 | + *y = data[7]; | |
208 | + | |
209 | + printx(DEBUG, UI, "Screen %s at X %d Y %d\n", data[2] == 1 ? "touched" : "untouched", *x, *y); | |
210 | + | |
211 | + return data[2] == 1; | |
212 | +} | ... | ... |