@@ -63,19 +63,31 @@ def __init__(self, address=0x77, mode=1, debug=False):
63
63
# Read the calibration data
64
64
self .readCalibrationData ()
65
65
66
+ def readS16 (self , register ):
67
+ "Reads a signed 16-bit value"
68
+ hi = self .i2c .readS8 (register )
69
+ lo = self .i2c .readU8 (register + 1 )
70
+ return (hi << 8 ) + lo
71
+
72
+ def readU16 (self , register ):
73
+ "Reads an unsigned 16-bit value"
74
+ hi = self .i2c .readU8 (register )
75
+ lo = self .i2c .readU8 (register + 1 )
76
+ return (hi << 8 ) + lo
77
+
66
78
def readCalibrationData (self ):
67
79
"Reads the calibration data from the IC"
68
- self ._cal_AC1 = self .i2c . readS16 (self .__BMP085_CAL_AC1 ) # INT16
69
- self ._cal_AC2 = self .i2c . readS16 (self .__BMP085_CAL_AC2 ) # INT16
70
- self ._cal_AC3 = self .i2c . readS16 (self .__BMP085_CAL_AC3 ) # INT16
71
- self ._cal_AC4 = self .i2c . readU16 (self .__BMP085_CAL_AC4 ) # UINT16
72
- self ._cal_AC5 = self .i2c . readU16 (self .__BMP085_CAL_AC5 ) # UINT16
73
- self ._cal_AC6 = self .i2c . readU16 (self .__BMP085_CAL_AC6 ) # UINT16
74
- self ._cal_B1 = self .i2c . readS16 (self .__BMP085_CAL_B1 ) # INT16
75
- self ._cal_B2 = self .i2c . readS16 (self .__BMP085_CAL_B2 ) # INT16
76
- self ._cal_MB = self .i2c . readS16 (self .__BMP085_CAL_MB ) # INT16
77
- self ._cal_MC = self .i2c . readS16 (self .__BMP085_CAL_MC ) # INT16
78
- self ._cal_MD = self .i2c . readS16 (self .__BMP085_CAL_MD ) # INT16
80
+ self ._cal_AC1 = self .readS16 (self .__BMP085_CAL_AC1 ) # INT16
81
+ self ._cal_AC2 = self .readS16 (self .__BMP085_CAL_AC2 ) # INT16
82
+ self ._cal_AC3 = self .readS16 (self .__BMP085_CAL_AC3 ) # INT16
83
+ self ._cal_AC4 = self .readU16 (self .__BMP085_CAL_AC4 ) # UINT16
84
+ self ._cal_AC5 = self .readU16 (self .__BMP085_CAL_AC5 ) # UINT16
85
+ self ._cal_AC6 = self .readU16 (self .__BMP085_CAL_AC6 ) # UINT16
86
+ self ._cal_B1 = self .readS16 (self .__BMP085_CAL_B1 ) # INT16
87
+ self ._cal_B2 = self .readS16 (self .__BMP085_CAL_B2 ) # INT16
88
+ self ._cal_MB = self .readS16 (self .__BMP085_CAL_MB ) # INT16
89
+ self ._cal_MC = self .readS16 (self .__BMP085_CAL_MC ) # INT16
90
+ self ._cal_MD = self .readS16 (self .__BMP085_CAL_MD ) # INT16
79
91
if (self .debug ):
80
92
self .showCalibrationData ()
81
93
@@ -97,7 +109,7 @@ def readRawTemp(self):
97
109
"Reads the raw (uncompensated) temperature from the sensor"
98
110
self .i2c .write8 (self .__BMP085_CONTROL , self .__BMP085_READTEMPCMD )
99
111
time .sleep (0.005 ) # Wait 5ms
100
- raw = self .i2c . readU16 (self .__BMP085_TEMPDATA )
112
+ raw = self .readU16 (self .__BMP085_TEMPDATA )
101
113
if (self .debug ):
102
114
print "DBG: Raw Temp: 0x%04X (%d)" % (raw & 0xFFFF , raw )
103
115
return raw
0 commit comments