Hi guys,

This is the third time I'm trying to post on this list, hopefully it'll work.

First, I'd like to thank Tuomo and all other who have contributed
to make ion such a great w. manager.

Second, sorry for not continuing with the existing thread on battery info
meter and such, but when that thread started I wasn't registered to
this list.  

I have some older code which was also doing the battery
meter thing, plus some other meters: network interface and ip address 
meter (including wifi), cpuspeed, etc.  I'll just append it below, and if 
anyone has use of it or wants to change it, so
be it.  The main difference is that this code will work with apm, as
my acpi isn't yet there (buggy) on my thinkpad.

Please take this code with a grain of salt; I'm new to lua and ion.  Any
suggestions for improvement are certainly welcome.

Best regards,
  -- relu

In .ion3/cfg_statusbar.lua, I personally use the minimal wifi info as follows:

template="%cpuspeed MHz  ..  %batt  ..  %iface%inet_addr%iw_info_min 
..  %date",


Permission to use all the code below is subject to the same licensing
agreement as the ion3 code.


-- cpuspeed meter {{{

local cpuspeed
local function get_cpuspeed_proc()
    local f=io.open('/proc/cpuinfo', 'r')
    if not f then
        return ""
    end
    local s=f:read('*a')
    f:close()
    local st, en, cpuspeed = string.find(s, 'cpu MHz[%s]*:[%s]*(%d+%.%d+)')
    return tostring(cpuspeed)
end

-- }}}

ext_statusbar.register_meter('cpuspeed', get_cpuspeed_proc, 'xxxxxxx')


-- batt meter {{{

local battInfoStr
local function get_batt_procapm()
    local f=io.open('/proc/apm', 'r')
    if not f then
        return ""
    end
    local s=f:read('*l')
    f:close()
    local st, en, battInfoStr = string.find(s, '(%d+%% [-]*%d+ [%?]*[%a]*)$')
    battInfoStr = string.gsub(battInfoStr, '-1.*',"-(= ")
    return tostring(battInfoStr)
end

ext_statusbar.register_meter('batt', get_batt_procapm, 'xxx xxx xxxxx')

-- }}}

