| 1 | -- CPU frequency 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 helpers = require("vicious.helpers") |
| 23 | -- }}} |
| 24 | |
| 25 | -- Cpufreq: provides freq, voltage and governor info for a requested CPU |
| 26 | -- vicious.widgets.cpufreq |
| 27 | local cpufreq_freebsd = {} |
| 28 | |
| 29 | -- {{{ CPU frequency widget type |
| 30 | function cpufreq_freebsd.async(format, warg, callback) |
| 31 | if not warg then return callback({}) end |
| 32 | |
| 33 | -- Default frequency and voltage values |
| 34 | local freqv = { |
| 35 | ["mhz"] = "N/A", ["ghz"] = "N/A", |
| 36 | ["v"] = "N/A", ["mv"] = "N/A", |
| 37 | ["governor"] = "N/A", |
| 38 | } |
| 39 | |
| 40 | helpers.sysctl_async( |
| 41 | { "dev.cpu." .. warg .. ".freq" }, |
| 42 | function (ret) |
| 43 | freqv.mhz = tonumber(ret["dev.cpu." .. warg .. ".freq"]) |
| 44 | freqv.ghz = freqv.mhz / 1000 |
| 45 | |
| 46 | return callback({ |
| 47 | freqv.mhz, |
| 48 | freqv.ghz, |
| 49 | freqv.mv, |
| 50 | freqv.v, |
| 51 | freqv.governor |
| 52 | }) |
| 53 | end) |
| 54 | end |
| 55 | -- }}} |
| 56 | |
| 57 | return helpers.setasyncall(cpufreq_freebsd) |