UPDATE: Added MIT license (not in download files yet).
This simple "ascii finger paint" demo shows a simple hack to use kindle touchscreen and eInk support in a shell script. I need touchscreen support for the GUI elements in my kindle recovery script, but I used a simple "ascii art" paint program to test it.
Because it does not lock the touchscreen device to prevent touches from affecting other apps using the touchscreen, it is best to run it from outside the framework. I suggest testing in in diagnostics "Lock to HOME button" menu, which prevents selecting anything while using this program.
You can put this "touchpaint-1.3" script on your kindle USB drive, then run it from an SSH session (or launch it in the kindle touch launcher menu).
To exit the program, touch the upper-left corner. The screenshots were taken before the "touch here to exit" code was added to the source code, but those updates are included in the script source code below.
Here is a little guy I painted quickly with my finger. I touched around him to test "button support":
And here are some "quick and dirty" crude text characters I drew with my finger on the kindle touchscreen (there was a fat USB cable under the kindle and it was rocking a little while drawing this):
And here is is the touchpaint script code:
EDIT: Notice that I wrapped the subprocess while loop in parentheses and check the exit status, to avoid the infamous "while loop local scope" problem. None of the "standard methods" worked in this version of busybox, so I had to "invent" this one. Also, I replaced the "cut" subprocess calls with much faster shell string processing.
Here is a safe place to test this touchscreen script:
# touchpaint-1.3 - Geekmaster Touchscreen Shell Paint
# (touchscreen ascii paint hack in a shell script)
# Copyright (C) 2012 geekmaster
# MIT License: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# Revision History (last change first):
# =ver= =date===== =author===== =description============================
# 1.3 2012-03-03 geekmaster smaller, better comments, file save.
# 1.2 2012-03-03 geekmaster change cut to shell string splits.
# 1.1 2012-03-03 geekmaster replace filter func with exit status.
# 1.0 2012-03-02 geekmaster first release
# get_touch - get scaled touch coords
# usage: get_touch XMax YMax
# returns: X Y S to STDOUT (S:1=press,2=move)
XMax=$1; YMax=$2; X=0; Y=0; S=2
while :;do (
hexdump -n48 /dev/input/event3|head -n3|while read L; do
[[ "$L" == "" ]]&& exit 1 # empty line, continue outer loop
set $L; C=$((0x$7)); V=$((0x$8)) # set hex parms, extract decimal
[[ $C -eq 57 -a $V -eq 0 ]]&& S=1 # press (else move)
[[ $C -eq 53 ]]&& X=$((V*XMax/4096)) # X (scaled to XMax)
[[ $C -eq 54 ]]&& Y=$((V*YMax/4096)) # Y (scaled to YMax)
[[ $X -gt 0 -a $Y -gt 0 ]]&& echo "$X $Y $S" && exit 0 # done
done )&& break
# character-mode touchscreen paint program
# usage: run from ssh. draw with finger. upper-left corner to exit.
# returns: (saves touchpaint.raw on USB drive)
T=0; eips -c
eips 0 39 "touchpaint-1.3 Geekmaster Touchscreen Shell Paint"
eips 10 2 "Draw stuff with your finger."
eips 0 0 " |<~~~~ Touch here to exit."
eips 0 1 "___|"
set $(get_touch 50 40); X=$1; Y=$2; S=$3 # get 50x40 touch coords
[[ $X -le 3 -a $Y -le 2 ]]&& break # touch upper-left corner?
[[ $S -eq 1 ]]&& n=$(((n+1)%10)) && X0=$X && Y0=$Y # inc $n on press
eips $X $Y "$n" # plot char $n at touched X,Y
while [[ $X0 -ne $X -o $Y0 -ne $Y ]];do # step to X,Y
eips $X0 $Y0 "$n" # plot char $n at interpolated X,Y
[[ $X0 -lt $X ]]&& X0=$((X0+1))
[[ $X0 -gt $X ]]&& X0=$((X0-1))
[[ $Y0 -lt $Y ]]&& Y0=$((Y0+1))
[[ $Y0 -gt $Y ]]&& Y0=$((Y0-1))
[[ $T -ne 1 ]]&& T=1 && eips 10 2 " "
eips 0 1 " "; eips 0 0 " "
cd /mnt/us # USB Drive for saved image
mv -f touchpaint.raw touchpaint.raw.bak
dd if=/dev/fb0 of=touchpaint.raw
eips 4 1 "~~~~> touchpaint.raw saved on USB drive."
This is what you see when you select that menu item:
In my script code, I plan to use eips to put a screenshot of the kindle framework keyboard screens on the screen and use the touchscreen to detect keypresses. I have already taken keyboard screenshots for my script GUI, and I have all my script output piped through eips, using its screen text scrolling feature (just put a pair of parentheses around the entire script, and pipe that indirectly to eips through a script variable). With this and the above touchscreen code, I will have a simple onscreen terminal console (but with no term ESC controls until later).
You are welcome to make free use of my touchscreen script support hack, and if you figure out cool things to do with script touchscreen support, please post your code back to this thread. But you do not need to worry about that -- just use my part of functions in your scripts and it will "just work".
P.S. As the versions progress, the code is following a typical pattern for me, where I add features by removing limitations, which has the side-effect of making the code smaller and simpler. As of version 1.3, the artwork you create with this program is automatically saved to touchpaint.raw on your USB drive when you exit the program (the previous image is renamed to touchcpaint.raw.bak).
You can use IrfanView (in Windows, or the Gimp in linux) to import raw framebuffer images as 608 wide by 800 high, 8 bits-per-pixel, then clip it to 600x800 and reduce it to 300x400 (eips text is pixel-doubled), and save it in your favorite file format. If it appears skewed when you load the raw image, try loading it as 600 wide instead. The virtual x_res can vary in different screen modes. You can find the current screen mode settings with:
(I forgot to clip the above screenshot images before resizing, so they are 304 px wide instead of 300.)