29
29
from adafruit_bus_device import i2c_device
30
30
from micropython import const
31
31
32
+
33
+ try :
34
+ from typing import Tuple
35
+
36
+ from busio import I2C
37
+ except ImportError :
38
+ pass
39
+
32
40
__version__ = "0.0.0+auto.0"
33
41
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_MPL115A2.git"
34
42
41
49
class MPL115A2 :
42
50
"""Driver for MPL115A2 I2C barometric pressure / temperature sensor."""
43
51
44
- def __init__ (self , i2c , address = _MPL115A2_ADDRESS ):
52
+ def __init__ (self , i2c : I2C , address : int = _MPL115A2_ADDRESS ):
45
53
self ._i2c = i2c_device .I2CDevice (i2c , address )
46
54
self ._buf = bytearray (4 )
47
55
self ._read_coefficients ()
48
56
49
57
@property
50
- def pressure (self ):
58
+ def pressure (self ) -> float :
51
59
"""The pressure in hPa."""
52
60
return self ._read ()[0 ] * 10
53
61
54
62
@property
55
- def temperature (self ):
63
+ def temperature (self ) -> float :
56
64
"""The temperature in deg C."""
57
65
return self ._read ()[1 ]
58
66
59
- def _read_coefficients (self ):
67
+ def _read_coefficients (self ) -> None :
60
68
# pylint: disable=invalid-name
61
69
buf = bytearray (8 )
62
70
buf [0 ] = _MPL115A2_REGISTER_A0_COEFF_MSB
@@ -71,7 +79,7 @@ def _read_coefficients(self):
71
79
self ._b2 = b2 / 16384
72
80
self ._c12 = c12 / 4194304
73
81
74
- def _read (self ):
82
+ def _read (self ) -> Tuple [ float , float ] :
75
83
# pylint: disable=invalid-name
76
84
self ._buf [0 ] = _MPL115A2_REGISTER_STARTCONVERSION
77
85
self ._buf [1 ] = 0x00 # why? see datasheet, pg. 9, fig. 4
0 commit comments