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-12-2012, 02:22 AM   #1
Ehhh
Connoisseur
Ehhh is a jewel in the roughEhhh is a jewel in the roughEhhh is a jewel in the roughEhhh is a jewel in the roughEhhh is a jewel in the roughEhhh is a jewel in the roughEhhh is a jewel in the roughEhhh is a jewel in the roughEhhh is a jewel in the roughEhhh is a jewel in the roughEhhh is a jewel in the rough
 
Posts: 73
Karma: 7140
Join Date: Feb 2012
Device: Kindle Touch
Touch screen events

How to get touch screen events(click, double click)? menu button's events?
Ehhh is offline   Reply With Quote
Old 05-12-2012, 03:00 AM   #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,066
Karma: 6789001
Join Date: Nov 2011
Location: Щедрость не имеет пределов.
Device: *.*
Arrow Touchpaint2

You can ignore all the unfinished motion predicition code. I was going to use that for touchscreen capture point compression, but I did not finish it... (Yes, the deeper derivatives of motion are named after a breakfast cereal. In real life motion control, people rarely go deeper than snap vector analysis.)

This is working code that was not cleaned up and not documented for publication. It writes binary directly to the framebuffer. It reads binary directly from the device input events. C code can do this same stuff. It is here to show you how you can read touchscreen data directly from the touchscreen device. This method is similar to how the myts onscreen terminal program reads keyboard events on a K3.

This old version contains debug code that displays all the touchscreen events, which I removed from later (better) code that I use elsewhere. I thought this old (unfinished "dirty") version with the debug stuff would be more helpful in this case, so here it is...

PHP Code:
#!/bin/sh

# Touchpaint2 (v2.12b)
# copyright (c) 2012 geekmaster
# MIT license.

self=$0cmd=$1shift 2
[[ $cmd ]] && $cmd $@ && exit

init() {
  
E3="echo"
#  E3="nop"
  
E2="echo"
  
E1="echo"
  
DN=/dev/nullDZ=/dev/zeroDF=/dev/fb0
  DT
=$(for i in /dev/input/event*;do evtest info $i|grep zforce>$DN&&echo $i&&break;done)  
  
set $(eips -i|grep line_length); VX=$4
  W
='\xff';W=$W$W$W$W$W$W;W=$W$W$W$W$W;W=$W$W$W$W$W;W=$W$W$W$W # 600px white
  
eips --# flash clear
  
X1=0 Y1=0 X2=0 Y2=0 X3=0 Y3=0 x1s=0 y1s0=0 x2s=0 y2s=0 B=0 S=0 Q=0 R='\x0d'
  
eips 44 38 '+~~~~~'                                                      
  
eips 44 39 '| Exit'                                                      
  
lm=# line mode
#  lm=1
#  gs=8 # granularity size
#  gs=16 # granularity size
#  gs=12 # granularity size
#  gs=5 # granularity size
  
gs=# granularity size
#  gs=2 # granularity size
#  gs=1 # granularity size
  
GG=$((gs*gs))
  
H=""
}

nop() {
  :
}

#=================================
# abortsh - abort subprocess shell
#--------------------------------- 
abortsh() {
  
set $(ps a|grep "sh -c hexdump $DT")
  
kill -HUP $# abort shell
  
Q=# signal quit
}

# Bresenham's line algorithm
line() {
  
local x0=$1 y0=$2 x1=$3 y1=$4 dx dy sx sy
  
if [[ $x1 -gt $x0 ]]; then dx=$((x1-x0)) sx=1; else dx=$((x0-x1)) sx=-1fi
  
if [[ $y1 -gt $y0 ]]; then ny=$((y0-y1)) sy=1; else ny=$((y1-y0)) sy=-1fi
  err
=$((dx+ny))
  while :; do 
# to do: use count="segment width"
    
dd if=$DZ of=$DF bs=1 count=1 seek=$((y0*VX+x0)) 2>$DN # black
#    dd if=$DZ of=$DF bs=1 count=8 seek=$((y0*VX+x0-4)) 2>$DN # black
#   echo $W|dd of=$DF bs=1 count=$((DX+1)) seek=$((Y0*VX+X)) 2>$DN # white
    
[[ $x0 -eq $x1 && $y0 -eq $y1 ]] && break
    
e2=$((2*err))
    [[ 
$e2 -gt $ny ]] && err=$((err+ny)) x0=$((x0+sx))
    [[ 
$e2 -lt $dx ]] && err=$((err+dx)) y0=$((y0+sy))
  
done
# eips '' # temp for testing
}

lineart() {
  for 
i in $(seq 0 1 50); do
    
j=$((50-i))
    
line $((i*12)) 0 599 $((i*16)); eips ''
    
line 599 $((i*16)) $((j*12)) 799eips '' 
    
line $((j*12)) 799 0 $((j*16)); eips ''
    
line 0 $((j*16)) $((i*12)) 0eips ''
  
done
}

