Skip to content

Commit

Permalink
Upgrade all dependencies to their latest versions, fix Rubocop lints.
Browse files Browse the repository at this point in the history
This brings lego-next into the 2018 with upgrade dependencies all
around, fixed lints for Rubocop, and confirmed compatibility with Ruby
2.5+.
  • Loading branch information
nathankleyn committed Sep 19, 2018
1 parent da99264 commit 9b65c53
Show file tree
Hide file tree
Showing 35 changed files with 405 additions and 293 deletions.
9 changes: 9 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
LineLength:
Max: 120

MethodLength:
Max: 100

Metrics/BlockLength:
Exclude:
- spec/**/*.rb
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
script: "bundle exec rspec"
rvm:
- 1.9.3
- 2.0.0
- 2.5.1
152 changes: 96 additions & 56 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,69 +2,109 @@ PATH
remote: .
specs:
lego-nxt (0.2.0)
activesupport (~> 3.2.13)
libusb (~> 0.3.4)
serialport (~> 1.1.0)
activesupport (~> 5.2.1)
libusb (~> 0.6.4)
serialport (~> 1.3.1)

GEM
remote: https://rubygems.org/
specs:
activesupport (3.2.13)
i18n (= 0.6.1)
multi_json (~> 1.0)
coderay (1.0.9)
colorize (0.5.8)
coveralls (0.6.7)
colorize
multi_json (~> 1.3)
rest-client
simplecov (>= 0.7)
thor
diff-lcs (1.2.4)
ffi (1.8.1)
i18n (0.6.1)
iobuffer (1.1.2)
libusb (0.3.4)
ffi (>= 1.0)
method_source (0.8.1)
mime-types (1.23)
multi_json (1.7.4)
pry (0.9.12.2)
coderay (~> 1.0.5)
method_source (~> 0.8)
slop (~> 3.4)
redcarpet (2.3.0)
rest-client (1.6.7)
mime-types (>= 1.16)
rev (0.3.2)
iobuffer (>= 0.1.3)
rspec (2.13.0)
rspec-core (~> 2.13.0)
rspec-expectations (~> 2.13.0)
rspec-mocks (~> 2.13.0)
rspec-core (2.13.1)
rspec-expectations (2.13.0)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.13.1)
serialport (1.1.0)
simplecov (0.7.1)
multi_json (~> 1.0)
simplecov-html (~> 0.7.1)
simplecov-html (0.7.1)
slop (3.4.5)
thor (0.18.1)
watchr (0.7)
yard (0.8.6.1)
activesupport (5.2.1)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
ast (2.4.0)
byebug (10.0.2)
coderay (1.1.2)
concurrent-ruby (1.0.5)
coveralls (0.8.22)
json (>= 1.8, < 3)
simplecov (~> 0.16.1)
term-ansicolor (~> 1.3)
thor (~> 0.19.4)
tins (~> 1.6)
diff-lcs (1.3)
docile (1.3.1)
ffi (1.9.25)
filewatcher (1.0.1)
trollop (~> 2.1, >= 2.1.2)
i18n (1.1.0)
concurrent-ruby (~> 1.0)
jaro_winkler (1.5.1)
json (2.1.0)
libusb (0.6.4)
ffi (~> 1.0)
mini_portile2 (~> 2.1)
method_source (0.9.0)
mini_portile2 (2.3.0)
minitest (5.11.3)
parallel (1.12.1)
parser (2.5.1.2)
ast (~> 2.4.0)
powerpack (0.1.2)
pry (0.11.3)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
pry-byebug (3.6.0)
byebug (~> 10.0)
pry (~> 0.10)
rainbow (3.0.0)
redcarpet (3.4.0)
rspec (3.8.0)
rspec-core (~> 3.8.0)
rspec-expectations (~> 3.8.0)
rspec-mocks (~> 3.8.0)
rspec-core (3.8.0)
rspec-support (~> 3.8.0)
rspec-expectations (3.8.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-mocks (3.8.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.0)
rubocop (0.58.2)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.5, != 2.5.1.1)
powerpack (~> 0.1)
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
rubocop-rspec (1.29.0)
rubocop (>= 0.58.0)
ruby-progressbar (1.10.0)
serialport (1.3.1)
simplecov (0.16.1)
docile (~> 1.1)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.2)
term-ansicolor (1.6.0)
tins (~> 1.0)
thor (0.19.4)
thread_safe (0.3.6)
tins (1.16.3)
trollop (2.9.9)
tzinfo (1.2.5)
thread_safe (~> 0.1)
unicode-display_width (1.4.0)
yard (0.9.16)

