mirror of
https://github.com/polybar/polybar.git
synced 2026-03-01 05:19:54 +00:00
fix(temperature): Calculate percentage value
This commit is contained in:
@ -34,6 +34,7 @@ namespace modules {
|
||||
int m_zone = 0;
|
||||
int m_tempwarn = 0;
|
||||
int m_temp = 0;
|
||||
int m_perc = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -28,6 +28,7 @@ namespace modules {
|
||||
|
||||
bool temperature_module::update() {
|
||||
m_temp = std::atoi(file_util::get_contents(m_path).c_str()) / 1000.0f + 0.5f;
|
||||
m_perc = math_util::cap(math_util::percentage(m_temp, 0, m_tempwarn), 0, 100);
|
||||
|
||||
const auto replace_tokens = [&](label_t& label) {
|
||||
label->reset_tokens();
|
||||
@ -55,7 +56,7 @@ namespace modules {
|
||||
else if (tag == TAG_LABEL_WARN)
|
||||
builder->node(m_label.at(temp_state::WARN));
|
||||
else if (tag == TAG_RAMP)
|
||||
builder->node(m_ramp->get_by_percentage(math_util::cap(m_temp, 0, m_tempwarn)));
|
||||
builder->node(m_ramp->get_by_percentage(m_perc));
|
||||
else
|
||||
return false;
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user