# Path: IoTPy/boards/metis.py
# class Metis(IoBoard):
# 
#     def __init__(self, io=None, **kwargs):
#         IoBoard.__init__(self, METIS_PINOUT, io, **kwargs)
# 
# Path: IoTPy/things/si70xx.py
# class Si7013:
#     """
#     Si7013 humidity and temperature sensor class.
# 
#     :param interface:  I2C communication interface.
#     :type interface: :class:`IoTPy.pyuper.i2c.I2C`
#     :param int address: Si7013 sensor I2C address. Optional, default 0x40 (64)
#     """
# 
#     def __init__(self, interface, address=0x40):
#         self.interface = interface
#         self.address = address
# 
#     def __enter__(self):
#         return self
# 
#     def temperature(self):
#         """
#         Read, convert and return temperature.
# 
#         :return: Temperature value in celsius.
#         :rtype: float
#         :raise: IoTPy_ThingError
#         """
#         try:
#             data, err = self.interface.transaction(self.address, SI70xx_CMD_TEMP_HOLD, 2)
#             result_integer = unpack('>H', data[:2])[0]
#             temp = (175.72 * result_integer)/65536 - 46.85
#         except IoTPy_ThingError:
#             raise IoTPy_ThingError("Si7020 - temperature reading error.")
#         return temp
# 
#     def humidity(self):
#         """
#         Read, convert and return humidity.
# 
#         :return: Humidity value in percent.
#         :rtype: float
#         :raise: IoTPy_ThingError
#         """
#         try:
#             data, err = self.interface.transaction(self.address, SI70xx_CMD_RH_HOLD, 2)
#             result_integer = unpack('>H', data[:2])[0]
#             rh = (125.0 * result_integer)/65536 - 6
#         except IoTPy_ThingError:
#             raise IoTPy_ThingError("Si7020 - humidity reading error.")
#         return rh
# 
#     def analog(self):
#         """
#         Read, convert and return analog sensor value.
# 
#         :return: Analog ADC value
#         :rtype: int
#         :raise: IoTPy_ThingError
#         """
#         try:
#             data, err = self.interface.transaction(self.address, SI70xx_CMD_ANALOG, 2)
#             result_integer = unpack('>H', data[:2])[0]
#             return result_integer
#         except IoTPy_ThingError:
#             raise IoTPy_ThingError("Si7020 - analog reading error.")
# 
#     def __exit__(self, ex_type, ex_value, traceback):
#         pass
# 
# class Si7020:
#     """
#     Si7020 humidity and temperature sensor class.
# 
#     :param interface:  I2C communication interface.
#     :type interface: :class:`IoTPy.pyuper.i2c.I2C`
#     :param int address: Si7020 sensor I2C address. Optional, default 0x40 (64)
#     """
# 
#     def __init__(self, interface, address=0x40):
#         self.interface = interface
#         self.address = address
# 
#     def __enter__(self):
#         return self
# 
#     def temperature(self):
#         """
#         Read, convert and return temperature.
# 
#         :return: Temperature value in celsius.
#         :rtype: float
#         :raise: IoTPy_ThingError
#         """
#         try:
#             data, err = self.interface.transaction(self.address, SI70xx_CMD_TEMP_HOLD, 2)
#             result_integer = unpack('>H', data[:2])[0]
#             temp = (175.72 * result_integer)/65536 - 46.85
#         except IoTPy_ThingError:
#             raise IoTPy_ThingError("Si7020 - temperature reading error.")
#         return temp
# 
#     def humidity(self):
#         """
#         Read, convert and return humidity.
# 
#         :return: Humidity value in percent.
#         :rtype: float
#         :raise: IoTPy_ThingError
#         """
#         try:
#             data, err = self.interface.transaction(self.address, SI70xx_CMD_RH_HOLD, 2)
#             result_integer = unpack('>H', data[:2])[0]
#             rh = (125.0 * result_integer)/65536 - 6
#         except IoTPy_ThingError:
#             raise IoTPy_ThingError("Si7020 - humidity reading error.")
#         return rh
# 
#     def __exit__(self, ex_type, ex_value, traceback):
#         pass


from time import sleep
from IoTPy.boards.metis import Metis
from IoTPy.things.si70xx import Si7013, Si7020


#with Metis() as board, board.i2c("I2C0") as i2c, Si7020(i2c, 0x40) as si7020, Si7013(i2c, 0x41) as si7013:
with Metis() as board, board.i2c("I2C0") as i2c, Si7013(i2c, 0x40) as si7013:
    while True:
        #print("Si7020 T=%.1f H=%.1f" % (si7020.temperature(), si7020.humidity()))
        print("Si7013 T=%.1f H=%.1f A=%i" % (si7013.temperature(), si7013.humidity(), si7013.analog()))

