-
Notifications
You must be signed in to change notification settings - Fork 58
Add wait for conversion #12
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
Conversation
self.buf[1] = (value >> 8) & 0xFF | ||
self.buf[2] = value & 0xFF | ||
with self.i2c_device as i2c: | ||
i2c.write(self.buf) |
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.
Any reason for not using Adafruit_CircuitPython_Register?
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.
Just haven't used it yet. I'll take a look.
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.
Deferring this to a future PR.
adafruit_ads1x15/adafruit_ads1x15.py
Outdated
self._write_register(ADS1X15_POINTER_CONFIG, config) | ||
# Wait for conversion to complete | ||
while not self._conversion_complete(): | ||
pass |
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.
wouldn't be better to have time.sleep() instead of pass?
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.
What's the reason? Easy enough to do, just curious what the trade off is.
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 suppose it's a good practice from regular Python, where you want to give the control back to the operating system and other applications, instead of running it at 100%.
Perhaps it will also make a difference for SAMD at some point, when we get to the power management options.
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.
Gotcha. I figured pass
took care of that. So is just a zero sleep good enough?
time.sleep(0)
adafruit_ads1x15/adafruit_ads1x15.py
Outdated
i2c.write(self.buf, end=1, stop=False) | ||
i2c.readinto(self.buf, start=1) | ||
# LSB MSB | ||
return self.buf[2], self.buf[1] |
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.
This function is only used in one place, does it really make sense to have it?
Also, where it is used, we don't use the first byte of the result, does it really make sense to create a new tuple every time, especially since we do it in a tight loop?
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.
Yah, I was wondering about the tuple also. Basically it's just left over from first version of code. I was thinking of changing to just passing back an int. I'll take a look, I'm not sure why I can't just go ahead and do that.
I think having the function makes sense for any future expansion of functionality - it'll be the generic register read for whatever.
Updating https://github.com/adafruit/Adafruit_CircuitPython_ADS1x15 to 0.4.0 from 0.3.1: > Merge pull request adafruit/Adafruit_CircuitPython_ADS1x15#12 from caternuson/wait_for_conversion Updating https://github.com/adafruit/Adafruit_CircuitPython_Crickit to 2.0.2 from 2.0.1: > evaluate reversed immediately; otherwise get not hashable error > correct DRIVE order for steppers; improve stepper names
This adds a wait for conversion polling loop to fix #11
However, also refactored a lot of the boiler plate register read / write code into private funcs.