Merge branch 'async' of github.com:vicious-widgets/vicious into async
This commit is contained in:
commit
687fd49376
|
@ -21,6 +21,7 @@ Fixed:
|
||||||
* wifi_linux, wifiiw_linux, hwmontemp_linux, hddtemp_linux
|
* wifi_linux, wifiiw_linux, hwmontemp_linux, hddtemp_linux
|
||||||
* bat_freebsd, mem_freebsd, net_freebsd, thermal_freebsd, uptime_freebsd,
|
* bat_freebsd, mem_freebsd, net_freebsd, thermal_freebsd, uptime_freebsd,
|
||||||
cpu_freebsd, cpufreq_freebsd, fanspeed_freebsd
|
cpu_freebsd, cpufreq_freebsd, fanspeed_freebsd
|
||||||
|
* bat_openbsd
|
||||||
* volume, gmail, mdir, mpd, fs
|
* volume, gmail, mdir, mpd, fs
|
||||||
- [mpd] Lua 5.3 compatibility (for real this time); also correct a typo
|
- [mpd] Lua 5.3 compatibility (for real this time); also correct a typo
|
||||||
- [pkg,weather,contrib/btc] Allow function call without Awesome
|
- [pkg,weather,contrib/btc] Allow function call without Awesome
|
||||||
|
@ -28,10 +29,10 @@ Fixed:
|
||||||
- [os] Splitted os_all into os_linux and os_bsd (and refactored to async)
|
- [os] Splitted os_all into os_linux and os_bsd (and refactored to async)
|
||||||
|
|
||||||
Removed:
|
Removed:
|
||||||
|
|
||||||
- `helpers.sysctl` and `helpers.sysctl_table` were removed in favour of
|
- `helpers.sysctl` and `helpers.sysctl_table` were removed in favour of
|
||||||
`helpers.sysctl_async`.
|
`helpers.sysctl_async`.
|
||||||
|
|
||||||
|
|
||||||
# Changes in 2.3.3
|
# Changes in 2.3.3
|
||||||
|
|
||||||
Feature: Add battery widget type for OpenBSD
|
Feature: Add battery widget type for OpenBSD
|
||||||
|
|
|
@ -542,7 +542,6 @@ Supported platforms: GNU/Linux.
|
||||||
`${rate}` (Mb/s), `${freq}` (MHz), `${linp}` (link quality in percent),
|
`${rate}` (Mb/s), `${freq}` (MHz), `${linp}` (link quality in percent),
|
||||||
`${txpw}` (transmission power, in dBm) and `${sign}` (signal level, in dBm)
|
`${txpw}` (transmission power, in dBm) and `${sign}` (signal level, in dBm)
|
||||||
|
|
||||||
|
|
||||||
## <a name="custom-widget"></a>Custom widget types
|
## <a name="custom-widget"></a>Custom widget types
|
||||||
|
|
||||||
Use any of the existing widget types as a starting point for your
|
Use any of the existing widget types as a starting point for your
|
||||||
|
|
|
@ -1,38 +1,57 @@
|
||||||
|
-- bat_openbsd.lua - provide battery information on OpenBSD
|
||||||
|
-- Copyright (C) 2019 Enric Morales
|
||||||
|
-- Copyright (C) 2019 Nguyễn Gia Phong
|
||||||
|
--
|
||||||
|
-- This file is part of Vicious.
|
||||||
|
--
|
||||||
|
-- Vicious is free software: you can redistribute it and/or modify
|
||||||
|
-- it under the terms of the GNU General Public License as
|
||||||
|
-- published by the Free Software Foundation, either version 2 of the
|
||||||
|
-- License, or (at your option) any later version.
|
||||||
|
--
|
||||||
|
-- Vicious is distributed in the hope that it will be useful,
|
||||||
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
-- GNU Affero General Public License for more details.
|
||||||
|
--
|
||||||
|
-- You should have received a copy of the GNU Affero General Public License
|
||||||
|
-- along with Vicious. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
-- {{{ Grab environment
|
-- {{{ Grab environment
|
||||||
local setmetatable = setmetatable
|
|
||||||
local tonumber = tonumber
|
local tonumber = tonumber
|
||||||
local string = { format = string.format, gmatch = string.gmatch }
|
|
||||||
local io = { popen = io.popen }
|
|
||||||
local math = { floor = math.floor, modf = math.modf }
|
local math = { floor = math.floor, modf = math.modf }
|
||||||
|
|
||||||
|
local helpers = require"vicious.helpers"
|
||||||
|
local spawn = require"vicious.spawn"
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
||||||
local bat_openbsd = {}
|
local STATES = { [0] = "↯", -- not charging
|
||||||
|
|
||||||
local function worker(format, warg)
|
|
||||||
local battery = warg or "bat0"
|
|
||||||
local filter = string.format("hw.sensors.acpi%s", battery)
|
|
||||||
local cmd = string.format("sysctl -a | grep '^%s'", filter)
|
|
||||||
local proc = io.popen(cmd)
|
|
||||||
|
|
||||||
local bat_info = {}
|
|
||||||
for line in proc:lines("*l") do
|
|
||||||
for key, value in string.gmatch(line, "(%S+)=(%S+)") do
|
|
||||||
key = key:gsub(filter .. ".", "")
|
|
||||||
bat_info[key] = value
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- current state
|
|
||||||
local states = {[0] = "↯", -- not charging
|
|
||||||
[1] = "-", -- discharging
|
[1] = "-", -- discharging
|
||||||
[2] = "!", -- critical
|
[2] = "!", -- critical
|
||||||
[3] = "+", -- charging
|
[3] = "+", -- charging
|
||||||
[4] = "N/A", -- unknown status
|
[4] = "N/A", -- unknown status
|
||||||
[255] = "N/A"} -- unimplemented by the driver
|
[255] = "N/A" } -- unimplemented by the driver
|
||||||
local state = states[tonumber(bat_info.raw0)]
|
|
||||||
|
return helpers.setasyncall{
|
||||||
|
async = function (format, warg, callback)
|
||||||
|
local filter = "hw.sensors.acpi" .. (warg or "bat0")
|
||||||
|
local pattern = filter .. ".(%S+)=(%S+)"
|
||||||
|
local bat_info = {}
|
||||||
|
|
||||||
|
spawn.with_line_callback_with_shell(
|
||||||
|
("sysctl -a | grep '^%s'"):format(filter),
|
||||||
|
{ stdout = function (line)
|
||||||
|
for key, value in line:gmatch(pattern) do
|
||||||
|
bat_info[key] = value
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
output_done = function ()
|
||||||
|
-- current state
|
||||||
|
local state = STATES[tonumber(bat_info.raw0)]
|
||||||
|
|
||||||
-- battery capacity in percent
|
-- battery capacity in percent
|
||||||
local percent = tonumber(bat_info.watthour3 / bat_info.watthour0 * 100)
|
local percent = tonumber(
|
||||||
|
bat_info.watthour3 / bat_info.watthour0 * 100)
|
||||||
|
|
||||||
local time
|
local time
|
||||||
if tonumber(bat_info.power0) < 1 then
|
if tonumber(bat_info.power0) < 1 then
|
||||||
|
@ -41,7 +60,7 @@ local function worker(format, warg)
|
||||||
local raw_time = bat_info.watthour3 / bat_info.power0
|
local raw_time = bat_info.watthour3 / bat_info.power0
|
||||||
local hours, hour_fraction = math.modf(raw_time)
|
local hours, hour_fraction = math.modf(raw_time)
|
||||||
local minutes = math.floor(60 * hour_fraction)
|
local minutes = math.floor(60 * hour_fraction)
|
||||||
time = string.format("%d:%0.2d", hours, minutes)
|
time = ("%d:%0.2d"):format(hours, minutes)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- calculate wear level from (last full / design) capacity
|
-- calculate wear level from (last full / design) capacity
|
||||||
|
@ -55,13 +74,12 @@ local function worker(format, warg)
|
||||||
-- dis-/charging rate as presented by battery
|
-- dis-/charging rate as presented by battery
|
||||||
local rate = bat_info.power0
|
local rate = bat_info.power0
|
||||||
|
|
||||||
-- returns
|
-- Pass the following arguments to callback function:
|
||||||
-- * state (high "↯", discharging "-", charging "+", N/A "⌁" }
|
-- * battery state symbol (↯, -, !, + or N/A)
|
||||||
-- * remaining_capacity (percent)
|
-- * remaining_capacity (in percent)
|
||||||
-- * remaining_time, by battery
|
-- * remaining_time, by battery
|
||||||
-- * wear level (percent)
|
-- * wear level (in percent)
|
||||||
-- * present_rate (W)
|
-- * present_rate (in Watts)
|
||||||
return {state, percent, time, wear, rate}
|
callback{state, percent, time, wear, rate}
|
||||||
end
|
end })
|
||||||
|
end }
|
||||||
return setmetatable(bat_openbsd, { __call = function(_, ...) return worker(...) end })
|
|
||||||
|
|
Loading…
Reference in New Issue