forked from optisimon/ft5406-capacitive-touch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcursor_emulation.sh
More file actions
executable file
·153 lines (129 loc) · 2.96 KB
/
Copy pathcursor_emulation.sh
File metadata and controls
executable file
·153 lines (129 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/bin/bash
#
# Author: Nazar Gerasymchuk,
# URL: trola.org
# Repo: https://github.com/troyane/ft5406-capacitive-touch
# 2019
usage () {
cat <<HELP_USAGE
$0 CTPSIZE X Y "EVENT"
This will display point with given coordinates
CTPSIZE int number of points in CTP module. We assume this module
is sqare (CTPSIZE x CTPSIZE).
X coordinate
Y coordinate
"EVENT" Possible values are "CLICK", "DRAG", "EMPTY" that represent
respective touch event. In case of "EMPTY" ignores X and Y,
you'll see empty screen. Use quotes for this argument.
Example of usage:
$ ./cursor_emulation.sh 240 20 100 "CLICK"
HELP_USAGE
}
check_input() {
SHOW_USAGE=0
re='^[0-9]+$'
if [ "$#" -eq 4 ];
then
if ! [[ "$1" =~ $re ]];
then
echo "CTPSIZE should be valid int number."
SHOW_USAGE=1
fi
if ! [[ "$2" =~ $re ]];
then
echo "X should be valid int number."
SHOW_USAGE=1
fi
if ! [[ "$3" =~ $re ]];
then
echo "Y should be valid int number."
SHOW_USAGE=1
fi
else
SHOW_USAGE=1
fi
if [ $SHOW_USAGE -eq 1 ];
then
usage
exit 1
fi
}
verify_dependencies() {
which bc > /dev/null || {
cat <<DEPS
ERROR: You need to have bc installed (to do some math in bash)
Install it by running:
sudo apt install bc
DEPS
exit 2
}
}
main() {
WIDTH=`tput cols`
HEIGHT=`tput lines`
# Get min
SIZE=$(($WIDTH < $HEIGHT ? $WIDTH : $HEIGHT))
if [ $SIZE -eq 0 ]; then
echo "SIZE = 0"
exit 0
fi
CTPSIZE=$1
K=`echo "$CTPSIZE/$SIZE" | bc`
if [ $K -eq 0 ]; then
echo "K = 0"
exit 0
fi
X=`echo "$2/$K" | bc`
Y=`echo "$3/$K" | bc`
if [ "$4" = "CLICK" ]; then
SYMBOL="*"
elif [ "$4" = "DRAG" ]; then
SYMBOL="-"
elif [ "$4" = "EMPTY" ]; then
SYMBOL=" "
else
usage
exit 3
fi
clear
for i in `seq 1 $SIZE`;
do
NEED_LINE=0
if [ $i -eq 1 -o $i -eq $SIZE ];
then
NEED_LINE=1
echo -n "+"
else
echo -n "|"
fi
# -2 because first and last symbol are '|'
for j in `seq 1 $(($SIZE-2))`;
do
if [ $NEED_LINE -eq 1 ];
then
echo -n "-"
else
echo -n " "
fi
done
if [ $NEED_LINE -eq 1 ];
then
echo "+"
else
echo "|"
fi
done
if [ "$SYMBOL" = " " ]; then
exit 0
fi
# Save current cursor
tput sc
# Draw point
tput cup $X $Y
echo -n "$SYMBOL"
# Restore cursor
tput rc
}
verify_dependencies
check_input "$@"
main "$@"