Battery indication on byobu

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Battery indication on byobu

Leandro Noferini
Ciao a tutti,

in my X240 with debian unstable I am using tpl (from
http://repo.linrunner.de/debian repository) to control the power
managment.

Everythingworks fine but I cannot understand how to have the
correct indication in my byobu configuration.

Does somebody know a way?

--
leandro
http://6xukrlqedfabdjrb.onion

signature.asc (474 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Battery indication on byobu

Jochen Spieker
Leandro Noferini:
> Ciao a tutti,
>
> in my X240 with debian unstable I am using tpl (from
> http://repo.linrunner.de/debian repository) to control the power
> managment.
>
> Everythingworks fine but I cannot understand how to have the
> correct indication in my byobu configuration.

I don't know byobu, but I have blogged about how I display battery
status in awesoem WM here:

http://blog.well-adjusted.de/posts/x240/

J.
--
I think the environment will be okay.
[Agree]   [Disagree]
                 <http://www.slowlydownward.com/NODATA/data_enter2.html>

signature.asc (836 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Battery indication on byobu

Leandro Noferini
Jochen Spieker <[hidden email]> writes:

> http://blog.well-adjusted.de/posts/x240/

Thanks a lot, I bookmarked your site and with the help of translation
services I will enjoy!

:-)

--
leandro
http://6xukrlqedfabdjrb.onion

signature.asc (474 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Battery indication on byobu

Jochen Spieker
Leandro Noferini:
> Jochen Spieker <[hidden email]> writes:
>
>> http://blog.well-adjusted.de/posts/x240/
>
> 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 = {}
    local cap_sum = 0
    local pow_sum = 0
    local now_sum = 0
    for i = 0, 9 do
        local cur_battery = {}
        local adapter = "BAT"..i
        local fnow = io.open("/sys/class/power_supply/"..adapter.."/energy_now")
        if fnow == nil then
            break
        end
        local fcap = io.open("/sys/class/power_supply/"..adapter.."/energy_full")
        local fdes = io.open("/sys/class/power_supply/"..adapter.."/energy_full_design")
        local fsta = io.open("/sys/class/power_supply/"..adapter.."/status")
        local fpow = io.open("/sys/class/power_supply/"..adapter.."/power_now")
        cur_battery.name = adapter
        cur_battery.now = fnow:read()
        cur_battery.cap = fcap:read()
        cur_battery.des = fdes:read()
        cur_battery.sta = fsta:read()
        cur_battery.pow = fpow:read()
        cap_sum = cap_sum + cur_battery.cap
        pow_sum = pow_sum + cur_battery.pow
        now_sum = now_sum + cur_battery.now
        fnow:close()
        fcap:close()
        fdes:close()
        fsta:close()
        fpow:close()
        batteries[i] = cur_battery
    end

    widget.text = " "
    local charge_status = 0
    local minutes = "--"
    local hours = "--"
    for idx, battery in pairs(batteries) do
        local arrow = "→"
        if battery.sta:match("^Discharging$") then
            arrow = "↘"
            charge_status = -1
        elseif battery.sta:match("^Charging$") then
            arrow = "↗"
            charge_status = 1
        end
        local percentage = math.floor(battery.now * 100 / battery.des)
        widget.text = widget.text .. arrow .. percentage .. "%  "
    end

    if charge_status < 0 then
        minutes = string.format("%02i", math.floor(60*now_sum/pow_sum % 60))
        hours = string.format("%02i", math.floor(now_sum/pow_sum))
    elseif charge_status > 0 then
        minutes = string.format( "%02i", math.floor(60*(cap_sum-now_sum)/pow_sum % 60) )
        hours = string.format( "%02i", math.floor((cap_sum-now_sum)/pow_sum) )
    end
    widget.text = widget.text .. " ("..hours..":"..minutes..")"
end


J.
--
If you do not move for long enough, you might see a rat.
[Agree]   [Disagree]
                 <http://www.slowlydownward.com/NODATA/data_enter2.html>

signature.asc (836 bytes) Download Attachment
Loading...