Added touch support to emulator. Implemented basic touch function.
This commit is contained in:
@@ -1,15 +1,45 @@
|
|||||||
#include "app.h"
|
#include "app.h"
|
||||||
#include "tft.h"
|
#include "tft.h"
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
|
#include "touch.h"
|
||||||
#include "pixy.h"
|
#include "pixy.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
bool pixy_connected = false;
|
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() {
|
void app_init() {
|
||||||
system_init();
|
system_init();
|
||||||
tft_init();
|
tft_init();
|
||||||
|
touch_init();
|
||||||
|
|
||||||
pixy_connected = (pixy_init()==0); //try to connect to pixy
|
pixy_connected = (pixy_init()==0); //try to connect to pixy
|
||||||
|
|
||||||
@@ -20,10 +50,24 @@ void app_init() {
|
|||||||
tft_draw_rectangle(40,210,60,235,BLUE);
|
tft_draw_rectangle(40,210,60,235,BLUE);
|
||||||
tft_fill_rectangle(100,215,200,225,GREEN);
|
tft_fill_rectangle(100,215,200,225,GREEN);
|
||||||
tft_draw_line(10,215,310,225,RGB(0xFF,0,0xFF));
|
tft_draw_line(10,215,310,225,RGB(0xFF,0,0xFF));
|
||||||
|
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int pixy_led_test();
|
int pixy_led_test();
|
||||||
int pixy_frame_test();
|
int pixy_frame_test();
|
||||||
|
|
||||||
@@ -122,7 +166,7 @@ int pixy_frame_test() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
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)
|
if (y&1)
|
||||||
{
|
{
|
||||||
|
|||||||
6
common/lowlevel/ll_touch.h
Normal file
6
common/lowlevel/ll_touch.h
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
bool ll_touch_init();
|
||||||
|
|
||||||
|
|
||||||
129
common/touch/touch.c
Normal file
129
common/touch/touch.c
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
#include "touch.h"
|
||||||
|
#include "ll_touch.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#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; i<NUM_AREAS; i++)
|
||||||
|
{
|
||||||
|
if(areas[i]==NULL) num--;
|
||||||
|
if(num==0) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
bool touch_register_area(TOUCH_AREA_STRUCT* area) //Registers an Area (fill Struct first). Return false if no more Space in the Pointertable (-->Change NUM_AREAS).
|
||||||
|
{
|
||||||
|
|
||||||
|
for(unsigned char i=0; i<NUM_AREAS; i++)
|
||||||
|
{
|
||||||
|
if(areas[i]==NULL)
|
||||||
|
{
|
||||||
|
area->flags=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<NUM_AREAS; i++)
|
||||||
|
{
|
||||||
|
if(areas[i]==area)
|
||||||
|
{
|
||||||
|
areas[i]=NULL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
#include<stdbool.h>
|
||||||
|
#include<stdint.h>
|
||||||
|
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ INCLUDES:=$(addprefix -I,$(INCLUDES))
|
|||||||
|
|
||||||
|
|
||||||
CPPFLAGS=-DUSE_USB_OTG_FS -DUSE_HOST_MODE $(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++
|
LIBS=pixy usbhost coreperiph stdc++
|
||||||
|
|||||||
6
discovery/src/ll_touch.c
Normal file
6
discovery/src/ll_touch.c
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#include "ll_touch.h"
|
||||||
|
|
||||||
|
bool ll_touch_init() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ QT_LIB=$(QT_DIR)/libemulatorqt.a
|
|||||||
|
|
||||||
|
|
||||||
CPPFLAGS= -march=x86-64 -mtune=generic -fPIC $(INCLUDES)
|
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
|
LIBS= pixy usb-1.0 boost_system boost_timer boost_chrono
|
||||||
|
|||||||
@@ -14,12 +14,14 @@ SOURCES += \
|
|||||||
mainwindow.cpp \
|
mainwindow.cpp \
|
||||||
main.cpp \
|
main.cpp \
|
||||||
ll_tft.cpp \
|
ll_tft.cpp \
|
||||||
ll_system.cpp
|
ll_system.cpp \
|
||||||
|
ll_touch.cpp
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
mainwindow.h \
|
mainwindow.h \
|
||||||
|
|
||||||
|
|
||||||
INCLUDEPATH+= ../../common/lowlevel/
|
INCLUDEPATH+= ../../common/lowlevel/ \
|
||||||
|
../../common/touch/
|
||||||
|
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
|
|||||||
8
emulator/qt/ll_touch.cpp
Normal file
8
emulator/qt/ll_touch.cpp
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include "ll_touch.h"
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ll_touch_init() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
@@ -3,6 +3,11 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <QMouseEvent>
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include "touch.h"
|
||||||
|
}
|
||||||
|
|
||||||
#define DISPLAY_WIDTH 320
|
#define DISPLAY_WIDTH 320
|
||||||
#define DISPLAY_HEIGHT 240
|
#define DISPLAY_HEIGHT 240
|
||||||
@@ -110,9 +115,38 @@ void MainWindow::paintEvent(QPaintEvent *)
|
|||||||
//render_mutex.unlock();
|
//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()
|
MainWindow::~MainWindow()
|
||||||
{
|
{
|
||||||
delete ui;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,11 +25,15 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent * evt);
|
void paintEvent(QPaintEvent * evt);
|
||||||
|
void mousePressEvent(QMouseEvent* evt);
|
||||||
|
void mouseReleaseEvent(QMouseEvent* evt);
|
||||||
|
void mouseMoveEvent(QMouseEvent* evt);
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//QMutex render_mutex;
|
//QMutex render_mutex;
|
||||||
QImage image;
|
QImage image;
|
||||||
|
void checkAndSendEvent(QPoint pos, bool down);
|
||||||
|
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user