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 05-16-2012, 06:13 PM   #1
JoppyFurr
Coding fuzzball
JoppyFurr juggles running chainsaws for a bit of light exerciseJoppyFurr juggles running chainsaws for a bit of light exerciseJoppyFurr juggles running chainsaws for a bit of light exerciseJoppyFurr juggles running chainsaws for a bit of light exerciseJoppyFurr juggles running chainsaws for a bit of light exerciseJoppyFurr juggles running chainsaws for a bit of light exerciseJoppyFurr juggles running chainsaws for a bit of light exerciseJoppyFurr juggles running chainsaws for a bit of light exerciseJoppyFurr juggles running chainsaws for a bit of light exerciseJoppyFurr juggles running chainsaws for a bit of light exerciseJoppyFurr juggles running chainsaws for a bit of light exercise
 
JoppyFurr's Avatar
 
Posts: 16
Karma: 38918
Join Date: May 2012
Device: Kindle Touch
Taking over touch screen input + a simple drawing program.

Hi,

I'm just getting started with Kindle development. My goal is to eventually write some form of terminal emulator, so that I could use my Kindle Touch to ssh back to my home computer.

I've started learning to use the frame buffer and touch screen. However, am curious of how to take over the touch screen so that the normal Kindle interface isn't trying to use it at the same time.

I've read this thread:
http://www.mobileread.com/forums/sho....php?t=178143-
Which showed me that touch events can be found at /dev/input/event3. However, I have not been able to find information on allowing a program to completely take over the input.

I've seen other programs that seem to do this. For example, the Sokoban game linked to on the Kindle Touch Hacks page allows you to play without it interfearing with menu items 'behind' the game.

I've made a program that allows you to draw to the screen with your finger. However, it seems like my program is figting with another over the touch screen. When drawing a line with my finger, it shows dashed. As if it was taking turns with the touch screen, getting access to it in chunks of a half second or so.

I have attached my code, if anybody wants to play with it. When it is running, you can stop the program by draging your finger to the top right corner and releasing. I've been compiling with the tcc compiler linked to from here:
http://www.mobileread.com/forums/sho...d.php?t=175834

Any tips would be appreciated :3
Thanks,

JoppyFurr
Attached Files
File Type: gz Plotting.tar.gz (2.8 KB, 135 views)
JoppyFurr is offline   Reply With Quote
Old 05-16-2012, 06:25 PM   #2
geekmaster
Всё гениальное просто.
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: 5,069
Karma: 6789001
Join Date: Nov 2011
Location: Щедрость не имеет пределов.
Device: *.*
Quote:
Originally Posted by JoppyFurr View Post
Hi,

I'm just getting started with Kindle development. My goal is to eventually write some form of terminal emulator, so that I could use my Kindle Touch to ssh back to my home computer.

I've started learning to use the frame buffer and touch screen. However, am curious of how to take over the touch screen so that the normal Kindle interface isn't trying to use it at the same time.

I've read this thread:
http://www.mobileread.com/forums/sho....php?t=178143-
Which showed me that touch events can be found at /dev/input/event3. However, I have not been able to find information on allowing a program to completely take over the input.

I've seen other programs that seem to do this. For example, the Sokoban game linked to on the Kindle Touch Hacks page allows you to play without it interfearing with menu items 'behind' the game.

I've made a program that allows you to draw to the screen with your finger. However, it seems like my program is figting with another over the touch screen. When drawing a line with my finger, it shows dashed. As if it was taking turns with the touch screen, getting access to it in chunks of a half second or so.

I have attached my code, if anybody wants to play with it. When it is running, you can stop the program by draging your finger to the top right corner and releasing. I've been compiling with the tcc compiler linked to from here:
http://www.mobileread.com/forums/sho...d.php?t=175834

Any tips would be appreciated :3
Thanks,

JoppyFurr
Actually, the device event number is different depending on whether you boot from main or diags, which is why the code shown searches for a device that returns the "zforce" identifier. You cannot trust that it will always be device 3.

If you look at my simpler version of that, published as a "signature capture" script, you will see that it pauses and resumes the framework (Xorg and cvm). That works quite well for my needs. You can do the same as a script command by enclosing it in a system() call; You can also see how it is handled in the various scripts published in the "eink algorithmic art" scripts thread. Of course, the "official" way is to use ioctl() calls to capture the event device, but because amazone BROKE stuff in the eink header files (and probably more), that would lock your program to only work on a specific minor version of the firmware. Doing it the "script" way is more robust because of amazon's recent arbitrary changes that violate linux standards. You can see how to capture a device by looking in the "myts" onscreen terminal code. Touchscreen events are just like keyboard events used there.

You can search to find the threads containing my various scripts and C programs. They give examples how to do lots of things from scripts and from C. I also have a series of C programs that do much faster graphics, including smooth animation and video playback on a K3 and newer.

