Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change init for KeDei 3.5" 480x320 V6.3 2018/4/9 #76

Open
wants to merge 62 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
d0ec8c8
Change init for KeDei 3.5" 480x320 V6.3 2018/4/9
kpishere Mar 13, 2019
756190d
apply suggested changes of juj
kpishere Mar 27, 2019
063b60d
Merge branch 'master' of https://github.com/juj/fbcp-ili9341
kpishere Apr 28, 2019
710fcf4
split spi user and kernel parts
kpishere May 11, 2019
5b155f3
split spi file for kernal and user space
kpishere May 11, 2019
9a07fed
both kernel and user code build -- kernal driver does nothing
kpishere May 11, 2019
9f24b56
reduce kernal module to what is needed
kpishere May 11, 2019
54ccff2
kernal part building again and outputting interrupts on screen touch
kpishere May 17, 2019
6495917
add hooks in client to read interrupt from kernel
kpishere May 17, 2019
f832499
user space experimental file writingwq
kpishere May 18, 2019
9f90f5e
read/write working nicely with kernal!
kpishere May 20, 2019
cffb099
kind of works but there is a bug
kpishere May 21, 2019
61424ad
alright, data flows but values not right. Also, touch only responsiv…
kpishere May 25, 2019
6f413a4
no blank screen, looks good! Only get one measurement between cold re…
kpishere May 26, 2019
90b3d99
it is now WORKING! But, is way too slow. Appears that interrupt must…
kpishere May 28, 2019
dcf2b71
kind of working, stil feedback loop on interrupt slows it down
kpishere May 30, 2019
1dcc1a9
it works! touch screen and fast driver.
kpishere May 31, 2019
31485d9
Update README.md
kpishere May 31, 2019
23b846c
timer for poling touch display and a bunch of debugging printf() stat…
kpishere Jun 15, 2019
b773147
Merge branch 'master' of https://github.com/kpishere/fbcp-ili9341
kpishere Jun 15, 2019
d0fd72e
more messing about
kpishere Jun 15, 2019
9e056cf
Added noop when in busy loop, touch works when not drawing
kpishere Jun 17, 2019
5c6e808
tidy up, adjust WAIT delay, enable awake on touch of screen
kpishere Jun 18, 2019
04483f5
blanks screen on inactivity but backlight still on
kpishere Jun 19, 2019
680e33b
added macros for documentation from datasheet
kpishere Jun 20, 2019
5cf3f60
set orientation to match display
kpishere Jun 21, 2019
69754d3
calibration utillity
kpishere Jun 24, 2019
1c4a318
added calibration fnction
kpishere Jun 25, 2019
f3234db
cleanup
kpishere Jun 25, 2019
4cb0e13
cleanup
kpishere Jun 25, 2019
cb182e7
.
kpishere Jun 25, 2019
6a062aa
retain intermediate changes
kpishere Aug 30, 2019
809a41a
Merge branch 'master' of https://github.com/juj/fbcp-ili9341
kpishere Aug 30, 2019
81d95b4
calibration components
kpishere Aug 30, 2019
ff4bead
Merge branch 'master' of https://github.com/kpishere/fbcp-ili9341
kpishere Aug 30, 2019
1965c9f
reamed to cpp
kpishere Aug 30, 2019
e9449c8
Merge branch 'master' of https://github.com/juj/fbcp-ili9341
kpishere Sep 5, 2019
59a92f3
functional calibration utillity with bugs
kpishere Sep 6, 2019
e7d91bc
calibration utility with bugs
kpishere Sep 6, 2019
c6fc74c
Merge branch 'master' of https://github.com/kpishere/fbcp-ili9341
kpishere Sep 6, 2019
438237f
fix merge conflicts
kpishere Sep 6, 2019
972a908
much better response math issue still
kpishere Sep 11, 2019
8901482
calibration utillity working
kpishere Sep 18, 2019
6732e57
add calibration in driver
kpishere Sep 18, 2019
5549b5e
calibration now in driver
kpishere Sep 22, 2019
f83855c
calibration now in driver, readme update
kpishere Sep 22, 2019
fad48e4
calibration utillity complete
kpishere Sep 26, 2019
6f2f007
type-o fix in readme
kpishere Sep 26, 2019
ded9465
done with backlight
kpishere Sep 30, 2019
3b950b8
update Kedei comments
kpishere Oct 2, 2019
be9e548
change to MIT
Links2004 Oct 2, 2019
9b54d8a
Update XPT2046.h
Links2004 Oct 2, 2019
3624ad3
Merge pull request #1 from Links2004/master
kpishere Oct 2, 2019
3eab455
some cosmetic changes for the util part:
Kunzol Oct 5, 2019
317d4ea
full fletched Makefile for kernel with features:
Kunzol Oct 6, 2019
c55dc62
Bugfix: make clean
Kunzol Oct 6, 2019
918c11d
Merge pull request #2 from Kunzol/util_fixes
kpishere Oct 7, 2019
e2ed474
Merge pull request #3 from Kunzol/kernel_makefile
kpishere Oct 7, 2019
82739e0
A first try to configure the repo for building a debian package.
Kunzol Oct 12, 2019
ddc55b7
Merge pull request #4 from Kunzol/debian_package
kpishere Oct 14, 2019
7cced72
remove bloker for uninstalled state
kpishere Oct 29, 2019
b96c4d1
rehide commands
kpishere Oct 29, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added calibration fnction
kpishere committed Jun 25, 2019
commit 1c4a318ca785c3bfdd8f93d83627c59f2ba88085
Empty file added File
Empty file.
Empty file added Makefile
Empty file.
1 change: 1 addition & 0 deletions calibrate.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* * * Copyright (c) 2001, Carlos E. Vidales. All rights reserved. * * This sample program was written and put in the public domain * by Carlos E. Vidales. The program is provided "as is" * without warranty of any kind, either expressed or implied. * If you choose to use the program within your own products * you do so at your own risk, and assume the responsibility * for servicing, repairing or correcting the program should * it prove defective in any manner. * You may copy and distribute the program's source code in any * medium, provided that you also include in each copy an * appropriate copyright notice and disclaimer of warranty. * You may also modify this program and distribute copies of * it provided that you include prominent notices stating * that you changed the file(s) and the date of any change, * and that you do not charge any royalties or licenses for * its use. * * * * File Name: calibrate.c * * * This file contains functions that implement calculations * necessary to obtain calibration factors for a touch screen * that suffers from multiple distortion effects: namely, * translation, scaling and rotation. * * The following set of equations represent a valid display * point given a corresponding set of touch screen points: * * * /- -\ * /- -\ /- -\ | | * | | | | | Xs | * | Xd | | A B C | | | * | | = | | * | Ys | * | Yd | | D E F | | | * | | | | | 1 | * \- -/ \- -/ | | * \- -/ * * * where: * * (Xd,Yd) represents the desired display point * coordinates, * * (Xs,Ys) represents the available touch screen * coordinates, and the matrix * * /- -\ * |A,B,C| * |D,E,F| represents the factors used to translate * \- -/ the available touch screen point values * into the corresponding display * coordinates. * * * Note that for practical considerations, the utilitities * within this file do not use the matrix coefficients as * defined above, but instead use the following * equivalents, since floating point math is not used: * * A = An/Divider * B = Bn/Divider * C = Cn/Divider * D = Dn/Divider * E = En/Divider * F = Fn/Divider * * * * The functions provided within this file are: * * setCalibrationMatrix() - calculates the set of factors * in the above equation, given * three sets of test points. * getDisplayPoint() - returns the actual display * coordinates, given a set of * touch screen coordinates. * translateRawScreenCoordinates() - helper function to transform * raw screen points into values * scaled to the desired display * resolution. * * */#define _CALIBRATE_C_/****************************************************//* *//* Included files *//* *//****************************************************/#include "Calibrate.h"/****************************************************//* *//* Local Definitions and macros *//* *//****************************************************//****************************************************//* *//* Global variables *//* *//****************************************************//****************************************************//* *//* Forward Declaration of local functions *//* *//****************************************************//********************************************************************** * * Function: setCalibrationMatrix() * * Description: Calling this function with valid input data * in the display and screen input arguments * causes the calibration factors between the * screen and display points to be calculated, * and the output argument - matrixPtr - to be * populated. * * This function needs to be called only when new * calibration factors are desired. * * * Argument(s): displayPtr (input) - Pointer to an array of three * sample, reference points. * screenPtr (input) - Pointer to the array of touch * screen points corresponding * to the reference display points. * matrixPtr (output) - Pointer to the calibration * matrix computed for the set * of points being provided. * * * From the article text, recall that the matrix coefficients are * resolved to be the following: * * * Divider = (Xs0 - Xs2)*(Ys1 - Ys2) - (Xs1 - Xs2)*(Ys0 - Ys2) * * * * (Xd0 - Xd2)*(Ys1 - Ys2) - (Xd1 - Xd2)*(Ys0 - Ys2) * A = --------------------------------------------------- * Divider * * * (Xs0 - Xs2)*(Xd1 - Xd2) - (Xd0 - Xd2)*(Xs1 - Xs2) * B = --------------------------------------------------- * Divider * * * Ys0*(Xs2*Xd1 - Xs1*Xd2) + * Ys1*(Xs0*Xd2 - Xs2*Xd0) + * Ys2*(Xs1*Xd0 - Xs0*Xd1) * C = --------------------------------------------------- * Divider * * * (Yd0 - Yd2)*(Ys1 - Ys2) - (Yd1 - Yd2)*(Ys0 - Ys2) * D = --------------------------------------------------- * Divider * * * (Xs0 - Xs2)*(Yd1 - Yd2) - (Yd0 - Yd2)*(Xs1 - Xs2) * E = --------------------------------------------------- * Divider * * * Ys0*(Xs2*Yd1 - Xs1*Yd2) + * Ys1*(Xs0*Yd2 - Xs2*Yd0) + * Ys2*(Xs1*Yd0 - Xs0*Yd1) * F = --------------------------------------------------- * Divider * * * Return: OK - the calibration matrix was correctly * calculated and its value is in the * output argument. * NOT_OK - an error was detected and the * function failed to return a valid * set of matrix values. * The only time this sample code returns * NOT_OK is when Divider == 0 * * * * NOTE! NOTE! NOTE! * * setCalibrationMatrix() and getDisplayPoint() will do fine * for you as they are, provided that your digitizer * resolution does not exceed 10 bits (1024 values). Higher * resolutions may cause the integer operations to overflow * and return incorrect values. If you wish to use these * functions with digitizer resolutions of 12 bits (4096 * values) you will either have to a) use 64-bit signed * integer variables and math, or b) judiciously modify the * operations to scale results by a factor of 2 or even 4. * * */int setCalibrationMatrix( POINT * displayPtr, POINT * screenPtr, MATRIX * matrixPtr){ int retValue = OK ; matrixPtr->Divider = ((screenPtr[0].x - screenPtr[2].x) * (screenPtr[1].y - screenPtr[2].y)) - ((screenPtr[1].x - screenPtr[2].x) * (screenPtr[0].y - screenPtr[2].y)) ; if( matrixPtr->Divider == 0 ) { retValue = NOT_OK ; } else { matrixPtr->An = ((displayPtr[0].x - displayPtr[2].x) * (screenPtr[1].y - screenPtr[2].y)) - ((displayPtr[1].x - displayPtr[2].x) * (screenPtr[0].y - screenPtr[2].y)) ; matrixPtr->Bn = ((screenPtr[0].x - screenPtr[2].x) * (displayPtr[1].x - displayPtr[2].x)) - ((displayPtr[0].x - displayPtr[2].x) * (screenPtr[1].x - screenPtr[2].x)) ; matrixPtr->Cn = (screenPtr[2].x * displayPtr[1].x - screenPtr[1].x * displayPtr[2].x) * screenPtr[0].y + (screenPtr[0].x * displayPtr[2].x - screenPtr[2].x * displayPtr[0].x) * screenPtr[1].y + (screenPtr[1].x * displayPtr[0].x - screenPtr[0].x * displayPtr[1].x) * screenPtr[2].y ; matrixPtr->Dn = ((displayPtr[0].y - displayPtr[2].y) * (screenPtr[1].y - screenPtr[2].y)) - ((displayPtr[1].y - displayPtr[2].y) * (screenPtr[0].y - screenPtr[2].y)) ; matrixPtr->En = ((screenPtr[0].x - screenPtr[2].x) * (displayPtr[1].y - displayPtr[2].y)) - ((displayPtr[0].y - displayPtr[2].y) * (screenPtr[1].x - screenPtr[2].x)) ; matrixPtr->Fn = (screenPtr[2].x * displayPtr[1].y - screenPtr[1].x * displayPtr[2].y) * screenPtr[0].y + (screenPtr[0].x * displayPtr[2].y - screenPtr[2].x * displayPtr[0].y) * screenPtr[1].y + (screenPtr[1].x * displayPtr[0].y - screenPtr[0].x * displayPtr[1].y) * screenPtr[2].y ; } return( retValue ) ;} /* end of setCalibrationMatrix() *//********************************************************************** * * Function: getDisplayPoint() * * Description: Given a valid set of calibration factors and a point * value reported by the touch screen, this function * calculates and returns the true (or closest to true) * display point below the spot where the touch screen * was touched. * * * * Argument(s): displayPtr (output) - Pointer to the calculated * (true) display point. * screenPtr (input) - Pointer to the reported touch * screen point. * matrixPtr (input) - Pointer to calibration factors * matrix previously calculated * from a call to * setCalibrationMatrix() * * * The function simply solves for Xd and Yd by implementing the * computations required by the translation matrix. * * /- -\ * /- -\ /- -\ | | * | | | | | Xs | * | Xd | | A B C | | | * | | = | | * | Ys | * | Yd | | D E F | | | * | | | | | 1 | * \- -/ \- -/ | | * \- -/ * * It must be kept brief to avoid consuming CPU cycles. * * * Return: OK - the display point was correctly calculated * and its value is in the output argument. * NOT_OK - an error was detected and the function * failed to return a valid point. * * * * NOTE! NOTE! NOTE! * * setCalibrationMatrix() and getDisplayPoint() will do fine * for you as they are, provided that your digitizer * resolution does not exceed 10 bits (1024 values). Higher * resolutions may cause the integer operations to overflow * and return incorrect values. If you wish to use these * functions with digitizer resolutions of 12 bits (4096 * values) you will either have to a) use 64-bit signed * integer variables and math, or b) judiciously modify the * operations to scale results by a factor of 2 or even 4. * * */int getDisplayPoint( POINT * displayPtr, POINT * screenPtr, MATRIX * matrixPtr ){ int retValue = OK ; if( matrixPtr->Divider != 0 ) { /* Operation order is important since we are doing integer */ /* math. Make sure you add all terms together before */ /* dividing, so that the remainder is not rounded off */ /* prematurely. */ displayPtr->x = ( (matrixPtr->An * screenPtr->x) + (matrixPtr->Bn * screenPtr->y) + matrixPtr->Cn ) / matrixPtr->Divider ; displayPtr->y = ( (matrixPtr->Dn * screenPtr->x) + (matrixPtr->En * screenPtr->y) + matrixPtr->Fn ) / matrixPtr->Divider ; } else { retValue = NOT_OK ; } return( retValue ) ;} /* end of getDisplayPoint() */
363 changes: 363 additions & 0 deletions calibrate.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,363 @@
/*
*
* Copyright (c) 2001, Carlos E. Vidales. All rights reserved.
*
* This sample program was written and put in the public domain
* by Carlos E. Vidales. The program is provided "as is"
* without warranty of any kind, either expressed or implied.
* If you choose to use the program within your own products
* you do so at your own risk, and assume the responsibility
* for servicing, repairing or correcting the program should
* it prove defective in any manner.
* You may copy and distribute the program's source code in any
* medium, provided that you also include in each copy an
* appropriate copyright notice and disclaimer of warranty.
* You may also modify this program and distribute copies of
* it provided that you include prominent notices stating
* that you changed the file(s) and the date of any change,
* and that you do not charge any royalties or licenses for
* its use.
*
*
*
* File Name: calibrate.c
*
*
* This file contains functions that implement calculations
* necessary to obtain calibration factors for a touch screen
* that suffers from multiple distortion effects: namely,
* translation, scaling and rotation.
*
* The following set of equations represent a valid display
* point given a corresponding set of touch screen points:
*
*
* /- -\
* /- -\ /- -\ | |
* | | | | | Xs |
* | Xd | | A B C | | |
* | | = | | * | Ys |
* | Yd | | D E F | | |
* | | | | | 1 |
* \- -/ \- -/ | |
* \- -/
*
*
* where:
*
* (Xd,Yd) represents the desired display point
* coordinates,
*
* (Xs,Ys) represents the available touch screen
* coordinates, and the matrix
*
* /- -\
* |A,B,C|
* |D,E,F| represents the factors used to translate
* \- -/ the available touch screen point values
* into the corresponding display
* coordinates.
*
*
* Note that for practical considerations, the utilitities
* within this file do not use the matrix coefficients as
* defined above, but instead use the following
* equivalents, since floating point math is not used:
*
* A = An/Divider
* B = Bn/Divider
* C = Cn/Divider
* D = Dn/Divider
* E = En/Divider
* F = Fn/Divider
*
*
*
* The functions provided within this file are:
*
* setCalibrationMatrix() - calculates the set of factors
* in the above equation, given
* three sets of test points.
* getDisplayPoint() - returns the actual display
* coordinates, given a set of
* touch screen coordinates.
* translateRawScreenCoordinates() - helper function to transform
* raw screen points into values
* scaled to the desired display
* resolution.
*
*
*/


