View Single Post
Old 05-14-2012, 08:10 PM   #1
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 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:
#!/bin/sh
#====================================================
# gmsigcap 1.0b - geekmaster vector signature capture
# Copyright (C) 2012 by geekmaster, with MIT license:
# http://www.opensource.org/licenses/mit-license.php
#----------------------------------------------------
# Tested on K5main,K5diags, uses touchscreen.
#----------------------------------------------------

#===========================
# initvar - init global vars
#---------------------------
initvar() {
  
gs=12 # granularity size (distance per capture point)
  
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
  
x=0 y=0 xs=0 ys0=0 B=0 Q=0 n=0 H="" R='\x0d' GG=$((gs*gs))
  
eips 44 38 '+~~~~~'
  
eips 44 39 '| Exit'
}

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

#==================================
# sigcap - signature vector capture
#----------------------------------
sigcap() {
  
script -"hexdump $DT$DN|while [[ $Q -eq 0 ]]; do
    
read L; [[ ${#L} -ne 48 ]]&& break # rare script exit output
    
set $Llocal T=$((0x$6)) C=$((0x$7)) V=$((0x$8))
    case 
$T in
    0
) if [[ $B -eq 9 ]]; then
        H
="$H 0 };$R\x0a"n=$((n+1))
        echo -
"unsigned short int sigvec[$n]={$R"; echo -e "$H$R"
        abortsh # abort subprocess shell
        Q=1 # signal quit
      elif [[ 
$x -ge 540 && $y -ge 750 ]]; then # on exit button
        if [[ 
$B -ne 1 ]]; then # was not pressed
          eips -v 44 38 '+~~~~~'
          eips -v 44 39 '| Exit'
        fi; B=1
      else # off exit button
        if [[ 
$B -ne 2 ]]; then # was not released
          eips 44 38 '+~~~~~'
          eips 44 39 '| Exit'
        fi; B=2
      fi
      Dx=$((x-xs)); [[ 
$Dx -lt 0 ]]&& Dx=$((0-Dx))
      Dy=$((y-ys)); [[ 
$Dy -lt 0 ]]&& Dy=$((0-Dy))
      RR=$((Dx*Dx+Dy*Dy))
      if [[ 
$RR -ge $GG ]];then
        H="
$H $((y*256/800*256+x*256/600)),$R\x0a"; n=$((n+1))
        dd if=
$DZ of=$DF bs=1 count=5 seek=$((y*VX+x-4)) 2>$DN # black
        xs=
$x ys=$y; eips '';
      fi ;;
    3) case 
$C in
      53) x=$((V*600/4096)) ;;
      54) y=$((V*800/4096)) ;;
      57) case 
$V in
        0) xs=0 ys=0 ;;
        65535) [[ 
$B -eq 1 ]]&& B=9 # signal exit button pressed
          H="
$H $((y*256/800*256+x*256/600)),$R\x0a"
          H="
$H 0,$R\x0a"; n=$((n+2)) ;;
        esac ;;
      esac ;;
    esac
  done
  eips 44 38 '      '
  eips 44 39 '      '
}

killall -STOP Xorg cvm # pause framework
initvar # init global vars
sigcap # signature vector capture
killall -CONT cvm Xorg # resume framework 
P.S. You can even draw "happy face" smilies with this, and animate them using code from my newtrix demo.

Here is the output from this script after I drew a large smiley icon with my finger, then pressed the "exit" button:
Spoiler:
Code:
unsigned short int sigvec[125]={
 23228,
 21944,
 20916,
 19886,
 19110,
 18333,
 17555,
 17549,
 17543,
 17538,
 17533,
 18036,
 18540,
 19302,
 20064,
 21083,
 22614,
 24401,
 25422,
 26443,
 27209,
 28231,
 29253,
 30533,
 31557,
 32581,
 33606,
 34632,
 35403,
 36430,
 37202,
 38230,
 39258,
 40032,
 40549,
 41065,
 41326,
 41587,
 41848,
 42110,
 42119,
 41869,
 41618,
 41371,
 40356,
 39848,
 39085,
 38577,
 37556,
 37048,
 36284,
 35010,
 33221,
 32455,
 30920,
 29641,
 28360,
 26823,
 25541,
 24002,
 22973,
 21687,
 20657,
 20392,
 20129,
 20129,
 0,
 22408,
 22402,
 22908,
 23674,
 24954,
 26236,
 25730,
 24965,
 23944,
 22919,
 22148,
 21890,
 0,
 29084,
 28822,
 29328,
 30348,
 31116,
 32399,
 32916,
 32921,
 32413,
 31650,
 30885,
 29858,
 29856,
 0,
 29281,
 30303,
 31328,
 32352,
 33378,
 34404,
 35175,
 35691,
 36464,
 36981,
 37243,
 37504,
 37254,
 37001,
 0,
 24958,
 25722,
 25472,
 24707,
 24704,
 0,
 31634,
 32150,
 31128,
 31379,
 32404,
 0,
 63727,
 63469,
 0,
 0 };

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!
Attached Files
File Type: gz gmsigcap-1.0b.tar.gz (1.3 KB, 116 views)

Last edited by geekmaster; 05-16-2012 at 02:57 PM.
geekmaster is offline   Reply With Quote