Skip to content

Commit cef63e4

Browse files
authored
Merge pull request #2 from chickadee-tech/doc_fix
Comment tweaks so the APIs appear in ReadTheDocs
2 parents fcf1089 + 217a20f commit cef63e4

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

adafruit_bmp280.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636

3737
# I2C ADDRESS/BITS/SETTINGS
3838
# -----------------------------------------------------------------------
39-
_BMP280_ADDRESS = const(0x77)
4039
_BMP280_CHIPID = const(0x58)
4140

4241
_BMP280_REGISTER_CHIPID = const(0xD0)
@@ -62,34 +61,35 @@
6261
_BMP280_REGISTER_TEMPDATA = const(0xFA)
6362

6463
class Adafruit_BMP280:
64+
"""Base BMP280 object. Use `Adafruit_BMP280_I2C` or `Adafruit_BMP280_SPI` instead of this. This checks the BMP280 was found, reads the coefficients and enables the sensor for continuous reads"""
6565
def __init__(self):
66-
"""Check the BMP280 was found, read the coefficients and enable the sensor for continuous reads"""
6766
# Check device ID.
6867
id = self._read_byte(_BMP280_REGISTER_CHIPID)
6968
if _BMP280_CHIPID != id:
7069
raise RuntimeError('Failed to find BMP280! Chip ID 0x%x' % id)
7170
self._read_coefficients()
7271
self.seaLevelhPa = 1013.25
72+
"""Pressure in hectoPascals at sea level. Used to calibrate `altitude`."""
7373

7474
@property
7575
def temperature(self):
7676
"""The compensated temperature in degrees celsius."""
7777
# perform one measurement in high res, forced mode
7878
self._write_register_byte(_BMP280_REGISTER_CONTROL, 0xFE)
79-
79+
8080
# Wait for conversion to complete
81-
while (self._read_byte(_BMP280_REGISTER_STATUS) & 0x08):
81+
while (self._read_byte(_BMP280_REGISTER_STATUS) & 0x08):
8282
time.sleep(0.002)
8383
# lowest 4 bits get dropped
84-
UT = self._read24(_BMP280_REGISTER_TEMPDATA) / 16
84+
UT = self._read24(_BMP280_REGISTER_TEMPDATA) / 16
8585
#print("raw temp: ", UT)
8686

8787
var1 = (UT / 16384.0 - self.dig_T1 / 1024.0) * self.dig_T2
8888
var2 = ((UT / 131072.0 - self.dig_T1 / 8192.0) * (
8989
UT / 131072.0 - self.dig_T1 / 8192.0)) * self.dig_T3
9090
self.t_fine = int(var1 + var2)
9191
#print("t_fine: ", self.t_fine)
92-
92+
9393
temp = (var1 + var2) / 5120.0
9494
return temp
9595

@@ -117,7 +117,7 @@ def pressure(self):
117117

118118
@property
119119
def altitude(self):
120-
"""The altitude based on the sea level pressure (seaLevelhPa) - which you must enter ahead of time)"""
120+
"""The altitude based on the sea level pressure (`seaLevelhPa`) - which you must enter ahead of time)"""
121121
p = self.pressure # in Si units for hPascal
122122
return 44330 * (1.0 - math.pow(p / self.seaLevelhPa, 0.1903));
123123

@@ -132,7 +132,7 @@ def _read_coefficients(self):
132132
#print("%d %d %d" % (self.dig_P1, self.dig_P2, self.dig_P3))
133133
#print("%d %d %d" % (self.dig_P4, self.dig_P5, self.dig_P6))
134134
#print("%d %d %d" % (self.dig_P7, self.dig_P8, self.dig_P9))
135-
135+
136136
def _read_byte(self, register):
137137
"""Read a byte register value and return it"""
138138
return self._read_register(register, 1)[0]
@@ -144,10 +144,11 @@ def _read24(self, register):
144144
ret *= 256.0
145145
ret += float(b & 0xFF)
146146
return ret
147-
147+
148+
148149
class Adafruit_BMP280_I2C(Adafruit_BMP280):
149-
def __init__(self, i2c, address=_BMP280_ADDRESS):
150-
"""Check the BMP280 was found, read the coefficients and enable the sensor for continuous reads. Default address is 0x77 but another address can be passed in as an argument"""
150+
"""Driver for I2C connected BMP280. Default address is 0x77 but another address can be passed in as an argument"""
151+
def __init__(self, i2c, address=0x77):
151152
import adafruit_bus_device.i2c_device as i2c_device
152153
self._i2c = i2c_device.I2CDevice(i2c, address)
153154
super().__init__()
@@ -168,8 +169,8 @@ def _write_register_byte(self, register, value):
168169
#print("$%02X <= 0x%02X" % (register, value))
169170

170171
class Adafruit_BMP280_SPI(Adafruit_BMP280):
172+
"""Driver for SPI connected BMP280. Default clock rate is 100000 but can be changed with 'baudrate'"""
171173
def __init__(self, spi, cs, baudrate=100000):
172-
"""Check the BMP280 was found, read the coefficients and enable the sensor for continuous reads. Default clock rate is 100000 but can be changed with 'baudrate'"""
173174
import adafruit_bus_device.spi_device as spi_device
174175
self._spi = spi_device.SPIDevice(spi, cs, baudrate=baudrate)
175176
super().__init__()

0 commit comments

Comments
 (0)