1
0
Fork 0
mirror of https://github.com/polybar/polybar.git synced 2024-11-11 13:50:56 -05:00

feat(temperature): Fahrenheit and Celsius tokens (#804)

%temperature-f% and %temperature-c%
This commit is contained in:
Chris Snell 2017-10-18 15:29:53 -05:00 committed by Patrick Ziegler
parent cbd87efc64
commit 5737156ae5

View file

@ -4,6 +4,7 @@
#include "drawtypes/ramp.hpp"
#include "utils/file.hpp"
#include "utils/math.hpp"
#include <cmath>
#include "modules/meta/base.inl"
@ -43,10 +44,13 @@ namespace modules {
bool temperature_module::update() {
m_temp = std::atoi(file_util::contents(m_path).c_str()) / 1000.0f + 0.5f;
int m_temp_f = floor(((1.8 * m_temp) + 32) + 0.5);
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();
label->replace_token("%temperature-f%", to_string(m_temp_f) + "°F");
label->replace_token("%temperature-c%", to_string(m_temp) + "°C");
label->replace_token("%temperature%", to_string(m_temp) + "°C");
};