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