-- network info {{{

local iface, wifi_link, wifi_signal, wifi_noise

local function get_wifi_link()
    local f=io.open('/proc/net/wireless', 'r')
    if not f then
        return ""
    end
    -- first 2 lines -- headers
    local s=f:read('*l')
    s=f:read('*l')
    -- the third line has wifi info
    s=f:read('*l')
    f:close()
    if not s then
        return tostring(0)
    end
    local st, en, quality = string.find(s, '(%d+%. +%d+%. +%d+%.)')
    quality = string.gsub(quality,'(%.)','')
    qiter = string.gfind(quality,'(%d+)')
    wifi_link = qiter()
    return tostring(wifi_link)
end

ext_statusbar.register_meter('wifi_link', get_wifi_link, 'xxx')

local function get_wifi_signal()
    local f=io.open('/proc/net/wireless', 'r')
    if not f then
        return ""
    end
    -- first 2 lines -- headers
    local s=f:read('*l')
    s=f:read('*l')
    -- the third line has wifi info
    s=f:read('*l')
    f:close()
    if not s then
        return tostring(0)
    end
    local st, en, quality = string.find(s, '(%d+%. +%d+%. +%d+%.)')
    quality = string.gsub(quality,'(%.)','')
    qiter = string.gfind(quality,'(%d+)')
    wifi_signal = qiter()
    wifi_signal = qiter()
    return tostring(256-wifi_signal)
end

ext_statusbar.register_meter('wifi_signal', get_wifi_signal, 'xxx')

local function get_wifi_noise()
    local f=io.open('/proc/net/wireless', 'r')
    if not f then
        return ""
    end
    -- first 2 lines -- headers
    local s=f:read('*l')
    s=f:read('*l')
    -- the third line has wifi info
    s=f:read('*l')
    f:close()
    if not s then
        return tostring(0)
    end
    local st, en, quality = string.find(s, '(%d+%. +%d+%. +%d+%.)')
    quality = string.gsub(quality,'(%.)','')
    qiter = string.gfind(quality,'(%d+)')
    wifi_noise = qiter()
    wifi_noise = qiter()
    wifi_noise = qiter()
    return tostring(256-wifi_noise)
end

ext_statusbar.register_meter('wifi_noise', get_wifi_noise, 'xxx')

local function get_iw_info()
    local f=io.open('/proc/net/wireless', 'r')
    if not f then
        return ""
    end
    -- first 2 lines -- headers
    local s=f:read('*l')
    s=f:read('*l')
    -- the third line has wifi info
    s=f:read('*l')
    f:close()
        local st, en, proto, ssid, bitrate, linkq, signal, noise = 0,0,0,0,0,0,0,0
    if not s then
                return tostring("Rate: " .. bitrate  .. "  lnk: " .. linkq .. " 
s/n: " .. signal .. "/" .. noise .. "dBm 802.11" .. proto)
    end
        local st, en, iface = string.find(s, '(%w+):')
        local f1 = io.popen("iwconfig " .. iface)
        if not f1 then
                return tostring("Rate: " .. bitrate  .. "  lnk: " .. linkq .. " 
s/n: " .. signal .. "/" .. noise .. "dBm 802.11" .. proto)
        else
                local iwOut = f1:read('*a')
                local st,en,proto = string.find(iwOut, '802.11([%-]*%a+)')
                local st,en,ssid = string.find(iwOut, 'ESSID:("[%w+%s*]+")')
                if not ssid then
                        ssid="N/A"
                end
                local st,en,bitrate = string.find(iwOut, 'Bit Rate:(%w+%/%a+)')
                local st,en,linkq = string.find(iwOut, 'Link Quality:(%d+%/%d+)')
                local st,en,signal = string.find(iwOut, 'Signal level:(%-%d+)')
                local st,en,noise = string.find(iwOut, 'Noise level:(%-%d+)')
        return tostring("Rate: " .. bitrate  .. "  lnk: " .. linkq .. " 
s/n: " .. signal .. "/" .. noise .. "dBm 802.11" .. proto)
        end
end

ext_statusbar.register_meter('iw_info', get_iw_info, 'xxxxx xxxxxx
xxxx xxxxx xxxx xxxxx xxxxxxxxxxxxxx')

local function get_iface()
    local st, en
    local f=io.open('/proc/net/wireless', 'r')
    if not f then
        return ""
    end
    -- first 2 lines -- headers
    local s=f:read('*l')
    s=f:read('*l')
    -- the third line has wifi info
    s=f:read('*l')
    if not s then
                f=io.open('/proc/net/dev', 'r')
                if not f then
                        return "net off"
                end
                -- first 2 lines -- headers, next line check for lo
        s=f:read('*l')
        s=f:read('*l')
        s=f:read('*l')
        st, en, iface = string.find(s, '(%w+:)')
                if iface == 'lo:' then
                s=f:read('*l')
                end
                if not s then
                        return "net off"
                end
        st, en, iface = string.find(s, '(%w+:)')
        f:close()
        return tostring(iface) 
    end
    st, en, iface = string.find(s, '(%w+:)')
    f:close()
    return tostring(iface)
end

ext_statusbar.register_meter('iface', get_iface, 'xxxxx')

local inet_addr
local function get_inet_addr()
        local st,en,iface = string.find(tostring(get_iface()), '(%w+):')
        local f = io.popen("ifconfig " .. iface)
        if not f then
                inet_addr=""
        else
                local ifconfig_info = f:read('*a')
                st,en,inet_addr = string.find(ifconfig_info, 'inet 
addr:(%d+\.%d+\.%d+\.%d+)')
                if not inet_addr then
                        inet_addr=""
                end
        end
        return tostring(" " .. inet_addr)
end

ext_statusbar.register_meter('inet_addr', get_inet_addr, 'xxx.xxx.xxx.xxx')

local function get_iw_info_min()
    local f=io.open('/proc/net/wireless', 'r')
    if not f then
        return ""
    end
    -- first 2 lines -- headers
    local s=f:read('*l')
    s=f:read('*l')
    -- the third line has wifi info
    s=f:read('*l')
    f:close()
        local st, en, proto, ssid, bitrate, linkq, signal, noise = 0,0,0,0,0,0,0,0
    if not s then
                -- return tostring(bitrate  .. " " .. linkq .. " " .. signal .. "/"
.. noise .. "dBm 802.11" .. proto)
                return tostring("")
    end
        local st, en, iface = string.find(s, '(%w+):')
        local f1 = io.popen("iwconfig " .. iface)
        if not f1 then
                -- return tostring(bitrate  .. " " .. linkq .. " " .. signal .. "/"
.. noise .. "dBm 802.11" .. proto)
                return tostring("")
        else
                local iwOut = f1:read('*a')
                local st,en,proto = string.find(iwOut, '802.11([%-]*%a+)')
                --local st,en,ssid = string.find(iwOut, 'ESSID:("%w+")')
                local st,en,ssid = string.find(iwOut, 'ESSID:("[%w+%s*]+")')
                if not ssid then
                        ssid="N/A"
                end
                local st,en,bitrate = string.find(iwOut, 'Bit Rate:(%w+%/%a+)')
                local st,en,linkq = string.find(iwOut, 'Link Quality:(%d+%/%d+)')
                local st,en,signal = string.find(iwOut, 'Signal level:(%-%d+)')
                local st,en,noise = string.find(iwOut, 'Noise level:(%-%d+)')
                return tostring(" " .. ssid .. " " .. bitrate  .. " " .. linkq .. "
" .. signal .. "/" .. noise .. "dBm 802.11" .. proto)
        end
end

ext_statusbar.register_meter('iw_info_min', get_iw_info_min,
'xxxxxxxxxxxxxxxxxxxx xxxxxx xxxxx xxxxxxxxxx xxxxxxxx')


-- }}}

Reply via email to