Source code for pyupm_ds18b20

# This file was automatically generated by SWIG (http://www.swig.org).
# Version 3.0.8
#
# Do not make changes to this file unless you know what you are doing--modify
# the SWIG interface file instead.





from sys import version_info
if version_info >= (2, 6, 0):
    def swig_import_helper():
        from os.path import dirname
        import imp
        fp = None
        try:
            fp, pathname, description = imp.find_module('_pyupm_ds18b20', [dirname(__file__)])
        except ImportError:
            import _pyupm_ds18b20
            return _pyupm_ds18b20
        if fp is not None:
            try:
                _mod = imp.load_module('_pyupm_ds18b20', fp, pathname, description)
            finally:
                fp.close()
            return _mod
    _pyupm_ds18b20 = swig_import_helper()
    del swig_import_helper
else:
    import _pyupm_ds18b20
del version_info
try:
    _swig_property = property
except NameError:
    pass  # Python < 2.2 doesn't have 'property'.


def _swig_setattr_nondynamic(self, class_type, name, value, static=1):
    if (name == "thisown"):
        return self.this.own(value)
    if (name == "this"):
        if type(value).__name__ == 'SwigPyObject':
            self.__dict__[name] = value
            return
    method = class_type.__swig_setmethods__.get(name, None)
    if method:
        return method(self, value)
    if (not static):
        if _newclass:
            object.__setattr__(self, name, value)
        else:
            self.__dict__[name] = value
    else:
        raise AttributeError("You cannot add attributes to %s" % self)


def _swig_setattr(self, class_type, name, value):
    return _swig_setattr_nondynamic(self, class_type, name, value, 0)


def _swig_getattr_nondynamic(self, class_type, name, static=1):
    if (name == "thisown"):
        return self.this.own()
    method = class_type.__swig_getmethods__.get(name, None)
    if method:
        return method(self)
    if (not static):
        return object.__getattr__(self, name)
    else:
        raise AttributeError(name)

def _swig_getattr(self, class_type, name):
    return _swig_getattr_nondynamic(self, class_type, name, 0)


def _swig_repr(self):
    try:
        strthis = "proxy of " + self.this.__repr__()
    except Exception:
        strthis = ""
    return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)

try:
    _object = object
    _newclass = 1
except AttributeError:
    class _object:
        pass
    _newclass = 0



def getVersion():
    return _pyupm_ds18b20.getVersion()
getVersion = _pyupm_ds18b20.getVersion

_pyupm_ds18b20.DS18B20_FAMILY_CODE_swigconstant(_pyupm_ds18b20)
DS18B20_FAMILY_CODE = _pyupm_ds18b20.DS18B20_FAMILY_CODE

_pyupm_ds18b20.DS18B20_CMD_CONVERT_swigconstant(_pyupm_ds18b20)
DS18B20_CMD_CONVERT = _pyupm_ds18b20.DS18B20_CMD_CONVERT

_pyupm_ds18b20.DS18B20_CMD_WRITE_SCRATCHPAD_swigconstant(_pyupm_ds18b20)
DS18B20_CMD_WRITE_SCRATCHPAD = _pyupm_ds18b20.DS18B20_CMD_WRITE_SCRATCHPAD

_pyupm_ds18b20.DS18B20_CMD_READ_SCRATCHPAD_swigconstant(_pyupm_ds18b20)
DS18B20_CMD_READ_SCRATCHPAD = _pyupm_ds18b20.DS18B20_CMD_READ_SCRATCHPAD

_pyupm_ds18b20.DS18B20_CMD_COPY_SCRATCHPAD_swigconstant(_pyupm_ds18b20)
DS18B20_CMD_COPY_SCRATCHPAD = _pyupm_ds18b20.DS18B20_CMD_COPY_SCRATCHPAD

_pyupm_ds18b20.DS18B20_CMD_RECALL_EEPROM_swigconstant(_pyupm_ds18b20)
DS18B20_CMD_RECALL_EEPROM = _pyupm_ds18b20.DS18B20_CMD_RECALL_EEPROM

_pyupm_ds18b20.DS18B20_CMD_READ_POWER_SUPPLY_swigconstant(_pyupm_ds18b20)
DS18B20_CMD_READ_POWER_SUPPLY = _pyupm_ds18b20.DS18B20_CMD_READ_POWER_SUPPLY

