diff --git a/common/app/app.c b/common/app/app.c index 229d3c4..07d08b2 100644 --- a/common/app/app.c +++ b/common/app/app.c @@ -1,14 +1,47 @@ #include "app.h" #include "tft.h" #include "system.h" +#include "touch.h" #include "pixy.h" #include +#include + +bool pixy_connected = false; + +TOUCH_AREA_STRUCT a1; + + +void touchCB(void* touchArea, TOUCH_ACTION triggeredAction) { + + switch(triggeredAction) { + case PEN_DOWN: + printf("action PEN_DOWN\n"); + break; + + case PEN_UP: + printf("action PEN_UP\n"); + break; + case PEN_MOVE: + printf("action PEN_MOVE\n"); + break; + case PEN_ENTER: + printf("action PEN_ENTER\n"); + break; + case PEN_LEAVE: + printf("action PEN_LEAVE\n"); + break; + default: + printf("action %s\n",triggeredAction); + break; + } +} void app_init() { system_init(); tft_init(); + touch_init(); - pixy_init(); + pixy_connected = (pixy_init()==0); //try to connect to pixy //only testwise tft_clear(WHITE); @@ -18,22 +51,53 @@ void app_init() { tft_fill_rectangle(100,215,200,225,GREEN); tft_draw_line(10,215,310,225,RGB(0xFF,0,0xFF)); tft_draw_circle(10,10,100, RED); + + a1.hookedActions = PEN_DOWN | PEN_UP | PEN_MOVE | PEN_ENTER | PEN_LEAVE; + a1.x1 = 30; + a1.y1 = 30; + a1.x2 = 100; + a1.y2 = 60; + a1.callback = touchCB; + touch_register_area(&a1); + + tft_draw_rectangle(30,30,100,60,BLUE); + } -void pixy_led_test(); -void pixy_frame_test(); + +int pixy_led_test(); +int pixy_frame_test(); //app event loop void app_process() { - pixy_service(); //send/receive event data + + system_process(); //Let the system handle it's pending events - //Code for tests see below - pixy_led_test(); - pixy_frame_test(); - - //system_delay(500); + + //Note: The only way to detect that pixy has been disconnected is if a command fails. There's no pixy_is_connected method yet :'( + + if(!pixy_connected) { //Pixy not connected + pixy_close(); //Ensure that all pixy resources are freed (failsafe) + if(pixy_init()==0) { //try to connect to pixy + pixy_connected=true; + } + } + + if(pixy_connected) { + pixy_service(); //Send/receive event data from/to pixy failed + + //Code for tests see below + if(pixy_led_test()!=0) { + pixy_connected=false; + } + + /*if(pixy_frame_test()!=0) { + pixy_connected=false; + }*/ + system_delay(500); + } } @@ -43,7 +107,7 @@ int colorind; const uint32_t colors [] = {0xFF0000, 0x00FF00,0x0000FF,0xFFFF00,0x00FFFF,0xFF00FF,0xFFFFFF,0x000000}; const int num_colors = sizeof(colors)/sizeof(uint32_t); -void pixy_led_test() { +int pixy_led_test() { if(colorind==0) { pixy_led_set_max_current(5); } @@ -52,6 +116,12 @@ void pixy_led_test() { int return_value; return_value = pixy_command("led_set", INT32(colors[colorind++]), END_OUT_ARGS, &response, END_IN_ARGS); colorind%=num_colors; + + if(return_value!=0) { + colorind=0; //reset color ind, to start at zero when plugging pixy in again + } + + return return_value; } //---------------------------------------------------------------------------------------------------------------------------- @@ -59,7 +129,7 @@ void pixy_led_test() { int renderBA81(uint8_t renderFlags, uint16_t width, uint16_t height, uint32_t frameLen, uint8_t *frame); -void pixy_frame_test() { +int pixy_frame_test() { uint8_t* videodata; int32_t response; @@ -86,15 +156,16 @@ void pixy_frame_test() { &videodata, // pointer to mem address for returned frame END_IN_ARGS); - if(return_value==0) { return_value = renderBA81(renderflags,xwidth,ywidth,size,videodata); - } + } + + return return_value; } -inline void interpolateBayer(uint16_t width, uint16_t x, uint16_t y, uint8_t *pixel, uint8_t* r, uint8_t* g, uint8_t* b) +void interpolateBayer(uint16_t width, uint16_t x, uint16_t y, uint8_t *pixel, uint8_t* r, uint8_t* g, uint8_t* b) { if (y&1) { @@ -143,24 +214,41 @@ int renderBA81(uint8_t renderFlags, uint16_t width, uint16_t height, uint32_t fr // don't render top and bottom rows, and left and rightmost columns because of color // interpolation //uint32_t decodedimage[(width-2)*(height-2)]; - uint16_t decodedimage[(width-2)*(height-2)]; - - uint16_t* line = decodedimage; - for (y=1; y +#include + +bool ll_touch_init(); + + diff --git a/common/system/system.c b/common/system/system.c index 6cb0887..f7a88cb 100644 --- a/common/system/system.c +++ b/common/system/system.c @@ -6,10 +6,14 @@ bool system_init() { return ll_system_init(); } - - void system_delay(uint32_t msec) { ll_system_delay(msec); } +void system_process() { + ll_system_process(); +} +void system_toggle_led() { + ll_system_toggle_led(); +} diff --git a/common/system/system.h b/common/system/system.h index 9513dd2..62b6720 100644 --- a/common/system/system.h +++ b/common/system/system.h @@ -3,3 +3,5 @@ bool system_init(); void system_delay(uint32_t msec); +void system_process(); +void system_toggle_led(); diff --git a/common/touch/touch.c b/common/touch/touch.c new file mode 100644 index 0000000..dbecbc6 --- /dev/null +++ b/common/touch/touch.c @@ -0,0 +1,129 @@ +#include "touch.h" +#include "ll_touch.h" +#include + +#define NUM_AREAS 50 //Number of Structs Reserved in Memory for TouchAreas (e.g Buttons) +TOUCH_AREA_STRUCT* areas[NUM_AREAS] = {NULL}; + +volatile int touchY=0; //Last Y Coordinate in pixels +volatile int touchX=0; //Last X Coordinate in pixels +volatile TOUCH_STATE oldState=TOUCH_UP; + +bool touch_init() { + return ll_touch_init(); +} + + +bool touch_add_raw_event(uint16_t x, uint16_t y, TOUCH_STATE state) { + bool penDown = (state==TOUCH_DOWN); + bool oldPenDown = (oldState==TOUCH_DOWN); + oldState=state; + uint16_t touchX = x; + uint16_t touchY = y; + if(penDown) + { + // tftDrawPixel(touchX,touchY,WHITE); + if(!oldPenDown) //First Touch + { + for(int z=0; z < NUM_AREAS; z++) // For every touch area + { + if(areas[z]!=NULL && touchX >= areas[z]->x1 && touchX <= areas[z]->x2 && touchY >= areas[z]->y1 && touchY <= areas[z]->y2 ) + { + areas[z]->flags=1; //PenInside=1 + if(areas[z]->hookedActions & PEN_DOWN) + areas[z]->callback(areas[z],PEN_DOWN); + } + } + } + else //Second, Third + { + for(int z=0; z < NUM_AREAS; z++) // For every touch area + { + if(areas[z]!=NULL ) + { + if(touchX >= areas[z]->x1 && touchX <= areas[z]->x2 && touchY >= areas[z]->y1 && touchY <= areas[z]->y2) + { + if(areas[z]->flags==0) //PenInside ==0 + { + areas[z]->flags=1; //PenInside=1 + if(areas[z]->hookedActions & PEN_ENTER) + areas[z]->callback(areas[z],PEN_ENTER); + } + } + else if(areas[z]->flags) //PenInside==1 + { + areas[z]->flags=0; //PenInside=0 + if(areas[z]->hookedActions & PEN_LEAVE) + areas[z]->callback(areas[z],PEN_LEAVE); + } + } + } + } + for(int z=0; z < NUM_AREAS; z++) // For every touch area + { + if(areas[z]!=NULL && areas[z]->hookedActions&PEN_MOVE) + { + if(touchX >= areas[z]->x1 && touchX <= areas[z]->x2 && touchY >= areas[z]->y1 && touchY <= areas[z]->y2) + { + areas[z]->callback(areas[z],PEN_MOVE); + } + } + } + } + else + { + if(oldPenDown) //Was the pen ever down (or was it a too short touch) + { + for(int z=0; z < NUM_AREAS; z++) // For every touch area + { + if(areas[z]!=NULL && touchX >= areas[z]->x1 && touchX <= areas[z]->x2 && touchY >= areas[z]->y1 && touchY <= areas[z]->y2 ) + { + areas[z]->flags=0; //PenInside = 0; + if(areas[z]->hookedActions & PEN_UP) + areas[z]->callback(areas[z],PEN_UP); + } + } + } + touchX=0xFFFF; + touchY=0xFFFF; + } + + return true; +} + +bool touch_have_empty(unsigned char num) +{ + for(unsigned char i=0; iChange NUM_AREAS). +{ + + for(unsigned char i=0; iflags=0; + areas[i]=area; + return true; + } + } + return false; +} + +void touch_unregister_area(TOUCH_AREA_STRUCT* area)//Unregisters an Area +{ + for(unsigned char i=0; i +#include + + +typedef enum {TOUCH_UP,TOUCH_DOWN} TOUCH_STATE ; +typedef enum {NONE=0x00,PEN_DOWN=0x01, PEN_UP=0x02, PEN_ENTER=0x04, PEN_LEAVE=0x08,PEN_MOVE=0x10} TOUCH_ACTION; + +typedef void (*TOUCH_CALLBACK)(void* touchArea, TOUCH_ACTION triggeredAction); + +typedef struct { + TOUCH_ACTION hookedActions; //Actions to listen to + unsigned int x1; //Top Left X Coordiate of Area + unsigned int y1; //Top Left Y Coordiate of Area + unsigned int x2; //Bottom Right X Coordiate of Area + unsigned int y2; //Bottom Right Y Coordiate of Area + TOUCH_CALLBACK callback; //Callback + uint8_t flags; //Internal Used, don't change +} TOUCH_AREA_STRUCT; + + +bool touch_init(); +bool touch_add_raw_event(uint16_t x, uint16_t y,TOUCH_STATE state); +bool touch_have_empty(unsigned char num); +bool touch_register_area(TOUCH_AREA_STRUCT* area); +void touch_unregister_area(TOUCH_AREA_STRUCT* area); + + diff --git a/discovery/Makefile b/discovery/Makefile index 08b4fd3..c7c4a45 100644 --- a/discovery/Makefile +++ b/discovery/Makefile @@ -8,6 +8,7 @@ CROSS_COMPILE=arm-none-eabi- CC=$(CROSS_COMPILE)gcc OBJCOPY=$(CROSS_COMPILE)objcopy GDB=$(CROSS_COMPILE)gdb +SIZE=$(CROSS_COMPILE)size MKDIR=mkdir -p RM=rm -f @@ -40,7 +41,7 @@ INCLUDES:=$(addprefix -I,$(INCLUDES)) CPPFLAGS=-DUSE_USB_OTG_FS -DUSE_HOST_MODE $(INCLUDES) -CFLAGS=$(ARCH_FLAGS) -O0 -g +CFLAGS=$(ARCH_FLAGS) -O0 -g -std=c99 LIBS=pixy usbhost coreperiph stdc++ @@ -90,6 +91,7 @@ stop: #elf to binary %.bin: %.elf $(OBJCOPY) -O binary $< $@ + $(SIZE) $< #Asm files to objects $(OBJ_DIR)/%.o: $(SRC_DIR)/%.s diff --git a/discovery/libs/Pixy/src/chirp.cpp b/discovery/libs/Pixy/src/chirp.cpp index 0ce1ed7..612f5a3 100644 --- a/discovery/libs/Pixy/src/chirp.cpp +++ b/discovery/libs/Pixy/src/chirp.cpp @@ -856,6 +856,10 @@ int Chirp::realloc(uint32_t min) min = m_bufSize+CRP_BUFSIZE; else min += CRP_BUFSIZE; + + if(min==m_bufSize) + return CRP_RES_OK; + uint8_t *newbuf = new (std::nothrow) uint8_t[min]; if (newbuf==NULL) return CRP_RES_ERROR_MEMORY; diff --git a/discovery/src/ll_system.c b/discovery/src/ll_system.c index db5307e..b666ff9 100644 --- a/discovery/src/ll_system.c +++ b/discovery/src/ll_system.c @@ -55,6 +55,17 @@ bool ll_system_init(void) return true; } +void ll_system_process() { + USBH_Process(&USB_OTG_Core, &USB_Host); +} + + + void ll_system_delay(uint32_t msec) { USB_OTG_BSP_mDelay(msec); } + + +void ll_system_toggle_led() { + STM_EVAL_LEDToggle(LED6); +} diff --git a/discovery/src/ll_touch.c b/discovery/src/ll_touch.c new file mode 100644 index 0000000..998001e --- /dev/null +++ b/discovery/src/ll_touch.c @@ -0,0 +1,6 @@ +#include "ll_touch.h" + +bool ll_touch_init() { + return false; +} + diff --git a/discovery/src/main.c b/discovery/src/main.c index 4703ec0..4429e45 100644 --- a/discovery/src/main.c +++ b/discovery/src/main.c @@ -7,7 +7,6 @@ int main(void) while (1) { app_process(); - //USBH_Process(&USB_OTG_Core, &USB_Host); } } diff --git a/discovery/src/usbh_msc_core.c b/discovery/src/usbh_msc_core.c index 0bdb405..28d99e6 100644 --- a/discovery/src/usbh_msc_core.c +++ b/discovery/src/usbh_msc_core.c @@ -1,7 +1,6 @@ #include "usbh_msc_core.h" #include "usbh_core.h" -#include "pixy.h" static USBH_Status USBH_MSC_InterfaceInit (USB_OTG_CORE_HANDLE *pdev , @@ -18,6 +17,8 @@ static USBH_Status USBH_MSC_ClassRequest(USB_OTG_CORE_HANDLE *pdev , extern USB_OTG_CORE_HANDLE USB_OTG_Core; +extern USBH_HOST USB_Host; + USBH_Class_cb_TypeDef USBH_MSC_cb = @@ -41,8 +42,6 @@ typedef struct MSC_Machine_TypeDef; MSC_Machine_TypeDef MSC_Machine; -enum {init,running,down}state; - static USBH_Status USBH_MSC_InterfaceInit ( USB_OTG_CORE_HANDLE *pdev, void *phost) @@ -108,11 +107,6 @@ static USBH_Status USBH_MSC_InterfaceInit ( USB_OTG_CORE_HANDLE *pdev, void USBH_MSC_InterfaceDeInit ( USB_OTG_CORE_HANDLE *pdev, void *phost) { - if(state==running) { - pixy_close(); - state=down; - } - if ( MSC_Machine.hc_num_out) { USB_OTG_HC_Halt(pdev, MSC_Machine.hc_num_out); @@ -133,8 +127,6 @@ static USBH_Status USBH_MSC_ClassRequest(USB_OTG_CORE_HANDLE *pdev , { USBH_Status status = USBH_OK ; - state=init; - return status; } @@ -147,32 +139,11 @@ static USBH_Status USBH_MSC_Handle(USB_OTG_CORE_HANDLE *pdev , if(HCD_IsDeviceConnected(pdev)) { - switch(state) - { - case init: - state = running; - USB_OTG_BSP_mDelay(3000); //let the pixy led flashing pass - pixy_init(); - break; - case running: - pixy_service(); - int appliStatus = pphost->usr_cb->USBH_USR_MSC_Application(); - if(appliStatus == 0) - { - state=running; //stay here - } - else if (appliStatus == 1) - { - status = USBH_APPLY_DEINIT; - pixy_close(); - state=down; - } - break; - case down: - break; - default: - break; - } + int appliStatus = pphost->usr_cb->USBH_USR_MSC_Application(); + if(appliStatus != 0) + { + status = USBH_APPLY_DEINIT; + } } return status; @@ -197,16 +168,36 @@ uint32_t USBH_LL_getTimer() { int USBH_LL_open() { + int timeoutDetect=100; + int timeoutStartup=3000; + cnt_int=0; //reset timer + + while(USB_Host.gState!=HOST_CLASS && cnt_int < timeoutDetect) { + USBH_Process(&USB_OTG_Core, &USB_Host); + } + + if(USB_Host.gState!=HOST_CLASS) { + return -5; // = LIBUSB_ERROR_NOT_FOUND + } + + + cnt_int=0; + while(cnt_int0 && cnt_int>=timeoutMs) { STM_EVAL_LEDOn(LED3); - return -7; //timeout (error code like with libusb + return -7; //timeout (error code like with libusb) } return -1; @@ -234,6 +225,8 @@ int USBH_LL_receive(uint8_t *data, uint32_t len, uint16_t timeoutMs) { USB_OTG_CORE_HANDLE *pdev = &USB_OTG_Core; + if(!HCD_IsDeviceConnected(pdev)) return -1; + USBH_BulkReceiveData (pdev, data, len , @@ -241,7 +234,7 @@ int USBH_LL_receive(uint8_t *data, uint32_t len, uint16_t timeoutMs) { URB_STATE state; cnt_int=0; //reset timer - if(timeoutMs==0) timeoutMs=10000; //Force 10s timeout (testwise) + if(timeoutMs==0) timeoutMs=1000; //Force 1s timeout (testwise) while((state=HCD_GetURB_State(pdev , MSC_Machine.hc_num_in)) == URB_IDLE && (timeoutMs==0 || cnt_int < timeoutMs)); @@ -249,7 +242,7 @@ int USBH_LL_receive(uint8_t *data, uint32_t len, uint16_t timeoutMs) { if(state!=URB_DONE) { if(timeoutMs>0 && cnt_int>=timeoutMs) { STM_EVAL_LEDOn(LED3); - return -7; //timeout (error code like with libusb + return -7; //timeout (error code like with libusb) } return -1; } diff --git a/discovery/src/usbh_usr.c b/discovery/src/usbh_usr.c index 909a876..c0ed14c 100644 --- a/discovery/src/usbh_usr.c +++ b/discovery/src/usbh_usr.c @@ -1,8 +1,6 @@ #include "usbh_usr.h" #include #include -#include "pixy.h" - USBH_Usr_cb_TypeDef USR_Callbacks = @@ -55,9 +53,9 @@ void USBH_USR_DeviceAttached(void) serial_ok=false; - STM_EVAL_LEDOff(LED5); - STM_EVAL_LEDOff(LED3); - STM_EVAL_LEDOn(LED4); + STM_EVAL_LEDOff(LED5); + STM_EVAL_LEDOff(LED3); + STM_EVAL_LEDOn(LED4); } /** @@ -144,7 +142,6 @@ void USBH_USR_Configuration_DescAvailable(USBH_CfgDesc_TypeDef * cfgDesc, void USBH_USR_Manufacturer_String(void *ManufacturerString) { manufacturer_ok = strcmp((char*)ManufacturerString,"Charmed Labs") == 0; - /* callback for Manufacturer String */ } /** @@ -155,7 +152,6 @@ void USBH_USR_Manufacturer_String(void *ManufacturerString) void USBH_USR_Product_String(void *ProductString) { product_ok = strcmp((char*)ProductString,"Pixy") == 0; - /* callback for Product String */ } /** @@ -166,7 +162,6 @@ void USBH_USR_Product_String(void *ProductString) void USBH_USR_SerialNum_String(void *SerialNumString) { serial_ok = strcmp((char*)SerialNumString,"DEMO 0.0") == 0; - /* callback for SerialNum_String */ } /** @@ -220,26 +215,8 @@ void USBH_USR_OverCurrentDetected (void) * @param None * @retval Staus */ - -/*int colorind; -const uint32_t colors [] = {0xFF0000, 0x00FF00,0x0000FF,0xFFFF00,0x00FFFF,0xFF00FF,0xFFFFFF,0x000000}; -const int num_colors = sizeof(colors)/sizeof(uint32_t); -*/ - int USBH_USR_MSC_Application(void) { - -/* if(colorind==0) { - pixy_led_set_max_current(5); - } - - int32_t response; - int return_value; - return_value = pixy_command("led_set", INT32(colors[colorind++]), END_OUT_ARGS, &response, END_IN_ARGS); - colorind%=num_colors; - USB_OTG_BSP_mDelay(500); -*/ - return 0; } @@ -254,10 +231,3 @@ void USBH_USR_DeInit(void) } -/** - * @} - */ - - - -/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ diff --git a/doc/.gitignore b/doc/.gitignore new file mode 100644 index 0000000..99cf5ff --- /dev/null +++ b/doc/.gitignore @@ -0,0 +1 @@ +*.*~ diff --git a/doc/docu.odt b/doc/docu.odt index bde0c51..b090e3f 100644 Binary files a/doc/docu.odt and b/doc/docu.odt differ diff --git a/doc/docu.pdf b/doc/docu.pdf new file mode 100644 index 0000000..78d7786 Binary files /dev/null and b/doc/docu.pdf differ diff --git a/doc/planung.ods b/doc/planung.ods index ccbb733..7ef2142 100644 Binary files a/doc/planung.ods and b/doc/planung.ods differ diff --git a/doc/screens.jpg b/doc/screens.jpg new file mode 100644 index 0000000..daf5005 Binary files /dev/null and b/doc/screens.jpg differ diff --git a/doc/usecasediagramm.dia b/doc/usecasediagramm.dia new file mode 100644 index 0000000..cc23299 Binary files /dev/null and b/doc/usecasediagramm.dia differ diff --git a/doc/usecasediagramm.png b/doc/usecasediagramm.png new file mode 100644 index 0000000..87c58c1 Binary files /dev/null and b/doc/usecasediagramm.png differ diff --git a/emulator/Makefile b/emulator/Makefile index 5917112..7fee00b 100644 --- a/emulator/Makefile +++ b/emulator/Makefile @@ -25,7 +25,7 @@ QT_LIB=$(QT_DIR)/libemulatorqt.a CPPFLAGS= -march=x86-64 -mtune=generic -fPIC $(INCLUDES) -CFLAGS= -O0 -g +CFLAGS= -O0 -g -std=c99 LIBS= pixy usb-1.0 boost_system boost_timer boost_chrono diff --git a/emulator/libs/Pixy/src/usblink.cpp b/emulator/libs/Pixy/src/usblink.cpp index 0a499ce..5e59c16 100644 --- a/emulator/libs/Pixy/src/usblink.cpp +++ b/emulator/libs/Pixy/src/usblink.cpp @@ -111,6 +111,7 @@ usblink_open__close_and_exit: usblink_open__exit: log("pixydebug: USBLink::open() returned %d\n", return_value); + usleep(100* 1000); //let pixy init pass return return_value; } diff --git a/emulator/qt/emulatorqt.pro b/emulator/qt/emulatorqt.pro index e604c2e..2059c2f 100644 --- a/emulator/qt/emulatorqt.pro +++ b/emulator/qt/emulatorqt.pro @@ -14,12 +14,14 @@ SOURCES += \ mainwindow.cpp \ main.cpp \ ll_tft.cpp \ - ll_system.cpp + ll_system.cpp \ + ll_touch.cpp HEADERS += \ mainwindow.h \ -INCLUDEPATH+= ../../common/lowlevel/ +INCLUDEPATH+= ../../common/lowlevel/ \ + ../../common/touch/ FORMS += \ diff --git a/emulator/qt/ll_system.cpp b/emulator/qt/ll_system.cpp index 861131b..1356956 100644 --- a/emulator/qt/ll_system.cpp +++ b/emulator/qt/ll_system.cpp @@ -1,4 +1,6 @@ #include +#include + extern "C" { #include "ll_system.h" } @@ -11,3 +13,10 @@ void ll_system_delay(uint32_t msec) { QThread::msleep(msec); } +void ll_system_process() { + QApplication::processEvents(); +} + +void ll_system_toggle_led() { + +} diff --git a/emulator/qt/ll_touch.cpp b/emulator/qt/ll_touch.cpp new file mode 100644 index 0000000..46e0c6c --- /dev/null +++ b/emulator/qt/ll_touch.cpp @@ -0,0 +1,8 @@ + +extern "C" { +#include "ll_touch.h" +} + +bool ll_touch_init() { + return true; +} diff --git a/emulator/qt/main.cpp b/emulator/qt/main.cpp index b3b8f97..dc67c83 100644 --- a/emulator/qt/main.cpp +++ b/emulator/qt/main.cpp @@ -10,7 +10,6 @@ extern "C" { void app_loop() { while(!QApplication::closingDown()) { app_process(); - QApplication::processEvents(); } } diff --git a/emulator/qt/mainwindow.cpp b/emulator/qt/mainwindow.cpp index 711c58e..43493db 100644 --- a/emulator/qt/mainwindow.cpp +++ b/emulator/qt/mainwindow.cpp @@ -3,6 +3,11 @@ #include #include #include +#include + +extern "C" { + #include "touch.h" +} #define DISPLAY_WIDTH 320 #define DISPLAY_HEIGHT 240 @@ -116,9 +121,38 @@ void MainWindow::paintEvent(QPaintEvent *) //render_mutex.unlock(); } +void MainWindow::mousePressEvent(QMouseEvent *evt) +{ + //qDebug() << "down" << evt->pos(); + checkAndSendEvent(evt->pos(),true); +} + +void MainWindow::mouseReleaseEvent(QMouseEvent *evt) +{ + //qDebug() << "up" << evt->pos(); + checkAndSendEvent(evt->pos(),false); +} + +void MainWindow::mouseMoveEvent(QMouseEvent *evt) +{ + //qDebug() << "move" << evt->pos(); + checkAndSendEvent(evt->pos(),true); + +} + MainWindow::~MainWindow() { delete ui; } +void MainWindow::checkAndSendEvent(QPoint pos, bool down) +{ + QPoint p = pos - QPoint(DISPLAY_X,DISPLAY_Y); + if(p.x()<0 || p.y()<0 || p.x() >= DISPLAY_WIDTH || p.y() >= DISPLAY_HEIGHT) return; + + //qDebug() << down << p; + + touch_add_raw_event(p.x(),p.y(),down?TOUCH_DOWN:TOUCH_UP); +} + diff --git a/emulator/qt/mainwindow.h b/emulator/qt/mainwindow.h index 2e903dc..397a5ad 100644 --- a/emulator/qt/mainwindow.h +++ b/emulator/qt/mainwindow.h @@ -26,11 +26,15 @@ public: protected: void paintEvent(QPaintEvent * evt); + void mousePressEvent(QMouseEvent* evt); + void mouseReleaseEvent(QMouseEvent* evt); + void mouseMoveEvent(QMouseEvent* evt); ~MainWindow(); private: //QMutex render_mutex; QImage image; + void checkAndSendEvent(QPoint pos, bool down); Ui::MainWindow *ui;