hidpp10: split reg07 (battery) parsing so it can be reused

This commit is contained in:
Peter Wu 2013-04-30 19:53:15 +02:00
parent 0f80901bce
commit d8e469a33a
1 changed files with 12 additions and 9 deletions

View File

@ -96,6 +96,9 @@ def get_battery(device):
if reply:
level = ord(reply[:1])
battery_status = ord(reply[1:2])
return parse_battery_reply(level, battery_status)
def parse_battery_reply(level, battery_status):
charge = (90 if level == 7 # full
else 50 if level == 5 # good
else 20 if level == 3 # low