robert-hh / Onewire_DS18X20

Classes for driving the DS18x20 sensor with the onewire protocol for Pycom MicroPython
11 stars 6 forks source link

Optionally start conversion for all devices on the bus, resolve #3. #6

Closed amotl closed 4 years ago

amotl commented 4 years ago

The idea is coming from the respective driver within Genuine MicroPython: https://github.com/micropython/micropython/blob/v1.11/drivers/onewire/ds18x20.py#L18-L21

robert-hh commented 4 years ago

I prefer another method for start_conversion, which I have implemented:

Code Snippet:

        if (rom is None) and (len(self.roms) == 1):
            rom = self.roms[0]

        assert rom is not None, "ROM address missing or ambiguous"

        ow = self.ow
        ow.reset()
        if rom is self.roms: 
            ow.write_byte(ow.CMD_SKIPROM)
        else:
            ow.select_rom(rom)
        ow.write_byte(0x44)  # Convert Temp
amotl commented 4 years ago

Dear Robert,

we feel the procedure regarding "if there is exactly one device on the bus" is very ambiguous and will not be compatible with Genuine MicroPython anyway, so I proposed to get rid of this within #2. However, I recognize you prefer it that way, so feel free to combine this.

Another way could be to provide the same functionality using a different method like start_conversion_smart which has less of a code smell.

With kind regards, Andreas.

robert-hh commented 4 years ago

I'm going to drop that Pycom specific version anyhow and make onewire.py/ds18x20.py mostly compatible to the micryopthon.org version.

amotl commented 4 years ago

Thanks a bunch! Then let's just close this in favor of #10.