Skip to content

Instantly share code, notes, and snippets.

@daniel-j
Created May 4, 2018 08:10
Show Gist options
  • Save daniel-j/aa7ab05683a2e36b92d64e249e884f61 to your computer and use it in GitHub Desktop.
Save daniel-j/aa7ab05683a2e36b92d64e249e884f61 to your computer and use it in GitHub Desktop.
Script to read the battery drain/charge rate of the GPD Pocket, outputs wattage. Negative is draining, positive is charging.
#!/usr/bin/python3
dir='/sys/class/power_supply/max170xx_battery/'
with open(dir + 'current_avg', 'r') as f:
current = int(f.read()) / 1000000.0
with open(dir + 'voltage_avg', 'r') as f:
voltage = int(f.read()) / 1000000.0
wattage = voltage * current
# print('{0:.2f}V {1:.2f}A {2:.2f}W'.format(voltage, current, wattage))
print('{0:.2f}W'.format(wattage))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment