Skip to content

Instantly share code, notes, and snippets.

@kimusan
Forked from parkerlreed/typec.sh
Created May 7, 2018 08:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kimusan/07e8a63860047fa2fd51833f53a43a27 to your computer and use it in GitHub Desktop.
Save kimusan/07e8a63860047fa2fd51833f53a43a27 to your computer and use it in GitHub Desktop.
#!/bin/bash
voltage() { cat /sys/class/power_supply/fusb302-typec-source/voltage_now; }
voltage_actual() { cat /sys/class/power_supply/max170xx_battery/voltage_now; }
current_actual() { cat /sys/class/power_supply/max170xx_battery/current_now; }
current() { cat /sys/class/power_supply/fusb302-typec-source/current_max; }
current_limit() { cat /sys/class/power_supply/bq24190-charger/input_current_limit; }
capacity() { cat /sys/class/power_supply/max170xx_battery/capacity; }
breaker() { echo "------------------------------------------------------"; }
echo "Voltage: $(expr `voltage` / 1000000)V DC"
echo "Voltage (battery): $(echo 'scale=2; '$(voltage_actual)'/1000000' | bc)V DC"
echo "Current (battery): $(echo 'scale=2; '$(current_actual)'/1000000' | bc)A"
echo "Current (negotiated): $(echo 'scale=2; '$(current)'/1000000' | bc)A"
echo "Current (max): $(echo 'scale=2; '$(current_limit)'/1000000' | bc)A"
echo "Capacity: $(capacity)%"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment