Skip to content

Commit

Permalink
Merge pull request #75 from iory/mp2760
Browse files Browse the repository at this point in the history
Write default value to register 0x10 (configuration register)
  • Loading branch information
iory authored Nov 2, 2024
2 parents 767052d + 5918029 commit 5956d3b
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions riberry/battery/mp2760.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,15 @@ def limit_charge_current(self, set_current): # unit: [mA]
return
return True

def write_default_value_to_0x10_register(self):
try:
self.bus.write_word_data(self.device_address, 0x10, 0x0A74)
print("[Battery Monitor] Successfully wrote 0x0A74 to register 0x10.")
return True
except Exception as e:
print(f"[Battery Monitor] Error writing to register 0x10: {e}")
return False

def read_charge_current_limit(self): # unit: [mA]
try:
bits = self.bus.read_word_data(self.device_address, 0x14)
Expand Down Expand Up @@ -404,7 +413,12 @@ def read_sensor_data(self, get_charge=False):

def run(self):
try:
loop_count = 0
while self.running:
loop_count += 1
if loop_count % 100 == 0:
self.write_default_value_to_0x10_register()
loop_count = 0
self.status_and_fault = self.read_register(0x17)
self.status_and_fault_string = print_status_and_fault_register(
self.status_and_fault
Expand Down

0 comments on commit 5956d3b

Please sign in to comment.