#define _CALIBRATE_C_



/****************************************************/
/* */
/* Included files */
/* */
/****************************************************/

#include "calibrate.h"


/****************************************************/
/* */
/* Local Definitions and macros */
/* */
/****************************************************/



/****************************************************/
/* */
/* Global variables */
/* */
/****************************************************/



/****************************************************/
/* */
/* Forward Declaration of local functions */
/* */
/****************************************************/






/**********************************************************************
*
* Function: setCalibrationMatrix()
*
* Description: Calling this function with valid input data
* in the display and screen input arguments
* causes the calibration factors between the
* screen and display points to be calculated,
* and the output argument - matrixPtr - to be
* populated.
*
* This function needs to be called only when new
* calibration factors are desired.
*
*
* Argument(s): displayPtr (input) - Pointer to an array of three
* sample, reference points.
* screenPtr (input) - Pointer to the array of touch
* screen points corresponding
* to the reference display points.
* matrixPtr (output) - Pointer to the calibration
* matrix computed for the set
* of points being provided.
*
*
* From the article text, recall that the matrix coefficients are
* resolved to be the following:
*
*
* Divider = (Xs0 - Xs2)*(Ys1 - Ys2) - (Xs1 - Xs2)*(Ys0 - Ys2)
*
*
*
* (Xd0 - Xd2)*(Ys1 - Ys2) - (Xd1 - Xd2)*(Ys0 - Ys2)
* A = ---------------------------------------------------
* Divider
*
*
* (Xs0 - Xs2)*(Xd1 - Xd2) - (Xd0 - Xd2)*(Xs1 - Xs2)
* B = ---------------------------------------------------
* Divider
*
*
* Ys0*(Xs2*Xd1 - Xs1*Xd2) +
* Ys1*(Xs0*Xd2 - Xs2*Xd0) +
* Ys2*(Xs1*Xd0 - Xs0*Xd1)
* C = ---------------------------------------------------
* Divider
*
*
* (Yd0 - Yd2)*(Ys1 - Ys2) - (Yd1 - Yd2)*(Ys0 - Ys2)
* D = ---------------------------------------------------
* Divider
*
*
* (Xs0 - Xs2)*(Yd1 - Yd2) - (Yd0 - Yd2)*(Xs1 - Xs2)
* E = ---------------------------------------------------
* Divider
*
*
* Ys0*(Xs2*Yd1 - Xs1*Yd2) +
* Ys1*(Xs0*Yd2 - Xs2*Yd0) +
* Ys2*(Xs1*Yd0 - Xs0*Yd1)
* F = ---------------------------------------------------
* Divider
*
*
* Return: OK - the calibration matrix was correctly
* calculated and its value is in the
* output argument.
* NOT_OK - an error was detected and the
* function failed to return a valid
* set of matrix values.
* The only time this sample code returns
* NOT_OK is when Divider == 0
*
*
*
* NOTE! NOTE! NOTE!
*
* setCalibrationMatrix() and getDisplayPoint() will do fine
* for you as they are, provided that your digitizer
* resolution does not exceed 10 bits (1024 values). Higher
* resolutions may cause the integer operations to overflow
* and return incorrect values. If you wish to use these
* functions with digitizer resolutions of 12 bits (4096
* values) you will either have to a) use 64-bit signed
* integer variables and math, or b) judiciously modify the
* operations to scale results by a factor of 2 or even 4.
*
*
*/
int setCalibrationMatrix( POINT * displayPtr,
POINT * screenPtr,
MATRIX * matrixPtr)
{

int retValue = OK ;



matrixPtr->Divider = ((screenPtr[0].x - screenPtr[2].x) * (screenPtr[1].y - screenPtr[2].y)) -
((screenPtr[1].x - screenPtr[2].x) * (screenPtr[0].y - screenPtr[2].y)) ;

if( matrixPtr->Divider == 0 )
{
retValue = NOT_OK ;
}
else
{
matrixPtr->An = ((displayPtr[0].x - displayPtr[2].x) * (screenPtr[1].y - screenPtr[2].y)) -
((displayPtr[1].x - displayPtr[2].x) * (screenPtr[0].y - screenPtr[2].y)) ;

matrixPtr->Bn = ((screenPtr[0].x - screenPtr[2].x) * (displayPtr[1].x - displayPtr[2].x)) -
((displayPtr[0].x - displayPtr[2].x) * (screenPtr[1].x - screenPtr[2].x)) ;

matrixPtr->Cn = (screenPtr[2].x * displayPtr[1].x - screenPtr[1].x * displayPtr[2].x) * screenPtr[0].y +
(screenPtr[0].x * displayPtr[2].x - screenPtr[2].x * displayPtr[0].x) * screenPtr[1].y +
(screenPtr[1].x * displayPtr[0].x - screenPtr[0].x * displayPtr[1].x) * screenPtr[2].y ;

matrixPtr->Dn = ((displayPtr[0].y - displayPtr[2].y) * (screenPtr[1].y - screenPtr[2].y)) -
((displayPtr[1].y - displayPtr[2].y) * (screenPtr[0].y - screenPtr[2].y)) ;

matrixPtr->En = ((screenPtr[0].x - screenPtr[2].x) * (displayPtr[1].y - displayPtr[2].y)) -
((displayPtr[0].y - displayPtr[2].y) * (screenPtr[1].x - screenPtr[2].x)) ;

matrixPtr->Fn = (screenPtr[2].x * displayPtr[1].y - screenPtr[1].x * displayPtr[2].y) * screenPtr[0].y +
(screenPtr[0].x * displayPtr[2].y - screenPtr[2].x * displayPtr[0].y) * screenPtr[1].y +
(screenPtr[1].x * displayPtr[0].y - screenPtr[0].x * displayPtr[1].y) * screenPtr[2].y ;
}

return( retValue ) ;

} /* end of setCalibrationMatrix() */



