Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Readers > Amazon Kindle > Kindle Developer's Corner

Notices

Reply
 
Thread Tools Search this Thread
Old 03-02-2012, 11:36 PM   #1
geekmaster
Carpe diem, c'est la vie.
geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.
 
geekmaster's Avatar
 
Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
geekmaster simple touchscreen script support hack

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:
PHP Code:
#!/bin/sh
#======================================================================
# 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)
#----------------------------------------------------------------------
get_touch() {
  
XMax=$1YMax=$2X=0Y=0S=2
  
while :;do (
    
hexdump -n48 /dev/input/event3|head -n3|while read L; do
      [[ 
"$L== "" ]]&& exit # empty line, continue outer loop
      
set $LC=$((0x$7)); V=$((0x$8)) # set hex parms, extract decimal
      
[[ $C -eq 57 -a $V -eq 0 ]]&& S=# 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 # done
    
done )&& break
  
done
}

#======================================================================
# 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=0eips -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 "___|"
while :;do
  
set $(get_touch 50 40); X=$1Y=$2S=$# 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))
  
done
  
[[ $T -ne 1 ]]&& T=&& eips 10 2 "                            "
done
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." 
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:


This is what you see when you select that menu item:



To Do:
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".

Thanks. Enjoy!

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:
eips -i

(I forgot to clip the above screenshot images before resizing, so they are 304 px wide instead of 300.)
Attached Files
File Type: gz gmpaint-1.0.gz (811 Bytes, 477 views)
File Type: gz gmpaint-1.2.gz (887 Bytes, 473 views)
File Type: gz touchpaint-1.3.gz (1.1 KB, 460 views)

Last edited by geekmaster; 04-04-2012 at 12:32 PM. Reason: version 1.3 update
geekmaster is offline   Reply With Quote
Old 03-03-2012, 08:10 AM   #2
geekmaster
Carpe diem, c'est la vie.
geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.
 
geekmaster's Avatar
 
Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
Bump...

What, no feedback? No improvements, or thanks? And here I had all these OTHER ideas I was planning to post. I thought posts like this one might encourage the "script kitties" (meow!) amongst us to create good things...

And even for experienced developers, there are times when only a script will do, like when you have only serial port or reverse shell access, but you CAN paste text into a file from the clipboard (like this script, so you can get feedback and control through the touchscreen).

Come on guys! If you want to see more stuff like this, give me some feedback, so I know that I am not wasting my valuable and limited time! Okay?

Last edited by geekmaster; 03-03-2012 at 08:53 AM.
geekmaster is offline   Reply With Quote
Advert
Old 03-03-2012, 09:47 AM   #3
Poetcop
Connoisseur
Poetcop began at the beginning.
 
Posts: 55
Karma: 46
Join Date: Feb 2012
Device: Kindle
That's cool! I can see a lot of potential in this.
Poetcop is offline   Reply With Quote
Old 03-03-2012, 10:28 AM   #4
geekmaster
Carpe diem, c'est la vie.
geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.
 
geekmaster's Avatar
 
Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
It looks like I can eliminate the filter function by using "subshell piping" to allow passing vars outside the loop. Also, after trying a number of string splitting methods that do not work on the touch busybox shell, I found one that does work.

Because this is an interactive application, I want to optimize it for speed by not calling external processes (like "[" and "cat"), replacing them with built-ins (like "[[" and shell string functions) whenever possible.

I will post an updated script soon.

I am redirecting my shell script STDOUT and STDERR to the eInk screen now, and I will eventually use this touchscreen hack to add onscreen keyboad support, for use in recovery (or other) shell scripts, with minimal dependency on external processes.

Last edited by geekmaster; 03-03-2012 at 10:38 AM.
geekmaster is offline   Reply With Quote
Old 03-03-2012, 02:43 PM   #5
geekmaster
Carpe diem, c'est la vie.
geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.
 
geekmaster's Avatar
 
Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
Updated first post in this thread to gmpaint-1.2.

Replaced "cut" subprocess calls with shell string processing (actually "set" command-line parsing used to parse output lines from hexdump).

Replaced wrapper filter function with parentheses around entire subprocess loop, and added subprocess exit status check.

It is "more better smaller faster simpler", and that is a "good thing" in my book!

I hope you learn something from this -- I know *I* did!

Enjoy!


P.S. I left the original gmpaint-1.0.gz file in the dowload links in the first post above, in case you want to compare the original and latest versions of the script, to see what I was talking about above.

Last edited by geekmaster; 03-03-2012 at 03:26 PM.
geekmaster is offline   Reply With Quote
Advert
Old 03-03-2012, 11:35 PM   #6
aditya3098
Guru
aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.
 
Posts: 608
Karma: 1588610
Join Date: Jan 2012
Device: Kindle Scribe
just use
Code:
lipc-set-prop com.lab126.appmgrd start app://com.lab126.draw
to launch a practical draw app. This is proof of concept.

Last edited by aditya3098; 03-03-2012 at 11:37 PM.
aditya3098 is offline   Reply With Quote
Old 03-04-2012, 12:17 AM   #7
geekmaster
Carpe diem, c'est la vie.
geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.
 
geekmaster's Avatar
 
Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
Quote:
Originally Posted by aditya3098 View Post
just use
Code:
lipc-set-prop com.lab126.appmgrd start app://com.lab126.draw
to launch a practical draw app. This is proof of concept.
I was playing with that draw app when it was included in yifanlu's first preliminary version of his launcher menu. I like using that draw program in its "box draw" (or is it rectangle?) mode, where the size of the boxes is proportional to your drawing speed. You can make some interesting screensaver images that way, like a spirograph.

But that is not the point. The "paint" function is merely a test stub for the touchscreen function. The final scripts (besides this ascii fingerpaint toy) will be a touchscreen reader script that returns scaled coordinates of your choice (600x800, 800x600, 50x40, or whatever). And another version will provide an onscreen keyboard, and will return a text string of whatever the user typed on the onscreen keyboard. These general touchscreen utility scripts will be callable by other scripts, for use in RUNME.sh recovery scripts (or anywhere else you want to use them).

As mentioned in previous posts, this is primarily intended to be used in diagnostics mode. Are you sure that your recommended lipc command will work in that mode? And how about BEFORE the startup scripts run, when the framework has not been started yet?

And for that matter, instead of that "paint" program you suggested I should use as a "practical" solution (it is really just a webpage) -- I make a counter suggestion: to be really "practical" (as you suggested) use the Gimp on a *real* computer.

Last edited by geekmaster; 03-04-2012 at 12:34 AM.
geekmaster is offline   Reply With Quote
Old 03-04-2012, 12:24 AM   #8
geekmaster
Carpe diem, c'est la vie.
geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.
 
geekmaster's Avatar
 
Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
The touchscreen paint program has been upgraded in the first post. It is now at version 1.3.

Check out the script code in the first post. It is getting smaller, and simpler, and better. It will be of more general use when it evolves into an onscreen touchscreen keyboard than can be called from shell scripts.

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 touchpaint.raw.bak).

Last edited by geekmaster; 03-22-2012 at 12:32 PM. Reason: fix typo
geekmaster is offline   Reply With Quote
Old 04-06-2012, 02:31 AM   #9
aBP
Member
aBP began at the beginning.
 
Posts: 18
Karma: 10
Join Date: Feb 2012
Device: K4NT
Keep up the great work GeekMaster, I can't wait to see the finished keyboard
aBP is offline   Reply With Quote
Old 04-06-2012, 08:27 AM   #10
pwright2
Connoisseur
pwright2 began at the beginning.
 
Posts: 92
Karma: 10
Join Date: Dec 2011
Device: Kindle Touch
A drawing program is amusing. An improved keyboard would be AMAZING! As a lurker, I can barely follow the commentary, much less the code, but please continue with your development, GeekMaster.
pwright2 is offline   Reply With Quote
Old 07-02-2012, 09:31 AM   #11
twobob
( ͡° ͜ʖ ͡°){ʇlnɐɟ ƃǝs}Týr
twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.
 
twobob's Avatar
 
Posts: 6,586
Karma: 6299991
Join Date: Jun 2012
Location: uti gratia usura (Yao ying da ying; Mo ying da yieng)
Device: PW-WIFI|K5-3G+WIFI| K4|K3-3G|DXG|K2| Rooted Nook Touch
a horse, a horse, my horse for a touchscreen....
twobob is offline   Reply With Quote
Old 07-02-2012, 10:58 AM   #12
geekmaster
Carpe diem, c'est la vie.
geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.
 
geekmaster's Avatar
 
Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
The next version of this that supports full 600x800 pixels was stripped down and released as "geekmaster signature capture": https://www.mobileread.com/forums/sho...d.php?t=178356

That is what I used to capture the signature used in my first "gmplay" video (and the newtrix demo, where the video generation code came from).
geekmaster is offline   Reply With Quote
Old 04-21-2021, 11:38 PM   #13
Amias
Member
Amias began at the beginning.
 
Posts: 11
Karma: 10
Join Date: Apr 2021
Device: KPW4
Help.
It works badly in KPW4, the words display is worse, plus that when i touch bottom right, it displays top left
Amias is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
geekmaster's simple guide to tcc (tinycc) geekmaster Kindle Developer's Corner 188 04-21-2021 07:09 PM
geekmaster touchscreen signature capture script geekmaster Kindle Developer's Corner 21 03-24-2016 05:59 PM
Simple Esperanto ePub conversion script? amuzulo ePub 10 03-06-2010 02:54 PM
Simple Script to move content to CF Card (works around WLAN - CF Performance Bug) torben iRex 0 12-03-2008 02:45 AM
PRS-500 Hack script reference for the 500? mdhuang Sony Reader Dev Corner 0 10-13-2007 12:15 AM


All times are GMT -4. The time now is 12:41 AM.


MobileRead.com is a privately owned, operated and funded community.