PLATFORMS
ruby

DEPENDENCIES
coveralls (~> 0.6.7)
coveralls (~> 0.8.22)
filewatcher (~> 1.0.1)
lego-nxt!
pry (~> 0.9.12.2)
redcarpet (~> 2.3.0)
rev (~> 0.3.2)
rspec (~> 2.13.0)
watchr (~> 0.7.0)
yard (~> 0.8.6.1)
pry-byebug (~> 3.6.0)
redcarpet (~> 3.4.0)
rspec (~> 3.8.0)
rubocop (~> 0.58.2)
rubocop-rspec (~> 1.29.0)
yard (~> 0.9.16)

BUNDLED WITH
1.16.3
18 changes: 6 additions & 12 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,12 @@ desc 'NXT related tasks'
namespace :nxt do
desc 'Detect a connected NXT brick within /dev.'
task :detect do
unless $DEV ||= ENV['NXT'] || ENV['DEV']
begin
devices = Dir['/dev/*NXT*']
if devices.size > 0
$DEV = devices[0]
puts "Detected a NXT brick at '#{$DEV}'."
else
puts 'Could not detect any connected NXT bricks.'
end
rescue
# FIXME: The /dev directory isn't there, possibly running on Windows.
end
unless ENV['NXT'] || ENV['DEV']
raise "/dev not fount, please ensure you're using a *nix system." unless Dir.exist?('/dev')

devices = Dir['/dev/*NXT*']
raise 'Could not detect any connected NXT bricks.' if devices.empty?
puts "Detected a NXT brick at '#{devices.first}'."
end
end
end
5 changes: 3 additions & 2 deletions examples/serial_port/motor_rotation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
# Run the motor for 5 rotations instead.
nxt.front_motor.duration(5, type: :rotations).move

begin
loop do
puts 'Waiting...'
sleep 0.5
end while !nxt.front_motor.stopped?
break if nxt.front_motor.stopped?
end

puts 'I am like, done rotationing dude.'
end
2 changes: 1 addition & 1 deletion examples/serial_port/no_block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
# You should always make sure this gets called by putting it in an `ensure`
# block.
nxt.disconnect
end
end
5 changes: 3 additions & 2 deletions examples/usb/motor_rotation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
# Run the motor for 5 rotations instead.
nxt.front_motor.duration(5, type: :rotations).move

begin
loop do
puts 'Waiting...'
sleep 0.5
end while !nxt.front_motor.stopped?
break if nxt.front_motor.stopped?
end

puts 'I am like, done rotationing dude.'
end
2 changes: 1 addition & 1 deletion examples/usb/no_block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
# You should always make sure this gets called by putting it in an `ensure`
# block.
nxt.disconnect
end
end
45 changes: 23 additions & 22 deletions lego-nxt.gemspec
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
Gem::Specification.new do |spec|
spec.name = 'lego-nxt'
spec.version = '0.2.0'
spec.extra_rdoc_files = ['README.md']
spec.summary = 'Ruby LEGO Mindstorms NXT 2.0 control via Bluetooth and USB.'
spec.description = spec.summary + ' See http://github.com/nathankleyn/lego-nxt for more information.'
spec.license = 'MIT'
spec.author = 'Nathan Kleyn'
spec.email = 'nathan@nathankleyn.com'
spec.homepage = 'http://github.com/nathankleyn/lego-nxt'
spec.files = %w(README.md Rakefile) + Dir.glob('{lib,spec}/**/*')
spec.require_path = 'lib'
Gem::Specification.new do |gem|
gem.name = 'lego-nxt'
gem.version = '0.2.0'
gem.extra_rdoc_files = ['README.md']
gem.summary = 'Ruby LEGO Mindstorms NXT 2.0 control via Bluetooth and USB.'
gem.description = gem.summary + ' See http://github.com/nathankleyn/lego-nxt for more information.'
gem.license = 'MIT'
gem.author = 'Nathan Kleyn'
gem.email = 'nathan@nathankleyn.com'
gem.homepage = 'http://github.com/nathankleyn/lego-nxt'
gem.files = %w[README.md Rakefile] + Dir.glob('{lib,spec}/**/*')
gem.require_path = 'lib'

