Source code for pyupm_ims

# 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_ims', [dirname(__file__)])
        except ImportError:
            import _pyupm_ims
            return _pyupm_ims
        if fp is not None:
            try:
                _mod = imp.load_module('_pyupm_ims', fp, pathname, description)
            finally:
                fp.close()
            return _mod
    _pyupm_ims = swig_import_helper()
    del swig_import_helper
else:
    import _pyupm_ims
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_ims.getVersion()
getVersion = _pyupm_ims.getVersion

_pyupm_ims.IMS_ADDRESS_DEFAULT_swigconstant(_pyupm_ims)
IMS_ADDRESS_DEFAULT = _pyupm_ims.IMS_ADDRESS_DEFAULT

_pyupm_ims.IMS_GET_CAPACITANCE_swigconstant(_pyupm_ims)
IMS_GET_CAPACITANCE = _pyupm_ims.IMS_GET_CAPACITANCE

_pyupm_ims.IMS_GET_ADDRESS_swigconstant(_pyupm_ims)
IMS_GET_ADDRESS = _pyupm_ims.IMS_GET_ADDRESS

_pyupm_ims.IMS_GET_LIGHT_swigconstant(_pyupm_ims)
IMS_GET_LIGHT = _pyupm_ims.IMS_GET_LIGHT

_pyupm_ims.IMS_GET_TEMPERATURE_swigconstant(_pyupm_ims)
IMS_GET_TEMPERATURE = _pyupm_ims.IMS_GET_TEMPERATURE

_pyupm_ims.IMS_GET_VERSION_swigconstant(_pyupm_ims)
IMS_GET_VERSION = _pyupm_ims.IMS_GET_VERSION

_pyupm_ims.IMS_GET_BUSY_swigconstant(_pyupm_ims)
IMS_GET_BUSY = _pyupm_ims.IMS_GET_BUSY

_pyupm_ims.IMS_SET_ADDRESS_swigconstant(_pyupm_ims)
IMS_SET_ADDRESS = _pyupm_ims.IMS_SET_ADDRESS

_pyupm_ims.IMS_MEASURE_LIGHT_swigconstant(_pyupm_ims)
IMS_MEASURE_LIGHT = _pyupm_ims.IMS_MEASURE_LIGHT

_pyupm_ims.IMS_RESET_swigconstant(_pyupm_ims)
IMS_RESET = _pyupm_ims.IMS_RESET

_pyupm_ims.IMS_SLEEP_swigconstant(_pyupm_ims)
IMS_SLEEP = _pyupm_ims.IMS_SLEEP
[docs]class IMS(_object): """ API for the Catnip Electronics I2C moisture sensor. ID: ims Name: I2C Moisture Sensor Category: liquid light temp Manufacturer: catnip Link:https://www.tindie.com/products/miceuz/i2c-soil-moisture-sensor/ Connection: i2c I2C sensor which can be used to read: moisture light temperature This sensor must run at 100 kHz C++ includes: ims.hpp """ __swig_setmethods__ = {} __setattr__ = lambda self, name, value: _swig_setattr(self, IMS, name, value) __swig_getmethods__ = {} __getattr__ = lambda self, name: _swig_getattr(self, IMS, name) __repr__ = _swig_repr def __init__(self, i2c_bus, i2c_address=0x20): """ IMS(int16_t i2c_bus, int16_t i2c_address=IMS_ADDRESS_DEFAULT) I2C Moisture Sensor constructor Initialize I2C Moisture Sensor Parameters: ----------- i2c_bus: Target I2C bus i2c_address: Target I2C address (default is 0x20) sensor context pointer Exceptions: ----------- std::runtime_error: if sensor initializate fails """ this = _pyupm_ims.new_IMS(i2c_bus, i2c_address) try: self.this.append(this) except Exception: self.this = this __swig_destroy__ = _pyupm_ims.delete_IMS __del__ = lambda self: None
[docs] def write(self, cmd, wr_data): """ void write(IMS_WR_COMMAND cmd, uint8_t wr_data) Write I2C Moisture Sensor registers Parameters: ----------- cmd: Write command wr_data: Target data to write (only used for IMS_SET_ADDRESS) Exceptions: ----------- std::runtime_error: if I2C write command fails """ return _pyupm_ims.IMS_write(self, cmd, wr_data)
[docs] def read(self, cmd): """ uint16_t read(IMS_RD_COMMAND cmd) Read I2C Moisture Sensor registers Parameters: ----------- cmd: Read command Data returned from sensor (1 or 2 bytes depending on CMD) Exceptions: ----------- std::runtime_error: if I2C read command fails """ return _pyupm_ims.IMS_read(self, cmd)
[docs] def get_version(self): """ uint16_t get_version() Get sensor version Sensor version Exceptions: ----------- std::runtime_error: if I2C read command fails """ return _pyupm_ims.IMS_get_version(self)
[docs] def get_moisture(self): """ uint16_t get_moisture() Get moisture reading from sensor Unitless, relative capacitance value (moisture) Exceptions: ----------- std::runtime_error: if I2C read command fails """ return _pyupm_ims.IMS_get_moisture(self)
[docs] def get_light(self): """ uint16_t get_light() Get light reading from LED on device. The technical data for the I2C moisture sensor specifies a 3 second wait. Loop for 3 seconds checking the GET_BUSY register. IF the sensor is NOT ready after 3 seconds, assume there is NO light and return a max uint16_t (dark) value. rd_data Unitless, relative value for brightness dark (0xFFFF)> light (0x0000) Exceptions: ----------- std::runtime_error: if I2C write/read command fails """ return _pyupm_ims.IMS_get_light(self)
[docs] def get_temperature(self): """ float get_temperature() Get temperature reading from device rd_data Temperature in degrees Celsius Exceptions: ----------- std::runtime_error: if I2C read command fails """ return _pyupm_ims.IMS_get_temperature(self)
[docs] def reset(self): """ void reset() Reset sensor Exceptions: ----------- std::runtime_error: if I2C write command fails """ return _pyupm_ims.IMS_reset(self)
[docs] def reset_i2c_address(self, address_new): """ void reset_i2c_address(uint8_t address_new) Set I2C address AND reset sensor Parameters: ----------- address_new: New I2C for device Exceptions: ----------- std::runtime_error: if I2C write command fails """ return _pyupm_ims.IMS_reset_i2c_address(self, address_new)
[docs] def sleep(self): """ void sleep() Put device into low-power mode. Device wakes on any I2C command. Exceptions: ----------- std::runtime_error: if I2C write command fails """ return _pyupm_ims.IMS_sleep(self)
IMS_swigregister = _pyupm_ims.IMS_swigregister IMS_swigregister(IMS) # This file is compatible with both classic and new-style classes.