Touchscreen Library modification
Posted: Thu Jan 17, 2008 10:40 pm
I tested the touchscreen library on hardware that needed to have the ADC ports connected differently from the library default. One can change the ports by defines but the library won't work with these defines different from the default. The reason is the ADC references are fixed and therefore refer to the wrong TS plate connection if the ports are changed. I "fixed" (for my purposes) the module by changing the ADC.Read lines in the subs below (I would have highlighted the changes with color but couldn't figure out how to do that within the code block!).
Using BitOf will work for AN0 through AN3 on most PICs but it gets much more complicated after that. ANx references don't always match port bit locations. I frankly couldn't come up with a good solution for those....
I welcome any solutions, although the above fixed my short term port issues. It may be more trouble than it's worth. If one wants to use the library-use it with the default ports and remove the capability to change the ports altogether.
Otherwise the Touchscreen library worked as advertised.....
Thanks Steven
Tom
Code: Select all
{
********************************************************************************
* Name : PenPressure (PUBLIC) *
* Purpose : Returns a value between 0-255 indicating pen pressure. *
* : Testing this value will allow a sensible value for *
* : Pen_Down_Threshold to be calculated. *
********************************************************************************
}
Public Function PenPressure() As Byte
Input(TS_X1) // X1 is input
Input(TS_X2) // X2 is input
Output(TS_Y1) // Y1 is output
Output(TS_Y2) // Y2 is output
TS_Y1 = 1 // Both Y plates high
TS_Y2 = 1
DelayUS(Pen_Down_DelayUS)
PenPressure = ADC.Read(BitOf(TS_X2,false)) >> 2 // Read ADC
Input(TS_Y1) // Y1 is input - power save
Input(TS_Y2) // Y2 is input - power save
End Function
{
********************************************************************************
* Name : ReadX (PRIVATE) *
* Purpose : *
********************************************************************************
}
Function ReadX() As Word
DelayMS(Read_XY_DelayMS) // Stabilise
Result = Max(ADC.Read(BitOf(TS_X1,false)), ADC.Read(BitOf(TS_X2,false))) // Read X co-ordinate
End Function
{
********************************************************************************
* Name : ReadY (PRIVATE) *
* Purpose : *
********************************************************************************
}
Function ReadY() As Word
DelayMS(Read_XY_DelayMS) // Stabilise
Result = Max(ADC.Read(BitOf(TS_Y1,false)), ADC.Read(BitOf(TS_Y2,false))) // Read Y co-ordinate
End Function
{
{
I welcome any solutions, although the above fixed my short term port issues. It may be more trouble than it's worth. If one wants to use the library-use it with the default ports and remove the capability to change the ports altogether.
Otherwise the Touchscreen library worked as advertised.....
Thanks Steven
Tom