I have recently gotten the Adafruit 2.8" TFT Touchscreen I've got it all set up and working correctly. All of my touchscreen calibration went well and appears to be functioning correctly.
I am now trying to write a program using pygame that will output somethings to the touchscreen and allow inputs via the touchscreen. This is functioning well if I run startx and then launch my script. However I'd like to be able to start my script directly from the console without the need for startx
This question got me most of the way there, the screen is now getting drawn to properly. It does seem to accept touch inputs the x/y coordinates are off. The answer provided on this question was to put this:
os.environ["SDL_FBDEV"] = "/dev/fb1"
in my script before calling pygame.init()
Using pygame if I leave the mouse turned on I can see that it does not follow my stylus as I touch various points on the screen. It appears that the x and y axis are flipped. If I move my stylus side to side the mouse cursor moves up and down, if I move up and down the cursor goes side to side.
However if I do startx first, and then launch my python script the mouse/touchscreen functions perfectly with all of the events getting sent to the correct coordinates.
What do I need to do in order to get my touch events to work properly inside of pygame with a script launched from console rather than inside of x?
Going back through the touchscreen setup procedures (which I admittedly did not fully understand while I was doing them) I've noticed they had me create a file: /etc/X11/xorg.conf.d/99-calibration.conf
and put this into it:
Section "InputClass"
Identifier "calibration"
MatchProduct "stmpe-ts"
Option "Calibration" "3800 200 200 3800"
Option "SwapAxes" "1"
EndSection
I assume the "SwapAxes" "1" is what is allowing the touch screen to work properly when I launch my script from x.
I just need to know how to "apply" this config file when I am running from the console rather than via x.
EDIT:
I've also noticed if I run the ts_test program (from console rather than X) the touch screen functions correctly. So there must be some way to allow it to work without X being launched.