/**********************************************************************
*
* Function: getDisplayPoint()
*
* Description: Given a valid set of calibration factors and a point
* value reported by the touch screen, this function
* calculates and returns the true (or closest to true)
* display point below the spot where the touch screen
* was touched.
*
*
*
* Argument(s): displayPtr (output) - Pointer to the calculated
* (true) display point.
* screenPtr (input) - Pointer to the reported touch
* screen point.
* matrixPtr (input) - Pointer to calibration factors
* matrix previously calculated
* from a call to
* setCalibrationMatrix()
*
*
* The function simply solves for Xd and Yd by implementing the
* computations required by the translation matrix.
*
* /- -\
* /- -\ /- -\ | |
* | | | | | Xs |
* | Xd | | A B C | | |
* | | = | | * | Ys |
* | Yd | | D E F | | |
* | | | | | 1 |
* \- -/ \- -/ | |
* \- -/
*
* It must be kept brief to avoid consuming CPU cycles.
*
*
* Return: OK - the display point was correctly calculated
* and its value is in the output argument.
* NOT_OK - an error was detected and the function
* failed to return a valid point.
*
*
*
* NOTE! NOTE! NOTE!
*
* setCalibrationMatrix() and getDisplayPoint() will do fine
* for you as they are, provided that your digitizer
* resolution does not exceed 10 bits (1024 values). Higher
* resolutions may cause the integer operations to overflow
* and return incorrect values. If you wish to use these
* functions with digitizer resolutions of 12 bits (4096
* values) you will either have to a) use 64-bit signed
* integer variables and math, or b) judiciously modify the
* operations to scale results by a factor of 2 or even 4.
*
*
*/
int getDisplayPoint( POINT * displayPtr,
POINT * screenPtr,
MATRIX * matrixPtr )
{
int retValue = OK ;


if( matrixPtr->Divider != 0 )
{

/* Operation order is important since we are doing integer */
/* math. Make sure you add all terms together before */
/* dividing, so that the remainder is not rounded off */
/* prematurely. */

displayPtr->x = ( (matrixPtr->An * screenPtr->x) +
(matrixPtr->Bn * screenPtr->y) +
matrixPtr->Cn
) / matrixPtr->Divider ;

displayPtr->y = ( (matrixPtr->Dn * screenPtr->x) +
(matrixPtr->En * screenPtr->y) +
matrixPtr->Fn
) / matrixPtr->Divider ;
}
else
{
retValue = NOT_OK ;
}

return( retValue ) ;

} /* end of getDisplayPoint() */


