-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller_start.rb
85 lines (78 loc) · 2.83 KB
/
controller_start.rb
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
# This stuff uses artoo.io to connect to a USB PS3 controller
# And grab button events to send as commands.
# It's also really cool.
require 'artoo'
require 'net/http'
http = Net::HTTP
uri = URI('http://hbar.kapsi.fi/ccserver/mote/put/')
id = http.get('hbar.kapsi.fi','/ccserver/mote/newID/')
puts "Your session ID is: " + id
puts "Connect using \"moteplus <id>\" on your CC Turtle"
connection :joystick, :adaptor => :joystick
device :joystick, :driver => :ps3, :connection => :joystick, :interval => 0.1
work do
on joystick, :button_triangle => proc { |*value|
res = http.post_form(uri, 'sessionId' => id, 'command' => 'up')
puts 'triangle'
}
on joystick, :button_square => proc { |*value|
res = http.post_form(uri, 'sessionId' => id, 'command' => 'suck')
puts 'square'
}
on joystick, :button_circle => proc { |*value|
res = http.post_form(uri, 'sessionId' => id, 'command' => 'drop')
puts 'circle'
}
on joystick, :button_x => proc { |*value|
res = http.post_form(uri, 'sessionId' => id, 'command' => 'down')
puts 'ex'
}
on joystick, :joystick => proc { |caller, value|
if value[:s] == 0 then
if value[:x] > 25000 then
res = http.post_form(uri, 'sessionId' => id, 'command' => 'place')
puts 'left stick right'
elsif value[:x] < -25000 then
puts 'left stick left'
elsif value[:y] > 25000 then
res = http.post_form(uri, 'sessionId' => id, 'command' => 'placeDown')
puts 'left stick down'
elsif value[:y] < -25000 then
res = http.post_form(uri, 'sessionId' => id, 'command' => 'placeUp')
puts 'left stick up'
end
elsif value[:s] == 1 then
if value[:x] > 25000 then
res = http.post_form(uri, 'sessionId' => id, 'command' => 'dig')
puts 'right stick right'
elsif value[:x] < -25000 then
puts 'right stick left'
elsif value[:y] > 25000 then
res = http.post_form(uri, 'sessionId' => id, 'command' => 'digDown')
puts 'right stick down'
elsif value[:y] < -25000 then
res = http.post_form(uri, 'sessionId' => id, 'command' => 'digUp')
puts 'right stick up'
end
end
}
on joystick, :button => proc { |*value|
if value[1] == 4 then
res = http.post_form(uri, 'sessionId' => id, 'command' => 'forward')
puts 'dpad up'
elsif value[1] == 6 then
res = http.post_form(uri, 'sessionId' => id, 'command' => 'back')
puts 'dpad down'
elsif value[1] == 7 then
res = http.post_form(uri, 'sessionId' => id, 'command' => 'left')
puts 'dpad left'
elsif value[1] == 5 then
res = http.post_form(uri, 'sessionId' => id, 'command' => 'right')
puts 'dpad right'
end
}
on joystick, :button_r1 => proc { |*value|
res = http.post_form(uri, 'sessionId' => id, 'command' => 'rs')
puts 'button r1'
}
end