File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -110,11 +110,12 @@ bq.soh(SohMeasureType.SOH_STAT) # Health status bits
110110#### Temperature
111111
112112``` python
113- bq.temperature(TempMeasureType.BATTERY ) # Battery temperature
114- bq.temperature(TempMeasureType.INTERNAL_TEMP ) # Internal IC temperature
115- ```
113+ bq.temperature() # Battery temperature in °C (default)
114+ bq.temperature(TempMeasureType.INTERNAL_TEMP ) # Internal IC temperature in °C
116115
117- ** Note:** Temperature is returned as a raw register value (units of 0.1 K). To convert to °C: ` temp_c = raw / 10.0 - 273.15 ` .
116+ bq.temperature_k() # Battery temperature in Kelvin
117+ bq.temperature_dk() # Battery temperature in decikelvin (raw)
118+ ```
118119
119120### Configuration
120121
@@ -208,4 +209,4 @@ mpremote mount lib/bq27441 run lib/bq27441/examples/fuel_gauge.py
208209* Default design capacity is 650 mAh (configurable via ` set_capacity() ` ).
209210* Some configuration operations require entering config mode with ` enter_config() ` .
210211* The device may be sealed; use ` unseal() ` before advanced configuration.
211- * Temperature readings are raw register values in 0.1 K units (see conversion above) .
212+ * ` temperature() ` returns °C by default. Use ` temperature_k() ` for Kelvin or ` temperature_dk() ` for raw decikelvin .
Original file line number Diff line number Diff line change @@ -242,15 +242,22 @@ def soh(self, soh_measure_type=SohMeasureType.PERCENT):
242242 else :
243243 return soh_status
244244
245- # Reads and returns specified temperature measurement
246- def temperature (self , temp_measure_type ):
247- temp = 0
245+ def _read_temperature_dk (self , temp_measure_type = TempMeasureType .BATTERY ):
248246 if temp_measure_type == TempMeasureType .BATTERY :
249- temp = self .read_word (BQ27441_COMMAND_TEMP )
247+ return self .read_word (BQ27441_COMMAND_TEMP )
250248 elif temp_measure_type == TempMeasureType .INTERNAL_TEMP :
251- temp = self .read_word (BQ27441_COMMAND_INT_TEMP )
249+ return self .read_word (BQ27441_COMMAND_INT_TEMP )
250+ else :
251+ raise ValueError ("Unsupported TempMeasureType: {!r}" .format (temp_measure_type ))
252+
253+ def temperature (self , temp_measure_type = TempMeasureType .BATTERY ):
254+ return self ._read_temperature_dk (temp_measure_type ) / 10.0 - 273.15
255+
256+ def temperature_k (self , temp_measure_type = TempMeasureType .BATTERY ):
257+ return self ._read_temperature_dk (temp_measure_type ) / 10.0
252258
253- return temp
259+ def temperature_dk (self , temp_measure_type = TempMeasureType .BATTERY ):
260+ return self ._read_temperature_dk (temp_measure_type )
254261
255262 # GPOUT Control Functions
256263
Original file line number Diff line number Diff line change @@ -90,11 +90,24 @@ tests:
9090 expect : 25
9191 mode : [mock]
9292
93- - name : " Battery temperature raw register value from mock data "
93+ - name : " Battery temperature in Celsius "
9494 action : script
9595 script : |
96- from bq27441.device import TempMeasureType
97- result = dev.temperature(TempMeasureType.BATTERY)
96+ result = dev.temperature()
97+ expect_range : [24.94, 24.96]
98+ mode : [mock]
99+
100+ - name : " Battery temperature in Kelvin"
101+ action : script
102+ script : |
103+ result = dev.temperature_k()
104+ expect_range : [298.09, 298.11]
105+ mode : [mock]
106+
107+ - name : " Battery temperature in decikelvin"
108+ action : script
109+ script : |
110+ result = dev.temperature_dk()
98111 expect : 2981
99112 mode : [mock]
100113
You can’t perform that action at this time.
0 commit comments