Example #1
0
def load_calibration_params(bus, address=DEFAULT_PORT):
    """
    The BME280 output consists of the ADC output values. However, each sensing
    element behaves differently. Therefore, the actual pressure and temperature
    must be calculated using a set of calibration parameters.

    The calibration parameters are subsequently used to with some compensation
    formula to perform temperature readout in degC, humidity in % and pressure
    in hPA.
    """
    read = reader(bus, address)
    compensation_params = params()

    # Temperature trimming params
    compensation_params.dig_T1 = read.unsigned_short(0x88)
    compensation_params.dig_T2 = read.signed_short(0x8A)
    compensation_params.dig_T3 = read.signed_short(0x8C)

    # Pressure trimming params
    compensation_params.dig_P1 = read.unsigned_short(0x8E)
    compensation_params.dig_P2 = read.signed_short(0x90)
    compensation_params.dig_P3 = read.signed_short(0x92)
    compensation_params.dig_P4 = read.signed_short(0x94)
    compensation_params.dig_P5 = read.signed_short(0x96)
    compensation_params.dig_P6 = read.signed_short(0x98)
    compensation_params.dig_P7 = read.signed_short(0x9A)
    compensation_params.dig_P8 = read.signed_short(0x9C)
    compensation_params.dig_P9 = read.signed_short(0x9E)

    # Humidity trimming params
    compensation_params.dig_H1 = read.unsigned_byte(0xA1)
    compensation_params.dig_H2 = read.signed_short(0xE1)
    compensation_params.dig_H3 = read.signed_byte(0xE3)

    e4 = read.signed_byte(0xE4)
    e5 = read.signed_byte(0xE5)
    e6 = read.signed_byte(0xE6)

    compensation_params.dig_H4 = e4 << 4 | e5 & 0x0F
    compensation_params.dig_H5 = ((e5 >> 4) & 0x0F) | (e6 << 4)
    compensation_params.dig_H6 = read.signed_byte(0xE7)

    return compensation_params
Example #2
0
def test_signed_short():
    smbus.read_word_data = MagicMock(return_value=0xCAFEBABE)
    read = reader(bus=smbus, address=0x76)
    assert read.signed_short(register=0x19A) == 0xBABE - 0x10000
    smbus.read_word_data.assert_called_with(0x76, 0x19A)
Example #3
0
def test_signed_byte():
    smbus.read_byte_data = MagicMock(return_value=0xEE)
    read = reader(bus=smbus, address=0x76)
    assert read.signed_byte(register=0x19A) == 0xEE - 0x100
    smbus.read_byte_data.assert_called_with(0x76, 0x19A)
Example #4
0
def test_unsigned_short():
    smbus.read_word_data = MagicMock(return_value=0xDEADBEEF)
    read = reader(bus=smbus, address=0x76)
    assert read.unsigned_short(register=0x19A) == 0xBEEF
    smbus.read_word_data.assert_called_with(0x76, 0x19A)