118 changes: 118 additions & 0 deletions calibrate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
*
* Copyright (c) 2001, Carlos E. Vidales. All rights reserved.
*
* This sample program was written and put in the public domain
* by Carlos E. Vidales. The program is provided "as is"
* without warranty of any kind, either expressed or implied.
* If you choose to use the program within your own products
* you do so at your own risk, and assume the responsibility
* for servicing, repairing or correcting the program should
* it prove defective in any manner.
* You may copy and distribute the program's source code in any
* medium, provided that you also include in each copy an
* appropriate copyright notice and disclaimer of warranty.
* You may also modify this program and distribute copies of
* it provided that you include prominent notices stating
* that you changed the file(s) and the date of any change,
* and that you do not charge any royalties or licenses for
* its use.
*
*
* File Name: calibrate.h
*
*
* Definition of constants and structures, and declaration of functions
* in Calibrate.c
*
* Revisions: Kevin Peck 2019
*/

#ifndef _CALIBRATE_H_

#define _CALIBRATE_H_

/****************************************************/
/* */
/* Included files */
/* */
/****************************************************/

#include <math.h>


/****************************************************/
/* */
/* Definitions */
/* */
/****************************************************/

#ifndef _CALIBRATE_C_
#define EXTERN extern
#else
#define EXTERN
#endif