paint() {
  
script -"hexdump $DT$DN|while [[ $Q -eq 0 ]]; do
    
read L; [[ ${#L} -ne 48 ]]&& break # rare script exit output
#    $E3 -ne "${L:0:$((${#L}-1))}"
    
set $Llocal T=$((0x$6)) C=$((0x$7)) V=$((0x$8))
    case 
$T in
    0
$E3 -ne " (Sync)"
      
$E3 -ne " [S=$S X1=$X1 Y1=$Y1 X2=$X2 Y2=$Y2]"
      
###  $E1 -e "SYN $S $x1s $y1s $X1 $Y1 $R"
      
if [[ $B -eq 9 ]]; then
        $E3 
-" exit button pressed"
        
abortsh # abort subprocess shell
        
Q=# signal quit
      
elif [[ $X1 -ge 540 && $Y1 -ge 750 ]]; then # on exit button
#      elif [[ $X1 -ge 135 && $Y1 -ge 188 ]]; then # on exit button
        
if [[ $B -ne 1 ]]; then # was not pressed                    
          
eips -v 44 38 '+~~~~~'                              
          
eips -v 44 39 '| Exit'                              
        
fi                                                    
        B
=1
        $E3 
" on exit button"
      
else # off exit button                                  
        
if [[ $B -ne 2 ]]; then # was not released
          
eips 44 38 '+~~~~~'                                 
          
eips 44 39 '| Exit'                                 
        
fi                                                    
        B
=2                                        
        $E3 
-ne " off exit button"
      
fi
      DX
=$((X1-x1s)); [[ $DX -lt 0 ]]&& DX=$((0-DX)) 
      
DY=$((Y1-y1s)); [[ $DY -lt 0 ]]&& DY=$((0-DY))
      
RR=$((DX*DX+DY*DY))
#      if [[ $DX -ge $gs -o $DY -ge $gs ]];then
      
if [[ $RR -ge $GG ]];then
#       $E2 -e "MOV $S $X1 $Y1 $X2 $Y2 $R"
#      H="$H:MOV $S $X1 $Y1 $X2 $Y2 $R\x0a"
#      echo -e "$H $R"
      
if  [[ $lm -eq 1 -a $x1s -ne 0 -a $y1s -ne 0 ]];then
        line $x1s $y1s $X1 $Y1 
#        line $((x1s*4)) $((y1s*4)) $((X1*4)) $((Y1*4)) 
      
else
        
dd if=$DZ of=$DF bs=1 count=5 seek=$((Y1*VX+X1-4)) 2>$DN # black
#        dd if=$DZ of=$DF bs=1 count=8 seek=$((Y1*VX*4+X1*4-4)) 2>$DN # black
      
fi
#      [[ $x1s -ne 0 -a $y1s -ne 0 ]]&& line $((x1s/4)) $((y1s/4)) $((X1/4)) $((Y1/4)) 
      
dd if=$DZ of=$DF bs=1 count=1 seek=$((Y1/5*VX+X1/5)) 2>$DN # black
# sliding-window position history:
      
x1h3=x1h2 y1h3=y1h2;x1h2=x1h1 y1h2=y1h1;x1h1=x1s y1h1=y1s;x1h=X1 y1h=Y1
# 1st derivative: velocity vectors:
      
x1v2=$((x1h2-x1h3)) y1v2=$((y1h2-y1h4));x1v1=$((x1h1-x1h2)) y1v1=$((y1h1-y1h2))
      
x1v=$((x1h-x1h1)) y1v=$((y1h-y1h1)) # velocity
# 2nd derivative: acceleration vectors:
      
x1a1=$((x1v2-x1v1)) y1a1=$((y1v2-y1v1));x1a=$((x1v-x1v1)) y1a=$((y1v-y1v1)) # accel
# 3rd derivative: jerk vectors:
      
x1t=$((x1a-x1a1)) y1t=$((y1a-y1a1)) # thrust
# jerk position interpolation:
### (more code here)

# 4th derivative: snap
# 5th derivative: crackle
# 6th derivative: pop


      
x1s=$X1 y1s=$Y1eips '';
      
fi
#      DX=$((X2-x2s)); [[ $DX -lt 0 ]]&& DX=$((0-DX)) 
#      DY=$((Y2-y2s)); [[ $DY -lt 0 ]]&& DY=$((0-DY))
#      if [[ $DX -ge 4 -o $DY -ge 4 ]];then
#       if  [[ $x2s -ne 0 && $y2s -ne 0 ]];then
#         line $x2s $y2s $X2 $Y2 
#       fi
#        dd if=$DZ of=$DF bs=1 count=8 seek=$((Y2*VX+X2-4)) 2>$DN # black
#        x2s=$X2 y2s=$Y2; eips '';
#      fi
      
;;

    
1$E3 -ne " (Key)"
      
case $C in
      0
)   $E3 -ne " (Reserved)" ;;
      
1)   $E3 -ne " (Esc)" ;;
      
325$E3 -ne " (ToolFinger)" ;;
      
330$E3 -ne " (Touch)" ;;
        
V=$((V*200/4096*4))
        
$E3 -ne " Y=$V [S=$S X1=$X1 X2=$X2]"
        
if [[ $S -eq 0 ]];then Y1=$V;
        
elif [[ $S -eq 1 ]];then Y2=$V
        
else echo -ne " *** slot $S *** "
        
fi
        
;;
      
57$E3 -ne " (MT Tracking ID) [0-255]"
        
$E3 -ne " [X1=$X1 Y1=$Y1 X2=$X2 Y2=$Y2]"
        
case $V in
        0
x1s=0 y1s=0eips -' '$E3 -ne " touch 1 ($((S+1)))"   
          
;;
        
1x2s=0 y2s=0eips -' '$E3 -ne " touch 2 ($((S+1)))"
          
;;   
        
65535eips ' '$E3 -ne " release $((S+1))"
#          $E1 -e "REL $S $X1 $Y1 $X2 $Y2 $R"
#          H="$H:REL $S $X1 $Y1 $X2 $Y2 $R\x0a"
#          echo -e "$H $R"
        ####abortsh # abort subprocess shell
          
[[ $B -eq 1 ]]&& B=# signal exit button pressed
          
;;                       
        *) 
$E3 -ne " (Value $V)"
          
;;
        
esac
#        if [[ $V -eq 0 ]]; then x1s=0 y1s=0; eips -v ' '; $E3 -ne " touch 1 ($((S+1)))"   
#        elif [[ $V -eq 1 ]]; then x2s=0 y2s=0; eips -v ' '; $E3 -ne " touch 2 ($((S+1)))"   
#        else eips ' '; $E3 -ne " release $((S+1))"
#          [[ $B -eq 1 ]]&& B=9 # signal exit button pressed
#        fi
        
;;                       
      *) 
