def __init__(self, i2c: I2C, sdo=False, rate=100.0): super().__init__(i2c, sdo, rate) self._registers.readRange(self._registers.h2, self._registers.h6) self._h4 = sign_extend( self._registers.h4.value << 4 | self._registers.h4h5.h4Low, 12) self._h5 = sign_extend( self._registers.h5.value << 4 | self._registers.h4h5.h5Low, 12) self._registers.ctrlHumidity.oversampling = Oversamplings.Oversampling_x16 self._registers.ctrlHumidity.write() self._registers.ctrlMeasure.write()
def setValue(self, value: int): self.value = sign_extend((value >> 0) & 0xFF, 8)
{{#Values.Values}} self.{{Name}} = 0 {{/Values.Values}} def read(self): self._manager.read(self) return self def getValue(self): return {{#Values.Values}}((self.{{Name}} & {{Bitmask}}) << {{Offset}}){{^Last}} | {{/Last}}{{/Values.Values}} def setValue(self, value: int): {{#Values.Values}} {{#IsSigned}} self.{{Name}} = sign_extend((value >> {{Offset}}) & {{Bitmask}}, {{Width}}) {{/IsSigned}} {{^IsSigned}} self.{{Name}} = ((value >> {{Offset}}) & {{Bitmask}}) {{/IsSigned}} {{/Values.Values}} def __str__(self): retVal = "" {{#Values.Values}} retVal += "{{CapitalizedName}}: {} (offset: {{Offset}}, width: {{Width}})\r\n".format(self.{{Name}}) {{/Values.Values}} return retVal {{/RegisterList}}
def update(self): data = sign_extend(self._dev.read_word_data_be(0x05), 13) self._celsius = data / 16
def update(self): data = sign_extend(self._dev.read_word_data_be(0), 16) self._celsius = data / 32 / 8