Skip to content

Commit

Permalink
Add cleanup pin calling on disconnect
Browse files Browse the repository at this point in the history
Bump version to v0.2.1
  • Loading branch information
sergio1990 committed Jul 18, 2022
1 parent 19cb156 commit d015c08
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
stepper_rpi (0.1.0)
stepper_rpi (0.2.1)

GEM
remote: https://rubygems.org/
Expand All @@ -12,6 +12,7 @@ GEM

PLATFORMS
x86_64-darwin-20
x86_64-linux

DEPENDENCIES
minitest (~> 5.0)
Expand Down
14 changes: 9 additions & 5 deletions examples/simple.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# https://github.com/theovidal/raspi-gpio-rb
# https://github.com/sergio1990/raspi-gpio-rb
require 'raspi-gpio'

$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
Expand All @@ -10,18 +10,22 @@ def initialize
end

def setup_pin(pin)
gpio_pin = GPIO.new(pin, OUT)
gpio_pin = GPIO.new(pin, GPIO::OUT)
# Give some time for the system to create needed files
# and set proper permissions
sleep(0.5)
gpio_pin.set_mode(OUT)
gpio_pin.mode = GPIO::OUT
@pins[pin] = gpio_pin
end

def cleanup_pin(pin)
@pins[pin].cleanup
end

def set_pin_value(pin, value)
gpio_pin = @pins[pin]
gpio_value = value == 1 ? HIGH : LOW
gpio_pin.set_value(gpio_value)
gpio_value = value == 1 ? GPIO::HIGH : GPIO::LOW
gpio_pin.value = gpio_value
end
end

Expand Down
1 change: 1 addition & 0 deletions lib/stepper_rpi/drivers/uln2003.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def connect
end

def disconnect
pins.each { gpio_adapter.cleanup_pin(_1) }
end

def step(dir:)
Expand Down
4 changes: 4 additions & 0 deletions lib/stepper_rpi/gpio_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ def setup_pin(pin)
raise NotImplementedError
end

def cleanup_pin(pin)
raise NotImplementedError
end

def set_pin_value(pin, value)
raise NotImplementedError
end
Expand Down
2 changes: 1 addition & 1 deletion lib/stepper_rpi/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module StepperRpi
VERSION = "0.2.0"
VERSION = "0.2.1"
end
6 changes: 6 additions & 0 deletions test/test_stepper_rpi_motor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,11 @@ def test_do_steps_successfully
assert motor.is_connected
refute motor.is_running
assert_equal 1, motor.position

driver.expects(:disconnect).once

motor.disconnect

refute motor.is_connected
end
end

0 comments on commit d015c08

Please sign in to comment.