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

Commit 172490d

Browse files
committed
Python 3 compatibilty fixes
1 parent e753669 commit 172490d

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

Adafruit_BMP/BMP085.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1919
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2020
# THE SOFTWARE.
21+
from __future__ import division
2122
import logging
2223
import time
2324

@@ -139,7 +140,7 @@ def read_temperature(self):
139140
#UT = 27898
140141
# Calculations below are taken straight from section 3.5 of the datasheet.
141142
X1 = ((UT - self.cal_AC6) * self.cal_AC5) >> 15
142-
X2 = (self.cal_MC << 11) / (X1 + self.cal_MD)
143+
X2 = (self.cal_MC << 11) // (X1 + self.cal_MD)
143144
B5 = X1 + X2
144145
temp = ((B5 + 8) >> 4) / 10.0
145146
self._logger.debug('Calibrated temperature {0} C'.format(temp))
@@ -155,7 +156,7 @@ def read_pressure(self):
155156
# Calculations below are taken straight from section 3.5 of the datasheet.
156157
# Calculate true temperature coefficient B5.
157158
X1 = ((UT - self.cal_AC6) * self.cal_AC5) >> 15
158-
X2 = (self.cal_MC << 11) / (X1 + self.cal_MD)
159+
X2 = (self.cal_MC << 11) // (X1 + self.cal_MD)
159160
B5 = X1 + X2
160161
self._logger.debug('B5 = {0}'.format(B5))
161162
# Pressure Calculations
@@ -164,7 +165,7 @@ def read_pressure(self):
164165
X1 = (self.cal_B2 * (B6 * B6) >> 12) >> 11
165166
X2 = (self.cal_AC2 * B6) >> 11
166167
X3 = X1 + X2
167-
B3 = (((self.cal_AC1 * 4 + X3) << self._mode) + 2) / 4
168+
B3 = (((self.cal_AC1 * 4 + X3) << self._mode) + 2) // 4
168169
self._logger.debug('B3 = {0}'.format(B3))
169170
X1 = (self.cal_AC3 * B6) >> 13
170171
X2 = (self.cal_B1 * ((B6 * B6) >> 12)) >> 16
@@ -174,9 +175,9 @@ def read_pressure(self):
174175
B7 = (UP - B3) * (50000 >> self._mode)
175176
self._logger.debug('B7 = {0}'.format(B7))
176177
if B7 < 0x80000000:
177-
p = (B7 * 2) / B4
178+
p = (B7 * 2) // B4
178179
else:
179-
p = (B7 / B4) * 2
180+
p = (B7 // B4) * 2
180181
X1 = (p >> 8) * (p >> 8)
181182
X1 = (X1 * 3038) >> 16
182183
X2 = (-7357 * p) >> 16

examples/simpletest.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
# consumption are primarily the differences). The default mode is STANDARD.
4646
#sensor = BMP085.BMP085(mode=BMP085.BMP085_ULTRAHIGHRES)
4747

48-
print 'Temp = {0:0.2f} *C'.format(sensor.read_temperature())
49-
print 'Pressure = {0:0.2f} Pa'.format(sensor.read_pressure())
50-
print 'Altitude = {0:0.2f} m'.format(sensor.read_altitude())
51-
print 'Sealevel Pressure = {0:0.2f} Pa'.format(sensor.read_sealevel_pressure())
48+
print('Temp = {0:0.2f} *C'.format(sensor.read_temperature()))
49+
print('Pressure = {0:0.2f} Pa'.format(sensor.read_pressure()))
50+
print('Altitude = {0:0.2f} m'.format(sensor.read_altitude()))
51+
print('Sealevel Pressure = {0:0.2f} Pa'.format(sensor.read_sealevel_pressure()))

0 commit comments

Comments
 (0)