-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
75 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,39 @@ | ||
module Thermostat::HardwareController::RaspberryPi | ||
module DelegatableMethods | ||
def delegatable_methods | ||
[ :clean_up, :rpi_gpio_loaded?, :setup, :set_high, :set_low, :set_numbering, :set_warnings ] | ||
end | ||
end | ||
|
||
begin | ||
require 'rpi_gpio' | ||
GPIO = RPi::GPIO | ||
GPIO = ::RPi::GPIO | ||
GPIO.set_warnings false | ||
module ::RPi::GPIO | ||
extend DelegatableMethods | ||
extend self | ||
def rpi_gpio_loaded?; true; end | ||
end | ||
|
||
rescue RuntimeError => e | ||
if( e.message =~ /this gem can only be run on a Raspberry Pi/ ) | ||
|
||
Thermostat.logger.warn(self.class.name) { "Couldn't load rpi_gpio library (#{e}) - using dummy GPIO" } | ||
|
||
module GPIO | ||
def self.clean_up(*); end | ||
def self.set_numbering(*); end | ||
def self.set_warnings(*); end | ||
extend DelegatableMethods | ||
extend self | ||
|
||
delegatable_methods.each do |m| | ||
define_method(m) { |*| } | ||
end | ||
|
||
def rpi_gpio_loaded?; false; end | ||
|
||
end | ||
else | ||
raise e | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
spec/cases/thermostat/hardware_controller/raspberry_pi/gpio_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
describe Thermostat::HardwareController::RaspberryPi::GPIO do | ||
|
||
let(:subject) { described_class } | ||
|
||
described_class.delegatable_methods.each do |m| | ||
it "has a #{m} method" do | ||
expect(subject).to respond_to(m) | ||
end | ||
end | ||
|
||
context 'testing if the real library was loaded' do | ||
let(:result) { subject.rpi_gpio_loaded? ? :be_truthy : :be_falsey } | ||
it "if the library #{described_class.rpi_gpio_loaded? ? "was" : "wasn't"} loaded, #rpi_gpio_loaded? should #{described_class.rpi_gpio_loaded? ? :be_truthy : :be_falsey}" do | ||
expect(subject.rpi_gpio_loaded?).to send(result) | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters