Skip to content
This repository was archived by the owner on Dec 20, 2018. It is now read-only.

Commit 5559f4c

Browse files
committed
Whitespace tabs to spaces.
1 parent 172490d commit 5559f4c

File tree

3 files changed

+159
-149
lines changed

3 files changed

+159
-149
lines changed

Adafruit_BMP/BMP085.py

+138-138
Original file line numberDiff line numberDiff line change
@@ -54,149 +54,149 @@
5454

5555

5656
class BMP085(object):
57-
def __init__(self, mode=BMP085_STANDARD, address=BMP085_I2CADDR, i2c=None, **kwargs):
58-
self._logger = logging.getLogger('Adafruit_BMP.BMP085')
59-
# Check that mode is valid.
60-
if mode not in [BMP085_ULTRALOWPOWER, BMP085_STANDARD, BMP085_HIGHRES, BMP085_ULTRAHIGHRES]:
61-
raise ValueError('Unexpected mode value {0}. Set mode to one of BMP085_ULTRALOWPOWER, BMP085_STANDARD, BMP085_HIGHRES, or BMP085_ULTRAHIGHRES'.format(mode))
62-
self._mode = mode
63-
# Create I2C device.
64-
if i2c is None:
65-
import Adafruit_GPIO.I2C as I2C
66-
i2c = I2C
67-
self._device = i2c.get_i2c_device(address, **kwargs)
68-
# Load calibration values.
69-
self._load_calibration()
57+
def __init__(self, mode=BMP085_STANDARD, address=BMP085_I2CADDR, i2c=None, **kwargs):
58+
self._logger = logging.getLogger('Adafruit_BMP.BMP085')
59+
# Check that mode is valid.
60+
if mode not in [BMP085_ULTRALOWPOWER, BMP085_STANDARD, BMP085_HIGHRES, BMP085_ULTRAHIGHRES]:
61+
raise ValueError('Unexpected mode value {0}. Set mode to one of BMP085_ULTRALOWPOWER, BMP085_STANDARD, BMP085_HIGHRES, or BMP085_ULTRAHIGHRES'.format(mode))
62+
self._mode = mode
63+
# Create I2C device.
64+
if i2c is None:
65+
import Adafruit_GPIO.I2C as I2C
66+
i2c = I2C
67+
self._device = i2c.get_i2c_device(address, **kwargs)
68+
# Load calibration values.
69+
self._load_calibration()
7070

71-
def _load_calibration(self):
72-
self.cal_AC1 = self._device.readS16BE(BMP085_CAL_AC1) # INT16
73-
self.cal_AC2 = self._device.readS16BE(BMP085_CAL_AC2) # INT16
74-
self.cal_AC3 = self._device.readS16BE(BMP085_CAL_AC3) # INT16
75-
self.cal_AC4 = self._device.readU16BE(BMP085_CAL_AC4) # UINT16
76-
self.cal_AC5 = self._device.readU16BE(BMP085_CAL_AC5) # UINT16
77-
self.cal_AC6 = self._device.readU16BE(BMP085_CAL_AC6) # UINT16
78-
self.cal_B1 = self._device.readS16BE(BMP085_CAL_B1) # INT16
79-
self.cal_B2 = self._device.readS16BE(BMP085_CAL_B2) # INT16
80-
self.cal_MB = self._device.readS16BE(BMP085_CAL_MB) # INT16
81-
self.cal_MC = self._device.readS16BE(BMP085_CAL_MC) # INT16
82-
self.cal_MD = self._device.readS16BE(BMP085_CAL_MD) # INT16
83-
self._logger.debug('AC1 = {0:6d}'.format(self.cal_AC1))
84-
self._logger.debug('AC2 = {0:6d}'.format(self.cal_AC2))
85-
self._logger.debug('AC3 = {0:6d}'.format(self.cal_AC3))
86-
self._logger.debug('AC4 = {0:6d}'.format(self.cal_AC4))
87-
self._logger.debug('AC5 = {0:6d}'.format(self.cal_AC5))
88-
self._logger.debug('AC6 = {0:6d}'.format(self.cal_AC6))
89-
self._logger.debug('B1 = {0:6d}'.format(self.cal_B1))
90-
self._logger.debug('B2 = {0:6d}'.format(self.cal_B2))
91-
self._logger.debug('MB = {0:6d}'.format(self.cal_MB))
92-
self._logger.debug('MC = {0:6d}'.format(self.cal_MC))
93-
self._logger.debug('MD = {0:6d}'.format(self.cal_MD))
71+
def _load_calibration(self):
72+
self.cal_AC1 = self._device.readS16BE(BMP085_CAL_AC1) # INT16
73+
self.cal_AC2 = self._device.readS16BE(BMP085_CAL_AC2) # INT16
74+
self.cal_AC3 = self._device.readS16BE(BMP085_CAL_AC3) # INT16
75+
self.cal_AC4 = self._device.readU16BE(BMP085_CAL_AC4) # UINT16
76+
self.cal_AC5 = self._device.readU16BE(BMP085_CAL_AC5) # UINT16
77+
self.cal_AC6 = self._device.readU16BE(BMP085_CAL_AC6) # UINT16
78+
self.cal_B1 = self._device.readS16BE(BMP085_CAL_B1) # INT16
79+
self.cal_B2 = self._device.readS16BE(BMP085_CAL_B2) # INT16
80+
self.cal_MB = self._device.readS16BE(BMP085_CAL_MB) # INT16
81+
self.cal_MC = self._device.readS16BE(BMP085_CAL_MC) # INT16
82+
self.cal_MD = self._device.readS16BE(BMP085_CAL_MD) # INT16
83+
self._logger.debug('AC1 = {0:6d}'.format(self.cal_AC1))
84+
self._logger.debug('AC2 = {0:6d}'.format(self.cal_AC2))
85+
self._logger.debug('AC3 = {0:6d}'.format(self.cal_AC3))
86+
self._logger.debug('AC4 = {0:6d}'.format(self.cal_AC4))
87+
self._logger.debug('AC5 = {0:6d}'.format(self.cal_AC5))
88+
self._logger.debug('AC6 = {0:6d}'.format(self.cal_AC6))
89+
self._logger.debug('B1 = {0:6d}'.format(self.cal_B1))
90+
self._logger.debug('B2 = {0:6d}'.format(self.cal_B2))
91+
self._logger.debug('MB = {0:6d}'.format(self.cal_MB))
92+
self._logger.debug('MC = {0:6d}'.format(self.cal_MC))
93+
self._logger.debug('MD = {0:6d}'.format(self.cal_MD))
9494

95-
def _load_datasheet_calibration(self):
96-
# Set calibration from values in the datasheet example. Useful for debugging the
97-
# temp and pressure calculation accuracy.
98-
self.cal_AC1 = 408
99-
self.cal_AC2 = -72
100-
self.cal_AC3 = -14383
101-
self.cal_AC4 = 32741
102-
self.cal_AC5 = 32757
103-
self.cal_AC6 = 23153
104-
self.cal_B1 = 6190
105-
self.cal_B2 = 4
106-
self.cal_MB = -32767
107-
self.cal_MC = -8711
108-
self.cal_MD = 2868
95+
def _load_datasheet_calibration(self):
96+
# Set calibration from values in the datasheet example. Useful for debugging the
97+
# temp and pressure calculation accuracy.
98+
self.cal_AC1 = 408
99+
self.cal_AC2 = -72
100+
self.cal_AC3 = -14383
101+
self.cal_AC4 = 32741
102+
self.cal_AC5 = 32757
103+
self.cal_AC6 = 23153
104+
self.cal_B1 = 6190
105+
self.cal_B2 = 4
106+
self.cal_MB = -32767
107+
self.cal_MC = -8711
108+
self.cal_MD = 2868
109109

110-
def read_raw_temp(self):
111-
"""Reads the raw (uncompensated) temperature from the sensor."""
112-
self._device.write8(BMP085_CONTROL, BMP085_READTEMPCMD)
113-
time.sleep(0.005) # Wait 5ms
114-
raw = self._device.readU16BE(BMP085_TEMPDATA)
115-
self._logger.debug('Raw temp 0x{0:X} ({1})'.format(raw & 0xFFFF, raw))
116-
return raw
110+
def read_raw_temp(self):
111+
"""Reads the raw (uncompensated) temperature from the sensor."""
112+
self._device.write8(BMP085_CONTROL, BMP085_READTEMPCMD)
113+
time.sleep(0.005) # Wait 5ms
114+
raw = self._device.readU16BE(BMP085_TEMPDATA)
115+
self._logger.debug('Raw temp 0x{0:X} ({1})'.format(raw & 0xFFFF, raw))
116+
return raw
117117

