-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathslip-key.fs
138 lines (113 loc) · 2.74 KB
/
slip-key.fs
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
$100 stringbuffer constant test-buf
\ $100 stringbuffer constant test-buf2
: debug test-buf stringbuf-byte-app ;
: debug~
$7E debug
dup debug
;
\ try to read another character
\ send 0x0D , wait 10 ms, maybe wait another configurable time and then call an error
: sys-key-timed-###
sys-key? not IF
\ $11 sys-emit
100 ms
sys-key? not IF
SLIP-timeout @ ms sys-key? not IF
SLIP-timeout-error
THEN THEN THEN
sys-key
;
: slip-key-timeout
sys-key? IF exit THEN
100 ms
sys-key? IF exit THEN
SLIP-timeout @ ms
sys-key? IF exit THEN
SLIP-timeout-error
;
: sys-key-timed
slip-key-timeout
sys-key
;
: SLIP-key-unescape ( char -- char )
dup SLIP_ESC = sys-key? and IF
sys-key-timed nip
THEN
;
: SLIP-key \ ( -- char )
sys-key
BEGIN
debug~
dup SLIP_END = IF
\ $23 emit
\ drop
SLIP-reading @ IF
\ finish slip reader
\ $2d emit
false SLIP-reading !
\ process SLIP message
SLIP-handler
ELSE
\ sart slip reader
\ $2b emit
true SLIP-reading !
THEN
\ false \ AGAIN
\ dup $0d = IF true ELSE false THEN
false
ELSE
SLIP-key-unescape
( key-unescaped -- )
SLIP-reading @ IF
\ $7C emit
dup SLIP-message stringbuf-byte-app
false \ AGAIN
ELSE
\ if not in slip mode and no special char, return char as 'key'
\ dup 0x0d = if false else true
true
THEN
THEN
( char flag - )
over $0d = IF
cr test-buf stringbuf-dump cr
THEN
\ dup IF
\ ELSE
\ nip sys-key-timed swap
\ THEN
over debug
\ hand over 0 as dummy to compiler and return in any case
not if drop 0 then
true
UNTIL
;
: Slip-key2
sys-key
SLIP-key-unescape
dup SLIP-message stringbuf-byte-app
dup $0D = IF SLIP-handler THEN
;
\ ' sys-key hook-key !
\ ' SLIP-key hook-key !
\ ESPL-sync memstr-counted slip-send
\ SLIP-message stringbuf-dump
\ test-buf stringbuf-dump
\ test-buf stringbuf-clear ok.
\ slip-message stringbuf-clear ok.
\ 5000 slip-timeout !
: run-test
." =========================== running test ================="
test-buf stringbuf-dump
test-buf stringbuf-clear
slip-message stringbuf-dump
slip-message stringbuf-clear
." ----------------------- start test -------------------------"
['] SLIP-key hook-key !
ESPL-sync memstr-counted slip-send
['] sys-key hook-key !
." ---------------------------finished test --------------------"
test-buf stringbuf-dump
slip-message stringbuf-dump
." =============================test finished =================="
;