# Path: IoTPy/boards/metis.py
# class Metis(IoBoard):
# 
#     def __init__(self, io=None, **kwargs):
#         IoBoard.__init__(self, METIS_PINOUT, io, **kwargs)
# 
# Path: IoTPy/things/si70xx.py
# class Si7013:
#     """
#     Si7013 humidity and temperature sensor class.
# 
#     :param interface:  I2C communication interface.
#     :type interface: :class:`IoTPy.pyuper.i2c.I2C`
#     :param int address: Si7013 sensor I2C address. Optional, default 0x40 (64)
#     """
# 
#     def __init__(self, interface, address=0x40):
#         self.interface = interface
#         self.address = address
# 
#     def __enter__(self):
#         return self
# 
#     def temperature(self):
#         """
#         Read, convert and return temperature.
# 
#         :return: Temperature value in celsius.
#         :rtype: float
#         :raise: IoTPy_ThingError
#         """
#         try:
#             data, err = self.interface.transaction(self.address, SI70xx_CMD_TEMP_HOLD, 2)
#             result_integer = unpack('>H', data[:2])[0]
#             temp = (175.72 * result_integer)/65536 - 46.85
#         except IoTPy_ThingError:
#             raise IoTPy_ThingError("Si7020 - temperature reading error.")
#         return temp
# 
#     def humidity(self):
#         """
#         Read, convert and return humidity.
# 
#         :return: Humidity value in percent.
#         :rtype: float
#         :raise: IoTPy_ThingError
#         """
#         try:
#             data, err = self.interface.transaction(self.address, SI70xx_CMD_RH_HOLD, 2)
#             result_integer = unpack('>H', data[:2])[0]
#             rh = (125.0 * result_integer)/65536 - 6
#         except IoTPy_ThingError:
#             raise IoTPy_ThingError("Si7020 - humidity reading error.")
#         return rh
# 
#     def analog(self):
#         """
#         Read, convert and return analog sensor value.
# 
#         :return: Analog ADC value
#         :rtype: int
#         :raise: IoTPy_ThingError
#         """
#         try:
#             data, err = self.interface.transaction(self.address, SI70xx_CMD_ANALOG, 2)
#             result_integer = unpack('>H', data[:2])[0]
#             return result_integer
#         except IoTPy_ThingError:
#             raise IoTPy_ThingError("Si7020 - analog reading error.")
# 
#     def __exit__(self, ex_type, ex_value, traceback):
#         pass
# 
# class Si7020:
#     """
#     Si7020 humidity and temperature sensor class.
# 
#     :param interface:  I2C communication interface.
#     :type interface: :class:`IoTPy.pyuper.i2c.I2C`
#     :param int address: Si7020 sensor I2C address. Optional, default 0x40 (64)
#     """
# 
#     def __init__(self, interface, address=0x40):
#         self.interface = interface
#         self.address = address
# 
#     def __enter__(self):
#         return self
# 
#     def temperature(self):
#         """
#         Read, convert and return temperature.
# 
#         :return: Temperature value in celsius.
#         :rtype: float
#         :raise: IoTPy_ThingError
#         """
#         try:
#             data, err = self.interface.transaction(self.address, SI70xx_CMD_TEMP_HOLD, 2)
#             result_integer = unpack('>H', data[:2])[0]
#             temp = (175.72 * result_integer)/65536 - 46.85
#         except IoTPy_ThingError:
#             raise IoTPy_ThingError("Si7020 - temperature reading error.")
#         return temp
# 
#     def humidity(self):
#         """
#         Read, convert and return humidity.
# 
#         :return: Humidity value in percent.
#         :rtype: float
#         :raise: IoTPy_ThingError
#         """
#         try:
#             data, err = self.interface.transaction(self.address, SI70xx_CMD_RH_HOLD, 2)
#             result_integer = unpack('>H', data[:2])[0]
#             rh = (125.0 * result_integer)/65536 - 6
#         except IoTPy_ThingError:
#             raise IoTPy_ThingError("Si7020 - humidity reading error.")
#         return rh
# 
#     def __exit__(self, ex_type, ex_value, traceback):
#         pass


# Path: examples/sensors/07_Si7020_Si7013.py
from time import sleep
from IoTPy.boards.metis import Metis
from IoTPy.things.si70xx import Si7013, Si7020



#with Metis() as board, board.i2c("I2C0") as i2c, Si7020(i2c, 0x40) as si7020, Si7013(i2c, 0x41) as si7013:
with Metis() as board, board.i2c("I2C0") as i2c, Si7013(i2c, 0x40) as si7013:
    while True:
        #print("Si7020 T=%.1f H=%.1f" % (si7020.temperature(), si7020.humidity()))
        print("Si7013 T=%.1f H=%.1f A=%i" % (si7013.temperature(), si7013.humidity(), si7013.analog()))

        sleep(1)