118-
def read_raw_pressure(self):
119-
"""Reads the raw (uncompensated) pressure level from the sensor."""
120-
self._device.write8(BMP085_CONTROL, BMP085_READPRESSURECMD + (self._mode << 6))
121-
if self._mode == BMP085_ULTRALOWPOWER:
122-
time.sleep(0.005)
123-
elif self._mode == BMP085_HIGHRES:
124-
time.sleep(0.014)
125-
elif self._mode == BMP085_ULTRAHIGHRES:
126-
time.sleep(0.026)
127-
else:
128-
time.sleep(0.008)
129-
msb = self._device.readU8(BMP085_PRESSUREDATA)
130-
lsb = self._device.readU8(BMP085_PRESSUREDATA+1)
131-
xlsb = self._device.readU8(BMP085_PRESSUREDATA+2)
132-
raw = ((msb << 16) + (lsb << 8) + xlsb) >> (8 - self._mode)
133-
self._logger.debug('Raw pressure 0x{0:04X} ({1})'.format(raw & 0xFFFF, raw))
134-
return raw
118+
def read_raw_pressure(self):
119+
"""Reads the raw (uncompensated) pressure level from the sensor."""
120+
self._device.write8(BMP085_CONTROL, BMP085_READPRESSURECMD + (self._mode << 6))
121+
if self._mode == BMP085_ULTRALOWPOWER:
122+
time.sleep(0.005)
123+
elif self._mode == BMP085_HIGHRES:
124+
time.sleep(0.014)
125+
elif self._mode == BMP085_ULTRAHIGHRES:
126+
time.sleep(0.026)
127+
else:
128+
time.sleep(0.008)
129+
msb = self._device.readU8(BMP085_PRESSUREDATA)
130+
lsb = self._device.readU8(BMP085_PRESSUREDATA+1)
131+
xlsb = self._device.readU8(BMP085_PRESSUREDATA+2)
132+
raw = ((msb << 16) + (lsb << 8) + xlsb) >> (8 - self._mode)
133+
self._logger.debug('Raw pressure 0x{0:04X} ({1})'.format(raw & 0xFFFF, raw))
134+
return raw
135135

136-
def read_temperature(self):
137-
"""Gets the compensated temperature in degrees celsius."""
138-
UT = self.read_raw_temp()
139-
# Datasheet value for debugging:
140-
#UT = 27898
141-
# Calculations below are taken straight from section 3.5 of the datasheet.
142-
X1 = ((UT - self.cal_AC6) * self.cal_AC5) >> 15
143-
X2 = (self.cal_MC << 11) // (X1 + self.cal_MD)
144-
B5 = X1 + X2
145-
temp = ((B5 + 8) >> 4) / 10.0
146-
self._logger.debug('Calibrated temperature {0} C'.format(temp))
147-
return temp
136+
def read_temperature(self):
137+
"""Gets the compensated temperature in degrees celsius."""
138+
UT = self.read_raw_temp()
139+
# Datasheet value for debugging:
140+
#UT = 27898
141+
# Calculations below are taken straight from section 3.5 of the datasheet.
142+
X1 = ((UT - self.cal_AC6) * self.cal_AC5) >> 15
143+
X2 = (self.cal_MC << 11) // (X1 + self.cal_MD)
144+
B5 = X1 + X2
145+
temp = ((B5 + 8) >> 4) / 10.0
146+
self._logger.debug('Calibrated temperature {0} C'.format(temp))
147+
return temp
148148

