Skip to content

Commit 7feacba

Browse files
committed
bq27441: remove debug print statements from driver.
Closes #16
1 parent fb0eb83 commit 7feacba

1 file changed

Lines changed: 9 additions & 47 deletions

File tree

lib/bq27441/bq27441/device.py

Lines changed: 9 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from utime import sleep_ms, ticks_ms
55
from machine import Pin, I2C
66

7-
import sys
87
import struct
98

109

@@ -94,7 +93,6 @@ def __init__(
9493
self.gpout_pin = gpout_pin
9594
self.capacity_mAh = capacity_mAh
9695
self.configure_gpout_input()
97-
print("call power_up after init to use")
9896
self.power_up()
9997

10098
def configure_gpout_input(self):
@@ -111,9 +109,8 @@ def power_up(self):
111109
sleep_ms(10)
112110
try:
113111
self.set_capacity(self.capacity_mAh)
114-
except Exception as e:
115-
print("Failed to wake up fuel gauge: %s" % e)
116-
sys.print_exception(e)
112+
except Exception:
113+
raise
117114

118115
def power_down(self):
119116
"""Put fuel gauge ic in shutdown mode by sending shutdown i2c cmd"""
@@ -129,7 +126,6 @@ def enter_shutdown_mode(self):
129126
self.configure_gpout_input()
130127
self.enable_shutdown_mode()
131128
self.executeControlWord(BQ27441_CONTROL_SHUTDOWN)
132-
print("WARNING: will need to power cycle board in order to use FuelGauge again")
133129

134130
def disable_shutdown_mode(self):
135131
if self.gpout_pin:
@@ -162,55 +158,29 @@ def current_average(self):
162158
try:
163159
result = self.current(CurrentMeasureType.AVG)
164160
return result
165-
except Exception as e:
166-
print("Failed to get average current (mA): %s" % e)
167-
sys.print_exception(e)
161+
except Exception:
162+
raise
168163

169164
def capacity_full(self):
170165
"""Return full capacity (mAh)"""
171-
try:
172-
result = self.capacity(CapacityMeasureType.FULL)
173-
return result
174-
except Exception as e:
175-
print("Failed to get max capacity (mAh): %s" % e)
176-
sys.print_exception(e)
166+
return self.capacity(CapacityMeasureType.FULL)
177167

178168
def capacity_remaining(self):
179169
"""Return remaining capacity (mAh)"""
180-
try:
181-
result = self.capacity(CapacityMeasureType.REMAIN)
182-
return result
183-
except Exception as e:
184-
print("Failed to get average current (mA): %s" % e)
185-
sys.print_exception(e)
170+
return self.capacity(CapacityMeasureType.REMAIN)
186171

187172
def state_of_charge(self):
188173
"""Return remaining charge %"""
189-
try:
190-
result = self.soc(SocMeasureType.FILTERED)
191-
return result
192-
except Exception as e:
193-
print("Failed to get state of charge (soc): %s" % e)
194-
sys.print_exception(e)
174+
return self.soc(SocMeasureType.FILTERED)
195175

196176
def state_of_health(self):
197177
"""Return state of health %"""
198-
try:
199-
result = self.soh(SohMeasureType.PERCENT)
200-
return result
201-
except Exception as e:
202-
print("Failed to get state of health (soh): %s" % e)
203-
sys.print_exception(e)
178+
return self.soh(SohMeasureType.PERCENT)
204179

205180
# Reads and returns the battery voltage
206181
def voltage(self):
207182
"""Return current voltage"""
208-
try:
209-
result = self.readWord(BQ27441_COMMAND_VOLTAGE)
210-
return result
211-
except Exception as e:
212-
print("Failed to get voltage: %s" % e)
213-
sys.print_exception(e)
183+
return self.readWord(BQ27441_COMMAND_VOLTAGE)
214184

215185
# Reads and returns the specified current measurement
216186
def current(self, current_measure_type):
@@ -396,7 +366,6 @@ def get_time_ms(self):
396366
# Enter configuration mode - set userControl if calling from an Arduino sketch
397367
# and you want control over when to exitConfig
398368
def enterConfig(self, userControl):
399-
print("enterConfig")
400369
if userControl:
401370
self._userConfigControl = True
402371

@@ -427,7 +396,6 @@ def exitConfig(self, resim=True):
427396
# measurement, and without resimulating to update unfiltered - SoC and SoC.
428397
# If a new OCV measurement or resimulation is desired, SOFT_RESET or
429398
# EXIT_RESIM should be used to exit config mode.
430-
print("exitConfig")
431399
if resim:
432400
if self.softReset():
433401
start_ms = self.get_time_ms()
@@ -524,19 +492,16 @@ def executeControlWord(self, function):
524492
# Extended Data Cmds
525493
# Issue a BlockDataControl() command to enable BlockData access
526494
def blockDataControl(self):
527-
print("blockDataControl")
528495
enableByte = [0x00]
529496
return self.i2cWriteBytes(BQ27441_EXTENDED_CONTROL, enableByte, 1)
530497

531498
# Issue a DataClass() command to set the data class to be accessed
532499

533500
def blockDataClass(self, _id):
534-
print("blockDataClass")
535501
return self.i2cWriteBytes(BQ27441_EXTENDED_DATACLASS, _id, 1)
536502

537503
# Issue a DataBlock() command to set the data block to be accessed
538504
def blockDataOffset(self, offset):
539-
print("blockDataOffset %s" % offset)
540505
offset = [offset]
541506
return self.i2cWriteBytes(BQ27441_EXTENDED_DATABLOCK, offset, 1)
542507

@@ -560,7 +525,6 @@ def writeBlockData(self, offset, data):
560525
# Read all 32 bytes of the loaded extended data and compute a
561526
# checksum based on the values.
562527
def computeBlockChecksum(self):
563-
print("computeBlockChecksum")
564528
data = self.i2cReadBytes(BQ27441_EXTENDED_BLOCKDATA, 32)
565529
csum = 0
566530
for i in range(32):
@@ -600,7 +564,6 @@ def readExtendedData(self, classID, offset):
600564
# class ID, position offset.
601565

602566
def writeExtendedData(self, class_id, offset, data, length):
603-
print("writeExtendedData")
604567
if length > 32:
605568
return False
606569

@@ -618,7 +581,6 @@ def writeExtendedData(self, class_id, offset, data, length):
618581
self.blockDataChecksum()
619582

620583
# Write data bytes:
621-
print("write data bytes for length %d" % length)
622584
for i in range(length):
623585
# Write to offset, mod 32 if offset is greater than 32 The blockDataOffset above sets
624586
# the 32 - bit block

0 commit comments

Comments
 (0)