[ltp] Re: Battery indication on byobu
Jochen Spieker
linux-thinkpad@linux-thinkpad.org
Mon, 20 Apr 2015 14:12:45 +0200
--7JfCtLOvnd9MIVvH
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
Leandro Noferini:
> Jochen Spieker <ml@well-adjusted.de> writes:
>=20
>> http://blog.well-adjusted.de/posts/x240/
>=20
> Thanks a lot, I bookmarked your site and with the help of translation
> services I will enjoy!
Sorry, I didn't mention it's in German. But just search for tp-smapi,
then you will find the Lua code that I use to create a text display of
battery status.
I have since tweaked this a little bit and have a combined display of
remaining time:
function batteryInfo(widget)
local batteries =3D {}
local cap_sum =3D 0
local pow_sum =3D 0
local now_sum =3D 0
for i =3D 0, 9 do
local cur_battery =3D {}
local adapter =3D "BAT"..i
local fnow =3D io.open("/sys/class/power_supply/"..adapter.."/energ=
y_now")
if fnow =3D=3D nil then
break
end
local fcap =3D io.open("/sys/class/power_supply/"..adapter.."/energ=
y_full")
local fdes =3D io.open("/sys/class/power_supply/"..adapter.."/energ=
y_full_design")
local fsta =3D io.open("/sys/class/power_supply/"..adapter.."/statu=
s")
local fpow =3D io.open("/sys/class/power_supply/"..adapter.."/power=
_now")
cur_battery.name =3D adapter
cur_battery.now =3D fnow:read()
cur_battery.cap =3D fcap:read()
cur_battery.des =3D fdes:read()
cur_battery.sta =3D fsta:read()
cur_battery.pow =3D fpow:read()
cap_sum =3D cap_sum + cur_battery.cap
pow_sum =3D pow_sum + cur_battery.pow
now_sum =3D now_sum + cur_battery.now
fnow:close()
fcap:close()
fdes:close()
fsta:close()
fpow:close()
batteries[i] =3D cur_battery
end
widget.text =3D " "
local charge_status =3D 0
local minutes =3D "--"
local hours =3D "--"
for idx, battery in pairs(batteries) do
local arrow =3D "=E2=86=92"
if battery.sta:match("^Discharging$") then
arrow =3D "=E2=86=98"
charge_status =3D -1
elseif battery.sta:match("^Charging$") then
arrow =3D "=E2=86=97"
charge_status =3D 1
end
local percentage =3D math.floor(battery.now * 100 / battery.des)
widget.text =3D widget.text .. arrow .. percentage .. "% "
end
if charge_status < 0 then
minutes =3D string.format("%02i", math.floor(60*now_sum/pow_sum % 6=
0))
hours =3D string.format("%02i", math.floor(now_sum/pow_sum))
elseif charge_status > 0 then
minutes =3D string.format( "%02i", math.floor(60*(cap_sum-now_sum)/=
pow_sum % 60) )
hours =3D string.format( "%02i", math.floor((cap_sum-now_sum)/pow_s=
um) )
end
widget.text =3D widget.text .. " ("..hours..":"..minutes..")"
end
J.
--=20
If you do not move for long enough, you might see a rat.
[Agree] [Disagree]
<http://www.slowlydownward.com/NODATA/data_enter2.html>
--7JfCtLOvnd9MIVvH
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
iQIcBAEBCAAGBQJVNO07AAoJEFOK7jlDb4WXQs4P/1Kzn65xAnCiMxi0dKFcxzCl
6S2T4hcJifscOdBV64A4OJQ8EJZJBIoFV21+0Q8qoLP7UA4nLkEWZPYcGH+2IIH7
APY7sv96X5Dija5ycZD4i8c0YoAasAbDYCAlJml6fbDjTQlbFimCcbh5/GeC/WkC
qFzY7JLF4Qx4X1wZAdGzT43lfO+FzRa/hjIIBEtm4crXpNn8e5SbQeTkxiUh+VYB
CxSXa9+9jTLOnA2SRkCdhX65/16pSIn4uXdMwz9JsGmSBtTnqYE6pVlN6Zch6NGr
P9pS1J6qdo0JcQOKt/nDSPKJary04i+3KU3lYsAkoRI5O71pvD3QSQm1fl3aXlSl
kErejqDr1MwvIvqWPpmuIGKnlcgEcj+C3x052n2uj1BeDiQvgcAcWn/pDeBuvPen
Xa6fNaE0FylzhwgNGzNfQzys+Tf/s9VFVtA1RGV5DB0JDOT73bCQ0dl24mxxyocJ
FKS2J/7qp/gpBcmo0SHBLOs96NJjEd9VybRfKV/lTs825ATR2IamyxbpHPzMFTGc
FnY6f9VdRAzWO3EvwEtF3U/D0KX9834REe5xqSZGEkbzWFSsLMLuGYGjBZ0SlWqe
XohezxD05F44/Tq56gMMgM0IlsT+VQqAbUCa8GZrpPqS5+ZBWbOilhVgQEYDKcOC
E7sSIbfLzdLnk6S6kaLC
=1y22
-----END PGP SIGNATURE-----
--7JfCtLOvnd9MIVvH--