#ifndef OK
#define OK 0
#define NOT_OK -1
#endif



#define INT32 long




/****************************************************/
/* */
/* Structures */
/* */
/****************************************************/


typedef struct Point {
INT32 x,
y ;
} POINT ;



typedef struct Matrix {
/* This arrangement of values facilitates
* calculations within getDisplayPoint()
*/
INT32 An, /* A = An/Divider */
Bn, /* B = Bn/Divider */
Cn, /* C = Cn/Divider */
Dn, /* D = Dn/Divider */
En, /* E = En/Divider */
Fn, /* F = Fn/Divider */
Divider ;
} MATRIX ;




/****************************************************/
/* */
/* Function declarations */
/* */
/****************************************************/


EXTERN int setCalibrationMatrix( POINT * display,
POINT * screen,
MATRIX * matrix) ;


EXTERN int getDisplayPoint( POINT * display,
POINT * screen,
MATRIX * matrix ) ;


#endif /* _CALIBRATE_H_ */

Empty file added tcCalib.c
Empty file.
185 changes: 185 additions & 0 deletions util/tcCalib.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@


#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include "VG/openvg.h"
#include "VG/vgu.h"
#include "fontinfo.h"
#include "shapes.h"

#include <linux/input.h>
#include <fcntl.h>
#include <pthread.h>

