<commit_before>"""
OneWire library ported to MicroPython by <NAME>.


TODO: 
  * implement and test parasite-power mode (as an init option)
  * port the crc checks

The original upstream copyright and terms follow.
------------------------------------------------------------------------------

Copyright (c) 2007, <NAME> (original old version - many contributors since)

OneWire has been maintained by <NAME> (<EMAIL>) since
January 2010.

26 Sept 2008 -- <NAME>

<NAME>'s original library was modified by <NAME>.

<NAME>, <EMAIL>, contributed around May 20, 2008

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Much of the code was inspired by Derek Yerger's code, though I don't
think much of that remains.  In any event that was..
    (copyleft) 2006 by <NAME> - Free to distribute freely.
"""

import pyb
from pyb import disable_irq
from pyb import enable_irq

class OneWire:
    def __init__(self, pin):
        """
        Pass the data pin connected to your one-wire device(s), for example Pin('X1').
        The one-wire protocol allows for multiple devices to be attached.
        """
        self.data_pin = pin
        self.write_delays = (1, 40, 40, 1)
        self.read_delays = (1, 1, 40)

        # cache a bunch of methods and attributes.  This is necessary in _write_bit and 
        # _read_bit to achieve the timing required by the OneWire protocol.
        self.cache = (pin.init, pin.value, pin.OUT_PP, pin.IN, pin.PULL_NONE)

        pin.init(pin.IN, pin.PULL_UP)

    def reset(self):
        """
        Perform the onewire reset function.
        Returns 1 if a device asserted a presence pulse, 0 otherwise.

        If you receive 0, then check your wiring and make sure you are providing
        power and ground to your devices.
        """
        retries = 25
        self.data_pin.init(self.data_pin.IN, self.data_pin.PULL_UP)
<commit_msg>drivers/onewire: Enable pull up on data pin.<commit_after>"""
OneWire library ported to MicroPython by <NAME>.


TODO: 
  * implement and test parasite-power mode (as an init option)
  * port the crc checks

The original upstream copyright and terms follow.
------------------------------------------------------------------------------

Copyright (c) 2007, <NAME> (original old version - many contributors since)

OneWire has been maintained by <NAME> (<EMAIL>) since
January 2010.

26 Sept 2008 -- <NAME>

<NAME>'s original library was modified by <NAME>.

<NAME>, <EMAIL>, contributed around May 20, 2008

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Much of the code was inspired by Derek Yerger's code, though I don't
think much of that remains.  In any event that was..
    (copyleft) 2006 by <NAME> - Free to distribute freely.
"""

import pyb
from pyb import disable_irq
from pyb import enable_irq

class OneWire:
    def __init__(self, pin):
        """
        Pass the data pin connected to your one-wire device(s), for example Pin('X1').
        The one-wire protocol allows for multiple devices to be attached.
        """
        self.data_pin = pin
        self.write_delays = (1, 40, 40, 1)
        self.read_delays = (1, 1, 40)

        # cache a bunch of methods and attributes.  This is necessary in _write_bit and 
        # _read_bit to achieve the timing required by the OneWire protocol.
        self.cache = (pin.init, pin.value, pin.OUT_PP, pin.IN, pin.PULL_UP)

        pin.init(pin.IN, pin.PULL_UP)

    def reset(self):
        """
        Perform the onewire reset function.
        Returns 1 if a device asserted a presence pulse, 0 otherwise.

        If you receive 0, then check your wiring and make sure you are providing
        power and ground to your devices.
        """
        retries = 25
        self.data_pin.init(self.data_pin.IN, self.data_pin.PULL_UP)

{'fraction_non_alphanumeric': 0.09062336301728653, 'fraction_numerical': 0.013968919154880391, 'mean_word_length': 3.002795248078267, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3595730', 'n_tokens_mistral': 1623, 'n_tokens_neox': 1473, 'n_words': 768}