-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Change gem structure #3
base: dev
Are you sure you want to change the base?
Conversation
…xtend the PiPiper::Driver class.
It seem's you pushed 3 hours before my comment on sysfs. |
No please continue. I wanted to see if we could get the driver in a test-able state (by stubbing the ffi call). I was able to do so but feel free to continue. I will work this branch around your code. A lot of what I implemented is sysfs code anyway. How about after merging #4, I will merge this one. Then we both can continue working in parallel. If not I can wait until you finish everything and then merge this branch. Does that sound reasonable to you? |
class << self | ||
def driver | ||
@driver ||= PiPiper::Bcm2835::Driver.new | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is a missunderstanding.
PiPiper.driver in my implementation is the only instance of any driver kind loaded at any moment.
I even though a moment to use the singleto module : http://ruby-doc.org/stdlib-1.9.3/libdoc/singleton/rdoc/Singleton.html
If we want to be able to have several drivers for several Object, we have to rethink the implementation. I don't think it is very useful, but we can discuss it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I thought we would do something like this in the user code:
require 'pi_piper'
require 'pi_piper-sysfs'
# or
require 'pi_piper-bcm2835'
PiPiper.driver = PiPiper::Sysfs.driver
# or
PiPiper.driver = PiPiper::Bcm2835.driver
# ... do stuff ...
And yes, only 1 driver would be loaded for PiPiper
at any given moment.
Is that what you meant, or something different?
And then later on if you do
PiPiper.driver = PiPiper::Sysfs.driver # => raise 'driver already loaded'
Or we could allow driver changes but that would complicate things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in PiPiper I wrote :
def driver=(klass)
if !klass.nil? && (klass <= PiPiper::Driver)
@driver.close if @driver
@driver = klass.new
else
raise ArgumentError, 'Supply a PiPiper::Driver subclass for driver'
end
end
It ensure the driver is properly closed before loading a new one. I thought it was enough, it free a bit of memory, and it lightened the at_exit
hook.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And as you only need one driver to be loaded my implementation allow to only write :
require 'pi_piper'
require 'pi_piper-bcm2835'
it load the code and load the driver with PiPiper.driver = PiPiper::Bcm2835
in the Bcm2835 module/class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see, I can certainly change my code so that it works like the above. It will load the driver when running require
.
@elmatou what are your thoughts on the new modules for |
I2C_REASON_ERROR_CLKT = 2 # Received Clock Stretch Timeout | ||
I2C_REASON_ERROR_DATA = 3 # Not all data is sent / received | ||
|
||
def setup_i2c |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll prefer the included(base)
hook for these kind of setup
BTW even without your workaround with attach_function I can have very good coverage (for now 270 / 289 LOC (93.43%))
Your module approach is a good idea, it parts code in meaningful segment. |
Yeah coverage was good before, I just wanted everything covered. I think I may rewrite the tests for the setup method. The other thing I wanted to do was to put the I am also a fan of leveraging OOP rather than procedural programming which is sort of how it was before. |
libbcm2835 are often used in different driver methods, anyhow I don't think it is a good practice to to do (dynamic assignement) with methods, it is prone to error. What you can do, and is often done when testing ffi based gems, is to stub the To be more pragmatic, do we really need to have travis-ci for this particular part of pi_piper ? (yes, there is pre travis-ci area and it was not dark ages !) |
@@ -0,0 +1,48 @@ | |||
require 'ffi' | |||
require 'pry' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not useful in production, could be added for dev
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
absolutely, it was just a placeholder since this PR was a work in progress.
Hi, |
@elmatou Hey, sure feel free. This is/was a work in progress anyway but if you want to take a crack at it go ahead. I will focus on getting out 3.0. |
🚧
Note to self: test this on the Pi first