| 1 | -- temperature 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 string = { match = string.match } |
| 22 | local type = type |
| 23 | |
| 24 | local helpers = require("vicious.helpers") |
| 25 | -- }}} |
| 26 | |
| 27 | -- Thermal: provides temperature levels of ACPI and coretemp thermal zones |
| 28 | -- vicious.widgets.thermal |
| 29 | local thermal_freebsd = {} |
| 30 | |
| 31 | -- {{{ Thermal widget type |
| 32 | function thermal_freebsd.async(format, warg, callback) |
| 33 | if not warg then return callback{} end |
| 34 | if type(warg) ~= "table" then warg = { warg } end |
| 35 | |
| 36 | helpers.sysctl_async(warg, function(ret) |
| 37 | local thermals = {} |
| 38 | |
| 39 | for i=1,#warg do |
| 40 | if ret[warg[i]] ~= nil then |
| 41 | thermals[i] = string.match(ret[warg[i]], "[%d]+") |
| 42 | else |
| 43 | thermals[i] = "N/A" |
| 44 | end |
| 45 | end |
| 46 | |
| 47 | callback(thermals) |
| 48 | end) |
| 49 | end |
| 50 | -- }}} |
| 51 | |
| 52 | return helpers.setasyncall(thermal_freebsd) |