I will look at your code now...


A few little tips:
1) If your code is based on other code (such as my simplified touch code in the script you referenced and translated to C), it is considered polite to give credit to the person whose ideas you borrow (although not strictly required under the MIT license that I use). This is called "user attribution" and is required under some licenses. In this case, the event code as documented is a lot more complex, and it took me significant experimentation and refinement to simplify it to the level in my sigcap script (almost identical to what you used).

2) If you want to share your code with others, many people cannot use it unless it has a clear open source license. GPL is forbidden to be used by programmers who white commercial apps, so I recommend MIT (or BSD).

3) In conditional expressions, experienced programmer ALWAYS put the constant to the left of the variable, so that accidentally changing "==" to "=" will cause a compiler warning instead of just changing to a VERY DIFFICULT to debug program error.

Now I am going to test your program...

It is a good start. I like the grid. Your lag is a lot worse in this C program than in my sigcap script that uses "dd" to write pixels to the screen. Your program will be MUCH faster after that little problem is solved. And yes, even my programs suffer these problems while they are in development. Each problem needs to be tracked down and fixed.

I am giving you the "geekmaster award" (bumping your karma to 2600, a special numbers familiar to hackers from long before there were computers).

P.S. Please add a "thanks geekmaster!" comment (or similar) and add the MIT license to it like I use. That will make me happy, and will make your code useful to a lot more people. Thanks.

*** I see that you defined the upper right corner as exit. Because I do most of my touch capture in landscape mode, I defined the lower right corner as exit (which IS the upper right corner when rotated the way I use if for signature capture).

Check out my "newtrix" demo to see how to shaded lines and circles from C, and how to draw vector art captured from the touchscreen using my sigcap script (which outputs a C structure to use in the newtrix code).


Last edited by geekmaster; 05-16-2012 at 07:03 PM.
geekmaster is offline   Reply With Quote
Old 05-16-2012, 07:08 PM   #3
geekmaster
Всё гениальное просто.
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: 5,069
Karma: 6789001
Join Date: Nov 2011
Location: Щедрость не имеет пределов.
Device: *.*
Try the sigcap program (script) for a baseline comparison of speed and responsiveness (lack of lag), and to see one way to prevent the framework from stealing your touchscreen events:


Especially notice that I have a "granularity size", which could also be called "sensitivity", or "hysteresis threshhold" depending on your background and experience.

Because the touchscreen puts out 0-4095 values for each axis, this can generate WAY more events than are useful. I filter the events down to only process events that go outside the bounding circle that is "granularity size" radius from the last captured finger position. You can adjust that value. Smaller gives a lot more capture points for higher resolution if you need it. I would not go below 4, personally (no need). I use 6 for my onscreen keyboard code.

Last edited by geekmaster; 05-16-2012 at 07:14 PM.
geekmaster is offline   Reply With Quote
Old 05-16-2012, 09:22 PM   #4
JoppyFurr
Coding fuzzball
JoppyFurr juggles running chainsaws for a bit of light exerciseJoppyFurr juggles running chainsaws for a bit of light exerciseJoppyFurr juggles running chainsaws for a bit of light exerciseJoppyFurr juggles running chainsaws for a bit of light exerciseJoppyFurr juggles running chainsaws for a bit of light exerciseJoppyFurr juggles running chainsaws for a bit of light exerciseJoppyFurr juggles running chainsaws for a bit of light exerciseJoppyFurr juggles running chainsaws for a bit of light exerciseJoppyFurr juggles running chainsaws for a bit of light exerciseJoppyFurr juggles running chainsaws for a bit of light exerciseJoppyFurr juggles running chainsaws for a bit of light exercise
 
JoppyFurr's Avatar
 
Posts: 16
Karma: 38918
Join Date: May 2012
Device: Kindle Touch
Updated Draw :3

Hi,

I have updated my program. It's now a bit smoother and has some new features.

Changes:
- Added MIT license
- Added a note thanking Geekmaster for code tips
- Multithreaded
- - - First thread to listen to the touch screen and write to the frame buffer
- - - Second thread to handle updating the eInk.
- Releasing in the top left of the screen now clears the image back to a blank grid
- Kindle framework stopped while running

Thanks for helping out Geekmaster :3

UPDATE: A new version adds better handling of multi-touch.
Attached Files
File Type: gz Draw.tar.gz (4.1 KB, 71 views)
File Type: gz Draw_updated.tar.gz (4.4 KB, 112 views)

Last edited by JoppyFurr; 05-17-2012 at 12:44 AM.
JoppyFurr is offline   Reply With Quote
Old 05-16-2012, 09:47 PM   #5
geekmaster
Всё гениальное просто.
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: 5,069
Karma: 6789001
Join Date: Nov 2011
Location: Щедрость не имеет пределов.
Device: *.*
Quote:
Originally Posted by JoppyFurr View Post
Hi,

