| 1 | -- fan speed widget type for FreeBSD |
| 2 | -- Copyright (C) 2017,2019 mutlusun <[email protected]> |
| 3 | -- Copyright (C) 2019 Nguyễn Gia Phong <[email protected]m> |
| 4 | -- |
| 5 | -- This file is part of Vicious. |
| 6 | -- |
| 7 | -- Vicious is free software: you can redistribute it and/or modify |
| 8 | -- it under the terms of the GNU General Public License as |
| 9 | -- published by the Free Software Foundation, either version 2 of the |
| 10 | -- License, or (at your option) any later version. |
| 11 | -- |
| 12 | -- Vicious is distributed in the hope that it will be useful, |
| 13 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | -- GNU General Public License for more details. |
| 16 | -- |
| 17 | -- You should have received a copy of the GNU General Public License |
| 18 | -- along with Vicious. If not, see <https://www.gnu.org/licenses/>. |
| 19 | |
| 20 | -- {{{ Grab environment |
| 21 | local tonumber = tonumber |
| 22 | local type = type |
| 23 | |
| 24 | local helpers = require("vicious.helpers") |
| 25 | -- }}} |
| 26 | |
| 27 | -- fanspeed: provides speed level of fans |
| 28 | -- vicious.widgets.fanspeed |
| 29 | -- |
| 30 | -- expects one or multiple full sysctl strings to entry |
| 31 | -- e.g.: "dev.acpi_ibm.0.fan_speed" |
| 32 | local fanspeed_freebsd = {} |
| 33 | |
| 34 | -- {{{ fanspeed widget type |
| 35 | function fanspeed_freebsd.async(format, warg, callback) |
| 36 | if not warg then return callback({}) end |
| 37 | if type(warg) ~= "table" then warg = { warg } end |
| 38 | |
| 39 | helpers.sysctl_async(warg, function(ret) |
| 40 | local fanspeed = {} |
| 41 | |
| 42 | for i=1,#warg do |
| 43 | if ret[warg[i]] ~= nil then |
| 44 | fanspeed[i] = tonumber(ret[warg[i]]) |
| 45 | else |
| 46 | fanspeed[i] = "N/A" |
| 47 | end |
| 48 | end |
| 49 | |
| 50 | callback(fanspeed) |
| 51 | end) |
| 52 | end |
| 53 | -- }}} |
| 54 | |
| 55 | return helpers.setasyncall(fanspeed_freebsd) |