05-14-2012, 09:10 PM | #1 |
Carpe diem, c'est la vie.
Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
geekmaster touchscreen signature capture script
If you watched my "newtrix" demo through to the end, you saw the animated "geekmaster signature". It was stored as a vector display list in the sv[] array.
In this thread, I present a useful tool to teach you a very simple way to use the K5 touchscreen. It does not support advanced features like multitouch pinch and stretch, but it is simple and easy to understand. When you run it, you can draw a trail of dots on the screen with your finger, each dot is stored as a touchscreen capture point. When you press the exit button in the lower-right corner, this script exits and outputs the contents of the display list in a C structure, ready to copy into a C program (like newtrix). You can either pipe this program to a file (./gmsigcap.sh >mysig.h), or you can copy its output from your ssh terminal scrollback buffer. You might even be tempted to replace the geekmaster signature with your own signature or vector art. Go ahead, but before distributing my code with your signature (with my MIT license intact) please change it to do some cool new stuff. Here is the script source code: PHP Code:
Here is the output from this script after I drew a large smiley icon with my finger, then pressed the "exit" button: Spoiler:
When adding this to a program, I suggest reformatting it to multiple numbers per line, using a source code style formatter such as AStyle. Enjoy! Last edited by geekmaster; 05-16-2012 at 03:57 PM. |
05-14-2012, 10:47 PM | #2 |
Carpe diem, c'est la vie.
Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
FYI: In the signature vector display list, the number 0 means "pen up" in this case. The other numbers all are connected by lines between the capture points. In the sample data above, the first group of numbers forms the large circle for the face. The second two groups are each a circle for the eyes. The third group is the smile. The fourth and fifth groups are fill-ins for the pupils of the eyes. The last group of numbers is the exit button touch and release -- you probably want to delete that group from your saved vector signature and artwork. The script ends with two zeros telling the program to stop drawing and go do other stuff.
The raw touchscreen data has values of 0-4095 for width and 0-4095 for height. Typical vector graphics that I plan to use can be represented with 0-255 values for width and height, so I rescale them so they can both pack into a 16-bit number (y*256+x). You can look at the code in the "goodbye" function in the newtrix demo, to see how to use this data. You can of course change the output to be more script friendly by removing the commas, if you prefer using this in variations on my "algorithmic art" scripts instead of my C demos. Again, I hope you enjoy this and learn something new from it. Comments are not only welcome -- they are required! Last edited by geekmaster; 05-14-2012 at 10:53 PM. |
Advert | |
|
05-15-2012, 03:29 AM | #3 | |
Fully Converged
Posts: 18,171
Karma: 14021202
Join Date: Oct 2002
Location: Switzerland
Device: Too many to count here.
|
Quote:
|
|
05-15-2012, 09:54 AM | #4 | |||
Going Viral
Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA
|
While fixing things - the login form is not international:
Quote:
Same problem with "new reply" - Quote:
Ah, but the "quick edit reply" does not use the windows-1252 character set - web-dev did not report the character set, so I assume the "quick edit reply" is using UTF-8. Edit 3: And then, if you choose the "go advanced" in the "quick edit reply" then you are back to windows-1252 character set. Quote:
Last edited by knc1; 05-15-2012 at 10:10 AM. |
|||
05-15-2012, 10:10 AM | #5 |
Fully Converged
Posts: 18,171
Karma: 14021202
Join Date: Oct 2002
Location: Switzerland
Device: Too many to count here.
|
knc1, the forum software we're still using is not UTF-8 aware. It is not enough to simply convert the underlying database to UTF-8 and to change the HTML headers accordingly; all string-related operations need to be replaced too when byte count matters. We did a sandbox in the past doing all the changes ourselves, and it seemed to have worked, but honestly, since we are planning to switch the forum software as soon as a adequate candidate is in sight, we don't want to apply any more custom changes than necessary. It might get harder to upgrade to the other forum software otherwise. Finding the right forum software we could migrate to is a real nightmare.
I don't think the ampersand issue described here by geekmaster is related to character-set issues as the ampersand should be part of either character-set. |
Advert | |
|
05-15-2012, 10:18 AM | #6 | |
Going Viral
Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA
|
Quote:
Then why not just make the quick edit reply use windows-1252 like the rest of the site? That should only require adding the missing character set def to the form. |
|
05-15-2012, 10:49 AM | #7 |
Fully Converged
Posts: 18,171
Karma: 14021202
Join Date: Oct 2002
Location: Switzerland
Device: Too many to count here.
|
Thanks knc1, it seems to be you are totally right. I was able to replicate the issue by posting above script via the quick reply form.
|
05-15-2012, 10:55 AM | #8 |
Carpe diem, c'est la vie.
Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
I just removed all the "amp;" using firefox in linux, and the save button added one back again, so it appears to not be browser related, and it appears that you were able to reproduce the bug.
In my experience, reproducing a bug is critical to finding it, fixing it, and testing the fix. It will be nice to see this fixed. It is odd that I did not see this until I posted other toushscreen support code recently, and it seems to only affect that single line of code (which is common initialization code used in many of my scripts). Thanks for looking into this. Looking forward to a fix. |
05-15-2012, 12:40 PM | #9 |
Carpe diem, c'est la vie.
Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
I guess the easy workaround in my code to avoid this "amp;" problem is to remove the "break" from the loop, so it scans all events, instead of quitting when it finds the zforce (touchscreen) device.
The reason I scan for the zforce device is because it is a different device number depending on whether you booted from main or diags when using the touchscreen. I wonder if the name "zforce" implies that it can read how much force is applied to the screen... When pressing the screen with a soft fingertip, more "pixels" are covered as the fingertip flattens out. You can see this effect when you run the "zforcediag" program on the diags partition. Unfortunately, you have to boot to diags using mmcblk0p2_ssh, because zforcediag looks for the touchscreen input device in the wrong location when booting from main. From diags, run "/usr/local/bin/zforcediag", and you will see that if you read the touchscreen LED and photodiodes directly instead of using the input device I am using, you could even measure the diameter of a coin or other object laid (carefully) on the screen. EDIT: Because the zforcediag program resides in the same directory as the dropbear files needed by SSH, the new 5.1.0 OTA updates probably delete this very useful diagnostic tool when they delete dropbear. Bad amazon! I plan to copy my /usr/local file to my usb drive to hide them from amazon. Last edited by geekmaster; 10-09-2012 at 08:05 PM. |
05-15-2012, 12:57 PM | #10 |
Carpe diem, c'est la vie.
Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
I decided to show you how zforcediag works. I want to use its low-level direct access to the touchscreen LEDs and photodiodes in my own code (I love getting closer to the "bare metal").
I rebooted to diags, and I started SSH from menu items N) U) Z) X), then I ran /usr/local/bin/zforcediag. Here is the output of zforcediag when I touch one finger, then two fingers, then release the first and then the second finger: Spoiler:
Here is the output of "strace zforcediags", while I touch the screen two times: Spoiler:
Being able to determine what coin is (gently) placed on the screen by measuring its diameter would be a cool hack. EDIT: By comparing the output of zforcediags to the 0-4095 outputs from the zforce event input device, you can see that they interpolate the touch centroid from the proportional "blocked light" values of the outermost blocked sensors. From my testing, it appears that they really DO get 4K pixel accuracy this way (which is why they patented it). You can roll your fingertip on the screen to see subpixel movements. I am curious why amazon is switching to capacitive touchscreens on future kindles -- perhaps to use a thinner bezel so the K5 can be as thin as the K4 (but more likely for cost savings). EDIT 2: You can see in the first output listing how two finger touches cast shadows forming a rectangle, making it difficult to determine where the two fingers really are without tracking movement history. In fact, the finger positions returned by the event device driver DO get confused and swap half the coordinate pair between fingers when you rotate two fingers on the screen across a common X or Y coordinate. This makes the finger positions reported suddenly jump to the "other" corners of the rectangle. I know how to compensate for this by using velocity tracking instead of position tracking (and in fact it does appear to be fixed in a recent update to the main code trunk for the linux touchscreen driver, but not in the version used in the kindle). Even though the coordinates reported may be for the wrong corners of the rectangle, they are still useful for pinch and stretch gestures, because both diagonals of a rectangle are the same length. I can resize an animated vector object (such as my signature vector) easily enough, but rotating it past a horizontal or vertical axis is difficult unless I add two-finger velocity tracking and "corner swap" correction (and that hack could break if they ever DO fix this problem, and preventing unwanted future behavior adds to the code complexity). Last edited by geekmaster; 05-15-2012 at 03:42 PM. |
05-15-2012, 02:47 PM | #11 |
Enthusiast
Posts: 29
Karma: 10
Join Date: May 2012
Device: Kindle Touch
|
Just registered to say how awesome you are geekamaster (I admit I'm not the first !).
Appreciate the way you do your stuff man Been downloading all your kindle touch codes lately. I would definitely love to work on them, unfortunately I'm always outta time. Expecting better touch interaction and finger gestures for kindlets from your findings ! Keep rocking geekmaster ! |
05-16-2012, 08:28 AM | #12 |
Fully Converged
Posts: 18,171
Karma: 14021202
Join Date: Oct 2002
Location: Switzerland
Device: Too many to count here.
|
I believe the issue has been fixed. It was triggered by the &&break; in geekmaster's code. An over-simplified regular expression in our Ajax handling code considered this piece a valid HTML entity and therefore decided to encode it into &&break;. We replaced the regular expression with something more robust.
|
05-16-2012, 10:24 AM | #13 | |
Carpe diem, c'est la vie.
Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
Quote:
|
|
10-06-2012, 06:02 PM | #14 |
Carpe diem, c'est la vie.
Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
This program partially works on the Paperwhite, but has some issues that need fixing. The name of the touchscreen device changed from zforce to cyttsp, so I need to change the code that searches for it in the input devices:
I needed to change this: DT=$(for i in /dev/input/event*;do evtest info $i|grep zforce>$DN&&echo $i&&break;done) to this: DT=$(for i in /dev/input/event*;do evtest info $i|grep -w "zforce\|cyttsp">$DN&&echo $i&&break;done) Also, the eips text output needs to be reformatted. On the K5 and earlier you had 40 lines of 50 characters. But on the Paperwhite, you havee 42 lines of 48 characters. Not only is the line 2 characters narrower, but you can only see the left half of the last character on the line. So practically speaking, in text mode, the new higher resolution eink screen cannot display the rightmost 3 characters of lines that displayed fine on earlier kindles. Here are the screen dimensions reported by eips: Code:
[root@kindle root]# eips -i
Fixed framebuffer info
id: mxc_epdc_fb smem_start: 0x75800000
smem_len: 4718592 type: PACKED_PIXELS
type_aux: 0 visual: STATIC_PSEUDOCOLOR
xpanstep: 1 ypanstep: 1
ywrapstep: 0 line_length: 768
mmio_start: 0x00000000 mmio_len: 0
accel: 0
Variable framebuffer info
xres: 758 yres: 1024
xres_virtual: 768 yres_virtual: 6144
xoffset: 0 yoffset: 0
bits_per_pixel: 8 grayscale: 1
red.offset: 0 green.offset: 0
red.length: 8 green.length: 8
red.msb_right: 0 green.msb_right: 0
blue.offset: 0 transp.offset: 0
blue.length: 8 transp.length: 0
blue.msb_right: 0 transp.msb_right: 0
nonstd: 0 activate: 128
width: -1 height: -1
accel_flags: 0 pixclock: 40000000
left_margin: 12 right_margin: 76
upper_margin: 4 lower_margin: 5
hsync_len: 12 vsync_len: 2
sync: 0 vmode: 0
rotate: 3
[root@kindle root]#
Last edited by geekmaster; 10-09-2012 at 11:12 PM. |
10-06-2012, 06:13 PM | #15 |
Going Viral
Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA
|
I think you can fix that 1/2 character if you make a change that solves:
xres = xres_virtual - left_margin But that may be hardcoded in the driver, I have not looked at the code. I.E: left_margin = 10 dot clocks not 12 dot clocks might work. If I had one in front of me, the first thing I would do is try a: modinfo command on that driver module to see what can be passed to it as options at load time. - - - - If the above does not help, Take another look at that report - the math there does not look right, but I may have missed the exact point of the problem. For the purpose of reading that report, think of it as trying to describe the components of a video scan line. (left over from when the drivers/hardware did generate scan lines) Last edited by knc1; 10-06-2012 at 06:18 PM. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
geekmaster simple touchscreen script support hack | geekmaster | Kindle Developer's Corner | 12 | 04-22-2021 12:38 AM |
I'd help HER capture Moose and Squirrel! | ardeegee | Lounge | 2 | 06-29-2010 01:17 PM |
Trying to Capture Rebecca | andavane | Calibre | 4 | 10-26-2009 02:47 PM |