Skip to content

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

Merged
merged 1 commit into from
Oct 15, 2018

Conversation

siddacious
Copy link
Contributor

Copy link
Contributor

@caternuson caternuson left a 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.

"""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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to match SPI.


float_low, float_high = val
int_low = int(float_low * 16)
int_high = int(float_high * 16)
Copy link
Contributor

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)


# # assert on any fault
self._write_u8(_MAX31856_MASK_REG, 0x0)
# turn off open circuit faults?
Copy link
Contributor

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.

Copy link
Contributor Author

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.


self._write_u8(_MAX31856_CJLF_REG, int_low)
self._write_u8(_MAX31856_CJHF_REG, int_high)

Copy link
Contributor

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]))

low = float( self._read_u8(_MAX31856_CJLF_REG))
high = float(self._read_u8(_MAX31856_CJHF_REG))
return (low, high)

Copy link
Contributor

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))



# these were shamelessly stolen from Tony's MAX31865 driver.
# I want to re-factor them to be more similar to the Arduino driver
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? They look OK.

Copy link
Contributor Author

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"]
Copy link
Contributor

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.

Copy link
Contributor

@kattni kattni Oct 2, 2018

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.

@@ -0,0 +1,17 @@
import adafruit_max31856
Copy link
Contributor

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

Copy link
Contributor

@kattni kattni left a 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.

@siddacious
Copy link
Contributor Author

@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 -a option. I'll add them with the other fixes @caternuson requested.

What is the proper proceedure to add the new commit(s)? I can leave it as separate or squash it.

@kattni
Copy link
Contributor

kattni commented Oct 2, 2018

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.

@tannewt
Copy link
Member

tannewt commented Oct 2, 2018

Specifically a PR tracks a branch. So, you can change the branch however you like and the PR will follow it.

Copy link
Member

@tannewt tannewt left a 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.


@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)`."""
Copy link
Member

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.)

Copy link
Contributor Author

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..

Copy link
Member

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"

@siddacious
Copy link
Contributor Author

I just pushed a rebased version that should address all the comments/suggestions. Let me know if I missed anything.

@siddacious siddacious force-pushed the master branch 5 times, most recently from 054e77c to 4229b12 Compare October 5, 2018 21:29
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
Copy link
Contributor

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.

@siddacious siddacious force-pushed the master branch 2 times, most recently from f39e48e to b21c8a2 Compare October 8, 2018 17:14
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)
Copy link
Contributor

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.

as a ``(low_temp, high_temp)`` tuple
"""
return (float(self._read_u8(_MAX31856_CJLF_REG)),
float(self._read_u8(_MAX31856_CJHF_REG)))
Copy link
Contributor

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)
>>> 

@caternuson
Copy link
Contributor

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}
>>>

max31856_test

@tannewt
Copy link
Member

tannewt commented Oct 15, 2018

Looks good to me! Thank you!

@tannewt tannewt merged commit 168c9ac into adafruit:master Oct 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants