-
Notifications
You must be signed in to change notification settings - Fork 9
first working commit with the feature set of the Arduino driver #1
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
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.
Looks good. Review suggestions are essentially cosmetic.
adafruit_max31856.py
Outdated
"""Driver for the MAX31856 Universal Thermocouple Amplifier | ||
|
||
:param ~busio.I2C i2c_bus: The I2C bus the DS3231 is connected to. | ||
:param int address: The I2C address of the device. |
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.
Change to match SPI.
adafruit_max31856.py
Outdated
|
||
float_low, float_high = val | ||
int_low = int(float_low * 16) | ||
int_high = int(float_high * 16) |
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 could be compacted a bit. Maybe instead of tuple unpacking, just grab them via index.
int_low = int(val[0] * 16)
int_high = int(val[1] * 16)
adafruit_max31856.py
Outdated
|
||
# # assert on any fault | ||
self._write_u8(_MAX31856_MASK_REG, 0x0) | ||
# turn off open circuit faults? |
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.
Why? This is worth checking for.
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.
After reading the datasheet again (and testing) this in fact turns on open circuit fault detection. Derp. I'll fix the comment.
adafruit_max31856.py
Outdated
|
||
self._write_u8(_MAX31856_CJLF_REG, int_low) | ||
self._write_u8(_MAX31856_CJHF_REG, int_high) | ||
|
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.
No need for any variables here. This entire function could become these two lines:
self._write_u8(_MAX31856_CJLF_REG, int(val[0]))
self._write_u8(_MAX31856_CJHF_REG, int(val[1]))
adafruit_max31856.py
Outdated
low = float( self._read_u8(_MAX31856_CJLF_REG)) | ||
high = float(self._read_u8(_MAX31856_CJHF_REG)) | ||
return (low, high) | ||
|
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.
Again here. Variables aren't used. So coud just:
return float(self._read_u8(_MAX31856_CJLF_REG)), float(self._read_u8(_MAX31856_CJHF_REG))
adafruit_max31856.py
Outdated
|
||
|
||
# these were shamelessly stolen from Tony's MAX31865 driver. | ||
# I want to re-factor them to be more similar to the Arduino driver |
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.
Why? They look OK.
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.
The Arduino code is a bit DRY-er, using a shared variable length read function from the set length read functions. Not the end of the world, just cleaner (and ever so slightly smaller I would presume)
docs/conf.py
Outdated
# Uncomment the below if you use native CircuitPython modules such as | ||
# digitalio, micropython and busio. List the modules you use. Without it, the | ||
# autodoc module docs will fail to generate with a warning. | ||
# autodoc_mock_imports = ["digitalio", "busio"] |
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.
You'd discovered this when Travis ran. You'll need to uncomment and add the modules.
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.
As long as you have requirements.txt
appropriately populated, you should not need to automock anything.
examples/max31856_simpletest.py
Outdated
@@ -0,0 +1,17 @@ | |||
import adafruit_max31856 |
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.
move this import to last
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.
There are files missing from this repo. @caternuson and I are looking into why, the same thing happened in a PR to another repo. The dotfiles are missing - .travis.yml
, .readthedocs.yml
and .gitignore
. Once we've sorted the problem, we'll need another commit with the correct files.
@kattni The missing dotfiles are my mistake; I copied the cookiecutter files into this repo from a different directory and omitted them because I forgot the What is the proper proceedure to add the new commit(s)? I can leave it as separate or squash it. |
Simply commit and push to this PR. We don't mind having a lot of commits on a PR as long as they're part of it. If you really wanted to, you can squash locally, but we seriously don't mind. I've done plenty with a ton of little commits to fix things I missed. |
Specifically a PR tracks a branch. So, you can change the branch however you like and the PR will follow 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.
Thank you for the new driver! One comment about the property documentation.
adafruit_max31856.py
Outdated
|
||
@temperature_thresholds.setter | ||
def temperature_thresholds(self, val): | ||
"""Set the thermocouple's low and high temperature thresholds as a tuple: `thermocouple.temperature_threshold = (low_threshold, high_threshold)`.""" |
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.
You only need the getter documented for ReadTheDocs. The property comments should read like its a variable and not a function (So no "Read" or "Set" to begin with.)
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 specifically documented the setter like this as it wasn't obvious to me that you would be able to assign it a tuple. Perhaps because the getter returns a tuple it should be obvious? Any specific recommendations would be welcome.
I take your second comment to mean the getter documentation should be:
The thermocouple's low and high temperature thresholds as a
(low_temp, high_temp)
tuple
Now that I write that it does seem to imply that you would set it with a tuple as well..
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.
Yup, exactly. You can document the type of the "variable"
I just pushed a rebased version that should address all the comments/suggestions. Let me know if I missed anything. |
054e77c
to
4229b12
Compare
adafruit_max31856.py
Outdated
sleep(0.250) # MEME FIX autocalculate based on oversampling | ||
|
||
# these were shamelessly stolen from Tony's MAX31865 driver. | ||
# I want to re-factor them to be more similar to the Arduino driver |
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.
Remove these "note to self" comments. This follow up is best done by creating an issue.
f39e48e
to
b21c8a2
Compare
adafruit_max31856.py
Outdated
low = round(((low_temp_high_byte << 8) | low_temp_low_byte)/16, 1) | ||
high = round(((high_temp_high_byte << 8) | high_temp_low_byte)/16, 1) | ||
|
||
return (low, high) |
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 is due to the same thing you were dealing with for temperatures.
>>> tc.temperature_thresholds = (20, -20)
>>> tc.temperature_thresholds
(20.0, 4076.0)
You may have to do some extra work in both the getter and setter methods to deal with this.
adafruit_max31856.py
Outdated
as a ``(low_temp, high_temp)`` tuple | ||
""" | ||
return (float(self._read_u8(_MAX31856_CJLF_REG)), | ||
float(self._read_u8(_MAX31856_CJHF_REG))) |
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.
Same comment as for temperature_thresholds
.
>>> tc.reference_temperature_thresholds = (20, -20)
>>> tc.reference_temperature_thresholds
(20.0, 236.0)
>>>
Travis is kicking on a few pylint things. Fix those and I think I'm good. @tannewt - how about you? Adafruit CircuitPython 3.0.2 on 2018-09-14; Adafruit Feather M4 Express with samd51j19
>>> import max_test as test
>>> tc = test.tc
>>> tc.temperature
23.7109
>>> tc.temperature
-1.23438
>>> tc.temperature_thresholds
(-2048.0, 2047.9)
>>> tc.temperature_thresholds = (-20, 50)
>>> tc.temperature_thresholds
(-20.0, 50.0)
>>> tc.fault
{'voltage': False, 'tc_low': False, 'tc_range': False, 'tc_high': False, 'cj_range': False, 'cj_high': False, 'open_tc': False, 'cj_low': False}
>>> |
Looks good to me! Thank you! |
Fixes adafruit/circuitpython#1200