blaster 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3912d3e8874c719fecb13268ec12815ecdca6acc
4
+ data.tar.gz: 209b109286dfc0480338854832497c662ee64b9b
5
+ SHA512:
6
+ metadata.gz: 5983eddad3f93c6f646a9d99eab6c213642a1ac84996d013c743045bb8ef9b6f6423e47763e5c4a06cde9290bb1f41159d264e797f2bb7f83b2a52950345f070
7
+ data.tar.gz: 7949bb0e05ab95f71259b81d094b6e897c54de0df811f23e3ff9ad5b9c0c48c3ae6ba5c173ddae2c277b5d226ecbc2eea1bdc00403eaa583b9a2e08c0198c60a
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in blaster.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Kaz Walker
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Blaster
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'blaster'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install blaster
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'blaster/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'blaster'
8
+ spec.version = Blaster::VERSION
9
+ spec.authors = ['Kaz Walker']
10
+ spec.email = ['kaz.walker@doopli.co']
11
+ spec.description = %q{A gem to control USB dart guns.}
12
+ spec.summary = %q{A gem to control USB dart guns.}
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.3'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_dependency 'libusb'
24
+ end
@@ -0,0 +1,13 @@
1
+ commands:
2
+ up = [0x02, 0x02]
3
+ down = [0x02, 0x03]
4
+ left = [0x02, 0x04]
5
+ right = [0x02, 0x08]
6
+ stop = [0x02, 0x20]
7
+
8
+ fire = [0x02, 0x10]
9
+
10
+ led_on = [0x03, 0x01]
11
+ led_off = [0x03, 0x00]
12
+
13
+ bmRequestType: 0x21, bRequest: 0x09, wValue: 0, wIndex: 0, dataOut: command.pack('CC')
@@ -0,0 +1,5 @@
1
+ require "blaster/version"
2
+
3
+ module Blaster
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,174 @@
1
+ require 'libusb'
2
+
3
+ module Blaster
4
+ class Thunder
5
+ LED_ON = [0x03, 0x01].pack('CC')
6
+ LED_OFF = [0x03, 0x00].pack('CC')
7
+
8
+ MOVE_UP = [0x02, 0x02].pack('CC')
9
+ MOVE_DOWN = [0x02, 0x03].pack('CC')
10
+ MOVE_LEFT = [0x02, 0x04].pack('CC')
11
+ MOVE_RIGHT = [0x02, 0x08].pack('CC')
12
+ STOP_MOVE = [0x02, 0x20].pack('CC')
13
+
14
+ FIRE = [0x02, 0x10].pack('CC')
15
+
16
+ attr_accessor :horizontal_degree_second, :vertical_degree_second,
17
+ :blink_duration, :blink_pause, :monitor_pause, :firing_pause
18
+
19
+ def initialize(do_blink = false, do_monitor = false, horizontal_move_rate = 5.5, vertical_move_rate = 0.5)
20
+ @usb_context = LIBUSB::Context.new
21
+ @device = @usb_context.devices(idVendor: 0x2123, idProduct: 0x1010).first
22
+ @handle = @device.open
23
+ @horizontal_degree_second = horizontal_move_rate / 270
24
+ @vertical_degree_second = vertical_move_rate / 55
25
+ blink_mode do_blink
26
+ monitor_mode do_monitor
27
+ end
28
+
29
+ def deactivate
30
+ stop_monitoring
31
+ stop_blinking
32
+ @handle = @handle.close
33
+ end
34
+
35
+ def send_raw(command)
36
+ return if command.nil? || !command.is_a?(String)
37
+ @handle.control_transfer bmRequestType: 0x21, bRequest: 0x09,
38
+ wValue: 0, wIndex: 0, dataOut: command
39
+ end
40
+
41
+ def move_then_stop(command, duration)
42
+ return if command.nil? || duration.nil? || !duration.is_a?(Numeric)
43
+ return if @firing
44
+ send_raw command
45
+ sleep duration
46
+ send_raw STOP_MOVE
47
+ end
48
+
49
+ def move_degrees(command, degrees)
50
+ if command == MOVE_LEFT || command == MOVE_RIGHT
51
+ move_then_stop command, degrees * @horizontal_degree_second
52
+ else
53
+ move_then_stop command, degrees * @vertical_degree_second
54
+ end
55
+ end
56
+
57
+ def fire!
58
+ @firing = true
59
+ @firing_pause ||= 5
60
+ send_raw FIRE
61
+ sleep @firing_pause
62
+ @firing = false
63
+ end
64
+
65
+ def blink(duration = 1)
66
+ return if @blink_loop
67
+ return if !duration.is_a?(Numeric)
68
+ send_raw LED_ON
69
+ sleep duration
70
+ send_raw LED_OFF
71
+ end
72
+
73
+ def led_on
74
+ send_raw LED_ON
75
+ end
76
+
77
+ def led_off
78
+ send_raw LED_OFF
79
+ end
80
+
81
+ def up(degrees = 10)
82
+ move_degrees MOVE_UP, degrees
83
+ end
84
+
85
+ def down(degrees = 10)
86
+ move_degrees MOVE_DOWN, degrees
87
+ end
88
+
89
+ def left(degrees = 10)
90
+ move_degrees MOVE_LEFT, degrees
91
+ end
92
+
93
+ def right(degrees = 10)
94
+ move_degrees MOVE_RIGHT, degrees
95
+ end
96
+
97
+ def stop
98
+ send_raw STOP_MOVE
99
+ end
100
+
101
+ def full_up
102
+ send_raw MOVE_UP
103
+ end
104
+
105
+ def full_down
106
+ send_raw MOVE_DOWN
107
+ end
108
+
109
+ def full_left
110
+ send_raw MOVE_LEFT
111
+ end
112
+
113
+ def full_right
114
+ send_raw MOVE_RIGHT
115
+ end
116
+
117
+ def blink_mode(do_blink)
118
+ if do_blink && !@blink_loop
119
+ @blink_loop = true
120
+ @blink_duration ||= 0.001
121
+ @blink_pause ||= 0.5
122
+ @blink_thread = Thread.new{ start_blinking() }
123
+ else
124
+ stop_blinking
125
+ end
126
+ end
127
+
128
+ def monitor_mode(do_monitor)
129
+ if do_monitor && !@monitor_loop
130
+ @monitor_loop = true
131
+ @monitor_pause ||= 10
132
+ @monitor_thread = Thread.new{ start_monitoring() }
133
+ else
134
+ stop_monitoring
135
+ end
136
+ end
137
+
138
+ private
139
+
140
+ def start_blinking
141
+ while @blink_loop
142
+ led_on
143
+ sleep @blink_duration
144
+ led_off
145
+ sleep @blink_pause
146
+ end
147
+ end
148
+
149
+ def stop_blinking
150
+ @blink_loop = false
151
+ @blink_thread.kill if !@blink_thread.nil? && @blink_thread.alive?
152
+ @blink_thread = nil
153
+ end
154
+
155
+ def start_monitoring
156
+ while @monitor_loop
157
+ full_right unless @firing
158
+ sleep @monitor_pause
159
+ full_down unless @firing
160
+ sleep 2
161
+ full_left unless @firing
162
+ sleep @monitor_pause
163
+ full_up unless @firing
164
+ sleep 2
165
+ end
166
+ end
167
+
168
+ def stop_monitoring
169
+ @monitor_loop = false
170
+ @monitor_thread.kill if !@monitor_thread.nil? && @monitor_thread.alive?
171
+ @monitor_thread = nil
172
+ end
173
+ end
174
+ end
@@ -0,0 +1,3 @@
1
+ module Blaster
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: blaster
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kaz Walker
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: libusb
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: A gem to control USB dart guns.
56
+ email:
57
+ - kaz.walker@doopli.co
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - blaster.gemspec
68
+ - command reference.txt
69
+ - lib/blaster.rb
70
+ - lib/blaster/thunder.rb
71
+ - lib/blaster/version.rb
72
+ homepage: ''
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.0.6
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: A gem to control USB dart guns.
96
+ test_files: []
97
+ has_rdoc: