From 8b194ee761699aab97c4994bd41d63e289d1dfc6 Mon Sep 17 00:00:00 2001 From: henyxia Date: Thu, 7 May 2015 11:44:08 +0200 Subject: [PATCH] Getting touch information from screen --- ui.c | 8 ++++++++ usb.c | 39 +++++++++++++++++++++++++++++++++------ usb.h | 1 + 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/ui.c b/ui.c index 6e619b4..8f4daaf 100644 --- a/ui.c +++ b/ui.c @@ -57,6 +57,8 @@ void setDebit(unsigned int d) void processScreen() { + int x = -1; + int y = -1; if(actScreen == SC_HOME) { if(uid[0] == '\0') @@ -67,6 +69,12 @@ void processScreen() displayPicture("img/main.boz"); } } + else if(actScreen == SC_MAIN) + { + if(screenTouched(&x, &y)) + displayPicture("img/home.boz"); + //displayPicture = calculateInteraction(displayPicture, x, y); + } } void* drawUI(void* we) diff --git a/usb.c b/usb.c index 69f2849..225f370 100644 --- a/usb.c +++ b/usb.c @@ -2,14 +2,17 @@ #include #include #include +#include "printx.h" #include "usb.h" -#define VENDOR_ID 0xfccf -#define PRODUCT_ID 0xa001 -#define ENDPOINT_OUT 0x01 -#define MAX_SIZE_OUT 64 -#define HEIGHT 240 -#define WIDTH 320 +#define VENDOR_ID 0xfccf +#define PRODUCT_ID 0xa001 +#define ENDPOINT_OUT 0x01 +#define ENDPOINT_IN 0x82 +#define MAX_SIZE_OUT 64 +#define HEIGHT 240 +#define WIDTH 320 +#define STATUS_QUERY_LENGTH 11 libusb_device_handle* screenHandle; unsigned char data[MAX_SIZE_OUT]; @@ -183,3 +186,27 @@ bool initUSB(void) return true; } + +bool screenTouched(int* x, int* y) +{ + unsigned char data[STATUS_QUERY_LENGTH]; + int transfered; + libusb_interrupt_transfer(screenHandle, ENDPOINT_IN, data, STATUS_QUERY_LENGTH, &transfered, 0); + if(transfered != STATUS_QUERY_LENGTH) + { + printx(ERROR, UI, "Status recieved is %d bytes long, and expected %d\n", transfered, STATUS_QUERY_LENGTH); + return false; + } + + //printx(DEBUG, UI, "%02X %02X %02X %02X", data[0], data[1], data[2], data[3]); + //printx(DEBUG, UI, "%02X %02X %02X %02X", data[4], data[5], data[6], data[7]); + //printx(DEBUG, UI, "%02X %02X %02X\n", data[8], data[9], data[10]); + + *x = data[3] + (256 * (int)data[4]); + + *y = data[7]; + + printx(DEBUG, UI, "Screen %s at X %d Y %d\n", data[2] == 1 ? "touched" : "untouched", *x, *y); + + return data[2] == 1; +} diff --git a/usb.h b/usb.h index 4a4d52a..22be5cc 100644 --- a/usb.h +++ b/usb.h @@ -3,5 +3,6 @@ bool initUSB(); void displayPicture(char*); +bool screenTouched(int*, int*); #endif -- libgit2 0.21.2