$E3 -ne " (Code $C)"
        
;;
      
esac
      
;;
    *) 
$E3 -ne " (Type $T)"
      
;;
    
esac
    $E3 
-e $R
  done
#  $E3 "touchscreen processing complete"
  
eips 44 38 '      '
  
eips 44 39 '      '
}

killall -STOP Xorg cvm # pause framework
init
#line 100 45 500 750; eips ''
#line 130 690 580 75; eips ''

#for i in $(seq 1 1 20);do
  
paint
#done

#paint #|while :;do
#  read L
#  echo "($L)"
#done


#lineart
killall -CONT cvm Xorg # resume framework 
Run it on the K5. If the touchscreen is not working (screensaver mode) tap the power button to wake it up.

I have newer code that supports two finger drawing, pinch and stretch, and limited rotate, but that is missing the debug output messages that you probably could use. I may publish a newer version soon.

I plan to port this stuff to C soon. It is all from the "eink algorithmic art" collection (but not yet published).

You should exit by pressing the "Exit" button in the lower right corner to resume Xorg and cvm. My newer versions of this script intercept ctrl-c and do a proper shutdown that includes resuming the framework. Not this old one.

P.S. Firmware for 5.0.x (and perhaps 5.1.x) has a bug when you are moving two fingers on the screen: when rotating, when both fingers cross the same X coord or Y coord, sometimes the OTHER coordinates get swapped (and stay swapped). This makes it return coordinates for other untouched coordinates of the bounding box. That is not a problem for pinch and stretch though.

ToDo: You can see in the myts program from matan, how to capture an input device so that the touches (in this case) are not passed through to the framework. I like to do touchscreen stuff in diags, where there is a menu item that stops looking at the touchscreen events until the menu button is pressed. (See the old Touchpaint 1.0 thread for details).


Last edited by geekmaster; 05-16-2012 at 02:56 PM.
geekmaster is offline   Reply With Quote
Old 05-14-2012, 10:48 AM   #3
Ehhh
Connoisseur
Ehhh is a jewel in the roughEhhh is a jewel in the roughEhhh is a jewel in the roughEhhh is a jewel in the roughEhhh is a jewel in the roughEhhh is a jewel in the roughEhhh is a jewel in the roughEhhh is a jewel in the roughEhhh is a jewel in the roughEhhh is a jewel in the roughEhhh is a jewel in the rough
 
Posts: 73
Karma: 7140
Join Date: Feb 2012
Device: Kindle Touch
Thank you for the detailed information.
Ehhh is offline   Reply With Quote
Old 05-16-2012, 02:33 PM   #4
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,066
Karma: 6789001
Join Date: Nov 2011
Location: Щедрость не имеет пределов.
Device: *.*
Quote:
Originally Posted by Ehhh View Post
Thank you for the detailed information.
You are welcome. You can see a simplified version of this script that assumes only one finger touching, in my "signature capture" thread. This one is more useful for extracting gestures, but if you want to be even more advanced, you can process the event timestamps that I discard here. Or you can just extract gestures from the Xorg log file.
geekmaster 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
PRS-650 Touch screen sensibility and screen protector bookmeal Sony Reader 16 09-18-2011 08:26 PM
book reader that supports touch screen tablets and has touch control colint3 General Discussions 1 06-22-2011 01:47 PM
How about an Events section? nigeldb Feedback 2 11-01-2009 09:37 PM
3 Ebook Events in May Nate the great News 2 03-18-2009 07:11 PM


All times are GMT -4. The time now is 01:26 PM.


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