// touch state structure
typedef struct {
int fd;
char[80] evbuff;
VGfloat x, y, z;
int max_x, max_y;
void parse(const char *buff) {

}
} touch_t;

touch_t touch; // global touch state
int left_count = 0;
int quitState = 0;
#define CUR_SIZ 16 // cursor size, pixels beyond centre dot

// evenThread reads from the touch input file
void *eventThread(void *arg) {

// Open touch driver
if ((touch.fd = open("/tmp/TCfifo", O_RDONLY)) < 0) {
fprintf(stderr, "Error opening touch!\n");
quitState = 1;
return &quitState;
}
touch.x = touch.max_x / 2; //Reset touch
touch.y = touch.max_y / 2;

while (1) {
read(touch.fd, &touch.evbuff, sizeof(char[80]));
// printf("[%4.0f,%4.0f]\r",touch.x,touch.y);

// Check events
touch.left = CUR_SIZ * 2; // Reset touch button states
touch.right = CUR_SIZ * 2;

if (touch.ev.type == EV_REL) {
if (touch.ev.code == REL_X) {
touch.x += (VGfloat) touch.ev.value;
if (touch.x < 0) {
touch.x = 0;
}
if (touch.x > touch.max_x) {
touch.x = touch.max_x;
}
}
if (touch.ev.code == REL_Y) { //This ones goes backwards hence the minus
touch.y -= (VGfloat) touch.ev.value;
if (touch.y < 0) {
touch.y = 0;
}
if (touch.y > touch.max_y) {
touch.y = touch.max_y;
}
}
}

if (touch.ev.type == EV_KEY) {
//printf("Time Stamp:%d - type %d, code %d, value %d\n",
// touch.ev.time.tv_usec,touch.ev.type,touch.ev.code,touch.ev.value);
if (touch.ev.code == BTN_LEFT) {
touch.left = 1;
// printf("Left button\n");
left_count++;
// printf("User Quit\n");
// quitState = 1;
// return &quitState; //Left touch to quit
}
if (touch.ev.code == BTN_RIGHT) {
touch.right = 1;
// printf("Right button\n");
}
}
}
}

