It builds again!

main
Chloe Fontenot 🏳️‍⚧️ 2024-04-24 14:52:19 +07:00
parent 6b9f1dcffe
commit 19e42fb13e
3 changed files with 33 additions and 26 deletions

@ -34,15 +34,18 @@ using namespace Pinetime::Applications;
const char* WeatherHelper::floatToRgbHex(lv_color_t rgb) { const char* WeatherHelper::floatToRgbHex(lv_color_t rgb) {
char *rgbHex = new char[7]; char *rgbHex = new char[7];
snprintf(rgbHex, 7, "%02X%02X%02X", rgb.red, rgb.green, rgb.blue); snprintf(rgbHex, 7, "%02X%02X%02X", LV_COLOR_GET_R(rgb), LV_COLOR_GET_G(rgb), LV_COLOR_GET_B(rgb));
return rgbHex; return rgbHex;
} }
lv_color_t hexToFloat(int rgb) { lv_color_t hexToFloat(int rgb) {
uint8_t r = ((rgb >> 16) & 0xFF); //uint16_t r = ((rgb >> 16) & 0xFF);
uint8_t g = ((rgb >> 8) & 0xFF); //uint16_t g = ((rgb >> 8) & 0xFF);
uint8_t b = (rgb & 0xFF); //int16_t b = (rgb & 0xFF);
return LV_COLOR_MAKE(r, g, b); //NRF_LOG_INFO("hexToFloat: %i, %i, %i", r, g, b);
lv_color_t outputLv = lv_color_hex3(rgb);
NRF_LOG_INFO("output lv struct: %i, %i, %i", LV_COLOR_GET_R(outputLv), LV_COLOR_GET_G(outputLv), LV_COLOR_GET_B(outputLv));
return outputLv;
} }
float normalize(float value) { float normalize(float value) {
@ -54,31 +57,28 @@ using namespace Pinetime::Applications;
return value; return value;
} }
} }
lv_color_t lerp(lv_color_t pointA, lv_color_t pointB, float normalValue) { const lv_color_t lerp(lv_color_t pointA, lv_color_t pointB, float normalValue) {
// reference: https://dev.to/ndesmic/linear-color-gradients-from-scratch-1a0e // reference: https://dev.to/ndesmic/linear-color-gradients-from-scratch-1a0e
//std::tuple<float, float, float> lerp(std::tuple<float, float, float> pointA, std::tuple<float, float, float> pointB, float normalValue) { //std::tuple<float, float, float> lerp(std::tuple<float, float, float> pointA, std::tuple<float, float, float> pointB, float normalValue) {
NRF_LOG_INFO("Normal value: %f", normalValue); NRF_LOG_INFO("Normal value: %f", normalValue);
auto redA = LV_COLOR_GET_R(pointA); auto redA = LV_COLOR_GET_R(pointA);
auto redB = LV_COLOR_GET_R(pointA); auto redB = LV_COLOR_GET_R(pointB);
auto greenA = LV_COLOR_GET_G(pointA); auto greenA = LV_COLOR_GET_G(pointA);
auto greenB = LV_COLOR_GET_G(pointA); auto greenB = LV_COLOR_GET_G(pointB);
auto blueA = LV_COLOR_GET_B(pointA); auto blueA = LV_COLOR_GET_B(pointA);
auto blueB = LV_COLOR_GET_B(pointA); auto blueB = LV_COLOR_GET_B(pointB);
auto lerpOutput = LV_COLOR_MAKE(
redA + (redB - redA) * normalValue, int outputRed = (redA + (redB - redA) * normalValue);
greenA + (greenB - greenA) * normalValue, int outputGreen = (greenA + (greenB - greenA) * normalValue);
blueA + (blueB - blueA) * normalValue int outputBlue = (blueA + (blueB - blueA) * normalValue);
//std::lerp(get<0>(pointA), get<0>(pointB), normalValue), auto lerpOutput = LV_COLOR_MAKE(outputRed, outputGreen, outputBlue);
//std::lerp(get<1>(pointA), get<1>(pointB), normalValue), NRF_LOG_INFO("pointA: %i, %i, %i", redA, greenA, blueA);
//std::lerp(get<2>(pointA), get<2>(pointB), normalValue) NRF_LOG_INFO("pointB: %i, %i, %i", redB, greenB, blueB);
); NRF_LOG_INFO("lerpOutput: %i, %i, %i", LV_COLOR_GET_R(lerpOutput), LV_COLOR_GET_G(lerpOutput), LV_COLOR_GET_B(lerpOutput));
NRF_LOG_INFO("pointA: %f, %f, %f", redA, greenA, blueA);
NRF_LOG_INFO("pointB: %f, %f, %f", redB, greenB, blueB);
NRF_LOG_INFO("lerpOutput: %f, %f, %f", LV_COLOR_GET_R(lerpOutput), LV_COLOR_GET_GlerpOutput), LV_COLOR_GET_B(lerpOutput));
return lerpOutput; return lerpOutput;
} }
lv_color_t WeatherHelper::TemperatureColor(int16_t temperature) { const lv_color_t WeatherHelper::TemperatureColor(int16_t temperature) {
const std::vector<int> colors = {0x5555ff, 0x00c9ff, 0xff9b00, 0xff0000}; const std::vector<int> colors = {0x5555ff, 0x00c9ff, 0xff9b00, 0xff0000};
std::vector<lv_color_t> stops; std::vector<lv_color_t> stops;
for (auto colorVal: colors) { for (auto colorVal: colors) {
@ -98,10 +98,10 @@ using namespace Pinetime::Applications;
float newValue = (((tempRounded - oldMin) * newRange) / oldRange) + newMin; float newValue = (((tempRounded - oldMin) * newRange) / oldRange) + newMin;
newValue = normalize(newValue); newValue = normalize(newValue);
if (newValue <= .33f) { if (newValue <= .33f) {
return floatToRgbHex(lerp(stops[0], stops[1], newValue)); return lerp(stops[0], stops[1], newValue);
} else if (newValue <= .66f) { } else if (newValue <= .66f) {
return floatToRgbHex(lerp(stops[1], stops[2], newValue)); return lerp(stops[1], stops[2], newValue);
} else { } else {
return floatToRgbHex(lerp(stops[2], stops[3], newValue)); return lerp(stops[2], stops[3], newValue);
} }
} }

@ -17,6 +17,7 @@
*/ */
#include <FreeRTOS.h> #include <FreeRTOS.h>
#include <lvgl/src/lv_misc/lv_color.h>
namespace Pinetime { namespace Pinetime {
namespace Applications { namespace Applications {

@ -133,8 +133,11 @@ void Weather::Refresh() {
lv_label_set_text(icon, Symbols::GetSymbol(optCurrentWeather->iconId)); lv_label_set_text(icon, Symbols::GetSymbol(optCurrentWeather->iconId));
lv_label_set_text(condition, Symbols::GetCondition(optCurrentWeather->iconId)); lv_label_set_text(condition, Symbols::GetCondition(optCurrentWeather->iconId));
lv_label_set_text_fmt(temperature, "%d°%c", WeatherHelper::RoundTemperature(temp), tempUnit); lv_label_set_text_fmt(temperature, "%d°%c", WeatherHelper::RoundTemperature(temp), tempUnit);
lv_label_set_text_fmt(minTemperature, "%d°", WeatherHelper::RoundTemperature(minTemp)); lv_label_set_text_fmt(minTemperature, "%d°", WeatherHelper::RoundTemperature(minTemp));
//color = WeatherHelper::floatToRgbHex(WeatherHelper::TemperatureColor(maxTemp));
lv_label_set_text_fmt(maxTemperature, "%d°", WeatherHelper::RoundTemperature(maxTemp)); lv_label_set_text_fmt(maxTemperature, "%d°", WeatherHelper::RoundTemperature(maxTemp));
//delete[] color;
} else { } else {
lv_label_set_text(icon, ""); lv_label_set_text(icon, "");
lv_label_set_text(condition, ""); lv_label_set_text(condition, "");
@ -180,8 +183,11 @@ void Weather::Refresh() {
maxPadding[0] = '\0'; maxPadding[0] = '\0';
minPadding[diff] = '\0'; minPadding[diff] = '\0';
} }
lv_table_set_cell_value_fmt(forecast, 2, i, "%s%d", maxPadding, maxTemp); auto color = WeatherHelper::floatToRgbHex(WeatherHelper::TemperatureColor(minTemp));
lv_table_set_cell_value_fmt(forecast, 3, i, "%s%d", minPadding, minTemp); lv_table_set_cell_value_fmt(forecast, 2, i, "# #%s %s%d", color, maxPadding, maxTemp);
color = WeatherHelper::floatToRgbHex(WeatherHelper::TemperatureColor(maxTemp));
lv_table_set_cell_value_fmt(forecast, 3, i, "# #%s %s%d", color, minPadding, minTemp);
delete[] color;
} }
} else { } else {
for (int i = 0; i < Controllers::SimpleWeatherService::MaxNbForecastDays; i++) { for (int i = 0; i < Controllers::SimpleWeatherService::MaxNbForecastDays; i++) {