71 lines
1.9 KiB
C++
71 lines
1.9 KiB
C++
#include <gui/containers/Temperature.hpp>
|
|
|
|
#include <cstring>
|
|
|
|
#include "texts/TextKeysAndLanguages.hpp"
|
|
#include "touchgfx/Color.hpp"
|
|
#include "touchgfx/Unicode.hpp"
|
|
|
|
Temperature::Temperature() : temp{0}, tempThresholds{0, 0, 0, 0} {
|
|
updateValueBuffer();
|
|
}
|
|
|
|
void Temperature::initialize() {
|
|
TemperatureBase::initialize();
|
|
setSmallText(false);
|
|
}
|
|
|
|
void Temperature::setTemp(int temp_in_celsius) {
|
|
if (temp_in_celsius < 0) {
|
|
// No space for displaying negative values
|
|
temp_in_celsius = 0;
|
|
}
|
|
if (temp_in_celsius == temp) {
|
|
// No change
|
|
return;
|
|
}
|
|
|
|
temp = temp_in_celsius;
|
|
updateValueBuffer();
|
|
if (temp < tempThresholds[0]) {
|
|
bg.setColor(touchgfx::Color::getColorFromRGB(0x05, 0x76, 0xb7));
|
|
} else if (temp < tempThresholds[1]) {
|
|
bg.setColor(touchgfx::Color::getColorFromRGB(0x05, 0x76, 0x64));
|
|
} else if (temp < tempThresholds[2]) {
|
|
bg.setColor(touchgfx::Color::getColorFromRGB(0x05, 0x95, 0x38));
|
|
} else if (temp < tempThresholds[3]) {
|
|
bg.setColor(touchgfx::Color::getColorFromRGB(0xdd, 0x6e, 0x22));
|
|
} else {
|
|
bg.setColor(touchgfx::Color::getColorFromRGB(0xdd, 0x2f, 0x22));
|
|
}
|
|
value.invalidate();
|
|
bg.invalidate(); // TODO: Only invalidate if color changed
|
|
}
|
|
|
|
void Temperature::setTempThresholds(int *thresholds) {
|
|
memcpy(tempThresholds, thresholds, sizeof(tempThresholds));
|
|
}
|
|
|
|
void Temperature::setSmallText(bool small_) {
|
|
this->small = small_;
|
|
if (small_) {
|
|
value.setTypedText(T_NUMBERSMALLWILDCARD);
|
|
value.setHeight(33);
|
|
value.setY(14);
|
|
} else {
|
|
value.setTypedText(T_HUGEVALUEWILDCARD);
|
|
value.setHeight(50);
|
|
value.setY(0);
|
|
}
|
|
updateValueBuffer();
|
|
}
|
|
|
|
void Temperature::updateValueBuffer() {
|
|
// Unicode::utoa(temp, valueBuffer, 3, 10);
|
|
const char *format = small ? "%03d" : "%02d";
|
|
Unicode::snprintf(valueBuffer,
|
|
sizeof(valueBuffer) / sizeof(Unicode::UnicodeChar), format,
|
|
temp);
|
|
value.setWildcard(valueBuffer);
|
|
}
|