rocket_launcher 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/rl +4 -4
- data/ext/extconf.rb +0 -2
- data/ext/usb.c +3 -2
- data/lib/rocket_launcher/rocket_launcher.rb +15 -12
- data/lib/rocket_launcher/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c97bf626bf96f4a7faad7b80ea5e3b46a608cd74
|
4
|
+
data.tar.gz: 4c3d82b3f5a7ec58a3b914d4e7c9568ff680adf6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c7bd5eab27a279a95026fc5d63d864da474d51eb6310a12851ce96acb976e6d72f8d6cc1f3e8a6976160b5a2458a1a8b931db93c1abab896f9aab5c6c592d84
|
7
|
+
data.tar.gz: 5f04b8c069941e71d1d2eb7c6cf50a3ae73d28ee40fa297699071fd1bc3cb3a6623269d6db6f8c652630559cdf40f15e7e6fcdbab8b57ce8468bec14262b3897
|
data/bin/rl
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
3
|
+
$LOAD_PATH << 'lib' << 'ext'
|
4
4
|
|
5
5
|
require 'readline'
|
6
6
|
require 'etc'
|
@@ -14,11 +14,11 @@ parser = OptionParser.new do |opts|
|
|
14
14
|
opts.separator 'Controls an USB rocket launcher device.'
|
15
15
|
opts.separator 'Valid commands are:' #{RocketLauncher::ACTIONS.keys.join(', ')}."
|
16
16
|
|
17
|
-
opts.separator ' down : moves the turret down. Accept a time param. (
|
17
|
+
opts.separator ' down : moves the turret down. Accept a time param in seconds. (down 0.5)'
|
18
18
|
opts.separator ' up : moves the turret up. Accept a time param. (up 0.5)'
|
19
19
|
opts.separator ' left : turns the turret to the left. Accept a time param. (left 3)'
|
20
20
|
opts.separator ' right : turns the turret to the right. Accept a time param. (right 3)'
|
21
|
-
opts.separator ' fire : shots a missile.
|
21
|
+
opts.separator ' fire : shots a missile. (fire)'
|
22
22
|
opts.separator ' stop : interrupt current action. (stop)'
|
23
23
|
opts.separator ' park : moves the turret to the start position. (park)'
|
24
24
|
opts.separator ''
|
@@ -98,4 +98,4 @@ elsif options[:c]
|
|
98
98
|
rl.close
|
99
99
|
else
|
100
100
|
puts parser.help; exit
|
101
|
-
end
|
101
|
+
end
|
data/ext/extconf.rb
CHANGED
@@ -6,14 +6,12 @@ require 'mkmf'
|
|
6
6
|
|
7
7
|
INCLUDE_DIRS = [
|
8
8
|
RbConfig::CONFIG['includedir'],
|
9
|
-
'/opt/local/include',
|
10
9
|
'/usr/local/include',
|
11
10
|
'/usr/include'
|
12
11
|
]
|
13
12
|
|
14
13
|
LIB_DIRS = [
|
15
14
|
RbConfig::CONFIG['libdir'],
|
16
|
-
'/opt/local/lib',
|
17
15
|
'/usr/local/lib',
|
18
16
|
'/usr/lib'
|
19
17
|
]
|
data/ext/usb.c
CHANGED
@@ -56,10 +56,11 @@ rl_close_device (VALUE self)
|
|
56
56
|
}
|
57
57
|
|
58
58
|
VALUE
|
59
|
-
rl_write (VALUE self, VALUE cmd)
|
59
|
+
rl_write (VALUE self, VALUE cmd, VALUE mode)
|
60
60
|
{
|
61
61
|
USB *usb;
|
62
62
|
Data_Get_Struct (self, USB, usb);
|
63
|
+
DATA[0] = mode == Qtrue ? 0x03 : 0x02;
|
63
64
|
DATA[1] = NUM2CHR (cmd);
|
64
65
|
if (libusb_control_transfer (usb->handler, 0x21, 0x9, 0, 0, DATA, 8, 0) != 8)
|
65
66
|
rb_raise (error, "Write error");
|
@@ -74,5 +75,5 @@ Init_usb ()
|
|
74
75
|
rb_define_alloc_func (usb, rl_usb_alloc);
|
75
76
|
rb_define_method (usb, "open", rl_open_device, 2);
|
76
77
|
rb_define_method (usb, "close", rl_close_device, 0);
|
77
|
-
rb_define_method (usb, "write", rl_write,
|
78
|
+
rb_define_method (usb, "write", rl_write, 2);
|
78
79
|
}
|
@@ -10,7 +10,7 @@ class RocketLauncher
|
|
10
10
|
:park => 0x00
|
11
11
|
}
|
12
12
|
|
13
|
-
def initialize(vendor_id =
|
13
|
+
def initialize(vendor_id = 0x2123, product_id = 0x1010)
|
14
14
|
@usb = USB.new
|
15
15
|
@usb.open(vendor_id, product_id)
|
16
16
|
end
|
@@ -20,32 +20,35 @@ class RocketLauncher
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def stop
|
23
|
-
@usb.write(ACTIONS[:stop])
|
23
|
+
@usb.write(ACTIONS[:stop], false)
|
24
24
|
end
|
25
25
|
|
26
|
-
def fire
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
end
|
26
|
+
def fire
|
27
|
+
light(true)
|
28
|
+
@usb.write(ACTIONS[:fire], false)
|
29
|
+
sleep 3.5
|
30
|
+
@usb.write(ACTIONS[:stop], false)
|
31
|
+
light(false)
|
33
32
|
end
|
34
33
|
|
35
34
|
[:down, :up, :left, :right].each do |dir|
|
36
35
|
define_method dir do |time = 0.1|
|
37
|
-
@usb.write(ACTIONS[dir])
|
36
|
+
@usb.write(ACTIONS[dir], false)
|
38
37
|
sleep time
|
39
38
|
stop
|
40
39
|
end
|
41
40
|
end
|
42
41
|
|
43
42
|
def park
|
44
|
-
@usb.write(ACTIONS[:down])
|
43
|
+
@usb.write(ACTIONS[:down], false)
|
45
44
|
sleep 1
|
46
|
-
@usb.write(ACTIONS[:left])
|
45
|
+
@usb.write(ACTIONS[:left], false)
|
47
46
|
sleep 6
|
48
47
|
stop
|
49
48
|
end
|
50
49
|
|
50
|
+
def light(status)
|
51
|
+
@usb.write(status ? 0x01 : 0x00, true)
|
52
|
+
end
|
53
|
+
|
51
54
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rocket_launcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Enrico Pilotto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A Ruby library to control your USB Rocket Launcher device.
|
14
14
|
email:
|
@@ -52,7 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
52
52
|
requirements:
|
53
53
|
- 'libusb1.0 - Debian package name: libusb-1.0-0-dev - Mac port package name: libusb-devel'
|
54
54
|
rubyforge_project: rocket_launcher
|
55
|
-
rubygems_version: 2.
|
55
|
+
rubygems_version: 2.6.13
|
56
56
|
signing_key:
|
57
57
|
specification_version: 4
|
58
58
|
summary: A Ruby library to control your USB Rocket Launcher device
|