_pyupm_ds18b20.DS18B20_CFG_RESOLUTION_R0_swigconstant(_pyupm_ds18b20)
DS18B20_CFG_RESOLUTION_R0 = _pyupm_ds18b20.DS18B20_CFG_RESOLUTION_R0

_pyupm_ds18b20.DS18B20_CFG_RESOLUTION_R1_swigconstant(_pyupm_ds18b20)
DS18B20_CFG_RESOLUTION_R1 = _pyupm_ds18b20.DS18B20_CFG_RESOLUTION_R1

_pyupm_ds18b20._DS18B20_CFG_RESOLUTION_MASK_swigconstant(_pyupm_ds18b20)
_DS18B20_CFG_RESOLUTION_MASK = _pyupm_ds18b20._DS18B20_CFG_RESOLUTION_MASK

_pyupm_ds18b20._DS18B20_CFG_RESOLUTION_SHIFT_swigconstant(_pyupm_ds18b20)
_DS18B20_CFG_RESOLUTION_SHIFT = _pyupm_ds18b20._DS18B20_CFG_RESOLUTION_SHIFT

_pyupm_ds18b20.DS18B20_RESOLUTION_9BITS_swigconstant(_pyupm_ds18b20)
DS18B20_RESOLUTION_9BITS = _pyupm_ds18b20.DS18B20_RESOLUTION_9BITS

_pyupm_ds18b20.DS18B20_RESOLUTION_10BITS_swigconstant(_pyupm_ds18b20)
DS18B20_RESOLUTION_10BITS = _pyupm_ds18b20.DS18B20_RESOLUTION_10BITS

_pyupm_ds18b20.DS18B20_RESOLUTION_11BITS_swigconstant(_pyupm_ds18b20)
DS18B20_RESOLUTION_11BITS = _pyupm_ds18b20.DS18B20_RESOLUTION_11BITS

_pyupm_ds18b20.DS18B20_RESOLUTION_12BITS_swigconstant(_pyupm_ds18b20)
DS18B20_RESOLUTION_12BITS = _pyupm_ds18b20.DS18B20_RESOLUTION_12BITS

