rocket_launcher 0.0.2 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 2f5329b904dac9417e7d967a6698d4c27f89c71d
4
- data.tar.gz: bac90e02abc8fb0d3ef4ce19839010816b214718
2
+ SHA256:
3
+ metadata.gz: 01a8d4a7e61bd31ce90a7bfb6c2028ea39f6cb2fb872b6b0ba59b405cc36ba89
4
+ data.tar.gz: 16ffa8bfbc2a6327640c8248f9756c4bc82e0974878dbd7e993162c494b182ab
5
5
  SHA512:
6
- metadata.gz: a5435a3bba6ca65e8e801f81ac6ddd880fdc36cd7147b34bd71f77110aa3e77c820934607efd34ee8dd90dcd0c49eafe918a93aab758888b4d18a95d64bd8e38
7
- data.tar.gz: 66b77c7e11db0d9441a0e8e45dddee90faa1bba6e117eecd0f7405e63b7d59d8623654bb53510f1933c3a512ba6a7e52abd875fb7bf0c4fd6e4438af9755004d
6
+ metadata.gz: 7a94deb37f5df1f146d695dbfd00657653bb8df0c1c4fb8cfdcfd01f463715305be7ac4642b8a6f6fd955eb1ebc61da7075db0c290b2f9a52d4dec90f79cb067
7
+ data.tar.gz: d79c261b3cf9cd2eec84dc106d16a206521f4ad092aa4d650c4d9b6d6e44c000c514c97f2fad90151086394a50ab28c648bbc89637fb4490814cdb8628aabdb1
data/bin/rl CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- #$LOAD_PATH << 'lib' << 'ext'
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. (donw 0.5)'
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. Accept the number of missile to shot. (fire 2)'
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,27 +6,22 @@ require 'mkmf'
6
6
 
7
7
  INCLUDE_DIRS = [
8
8
  RbConfig::CONFIG['includedir'],
9
- '/opt/local/include',
10
9
  '/usr/local/include',
11
- '/usr/include'
10
+ '/usr/include',
11
+ '/opt/homebrew/include'
12
12
  ]
13
13
 
14
14
  LIB_DIRS = [
15
15
  RbConfig::CONFIG['libdir'],
16
- '/opt/local/lib',
17
16
  '/usr/local/lib',
18
- '/usr/lib'
17
+ '/usr/lib',
18
+ '/opt/homebrew/lib'
19
19
  ]
20
20
 
21
21
  dir_config('rocket_launcher', INCLUDE_DIRS, LIB_DIRS)
22
22
 
23
- unless find_header('libusb-1.0/libusb.h')
24
- abort 'libusb-1.0 is missing.'
25
- end
26
-
27
- unless find_library('usb-1.0', 'libusb_init')
28
- abort 'libusb-1.0 is missing.'
29
- end
23
+ abort 'libusb-1.0 is missing' unless find_header('libusb-1.0/libusb.h')
24
+ abort 'libusb-1.0 is missing' unless find_library('usb-1.0', 'libusb_init')
30
25
 
31
26
  create_makefile('usb/usb')
32
27
 
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, 1);
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 = 8483, product_id = 4112)
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(missiles = 1)
27
- missiles = 4 if missiles > 4
28
- missiles.to_i.times do
29
- @usb.write(ACTIONS[:fire])
30
- sleep 4
31
- stop
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
@@ -1,3 +1,3 @@
1
1
  class RocketLauncher
2
- VERSION = '0.0.2'
2
+ VERSION = '0.1.1'.freeze
3
3
  end
@@ -20,4 +20,6 @@ Gem::Specification.new do |s|
20
20
  s.extensions = ['ext/extconf.rb']
21
21
 
22
22
  s.requirements = ['libusb1.0 - Debian package name: libusb-1.0-0-dev - Mac port package name: libusb-devel']
23
+
24
+ s.add_development_dependency 'rake', '~> 13'
23
25
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rocket_launcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Enrico Pilotto
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-27 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2023-02-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '13'
13
27
  description: A Ruby library to control your USB Rocket Launcher device.
14
28
  email:
15
29
  - enrico@megiston.it
@@ -34,7 +48,7 @@ files:
34
48
  homepage: ''
35
49
  licenses: []
36
50
  metadata: {}
37
- post_install_message:
51
+ post_install_message:
38
52
  rdoc_options: []
39
53
  require_paths:
40
54
  - lib
@@ -51,9 +65,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
65
  version: '0'
52
66
  requirements:
53
67
  - 'libusb1.0 - Debian package name: libusb-1.0-0-dev - Mac port package name: libusb-devel'
54
- rubyforge_project: rocket_launcher
55
- rubygems_version: 2.4.5
56
- signing_key:
68
+ rubygems_version: 3.3.26
69
+ signing_key:
57
70
  specification_version: 4
58
71
  summary: A Ruby library to control your USB Rocket Launcher device
59
72
  test_files: []