I have updated my program. It's now a bit smoother and has some new features.

Changes:
- Added MIT license
- Added a note thanking Geekmaster for code tips
- Multithreaded
- - - First thread to listen to the touch screen and write to the frame buffer
- - - Second thread to handle updating the eInk.
- Releasing in the top left of the screen now clears the image back to a blank grid
- Kindle framework stopped while running

Thanks for helping out Geekmaster :3
A huge performance improvement! Good job JoppyFurr!

In the code, the killall -STOP is really not the same as "framework stop" (or equivalent). It is really a pause (the complement of resume). I would rename the STOP_FRAMEWORK define to PAUSE_FRAMEWORK just to avoid confusion.

EDIT: That background grid does an excellent job of distracting your eye away from the ghosting artifacts left behind when erasing to black. Good idea there. Another method is to ERASE the ghosting with "color palette animation" like I did in the "goodbye" function in my newtrix demo (and used again in the gmvid.gmv.gz video file played with gmplay). Your method certainly saves on battery life though.

EDIT 2: You can demonstrate the multitouch driver bug with your program too (just like mine). Put two fingers on the screen and rotate them around each other. When they cross a common axis (same X or same Y coordinate, the points returned jump to the OTHER corners of the bounding box). You can still measure the diagonal for pinch and stretch like I do, but rotation gets a bit more difficult if you compensate for the multitouch bug in your code (which could break if they ever fix the bug). It is important to "future-proof" workarounds so that they can survive the bug they compensate for going away in the future.

EDIT 3: I see on two fingers that you sometimes sync at the wrong time, which OCCASIONALLY puts a point in the other bounding box corner. You should not sync on Y, because some frames only contain a singe X or single Y. And sometimes you START out of sync (wrong bounding box corner) without triggering the driver bug. There is a separate sync event you should use (see my script you linked to). Of course, that only matters when you use two fingers. I "oversimplified" it for my sigcap script to rely on ONLY one finger, just to make the code smaller and simpler.

Last edited by geekmaster; 05-16-2012 at 10:09 PM.
geekmaster is offline   Reply With Quote
Old 05-18-2012, 05:19 AM   #6
MaPePeR
Connoisseur
MaPePeR can shake the floor when laughingMaPePeR can shake the floor when laughingMaPePeR can shake the floor when laughingMaPePeR can shake the floor when laughingMaPePeR can shake the floor when laughingMaPePeR can shake the floor when laughingMaPePeR can shake the floor when laughingMaPePeR can shake the floor when laughingMaPePeR can shake the floor when laughingMaPePeR can shake the floor when laughingMaPePeR can shake the floor when laughing
 
Posts: 58
Karma: 63518
Join Date: Apr 2012
Device: KT
Quote:
Originally Posted by geekmaster View Post
EDIT 2: You can demonstrate the multitouch driver bug with your program too (just like mine). Put two fingers on the screen and rotate them around each other. When they cross a common axis (same X or same Y coordinate, the points returned jump to the OTHER corners of the bounding box). You can still measure the diagonal for pinch and stretch like I do, but rotation gets a bit more difficult if you compensate for the multitouch bug in your code (which could break if they ever fix the bug). It is important to "future-proof" workarounds so that they can survive the bug they compensate for going away in the future.
Maybe a bit Off Topic but, allways when I read about this "multitouch bug" i wonder if it may be useful to detect rotation events(with two fingers) more easily?
I would not really expect them to fix that. (like i would not expect them to change header files without renaming them -.-)

Greetings
MaPePeR is offline   Reply With Quote
Old 05-18-2012, 08:25 AM   #7
knc1
Embedded Cheerleader
knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.
 
knc1's Avatar
 
Posts: 6,495
Karma: 5840130
Join Date: Feb 2012
Device: Too many.
I have managed to get along for many decades with computers while only using a single finger gesture.
knc1 is offline   Reply With Quote
Old 05-18-2012, 10:15 AM   #8
geekmaster
Всё гениальное просто.
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: 5,069
Karma: 6789001
Join Date: Nov 2011
Location: Щедрость не имеет пределов.
Device: *.*
Quote:
Originally Posted by MaPePeR View Post
Maybe a bit Off Topic but, allways when I read about this "multitouch bug" i wonder if it may be useful to detect rotation events(with two fingers) more easily?
I would not really expect them to fix that. (like i would not expect them to change header files without renaming them -.-)

Greetings
Actually, you can read gestures from the Xorg file in /var/log, but that only works if you do not pause cvm and Xorg.

And there was a multi-touch bug fix added to the (non-amazon) linux multitouch source trunk recently, so amazon may eventually get that fix into their code.

The problem is that your fingers cast shadows creating all four corners when two fingers are on the display, and the code must track them using VELOCITY history to prevent this problem, but they only use POSITION tracking...

