Merge pull request #3674 from PassiHD2004/master
Add warning threshold to temperature module
This commit is contained in:
@ -18,6 +18,7 @@ class Temperature : public ALabel {
|
|||||||
private:
|
private:
|
||||||
float getTemperature();
|
float getTemperature();
|
||||||
bool isCritical(uint16_t);
|
bool isCritical(uint16_t);
|
||||||
|
bool isWarning(uint16_t);
|
||||||
|
|
||||||
std::string file_path_;
|
std::string file_path_;
|
||||||
util::SleeperThread thread_;
|
util::SleeperThread thread_;
|
||||||
|
@ -31,6 +31,10 @@ Addressed by *temperature*
|
|||||||
typeof: string ++
|
typeof: string ++
|
||||||
The temperature filename of your *hwmon-path-abs*, e.g. *temp1_input*
|
The temperature filename of your *hwmon-path-abs*, e.g. *temp1_input*
|
||||||
|
|
||||||
|
*warning-threshold*: ++
|
||||||
|
typeof: integer ++
|
||||||
|
The threshold before it is considered warning (Celsius).
|
||||||
|
|
||||||
*critical-threshold*: ++
|
*critical-threshold*: ++
|
||||||
typeof: integer ++
|
typeof: integer ++
|
||||||
The threshold before it is considered critical (Celsius).
|
The threshold before it is considered critical (Celsius).
|
||||||
@ -40,6 +44,10 @@ Addressed by *temperature*
|
|||||||
default: 10 ++
|
default: 10 ++
|
||||||
The interval in which the information gets polled.
|
The interval in which the information gets polled.
|
||||||
|
|
||||||
|
*format-warning*: ++
|
||||||
|
typeof: string ++
|
||||||
|
The format to use when temperature is considered warning
|
||||||
|
|
||||||
*format-critical*: ++
|
*format-critical*: ++
|
||||||
typeof: string ++
|
typeof: string ++
|
||||||
The format to use when temperature is considered critical
|
The format to use when temperature is considered critical
|
||||||
|
@ -69,12 +69,17 @@ auto waybar::modules::Temperature::update() -> void {
|
|||||||
uint16_t temperature_f = std::round(temperature * 1.8 + 32);
|
uint16_t temperature_f = std::round(temperature * 1.8 + 32);
|
||||||
uint16_t temperature_k = std::round(temperature + 273.15);
|
uint16_t temperature_k = std::round(temperature + 273.15);
|
||||||
auto critical = isCritical(temperature_c);
|
auto critical = isCritical(temperature_c);
|
||||||
|
auto warning = isWarning(temperature_c);
|
||||||
auto format = format_;
|
auto format = format_;
|
||||||
if (critical) {
|
if (critical) {
|
||||||
format = config_["format-critical"].isString() ? config_["format-critical"].asString() : format;
|
format = config_["format-critical"].isString() ? config_["format-critical"].asString() : format;
|
||||||
label_.get_style_context()->add_class("critical");
|
label_.get_style_context()->add_class("critical");
|
||||||
|
} else if (warning) {
|
||||||
|
format = config_["format-warning"].isString() ? config_["format-warning"].asString() : format;
|
||||||
|
label_.get_style_context()->add_class("warning");
|
||||||
} else {
|
} else {
|
||||||
label_.get_style_context()->remove_class("critical");
|
label_.get_style_context()->remove_class("critical");
|
||||||
|
label_.get_style_context()->remove_class("warning");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (format.empty()) {
|
if (format.empty()) {
|
||||||
@ -135,6 +140,11 @@ float waybar::modules::Temperature::getTemperature() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool waybar::modules::Temperature::isWarning(uint16_t temperature_c) {
|
||||||
|
return config_["warning-threshold"].isInt() &&
|
||||||
|
temperature_c >= config_["warning-threshold"].asInt();
|
||||||
|
}
|
||||||
|
|
||||||
bool waybar::modules::Temperature::isCritical(uint16_t temperature_c) {
|
bool waybar::modules::Temperature::isCritical(uint16_t temperature_c) {
|
||||||
return config_["critical-threshold"].isInt() &&
|
return config_["critical-threshold"].isInt() &&
|
||||||
temperature_c >= config_["critical-threshold"].asInt();
|
temperature_c >= config_["critical-threshold"].asInt();
|
||||||
|
Reference in New Issue
Block a user