static int cur_sx, cur_sy, cur_w, cur_h; // cursor location and dimensions
static int cur_saved = 0; // amount of data saved in cursor image backup

// saveCursor saves the pixels under the touch cursor
void saveCursor(VGImage CursorBuffer, int curx, int cury, int screen_width, int screen_height, int s) {
int sx, sy, ex, ey;

sx = curx - s; // horizontal
if (sx < 0) {
sx = 0;
}
ex = curx + s;
if (ex > screen_width) {
ex = screen_width;
}
cur_sx = sx;
cur_w = ex - sx;

sy = cury - s; // vertical
if (sy < 0) {
sy = 0;
}
ey = cury + s;
if (ey > screen_height) {
ey = screen_height;
}
cur_sy = sy;
cur_h = ey - sy;

vgGetPixels(CursorBuffer, 0, 0, cur_sx, cur_sy, cur_w, cur_h);
cur_saved = cur_w * cur_h;
}

// restoreCursor restores the pixels under the touch cursor
void restoreCursor(VGImage CursorBuffer) {
if (cur_saved != 0) {
vgSetPixels(cur_sx, cur_sy, CursorBuffer, 0, 0, cur_w, cur_h);
}
}

// circleCursor draws a translucent circle as the touch cursor
void circleCursor(int curx, int cury, int width, int height, int s) {
Fill(100, 0, 0, 0.50);
Circle(curx, cury, s);
Fill(0, 0, 0, 1);
Circle(curx, cury, 2);
}