149-
def read_pressure(self):
150-
"""Gets the compensated pressure in Pascals."""
151-
UT = self.read_raw_temp()
152-
UP = self.read_raw_pressure()
153-
# Datasheet values for debugging:
154-
#UT = 27898
155-
#UP = 23843
156-
# Calculations below are taken straight from section 3.5 of the datasheet.
157-
# Calculate true temperature coefficient B5.
158-
X1 = ((UT - self.cal_AC6) * self.cal_AC5) >> 15
159-
X2 = (self.cal_MC << 11) // (X1 + self.cal_MD)
160-
B5 = X1 + X2
161-
self._logger.debug('B5 = {0}'.format(B5))
162-
# Pressure Calculations
163-
B6 = B5 - 4000
164-
self._logger.debug('B6 = {0}'.format(B6))
165-
X1 = (self.cal_B2 * (B6 * B6) >> 12) >> 11
166-
X2 = (self.cal_AC2 * B6) >> 11
167-
X3 = X1 + X2
168-
B3 = (((self.cal_AC1 * 4 + X3) << self._mode) + 2) // 4
169-
self._logger.debug('B3 = {0}'.format(B3))
170-
X1 = (self.cal_AC3 * B6) >> 13
171-
X2 = (self.cal_B1 * ((B6 * B6) >> 12)) >> 16
172-
X3 = ((X1 + X2) + 2) >> 2
173-
B4 = (self.cal_AC4 * (X3 + 32768)) >> 15
174-
self._logger.debug('B4 = {0}'.format(B4))
175-
B7 = (UP - B3) * (50000 >> self._mode)
176-
self._logger.debug('B7 = {0}'.format(B7))
177-
if B7 < 0x80000000:
178-
p = (B7 * 2) // B4
179-
else:
180-
p = (B7 // B4) * 2
181-
X1 = (p >> 8) * (p >> 8)
182-
X1 = (X1 * 3038) >> 16
183-
X2 = (-7357 * p) >> 16
184-
p = p + ((X1 + X2 + 3791) >> 4)
185-
self._logger.debug('Pressure {0} Pa'.format(p))
186-
return p
149+
def read_pressure(self):
150+
"""Gets the compensated pressure in Pascals."""
151+
UT = self.read_raw_temp()
152+
UP = self.read_raw_pressure()
153+
# Datasheet values for debugging:
154+
#UT = 27898
155+
#UP = 23843
156+
# Calculations below are taken straight from section 3.5 of the datasheet.
157+
# Calculate true temperature coefficient B5.
158+
X1 = ((UT - self.cal_AC6) * self.cal_AC5) >> 15
159+
X2 = (self.cal_MC << 11) // (X1 + self.cal_MD)
160+
B5 = X1 + X2
161+
self._logger.debug('B5 = {0}'.format(B5))
162+
# Pressure Calculations
163+
B6 = B5 - 4000
164+
self._logger.debug('B6 = {0}'.format(B6))
165+
X1 = (self.cal_B2 * (B6 * B6) >> 12) >> 11
166+
X2 = (self.cal_AC2 * B6) >> 11
167+
X3 = X1 + X2
168+
B3 = (((self.cal_AC1 * 4 + X3) << self._mode) + 2) // 4
169+
self._logger.debug('B3 = {0}'.format(B3))
170+
X1 = (self.cal_AC3 * B6) >> 13
171+
X2 = (self.cal_B1 * ((B6 * B6) >> 12)) >> 16
172+
X3 = ((X1 + X2) + 2) >> 2
173+
B4 = (self.cal_AC4 * (X3 + 32768)) >> 15
174+
self._logger.debug('B4 = {0}'.format(B4))
175+
B7 = (UP - B3) * (50000 >> self._mode)
176+
self._logger.debug('B7 = {0}'.format(B7))
177+
if B7 < 0x80000000:
178+
p = (B7 * 2) // B4
179+
else:
180+
p = (B7 // B4) * 2
181+
X1 = (p >> 8) * (p >> 8)
182+
X1 = (X1 * 3038) >> 16
183+
X2 = (-7357 * p) >> 16
184+
p = p + ((X1 + X2 + 3791) >> 4)
185+
self._logger.debug('Pressure {0} Pa'.format(p))
186+
return p
187187

188-
def read_altitude(self, sealevel_pa=101325.0):
189-
"""Calculates the altitude in meters."""
190-
# Calculation taken straight from section 3.6 of the datasheet.
191-
pressure = float(self.read_pressure())
192-
altitude = 44330.0 * (1.0 - pow(pressure / sealevel_pa, (1.0/5.255)))
193-
self._logger.debug('Altitude {0} m'.format(altitude))
194-
return altitude
188+
def read_altitude(self, sealevel_pa=101325.0):
189+
"""Calculates the altitude in meters."""
190+
# Calculation taken straight from section 3.6 of the datasheet.
191+
pressure = float(self.read_pressure())
192+
altitude = 44330.0 * (1.0 - pow(pressure / sealevel_pa, (1.0/5.255)))
193+
self._logger.debug('Altitude {0} m'.format(altitude))
194+
return altitude
195195

196-
def read_sealevel_pressure(self, altitude_m=0.0):
197-
"""Calculates the pressure at sealevel when given a known altitude in
198-
meters. Returns a value in Pascals."""
199-
pressure = float(self.read_pressure())
200-
p0 = pressure / pow(1.0 - altitude_m/44330.0, 5.255)
201-
self._logger.debug('Sealevel pressure {0} Pa'.format(p0))
202-
return p0
196+
def read_sealevel_pressure(self, altitude_m=0.0):
197+
"""Calculates the pressure at sealevel when given a known altitude in
198+
meters. Returns a value in Pascals."""
199+
pressure = float(self.read_pressure())
200+
p0 = pressure / pow(1.0 - altitude_m/44330.0, 5.255)
201+
self._logger.debug('Sealevel pressure {0} Pa'.format(p0))
202+
return p0

examples/simpletest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
# Optionally you can override the bus number:
4040
#sensor = BMP085.BMP085(busnum=2)
4141

42-
# You can also optionally change the BMP085 mode to one of BMP085_ULTRALOWPOWER,
42+
# You can also optionally change the BMP085 mode to one of BMP085_ULTRALOWPOWER,
4343
# BMP085_STANDARD, BMP085_HIGHRES, or BMP085_ULTRAHIGHRES. See the BMP085
4444
# datasheet for more details on the meanings of each mode (accuracy and power
4545
# consumption are primarily the differences). The default mode is STANDARD.

setup.py

+20-10
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,23 @@
22
use_setuptools()
33
from setuptools import setup, find_packages
44

5-
setup(name = 'Adafruit_BMP',
6-
version = '1.5.0',
7-
author = 'Tony DiCola',
8-
author_email = 'tdicola@adafruit.com',
9-
description = 'Library for accessing the BMP series pressure and temperature sensors like the BMP085/BMP180 on a Raspberry Pi or Beaglebone Black.',
10-
license = 'MIT',
11-
url = 'https://github.com/adafruit/Adafruit_Python_BMP/',
12-
dependency_links = ['https://github.com/adafruit/Adafruit_Python_GPIO/tarball/master#egg=Adafruit-GPIO-0.6.5'],
13-
install_requires = ['Adafruit-GPIO>=0.6.5'],
14-
packages = find_packages())
5+
classifiers = ['Development Status :: 4 - Beta',
6+
'Operating System :: POSIX :: Linux',
7+
'License :: OSI Approved :: MIT License',
8+
'Intended Audience :: Developers',
9+
'Programming Language :: Python :: 2.7',
10+
'Programming Language :: Python :: 3',
11+
'Topic :: Software Development',
12+
'Topic :: System :: Hardware']
13+
14+
setup(name = 'Adafruit_BMP',
15+
version = '1.5.1',
16+
author = 'Tony DiCola',
17+
author_email = 'tdicola@adafruit.com',
18+
description = 'Library for accessing the BMP series pressure and temperature sensors like the BMP085/BMP180 on a Raspberry Pi or Beaglebone Black.',
19+
license = 'MIT',
20+
classifiers = classifiers,
21+
url = 'https://github.com/adafruit/Adafruit_Python_BMP/',
22+
dependency_links = ['https://github.com/adafruit/Adafruit_Python_GPIO/tarball/master#egg=Adafruit-GPIO-0.6.5'],
23+
install_requires = ['Adafruit-GPIO>=0.6.5'],
24+
packages = find_packages())

0 commit comments

Comments
 (0)