Merge pull request #3011 from nicolarevelant/master
Use the correct thermal zone in FreeBSD
This commit is contained in:
commit
8174dce776
|
@ -9,7 +9,7 @@
|
|||
waybar::modules::Temperature::Temperature(const std::string& id, const Json::Value& config)
|
||||
: ALabel(config, "temperature", id, "{temperatureC}°C", 10) {
|
||||
#if defined(__FreeBSD__)
|
||||
// try to read sysctl?
|
||||
// FreeBSD uses sysctlbyname instead of read from a file
|
||||
#else
|
||||
auto& hwmon_path = config_["hwmon-path"];
|
||||
if (hwmon_path.isString()) {
|
||||
|
@ -37,11 +37,19 @@ waybar::modules::Temperature::Temperature(const std::string& id, const Json::Val
|
|||
auto zone = config_["thermal-zone"].isInt() ? config_["thermal-zone"].asInt() : 0;
|
||||
file_path_ = fmt::format("/sys/class/thermal/thermal_zone{}/temp", zone);
|
||||
}
|
||||
|
||||
// check if file_path_ can be used to retrive the temperature
|
||||
std::ifstream temp(file_path_);
|
||||
if (!temp.is_open()) {
|
||||
throw std::runtime_error("Can't open " + file_path_);
|
||||
}
|
||||
if (!temp.good()) {
|
||||
temp.close();
|
||||
throw std::runtime_error("Can't read from " + file_path_);
|
||||
}
|
||||
temp.close();
|
||||
#endif
|
||||
|
||||
thread_ = [this] {
|
||||
dp.emit();
|
||||
thread_.sleep_for(interval_);
|
||||
|
@ -93,11 +101,11 @@ float waybar::modules::Temperature::getTemperature() {
|
|||
size_t size = sizeof temp;
|
||||
|
||||
auto zone = config_["thermal-zone"].isInt() ? config_["thermal-zone"].asInt() : 0;
|
||||
auto sysctl_thermal = fmt::format("hw.acpi.thermal.tz{}.temperature", zone);
|
||||
|
||||
if (sysctlbyname("hw.acpi.thermal.tz0.temperature", &temp, &size, NULL, 0) != 0) {
|
||||
throw std::runtime_error(
|
||||
"sysctl hw.acpi.thermal.tz0.temperature or dev.cpu.0.temperature failed");
|
||||
if (sysctlbyname(fmt::format("hw.acpi.thermal.tz{}.temperature", zone).c_str(), &temp, &size,
|
||||
NULL, 0) != 0) {
|
||||
throw std::runtime_error(fmt::format(
|
||||
"sysctl hw.acpi.thermal.tz{}.temperature or dev.cpu.{}.temperature failed", zone, zone));
|
||||
}
|
||||
auto temperature_c = ((float)temp - 2732) / 10;
|
||||
return temperature_c;
|
||||
|
@ -110,6 +118,9 @@ float waybar::modules::Temperature::getTemperature() {
|
|||
std::string line;
|
||||
if (temp.good()) {
|
||||
getline(temp, line);
|
||||
} else {
|
||||
temp.close();
|
||||
throw std::runtime_error("Can't read from " + file_path_);
|
||||
}
|
||||
temp.close();
|
||||
auto temperature_c = std::strtol(line.c_str(), nullptr, 10) / 1000.0;
|
||||
|
|
Loading…
Reference in New Issue