So... with Xorg and cvm paused, there really is not a simpler way to read gestures other than to include gesture recognition in your own code (or use a linked or loadable library to supply it).
geekmaster is offline   Reply With Quote
Old 05-18-2012, 10:17 AM   #9
geekmaster
Всё гениальное просто.
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: 5,069
Karma: 6789001
Join Date: Nov 2011
Location: Щедрость не имеет пределов.
Device: *.*
Quote:
Originally Posted by knc1 View Post
I have managed to get along for many decades with computers while only using a single finger gesture.
Unless you use one of those antique computers with the BRS (Big Red Switch) as an integral feature of the power supply, you must occasional need a "three-finger-salute" (ctrl-atl-del). The gesture you refer to sometimes makes things worse instead of better.
geekmaster is offline   Reply With Quote
Old 07-27-2012, 04:17 AM   #10
TulseLuper
Connoisseur
TulseLuper plays well with othersTulseLuper plays well with othersTulseLuper plays well with othersTulseLuper plays well with othersTulseLuper plays well with othersTulseLuper plays well with othersTulseLuper plays well with othersTulseLuper plays well with othersTulseLuper plays well with othersTulseLuper plays well with othersTulseLuper plays well with others
 
TulseLuper's Avatar
 
Posts: 61
Karma: 2667
Join Date: Mar 2012
Device: kindle touch
Quote:
Originally Posted by JoppyFurr View Post
Hi,

I have updated my program. It's now a bit smoother and has some new features.

Changes:
- Added MIT license
- Added a note thanking Geekmaster for code tips
- Multithreaded
- - - First thread to listen to the touch screen and write to the frame buffer
- - - Second thread to handle updating the eInk.
- Releasing in the top left of the screen now clears the image back to a blank grid
- Kindle framework stopped while running

Thanks for helping out Geekmaster :3

UPDATE: A new version adds better handling of multi-touch.

I would really like to test it , how should I suppose to do to install on my kt ? thanks
TulseLuper is offline   Reply With Quote
Old 07-27-2012, 09:04 PM   #11
Titano
Definitely not King Kong
Titano never is beset by a damp, drizzly November in his or her soul.Titano never is beset by a damp, drizzly November in his or her soul.Titano never is beset by a damp, drizzly November in his or her soul.Titano never is beset by a damp, drizzly November in his or her soul.Titano never is beset by a damp, drizzly November in his or her soul.Titano never is beset by a damp, drizzly November in his or her soul.Titano never is beset by a damp, drizzly November in his or her soul.Titano never is beset by a damp, drizzly November in his or her soul.Titano never is beset by a damp, drizzly November in his or her soul.Titano never is beset by a damp, drizzly November in his or her soul.Titano never is beset by a damp, drizzly November in his or her soul.
 
Titano's Avatar
 
Posts: 126
Karma: 59238
Join Date: Jul 2012
Location: United States
Device: Kindle Touch
Quote:
Originally Posted by TulseLuper View Post

I would really like to test it , how should I suppose to do to install on my kt ? thanks
Copy it to your kindle and launch it from xterm or usbnetwork hack. It's a native app so it runs through the linux part of the kindle. You can also create a sh with something like.
Quote:
/mnt/us/draw
Titano is offline   Reply With Quote
Old 07-28-2012, 07:25 PM   #12
TulseLuper
Connoisseur
TulseLuper plays well with othersTulseLuper plays well with othersTulseLuper plays well with othersTulseLuper plays well with othersTulseLuper plays well with othersTulseLuper plays well with othersTulseLuper plays well with othersTulseLuper plays well with othersTulseLuper plays well with othersTulseLuper plays well with othersTulseLuper plays well with others
 
TulseLuper's Avatar
 
Posts: 61
Karma: 2667
Join Date: Mar 2012
Device: kindle touch
thanks titano ! i´ve tested it here this way and it does works . ill just wait now to try to get the raw output now !

thanks joppyfur and geekmaster too !!

i like the ideia of drawing from bricks ! lol
TulseLuper 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
Drawing to the e-ink screen sanek_vi Kindle Developer's Corner 2 05-07-2014 07:00 PM
ConsumerReport: E-book readers: Nook Simple Touch tops Kindle Touch afv011 Barnes & Noble NOOK 4 11-22-2011 03:39 PM
Touch issues in third-party IME input(Simple Chinese) tigerszheng Barnes & Noble NOOK 3 07-07-2011 10:32 AM
Kindle 3, Nook Simple Touch, Kobo Touch and Libra Pro Touch jbcohen Which one should I buy? 4 06-18-2011 07:58 PM
broken screen. is there a program that skims off top one inch of screen? pennpin Sony Reader 5 08-19-2009 04:42 PM


All times are GMT -4. The time now is 08:37 AM.


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