_pyupm_ds18b20.DS18B20_DEFAULT_UART_swigconstant(_pyupm_ds18b20)
DS18B20_DEFAULT_UART = _pyupm_ds18b20.DS18B20_DEFAULT_UART
[docs]class DS18B20(_object): """ API for the DS18B20 1-Wire Temperature Sensor. ID: ds18b20 Name: Programmable Resolution 1-Wire Digital Thermometer Category: uart Manufacturer: maxim Connection: uart Link:https://www.sparkfun.com/products/11050 This driver supports, and was tested with, a DS18B20 with external power. Multiple DS18B20 devices can be connected to this bus. This module will identify all such devices connected, and allow you to access them using an index starting at 0. Parasitic power is not currently supported due to the very tight 10us limit on switching a GPIO properly to supply power during certain operations. For this reason, you should use external power for your sensors. Setting the alarm values (Tl, Th) is also not supported, since this is only useful when doing a 1-wire device search looking for devices in an alarm state, a capability not yet supported in MRAA. In reality, this is trivial to handle yourself in your application. This device requires the use of a TTL level UART (specifically through the UartOW MRAA context class) to provide access to a Dallas 1-wire bus. It is important to realize that the UART is only being used to provide an interface to devices on a Dallas 1-wire compliant bus. A circuit like the following should be used for the UART interface (ASCII schematic - best viewed in a fixed monospace font): -| U| (D1) A| TX|<+ R| | T| RX----o-----o >to 1-wire data bus -| Vcc | o------------+ | | R1 | | o(+) >1-wire---o-----o[ DS18B20] o(-) | GND D1 = 1N4148 R1 = 4.7K The cathode of D1 is connected to the UART TX. C++ includes: ds18b20.hpp """ __swig_setmethods__ = {} __setattr__ = lambda self, name, value: _swig_setattr(self, DS18B20, name, value) __swig_getmethods__ = {} __getattr__ = lambda self, name: _swig_getattr(self, DS18B20, name) __repr__ = _swig_repr def __init__(self, uart=0): """ DS18B20(int uart=DS18B20_DEFAULT_UART) DS18B20 object constructor This method will search the 1-wire bus and store information on each device detected on the bus. If no devices are found, an exception is thrown. Once this function completes successfully, you can use devicesFound() to determine how many devices were detected. Parameters: ----------- uart: Default UART to use (0 or 1). Default is 0. """ this = _pyupm_ds18b20.new_DS18B20(uart) try: self.this.append(this) except Exception: self.this = this __swig_destroy__ = _pyupm_ds18b20.delete_DS18B20 __del__ = lambda self: None
[docs] def init(self): """ void init() Deprecated This method is deprecated. It's functionality is handled in the constructor now. """ return _pyupm_ds18b20.DS18B20_init(self)
[docs] def update(self, index=-1): """ void update(int index=-1) Update our stored temperature for a device. This method must be called prior to getTemperature(). Parameters: ----------- index: The device index to access (starts at 0). Specify -1 to query all detected devices. Default: -1 """ return _pyupm_ds18b20.DS18B20_update(self, index)
[docs] def getTemperature(self, index, fahrenheit=False): """ float getTemperature(unsigned int index, bool fahrenheit=false) Get the current temperature. update() must have been called prior to calling this method. Parameters: ----------- index: The device index to access (starts at 0). fahrenheit: true to return the temperature in degrees fahrenheit, false to return the temperature in degrees celsius. The default is false (degrees Celsius). The last temperature reading in Celsius or Fahrenheit """ return _pyupm_ds18b20.DS18B20_getTemperature(self, index, fahrenheit)
[docs] def setResolution(self, index, res): """ void setResolution(unsigned int index, DS18B20_RESOLUTIONS_T res) Set the device resolution for a device. These devices support 9, 10, 11, and 12 bits of resolution, with the default from the factory at 12 bits. Parameters: ----------- index: The device index to access (starts at 0). res: One of the RESOLUTIONS_T values """ return _pyupm_ds18b20.DS18B20_setResolution(self, index, res)
[docs] def copyScratchPad(self, index): """ void copyScratchPad(unsigned int index) Copy the device's scratchpad memory to the EEPROM. This includes the configuration byte (resolution). Parameters: ----------- index: The device index to access (starts at 0). """ return _pyupm_ds18b20.DS18B20_copyScratchPad(self, index)
[docs] def recallEEPROM(self, index): """ void recallEEPROM(unsigned int index) Copy the device's EEPROM memory to the scratchpad. This method will return when the copy completes. This operation is performed by the device automatically on power up, so it is rarely needed. Parameters: ----------- index: The device index to access (starts at 0). """ return _pyupm_ds18b20.DS18B20_recallEEPROM(self, index)
[docs] def devicesFound(self): """ int devicesFound() This method will return the number of DS18B20 devices that were found on the bus by init(). number of DS18B20's that were found on the bus """ return _pyupm_ds18b20.DS18B20_devicesFound(self)
[docs] def getId(self, index): """ string getId(unsigned int index) Return an 8 byte string representing the unique device ID (1-wire romcode) for a given device index. Parameters: ----------- index: The device index to access (starts at 0). 8 byte string representing the 1-wire device's unique romcode. """ return _pyupm_ds18b20.DS18B20_getId(self, index)
DS18B20_swigregister = _pyupm_ds18b20.DS18B20_swigregister DS18B20_swigregister(DS18B20)
[docs]class charArray(_object): __swig_setmethods__ = {} __setattr__ = lambda self, name, value: _swig_setattr(self, charArray, name, value) __swig_getmethods__ = {} __getattr__ = lambda self, name: _swig_getattr(self, charArray, name) __repr__ = _swig_repr def __init__(self, nelements): this = _pyupm_ds18b20.new_charArray(nelements) try: self.this.append(this) except Exception: self.this = this __swig_destroy__ = _pyupm_ds18b20.delete_charArray __del__ = lambda self: None def __getitem__(self, index): return _pyupm_ds18b20.charArray___getitem__(self, index) def __setitem__(self, index, value): return _pyupm_ds18b20.charArray___setitem__(self, index, value)
[docs] def cast(self): return _pyupm_ds18b20.charArray_cast(self)
__swig_getmethods__["frompointer"] = lambda x: _pyupm_ds18b20.charArray_frompointer if _newclass: frompointer = staticmethod(_pyupm_ds18b20.charArray_frompointer)
charArray_swigregister = _pyupm_ds18b20.charArray_swigregister charArray_swigregister(charArray) def charArray_frompointer(t): return _pyupm_ds18b20.charArray_frompointer(t) charArray_frompointer = _pyupm_ds18b20.charArray_frompointer # This file is compatible with both classic and new-style classes.