// touchinit starts the touch event thread
int touchinit(int w, int h) {
pthread_t inputThread;
touch.max_x = w;
touch.max_y = h;
return pthread_create(&inputThread, NULL, &eventThread, NULL);
}

int main() {
int width, height, cursorx, cursory, cbsize;

init(&width, &height); // Graphics initialization
cursorx = width / 2;
cursory = height / 2;
cbsize = (CUR_SIZ * 2) + 1;
VGImage CursorBuffer = vgCreateImage(VG_sABGR_8888, cbsize, cbsize, VG_IMAGE_QUALITY_BETTER);

if (touchinit(width, height) != 0) {
fprintf(stderr, "Unable to initialize the touch\n");
exit(1);
}
Start(width, height); // Start the picture
Background(0, 0, 0); // Black background
Fill(44, 77, 232, 1); // Big blue marble
Circle(width / 2, 0, width); // The "world"
Fill(255, 255, 255, 1); // White text
TextMid(width / 2, height / 2, "hello, world", SerifTypeface, width / 10); // Greetings
End(); // update picture

// MAIN LOOP
while (left_count < 2) { // Loop until the left touch button pressed & released
// if the touch moved...
if (touch.x != cursorx || touch.y != cursory) {
restoreCursor(CursorBuffer);
cursorx = touch.x;
cursory = touch.y;
saveCursor(CursorBuffer, cursorx, cursory, width, height, CUR_SIZ);
circleCursor(cursorx, cursory, width, height, CUR_SIZ);
End(); // update picture
}
}
restoreCursor(CursorBuffer); // not strictly necessary as display will be closed
vgDestroyImage(CursorBuffer); // tidy up memory
finish(); // Graphics cleanup
exit(0);
}