spec.add_dependency('activesupport', '~>3.2.13')
spec.add_dependency('libusb', '~>0.3.4')
spec.add_dependency('serialport', '~>1.1.0')
spec.add_development_dependency('coveralls', '~>0.6.7')
spec.add_development_dependency('redcarpet', '~>2.3.0')
spec.add_development_dependency('rev', '~>0.3.2')
spec.add_development_dependency('rspec', '~>2.13.0')
spec.add_development_dependency('pry', '~>0.9.12.2')
spec.add_development_dependency('watchr', '~>0.7.0')
spec.add_development_dependency('yard', '~>0.8.6.1')
gem.add_dependency 'activesupport', '~>5.2.1'
gem.add_dependency 'libusb', '~>0.6.4'
gem.add_dependency 'serialport', '~>1.3.1'
gem.add_development_dependency 'coveralls', '~> 0.8.22'
gem.add_development_dependency 'filewatcher', '~> 1.0.1'
gem.add_development_dependency 'pry-byebug', '~> 3.6.0'
gem.add_development_dependency 'redcarpet', '~> 3.4.0'
gem.add_development_dependency 'rspec', '~> 3.8.0'
gem.add_development_dependency 'rubocop', '~> 0.58.2'
gem.add_development_dependency 'rubocop-rspec', '~> 1.29.0'
gem.add_development_dependency 'yard', '~> 0.9.16'
end
6 changes: 3 additions & 3 deletions lib/lego-nxt.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$:.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.dirname(__FILE__))

require 'active_support/inflector'

Expand All @@ -24,11 +24,11 @@
require 'nxt/commands/sound'
require 'nxt/commands/tone'

require 'nxt/connectors/input/base'
require 'nxt/connectors/input/color'
require 'nxt/connectors/input/touch'
require 'nxt/connectors/input/ultrasonic'
require 'nxt/connectors/output/base'
require 'nxt/connectors/output/motor'

require 'nxt/nxt_brick'

require 'pry'
45 changes: 27 additions & 18 deletions lib/nxt/commands/base.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
module NXT
module Command
# The base implementation of all commands, providing low-level details that
# are consistent across all supported types. These are things such as:
#
# * Errors.
# * Sending and receiving of responses.
# * Addressing the port safely.
# * Command types.
module Base
private

Expand Down Expand Up @@ -40,33 +47,35 @@ module Base
'Bad arguments' => 0xFF
}.invert.freeze

def port_as_byte(port)
PORTS[port]
end

def send_and_receive(command_identifier, payload = [], response_required = true)
unless response_required
command_identifier |= 0x80
end
send(command_identifier, payload, response_required)
# We bail unless we need to wait for response.
return unless response_required
receive
end

def send(command_identifier, payload = [], response_required = true)
command_identifier |= 0x80 unless response_required

@interface.send([
command_type,
command_identifier,
port_as_byte(self.port)
port_as_byte(port)
] + payload)
end

if response_required
response = @interface.receive

puts response.inspect
puts command_identifier.inspect

raise 'Not a valid response package.' unless response[0] == 0x02
raise 'Not a valid response to the command that was sent.' unless response[1] == command_identifier
raise ERRORS[response[2]] unless response[2] == 0x00
def receive
response = @interface.receive

response[3..-1]
end
end
raise 'Not a valid response package.' unless response[0] == 0x02
raise 'Not a valid response to the command that was sent.' unless response[1] == command_identifier
raise ERRORS[response[2]] unless response[2].zero?

def port_as_byte(port)
PORTS[port]
response[3..-1]
end
end
end
Expand Down
Loading

0 comments on commit 9b65c53

Please sign in to comment.