#! /usr/bin/Python3
#coding=utf-8

#Bibliotheken importieren
from smbus import SMBus
import time

# Get I2C bus
bus = SMBus(1)

def read():
    #HYT939 address, 0x28(40)
    #0x80 Send Normal Mode
    bus.write_byte(0x28, 0x80)
    
    time.sleep(0.5)
    
    #Daten lesen aus 0x00. 4 Byte
    #Zusammensetzung Feuchte MSB, LSB Temperatur MSB, LSB
    data = bus.read_i2c_block_data(0x28, 0x00, 4)
    
    #Umwandeln von 16 auf 14 bit und berechnen der Zielwerte
    humidity = ((data[0] & 0x3F) *256 + data[1]) * (100 / 16383.0)
    cTemp = ((data[2] * 256 + (data[3] & 0xFC)) / 4) * (165 / 16383.0) - 40
    
    return [cTemp, humidity]