-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.rb
More file actions
57 lines (50 loc) · 1.22 KB
/
controller.rb
File metadata and controls
57 lines (50 loc) · 1.22 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
require 'rubygems'
require 'termios'
require 'timeout'
def with_unbuffered_input
old_attrs = Termios.tcgetattr(STDOUT)
new_attrs = old_attrs.dup
new_attrs.lflag &= ~Termios::ECHO
new_attrs.lflag &= ~Termios::ICANON
Termios::tcsetattr(STDOUT, Termios::TCSANOW, new_attrs)
yield
ensure
Termios::tcsetattr(STDOUT, Termios::TCSANOW, old_attrs)
end
ip = "192.168.1.41"
with_unbuffered_input do
while true do
c = nil
stopped = false
begin
status = Timeout::timeout(0.250) {
c = STDIN.getc
}
rescue Timeout::Error
puts "Timeout"
end
if c == "w"
`echo "UP" | ncat #{ip} 8888 -u --send-only`
puts "Up command sent"
stop = false
elsif c == "s"
`echo "DOWN" | ncat #{ip} 8888 -u --send-only`
puts "Down command sent"
stop = false
elsif c == "a"
`echo "LEFT" | ncat #{ip} 8888 -u --send-only`
puts "Left command sent"
stop = false
elsif c == "d"
`echo "RIGHT" | ncat #{ip} 8888 -u --send-only`
puts "Right command sent"
stop = false
elsif c == nil
if !stop
`echo "STOP" | ncat #{ip} 8888 -u --send-only`
puts "Stop command sent"
stop = true
end
end
end
end