Skip to content

Initial commit #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
Feb 14, 2017
Merged

Initial commit #1

merged 1 commit into from
Feb 14, 2017

Conversation

deshipu
Copy link
Contributor

@deshipu deshipu commented Feb 4, 2017

No description provided.

@tannewt tannewt self-assigned this Feb 5, 2017
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.

Please also hand merge the README and conf.py.

If ``raw`` is ``True``, return the values as 14- and 12- bit integers,
otherwise convert them to Celsuius degrees and return as floating point
numbers.
"""
Copy link
Member

Choose a reason for hiding this comment

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

Why provide raw access? What combine the reading of external and internal temps into one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You don't really have any choice about what you are reading from this chip. There are no registers, you just do a single read and get all the data all at once.

Raw access is useful for debugging or for getting more precision than the puny ~6 decimal digits supported by the float type. It generally opens the driver for use cases that we didn't anticipate, but that can still be useful, giving the user who knows what they are doing more power, but at the same time letting the common use cases stay simple.

Copy link
Contributor Author

@deshipu deshipu Feb 6, 2017

Choose a reason for hiding this comment

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

I considered other approaches:

  • Having two separate methods (or properties) that would read all the data, but discard half of it and only return the other half. This is useless, as you really want to get the internal reference temperature from exactly the same measurement, as your temperature measurement. Doing two separate measurements defeats the whole purpose.
  • Returning the temperature, and saving the internal reference to an attribute on this class. This introduces an asymmetry, where one property causes a new measurement to be made, but the other doesn't. I found that really confusing and surprising, so I decided against it.
  • The problem with the former approach could be somewhat alleviated by naming the attribute appropriately, such as "last_measurement_internal_reference_temperature" or something similar, however that gets ridiculously long.
  • Returning an object that behaves like a float for all operators, but has an additional attribute with the internal reference. That seemed too magical and with too much overhead.

Copy link
Member

Choose a reason for hiding this comment

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

Although the device doesn't have registers, we can still choose to use properties to represent the device state. I think that having two properties, temperature and internal_temperature, that each read and discard the other temperature is fine. The Adafruit Arduino library does exactly that. Not having them in-sync is also OK by me because the device itself uses the internal temperature to adjust the other "hot end" temperature already. You shouldn't need to do it yourself, its just available in case you also want to know that value.

Regarding raw access, I agree it could be useful for some people. However, I think those people would have no trouble doing the SPI read themselves. I'd rather have this driver expose two simple properties which are easy for beginners who don't need that accuracy.

# THE SOFTWARE.

import ustruct

Copy link
Member

Choose a reason for hiding this comment

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

Please add the description comment here. It provides the title of the API docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do.

If ``raw`` is ``True``, return the values as 14- and 12- bit integers,
otherwise convert them to Celsuius degrees and return as floating point
numbers.
"""
Copy link
Member

Choose a reason for hiding this comment

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

Although the device doesn't have registers, we can still choose to use properties to represent the device state. I think that having two properties, temperature and internal_temperature, that each read and discard the other temperature is fine. The Adafruit Arduino library does exactly that. Not having them in-sync is also OK by me because the device itself uses the internal temperature to adjust the other "hot end" temperature already. You shouldn't need to do it yourself, its just available in case you also want to know that value.

Regarding raw access, I agree it could be useful for some people. However, I think those people would have no trouble doing the SPI read themselves. I'd rather have this driver expose two simple properties which are easy for beginners who don't need that accuracy.

if hasattr(self.cs, 'high'):
self.cs.high()
else:
self.cs.value = 1
Copy link
Member

Choose a reason for hiding this comment

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

Please remove this. I understand its for MicroPython compatibility but I'd rather you use BusDevice to manage the CS line and create a BusDevice library for MicroPython. That way the compatiblity is done in one spot and not many.

Just fork this repo and edit this line for MicroPython: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice/blob/master/adafruit_bus_device/spi_device.py#L64

Then you'd have every BusDevice based library and driver work with MicroPython.

This section would become:

with self.spi as spi:
    spi.readinto(self.data)

@deshipu
Copy link
Contributor Author

deshipu commented Feb 7, 2017

Please don't merge yet.

@deshipu
Copy link
Contributor Author

deshipu commented Feb 11, 2017

I now tested it with HUZZAH and M0, ready to merge.

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.

Two small things and then its good to go.


@property
def temperature(self):
"""Return measured temperature in degrees Celsius."""
Copy link
Member

Choose a reason for hiding this comment

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

One small nitpick. This can just be "Thermocouple temperature in degree Celsius." because its a property rather than a function to the outside world.


@property
def reference_temperature(self):
"""Return internal reference temperature in degrees Celsius."""
Copy link
Member

Choose a reason for hiding this comment

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

Same here: "Internal reference temperature in degrees Celsius."

@deshipu
Copy link
Contributor Author

deshipu commented Feb 13, 2017

Nitpicks applied.

@tannewt tannewt merged commit d86026b into adafruit:master Feb 14, 2017
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.

2 participants