aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMitch Bradley <wmb@firmworks.com>2018-03-30 16:06:52 -1000
committerMitch Bradley <wmb@firmworks.com>2018-03-30 16:06:52 -1000
commit2d5eb11bdd4c65706af83fa4f933b00f35030988 (patch)
treed65c53e34be9cf78739ffac7e024ac3aa205efb3
parent155eaae793221eccff17994bfc20a8142bb0ac7c (diff)
downloadcforth-2d5eb11bdd4c65706af83fa4f933b00f35030988.tar.gz
Added touchscreen support
-rw-r--r--src/app/grbl/grbl.fth6
-rw-r--r--src/app/grbl/grblapp-ts.fth37
-rw-r--r--src/app/grbl/touchscreen.fth35
3 files changed, 74 insertions, 4 deletions
diff --git a/src/app/grbl/grbl.fth b/src/app/grbl/grbl.fth
index 13b789c..2d633b4 100644
--- a/src/app/grbl/grbl.fth
+++ b/src/app/grbl/grbl.fth
@@ -6,7 +6,7 @@ false value show-gcode? \ Show GCode lines as they are sent
false value show-ack? \ Show OK/Error ack lines as they are received
false value show-line#? \ Show how many lines have been executed and how many are queued
false value show-buf? \ Show the space left in GRBL's Rx buffer
-true value show-time? \ Show the elapsed time in seconds
+false value show-time? \ Show the elapsed time in seconds
-1 value comport \ File handle for serial port
@@ -36,7 +36,6 @@ defer handle-ui-events
" "(18)" send-gcode-line
#1000 flush-grbl
#1000 flush-grbl
-
" $X"n" send-gcode-line
#1000 flush-grbl
#1000 flush-grbl
@@ -195,5 +194,4 @@ defer show-stats
: send ( "filename" -- ) safe-parse-word $send-file ;
-: t " LogoArray.gcode" $send-file ;
-
+: t " GCode/LogoArray.gcode" $send-file ;
diff --git a/src/app/grbl/grblapp-ts.fth b/src/app/grbl/grblapp-ts.fth
new file mode 100644
index 0000000..1d0bce9
--- /dev/null
+++ b/src/app/grbl/grblapp-ts.fth
@@ -0,0 +1,37 @@
+fl grbl.fth
+fl fb16.fth
+fl touchscreen.fth
+
+: touched? ( -- flag )
+ ts-event? if
+ event-type ev-key = if
+ event-code btn-touch = if
+ event-value 1 = if
+ true exit
+ then
+ then
+ then
+ then
+ false
+;
+: kill-on-button ( -- )
+ touched? if fb-magenta abort then
+;
+
+: run
+ ['] kill-on-button to handle-ui-events
+
+ fb-red
+ ['] t catch if
+ \ #2000 ms
+ then
+;
+: fb-ui ( -- )
+ open-fb
+ open-touchscreen
+ begin
+ fb-green
+ touched? if run then
+ #10 ms
+ again
+;
diff --git a/src/app/grbl/touchscreen.fth b/src/app/grbl/touchscreen.fth
new file mode 100644
index 0000000..9a07ecb
--- /dev/null
+++ b/src/app/grbl/touchscreen.fth
@@ -0,0 +1,35 @@
+-1 value ts-fid
+: open-touchscreen ( -- )
+ ts-fid 0< if
+ " /dev/input/touchscreen" h-open-file to ts-fid
+ ts-fid non-blocking
+ then
+;
+\ This is a struct input_event, consisting of
+\ struct timeval time (which is two C longs - or two Forth cells)
+\ __u16 type (Forth /w)
+\ __u16 code (Forth /w)
+\ __s32 value (Forth /l)
+2 /n* 2 /w* + /l + constant /input-event
+/input-event buffer: the-event
+: input-event-data ( -- adr ) the-event 2 na+ ; \ Skips timeval
+
+: ts-event? ( -- any? )
+ the-event /input-event ts-fid h-read-file ( actual )
+ /input-event =
+;
+1 constant ev-key
+3 constant ev-abs
+$14a constant btn-touch
+: event-type ( -- n ) input-event-data w@ ;
+: event-code ( -- n ) input-event-data wa1+ w@ ;
+: event-value ( -- n ) input-event-data 2 wa+ l@ ;
+
+: .events ( -- )
+ begin
+ ts-event? if
+ event-type . event-code . event-value . cr
+ then
+ key? until
+ key drop
+;