Updated fileheaders and styled files using astyle.
This commit is contained in:
@@ -1,3 +1,17 @@
|
||||
/**************************************************************************************************************************************
|
||||
* Project: discoverpixy
|
||||
* Website: https://github.com/t-moe/discoverpixy
|
||||
* Authors: Aaron Schmocker, Timo Lang
|
||||
* Institution: BFH Bern University of Applied Sciences
|
||||
* File: common/touch/screen_calibrate.c
|
||||
*
|
||||
* Version History:
|
||||
* Date Autor Email SHA Changes
|
||||
* 2015-06-01 timolang@gmail.com 06227da Added calibrate screen (WIP). fixed bug in emulator drawing.
|
||||
* 2015-06-01 timolang@gmail.com eb573bc Finalized calibration. Fixed a bug in screen module.
|
||||
*
|
||||
**************************************************************************************************************************************/
|
||||
|
||||
#include "screen_calibrate.h"
|
||||
#include "tft.h"
|
||||
#include "touch.h"
|
||||
@@ -6,90 +20,102 @@
|
||||
extern volatile bool calibration; //from touch.c
|
||||
|
||||
|
||||
static void enter(void* screen) {
|
||||
tft_clear(BLACK);
|
||||
static void enter(void* screen)
|
||||
{
|
||||
tft_clear(BLACK);
|
||||
}
|
||||
|
||||
static void leave(void* screen) {
|
||||
static void leave(void* screen)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static void update(void* screen) {
|
||||
int x1,y1,x2,y2,dx,dy;
|
||||
static void update(void* screen)
|
||||
{
|
||||
int x1, y1, x2, y2, dx, dy;
|
||||
|
||||
|
||||
tft_print_line(50,50,WHITE,BLACK,1,"Calibration:");
|
||||
tft_print_line(50,120,WHITE,BLACK,0,"Hit the markers exactly!");
|
||||
//-----------------First Point--------------------
|
||||
tft_draw_line(CCENTER,CBEGIN,CCENTER,CEND,WHITE); //Draw Cross
|
||||
tft_draw_line(CBEGIN,CCENTER,CEND,CCENTER,WHITE); //Draw Cross
|
||||
calibration=1; //TouchX + TouchY Values will not be converted to Pixels
|
||||
while(calibration); //Wait on PenUp
|
||||
POINT_STRUCT p1 = touch_get_last_point();
|
||||
x1=p1.x;
|
||||
y1=p1.y;
|
||||
tft_fill_rectangle(CBEGIN,CBEGIN,CEND,CEND,BLACK); //Clear Cross
|
||||
tft_print_line(50, 50, WHITE, BLACK, 1, "Calibration:");
|
||||
tft_print_line(50, 120, WHITE, BLACK, 0, "Hit the markers exactly!");
|
||||
//-----------------First Point--------------------
|
||||
tft_draw_line(CCENTER, CBEGIN, CCENTER, CEND, WHITE); //Draw Cross
|
||||
tft_draw_line(CBEGIN, CCENTER, CEND, CCENTER, WHITE); //Draw Cross
|
||||
calibration = 1; //TouchX + TouchY Values will not be converted to Pixels
|
||||
|
||||
//-----------------Second Point-------------------
|
||||
tft_draw_line(DWIDTH-CCENTER,DHEIGHT-CBEGIN,DWIDTH-CCENTER,DHEIGHT-CEND,WHITE);
|
||||
tft_draw_line(DWIDTH-CBEGIN,DHEIGHT-CCENTER,DWIDTH-CEND,DHEIGHT-CCENTER,WHITE);
|
||||
calibration=1;
|
||||
while(calibration);
|
||||
POINT_STRUCT p2 = touch_get_last_point();
|
||||
x2=p2.x;
|
||||
y2=p2.y;
|
||||
tft_fill_rectangle(DWIDTH-CBEGIN,DHEIGHT-CBEGIN,DWIDTH-CEND,DHEIGHT-CEND,BLACK);
|
||||
while (calibration); //Wait on PenUp
|
||||
|
||||
//-----------------Third Point--------------------
|
||||
tft_draw_line(CCENTER,DHEIGHT-CBEGIN,CCENTER,DHEIGHT-CEND,WHITE);
|
||||
tft_draw_line(CBEGIN,DHEIGHT-CCENTER,CEND,DHEIGHT-CCENTER,WHITE);
|
||||
calibration=1;
|
||||
while(calibration);
|
||||
POINT_STRUCT p3 = touch_get_last_point();
|
||||
x1+=p3.x; //Add(!) values. We'll build the average later
|
||||
y2+=p3.y;
|
||||
tft_fill_rectangle(CBEGIN,DHEIGHT-CBEGIN,CEND,DHEIGHT-CEND,BLACK);
|
||||
POINT_STRUCT p1 = touch_get_last_point();
|
||||
x1 = p1.x;
|
||||
y1 = p1.y;
|
||||
tft_fill_rectangle(CBEGIN, CBEGIN, CEND, CEND, BLACK); //Clear Cross
|
||||
|
||||
//------------------4. Point---------------------
|
||||
tft_draw_line(DWIDTH-CCENTER,CBEGIN,DWIDTH-CCENTER,CEND,WHITE);
|
||||
tft_draw_line(DWIDTH-CBEGIN,CCENTER,DWIDTH-CEND,CCENTER,WHITE);
|
||||
calibration=1;
|
||||
while(calibration);
|
||||
POINT_STRUCT p4 = touch_get_last_point();
|
||||
x2+=p4.x;
|
||||
y1+=p4.y;
|
||||
tft_fill_rectangle(DWIDTH-CBEGIN,CBEGIN,DWIDTH-CEND,CEND,BLACK);
|
||||
//-------------------Calculation---------------------
|
||||
x1++; //Add 1 and divide by 2 later = +0.5 (for correct rounding)
|
||||
y1++;
|
||||
x2++;
|
||||
y2++;
|
||||
x1>>=1; //Divide by 2
|
||||
y1>>=1;
|
||||
x2>>=1;
|
||||
y2>>=1;
|
||||
dx = (x2-x1); //Build the Difference
|
||||
dy = (y2-y1);
|
||||
//-----------------Second Point-------------------
|
||||
tft_draw_line(DWIDTH - CCENTER, DHEIGHT - CBEGIN, DWIDTH - CCENTER, DHEIGHT - CEND, WHITE);
|
||||
tft_draw_line(DWIDTH - CBEGIN, DHEIGHT - CCENTER, DWIDTH - CEND, DHEIGHT - CCENTER, WHITE);
|
||||
calibration = 1;
|
||||
|
||||
touch_set_calibration_values(x1,dx,y1,dy);
|
||||
tft_print_line(50,120,WHITE,BLACK,0,"Calibration Done. Press anywhere");
|
||||
while (calibration);
|
||||
|
||||
calibration=1;
|
||||
while(calibration);
|
||||
gui_screen_back();
|
||||
POINT_STRUCT p2 = touch_get_last_point();
|
||||
x2 = p2.x;
|
||||
y2 = p2.y;
|
||||
tft_fill_rectangle(DWIDTH - CBEGIN, DHEIGHT - CBEGIN, DWIDTH - CEND, DHEIGHT - CEND, BLACK);
|
||||
|
||||
//-----------------Third Point--------------------
|
||||
tft_draw_line(CCENTER, DHEIGHT - CBEGIN, CCENTER, DHEIGHT - CEND, WHITE);
|
||||
tft_draw_line(CBEGIN, DHEIGHT - CCENTER, CEND, DHEIGHT - CCENTER, WHITE);
|
||||
calibration = 1;
|
||||
|
||||
while (calibration);
|
||||
|
||||
POINT_STRUCT p3 = touch_get_last_point();
|
||||
x1 += p3.x; //Add(!) values. We'll build the average later
|
||||
y2 += p3.y;
|
||||
tft_fill_rectangle(CBEGIN, DHEIGHT - CBEGIN, CEND, DHEIGHT - CEND, BLACK);
|
||||
|
||||
//------------------4. Point---------------------
|
||||
tft_draw_line(DWIDTH - CCENTER, CBEGIN, DWIDTH - CCENTER, CEND, WHITE);
|
||||
tft_draw_line(DWIDTH - CBEGIN, CCENTER, DWIDTH - CEND, CCENTER, WHITE);
|
||||
calibration = 1;
|
||||
|
||||
while (calibration);
|
||||
|
||||
POINT_STRUCT p4 = touch_get_last_point();
|
||||
x2 += p4.x;
|
||||
y1 += p4.y;
|
||||
tft_fill_rectangle(DWIDTH - CBEGIN, CBEGIN, DWIDTH - CEND, CEND, BLACK);
|
||||
//-------------------Calculation---------------------
|
||||
x1++; //Add 1 and divide by 2 later = +0.5 (for correct rounding)
|
||||
y1++;
|
||||
x2++;
|
||||
y2++;
|
||||
x1 >>= 1; //Divide by 2
|
||||
y1 >>= 1;
|
||||
x2 >>= 1;
|
||||
y2 >>= 1;
|
||||
dx = (x2 - x1); //Build the Difference
|
||||
dy = (y2 - y1);
|
||||
|
||||
touch_set_calibration_values(x1, dx, y1, dy);
|
||||
tft_print_line(50, 120, WHITE, BLACK, 0, "Calibration Done. Press anywhere");
|
||||
|
||||
calibration = 1;
|
||||
|
||||
while (calibration);
|
||||
|
||||
gui_screen_back();
|
||||
|
||||
}
|
||||
|
||||
|
||||
static SCREEN_STRUCT screen = {
|
||||
enter,
|
||||
leave,
|
||||
update
|
||||
enter,
|
||||
leave,
|
||||
update
|
||||
};
|
||||
|
||||
|
||||
SCREEN_STRUCT* get_screen_calibrate() {
|
||||
return &screen;
|
||||
SCREEN_STRUCT* get_screen_calibrate()
|
||||
{
|
||||
return &screen;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
/**************************************************************************************************************************************
|
||||
* Project: discoverpixy
|
||||
* Website: https://github.com/t-moe/discoverpixy
|
||||
* Authors: Aaron Schmocker, Timo Lang
|
||||
* Institution: BFH Bern University of Applied Sciences
|
||||
* File: common/touch/screen_calibrate.h
|
||||
*
|
||||
* Version History:
|
||||
* Date Autor Email SHA Changes
|
||||
* 2015-06-01 timolang@gmail.com 06227da Added calibrate screen (WIP). fixed bug in emulator drawing.
|
||||
* 2015-06-01 timolang@gmail.com eb573bc Finalized calibration. Fixed a bug in screen module.
|
||||
*
|
||||
**************************************************************************************************************************************/
|
||||
|
||||
#include "screen.h"
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,3 +1,21 @@
|
||||
/**************************************************************************************************************************************
|
||||
* Project: discoverpixy
|
||||
* Website: https://github.com/t-moe/discoverpixy
|
||||
* Authors: Aaron Schmocker, Timo Lang
|
||||
* Institution: BFH Bern University of Applied Sciences
|
||||
* File: common/touch/touch.c
|
||||
*
|
||||
* Version History:
|
||||
* Date Autor Email SHA Changes
|
||||
* 2015-04-27 timolang@gmail.com 259d446 Added touch support to emulator. Implemented basic touch function.
|
||||
* 2015-05-02 timolang@gmail.com 3281616 Added some more touch functions. Improved pixy test. Drag the Image around!
|
||||
* 2015-05-17 timolang@gmail.com 2d46336 Improved comments in implementation of button, checkbox, numupdown, tft, touch and screen modules/submodules.
|
||||
* 2015-06-01 timolang@gmail.com 06227da Added calibrate screen (WIP). fixed bug in emulator drawing.
|
||||
* 2015-06-01 timolang@gmail.com eb573bc Finalized calibration. Fixed a bug in screen module.
|
||||
* 2015-06-06 timolang@gmail.com c06661d Fixed some outdated comments in source code. Documented Gui Module in docu.
|
||||
*
|
||||
**************************************************************************************************************************************/
|
||||
|
||||
#include "touch.h"
|
||||
#include "ll_touch.h"
|
||||
#include "screen_calibrate.h"
|
||||
@@ -18,184 +36,179 @@
|
||||
TOUCH_AREA_STRUCT* areas[NUM_AREAS] = {NULL}; //list with pointers to all managed touch area's
|
||||
|
||||
volatile POINT_STRUCT pos; //the last touch point
|
||||
volatile TOUCH_STATE oldState=TOUCH_UP; //the last touch state
|
||||
volatile TOUCH_STATE oldState = TOUCH_UP; //the last touch state
|
||||
volatile bool calibration = false; //whether or not we're currently calibrating
|
||||
|
||||
bool use_calibration=false; //Whether or not the current platform needs calibration and recalc of the values
|
||||
bool use_calibration = false; //Whether or not the current platform needs calibration and recalc of the values
|
||||
|
||||
//Calibration parameters (dummy values).
|
||||
int cal_xs=10;
|
||||
int cal_dx=100;
|
||||
int cal_ys=10;
|
||||
int cal_dy=100;
|
||||
int cal_xs = 10;
|
||||
int cal_dx = 100;
|
||||
int cal_ys = 10;
|
||||
int cal_dy = 100;
|
||||
|
||||
|
||||
void touch_set_calibration_values(int xs, int dx, int ys, int dy) {
|
||||
cal_xs = xs;
|
||||
cal_ys = ys;
|
||||
cal_dx = dx;
|
||||
cal_dy = dy;
|
||||
void touch_set_calibration_values(int xs, int dx, int ys, int dy)
|
||||
{
|
||||
cal_xs = xs;
|
||||
cal_ys = ys;
|
||||
cal_dx = dx;
|
||||
cal_dy = dy;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool touch_init() {
|
||||
return ll_touch_init();
|
||||
bool touch_init()
|
||||
{
|
||||
return ll_touch_init();
|
||||
}
|
||||
|
||||
void touch_set_value_convert_mode(bool uc) {
|
||||
use_calibration=uc;
|
||||
void touch_set_value_convert_mode(bool uc)
|
||||
{
|
||||
use_calibration = uc;
|
||||
}
|
||||
|
||||
|
||||
bool touch_add_raw_event(uint16_t touchX, uint16_t touchY, TOUCH_STATE state) {
|
||||
//Update current and old position/state
|
||||
bool penDown = (state==TOUCH_DOWN);
|
||||
bool oldPenDown = (oldState==TOUCH_DOWN);
|
||||
oldState=state;
|
||||
bool touch_add_raw_event(uint16_t touchX, uint16_t touchY, TOUCH_STATE state)
|
||||
{
|
||||
//Update current and old position/state
|
||||
bool penDown = (state == TOUCH_DOWN);
|
||||
bool oldPenDown = (oldState == TOUCH_DOWN);
|
||||
oldState = state;
|
||||
|
||||
if(calibration) //If in Calibration mode
|
||||
{
|
||||
if(penDown)
|
||||
{
|
||||
pos.x=touchX;
|
||||
pos.y=touchY;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(oldPenDown) //Run only if we got at least one pen down
|
||||
calibration=0; //Calibration finish (Touch X and Y are the values from the last measure, where the pen was down)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (calibration) { //If in Calibration mode
|
||||
if (penDown) {
|
||||
pos.x = touchX;
|
||||
pos.y = touchY;
|
||||
} else {
|
||||
if (oldPenDown) { //Run only if we got at least one pen down
|
||||
calibration = 0; //Calibration finish (Touch X and Y are the values from the last measure, where the pen was down)
|
||||
}
|
||||
}
|
||||
|
||||
//If we reach this point we're not in calibration mode and we need to process the event and call the registred handlers..
|
||||
return true;
|
||||
}
|
||||
|
||||
if(use_calibration) { //the underlying touch hardware uses calibration
|
||||
//Calculate the real touch position out of the passed ones, and the calibration values
|
||||
pos.x=touchX=(((long)(DWIDTH-2*CCENTER)*2*(long)((long)touchX-cal_xs)/cal_dx+1)>>1)+CCENTER;
|
||||
pos.y=touchY=(((long)(DHEIGHT-2*CCENTER)*2*(long)((long)touchY-cal_ys)/cal_dy+1)>>1)+CCENTER;
|
||||
} else { //no conversion needed for the underlying hardware
|
||||
pos.x=touchX;
|
||||
pos.y=touchY;
|
||||
}
|
||||
//If we reach this point we're not in calibration mode and we need to process the event and call the registred handlers..
|
||||
|
||||
if(penDown) //pen is down now
|
||||
{
|
||||
//tft_draw_pixel(touchX,touchY,WHITE);
|
||||
if(!oldPenDown) //pen wasn't down before (positive edge) => First Touch
|
||||
{
|
||||
for(int z=0; z < NUM_AREAS; z++) // For every touch area
|
||||
{
|
||||
//Check if pos is inside 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; //Save PenInside=1
|
||||
if(areas[z]->hookedActions & PEN_DOWN) //The user wants to receive pen down events
|
||||
areas[z]->callback(areas[z],PEN_DOWN); //Send event to user callback
|
||||
}
|
||||
}
|
||||
}
|
||||
else //Pen was down before => Second, Third event in row
|
||||
{
|
||||
for(int z=0; z < NUM_AREAS; z++) // For every touch area
|
||||
{
|
||||
if(areas[z]!=NULL )
|
||||
{
|
||||
//Check if pos is inside area
|
||||
if(touchX >= areas[z]->x1 && touchX <= areas[z]->x2 && touchY >= areas[z]->y1 && touchY <= areas[z]->y2)
|
||||
{
|
||||
if(areas[z]->flags==0) //Pen was not inside before (PenInside==0)
|
||||
{
|
||||
areas[z]->flags=1; //Pen is inside now (PenInside=1)
|
||||
if(areas[z]->hookedActions & PEN_ENTER) //The user wants to receive pen enter events
|
||||
areas[z]->callback(areas[z],PEN_ENTER);
|
||||
}
|
||||
}
|
||||
else if(areas[z]->flags) //Pos not inside area, but it was before (PenInside==1)
|
||||
{
|
||||
areas[z]->flags=0; //Pen is no longer inside (PenInside=0)
|
||||
if(areas[z]->hookedActions & PEN_LEAVE) //The user wants to receive pen leave events
|
||||
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)) //User want's to receive pen move events
|
||||
{
|
||||
//Check if pos is inside area
|
||||
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 //pen is not down now
|
||||
{
|
||||
if(oldPenDown) //but it was down before (negative edge)
|
||||
{
|
||||
for(int z=0; z < NUM_AREAS; z++) // For every touch area
|
||||
{
|
||||
//Check if pos is inside 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; //The pen is no longer inside (PenInside = 0);
|
||||
if(areas[z]->hookedActions & PEN_UP) //user want's to receive pen up events
|
||||
areas[z]->callback(areas[z],PEN_UP);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
if (use_calibration) { //the underlying touch hardware uses calibration
|
||||
//Calculate the real touch position out of the passed ones, and the calibration values
|
||||
pos.x = touchX = (((long)(DWIDTH - 2 * CCENTER) * 2 * (long)((long)touchX - cal_xs) / cal_dx + 1) >> 1) + CCENTER;
|
||||
pos.y = touchY = (((long)(DHEIGHT - 2 * CCENTER) * 2 * (long)((long)touchY - cal_ys) / cal_dy + 1) >> 1) + CCENTER;
|
||||
} else { //no conversion needed for the underlying hardware
|
||||
pos.x = touchX;
|
||||
pos.y = touchY;
|
||||
}
|
||||
|
||||
if (penDown) { //pen is down now
|
||||
//tft_draw_pixel(touchX,touchY,WHITE);
|
||||
if (!oldPenDown) { //pen wasn't down before (positive edge) => First Touch
|
||||
for (int z = 0; z < NUM_AREAS; z++) { // For every touch area
|
||||
//Check if pos is inside 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; //Save PenInside=1
|
||||
|
||||
if (areas[z]->hookedActions & PEN_DOWN) { //The user wants to receive pen down events
|
||||
areas[z]->callback(areas[z], PEN_DOWN); //Send event to user callback
|
||||
}
|
||||
}
|
||||
}
|
||||
} else { //Pen was down before => Second, Third event in row
|
||||
for (int z = 0; z < NUM_AREAS; z++) { // For every touch area
|
||||
if (areas[z] != NULL) {
|
||||
//Check if pos is inside area
|
||||
if (touchX >= areas[z]->x1 && touchX <= areas[z]->x2 && touchY >= areas[z]->y1 && touchY <= areas[z]->y2) {
|
||||
if (areas[z]->flags == 0) { //Pen was not inside before (PenInside==0)
|
||||
areas[z]->flags = 1; //Pen is inside now (PenInside=1)
|
||||
|
||||
if (areas[z]->hookedActions & PEN_ENTER) { //The user wants to receive pen enter events
|
||||
areas[z]->callback(areas[z], PEN_ENTER);
|
||||
}
|
||||
}
|
||||
} else if (areas[z]->flags) { //Pos not inside area, but it was before (PenInside==1)
|
||||
areas[z]->flags = 0; //Pen is no longer inside (PenInside=0)
|
||||
|
||||
if (areas[z]->hookedActions & PEN_LEAVE) { //The user wants to receive pen leave events
|
||||
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)) { //User want's to receive pen move events
|
||||
//Check if pos is inside area
|
||||
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 { //pen is not down now
|
||||
if (oldPenDown) { //but it was down before (negative edge)
|
||||
for (int z = 0; z < NUM_AREAS; z++) { // For every touch area
|
||||
//Check if pos is inside 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; //The pen is no longer inside (PenInside = 0);
|
||||
|
||||
if (areas[z]->hookedActions & PEN_UP) { //user want's to receive pen up events
|
||||
areas[z]->callback(areas[z], PEN_UP);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool touch_have_empty(unsigned char num)
|
||||
{
|
||||
//go through pointer array and check for free spaces
|
||||
for(unsigned char i=0; i<NUM_AREAS; i++)
|
||||
{
|
||||
if(areas[i]==NULL) num--; //a free space was found, we need one less
|
||||
if(num==0) return true; //enough free spaces found
|
||||
}
|
||||
return false; //not enough free spaces found
|
||||
//go through pointer array and check for free spaces
|
||||
for (unsigned char i = 0; i < NUM_AREAS; i++) {
|
||||
if (areas[i] == NULL) {
|
||||
num--; //a free space was found, we need one less
|
||||
}
|
||||
|
||||
if (num == 0) {
|
||||
return true; //enough free spaces found
|
||||
}
|
||||
}
|
||||
|
||||
return false; //not enough free spaces found
|
||||
}
|
||||
|
||||
bool touch_register_area(TOUCH_AREA_STRUCT* area)
|
||||
{
|
||||
//go through pointer array and check for free space
|
||||
for(unsigned char i=0; i<NUM_AREAS; i++)
|
||||
{
|
||||
if(areas[i]==NULL) //free space found
|
||||
{
|
||||
area->flags=0; //we start with empty flags (PenInside=0)
|
||||
areas[i]=area; //save pointer into list
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false; //no free space found
|
||||
//go through pointer array and check for free space
|
||||
for (unsigned char i = 0; i < NUM_AREAS; i++) {
|
||||
if (areas[i] == NULL) { //free space found
|
||||
area->flags = 0; //we start with empty flags (PenInside=0)
|
||||
areas[i] = area; //save pointer into list
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false; //no free space found
|
||||
}
|
||||
|
||||
void touch_unregister_area(TOUCH_AREA_STRUCT* area)
|
||||
{
|
||||
if(area==NULL) return;
|
||||
if (area == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
//go through pointer array and find the area to remove
|
||||
for(unsigned char i=0; i<NUM_AREAS; i++)
|
||||
{
|
||||
if(areas[i]==area) //area found in pointer array at pos i
|
||||
{
|
||||
areas[i]=NULL; //set pointer in list to NULL again
|
||||
break;
|
||||
}
|
||||
}
|
||||
//go through pointer array and find the area to remove
|
||||
for (unsigned char i = 0; i < NUM_AREAS; i++) {
|
||||
if (areas[i] == area) { //area found in pointer array at pos i
|
||||
areas[i] = NULL; //set pointer in list to NULL again
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
POINT_STRUCT touch_get_last_point() {
|
||||
return pos;
|
||||
POINT_STRUCT touch_get_last_point()
|
||||
{
|
||||
return pos;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,25 @@
|
||||
/**************************************************************************************************************************************
|
||||
* Project: discoverpixy
|
||||
* Website: https://github.com/t-moe/discoverpixy
|
||||
* Authors: Aaron Schmocker, Timo Lang
|
||||
* Institution: BFH Bern University of Applied Sciences
|
||||
* File: common/touch/touch.h
|
||||
*
|
||||
* Version History:
|
||||
* Date Autor Email SHA Changes
|
||||
* 2015-04-03 timolang@gmail.com 51089aa Refactored Project Structure for use with emulator
|
||||
* 2015-04-27 timolang@gmail.com 259d446 Added touch support to emulator. Implemented basic touch function.
|
||||
* 2015-04-27 timolang@gmail.com cf72baa Introduced a Screen (sub) module and divided app into multiple screens.
|
||||
* 2015-05-02 timolang@gmail.com 3281616 Added some more touch functions. Improved pixy test. Drag the Image around!
|
||||
* 2015-05-11 timolang@gmail.com a175a2f Added doxygen docu for touch module
|
||||
* 2015-05-11 timolang@gmail.com 08d9fe0 More work on doxygen module structure
|
||||
* 2015-05-12 timolang@gmail.com 1402598 Added doxygen stuff for button module and some minor changes to touch, screen_main and tft module.
|
||||
* 2015-05-15 timolang@gmail.com 9a16865 Added doxgen comments to filesyste, checkbox, numupdown and screen module. And some minor changes to the other modules.
|
||||
* 2015-06-01 timolang@gmail.com 06227da Added calibrate screen (WIP). fixed bug in emulator drawing.
|
||||
* 2015-06-01 timolang@gmail.com eb573bc Finalized calibration. Fixed a bug in screen module.
|
||||
*
|
||||
**************************************************************************************************************************************/
|
||||
|
||||
#ifndef TOUCH_H
|
||||
#define TOUCH_H
|
||||
|
||||
@@ -19,8 +41,8 @@
|
||||
Enum to describe the current Touch State. \sa touch_add_raw_event
|
||||
*/
|
||||
typedef enum {
|
||||
TOUCH_UP, //!< The display is currently not touched
|
||||
TOUCH_DOWN //!< The display is currently touched at some point
|
||||
TOUCH_UP, //!< The display is currently not touched
|
||||
TOUCH_DOWN //!< The display is currently touched at some point
|
||||
} TOUCH_STATE ;
|
||||
|
||||
/**
|
||||
@@ -28,12 +50,12 @@ typedef enum {
|
||||
* You can OR-combine them. \sa touch_register_area
|
||||
*/
|
||||
typedef enum {
|
||||
NONE=0x00, //!< Do not receive any events
|
||||
PEN_DOWN=0x01, //!< Receive an event when the pen goes down inside the region
|
||||
PEN_UP=0x02, //!< Receive an event when the pen goes up inside the region
|
||||
PEN_ENTER=0x04, //!< Receive an event when the pen enters the region (pen was down before)
|
||||
PEN_LEAVE=0x08, //!< Receive an event when the pen leaves the region (pen was inside region before)
|
||||
PEN_MOVE=0x10 //!< Receive an event when the pen moves inside the region (pen is down)
|
||||
NONE = 0x00, //!< Do not receive any events
|
||||
PEN_DOWN = 0x01, //!< Receive an event when the pen goes down inside the region
|
||||
PEN_UP = 0x02, //!< Receive an event when the pen goes up inside the region
|
||||
PEN_ENTER = 0x04, //!< Receive an event when the pen enters the region (pen was down before)
|
||||
PEN_LEAVE = 0x08, //!< Receive an event when the pen leaves the region (pen was inside region before)
|
||||
PEN_MOVE = 0x10 //!< Receive an event when the pen moves inside the region (pen is down)
|
||||
} TOUCH_ACTION;
|
||||
|
||||
/**
|
||||
@@ -48,13 +70,13 @@ typedef void (*TOUCH_CALLBACK)(void* touchArea, TOUCH_ACTION triggeredAction);
|
||||
* Structure to configure a Touch Area
|
||||
*/
|
||||
typedef struct {
|
||||
TOUCH_ACTION hookedActions; //!< Actions to listen to
|
||||
uint16_t x1; //!< Top Left X-Coordinate of Area
|
||||
uint16_t y1; //!< Top Left Y-Coordinate of Area
|
||||
uint16_t x2; //!< Bottom Right X-Coordinate of Area
|
||||
uint16_t y2; //!< Bottom Right Y-Coordinate of Area
|
||||
TOUCH_CALLBACK callback; //!< Callback which is executed when an event occurred in this Area.
|
||||
uint8_t flags; //!< For internal use, don't change, don't initialize
|
||||
TOUCH_ACTION hookedActions; //!< Actions to listen to
|
||||
uint16_t x1; //!< Top Left X-Coordinate of Area
|
||||
uint16_t y1; //!< Top Left Y-Coordinate of Area
|
||||
uint16_t x2; //!< Bottom Right X-Coordinate of Area
|
||||
uint16_t y2; //!< Bottom Right Y-Coordinate of Area
|
||||
TOUCH_CALLBACK callback; //!< Callback which is executed when an event occurred in this Area.
|
||||
uint8_t flags; //!< For internal use, don't change, don't initialize
|
||||
} TOUCH_AREA_STRUCT;
|
||||
|
||||
|
||||
@@ -62,8 +84,8 @@ typedef struct {
|
||||
* Struct which represents a 2D point on the display
|
||||
*/
|
||||
typedef struct {
|
||||
uint16_t x; //!< The X-Coordinate of the point
|
||||
uint16_t y; //!< The Y-Coordinate of the point
|
||||
uint16_t x; //!< The X-Coordinate of the point
|
||||
uint16_t y; //!< The Y-Coordinate of the point
|
||||
} POINT_STRUCT;
|
||||
|
||||
/**
|
||||
@@ -82,7 +104,7 @@ bool touch_init();
|
||||
* @param state Whether the pen is up or down
|
||||
* @return True on success
|
||||
*/
|
||||
bool touch_add_raw_event(uint16_t x, uint16_t y,TOUCH_STATE state);
|
||||
bool touch_add_raw_event(uint16_t x, uint16_t y, TOUCH_STATE state);
|
||||
|
||||
/**
|
||||
* Checks whether or not we have memory to manage and track additional \p num TOUCH_AREA_STRUCT%s
|
||||
|
||||
Reference in New Issue
Block a user