Skip to content

Commit f21c394

Browse files
committed
color weather
1 parent 15f6293 commit f21c394

File tree

1 file changed

+74
-3
lines changed

1 file changed

+74
-3
lines changed

src/displayapp/screens/WatchFaceMixed.cpp

+74-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "displayapp/screens/WatchFaceMixed.h"
22
#include <cmath>
3+
#include <cstdint>
4+
#include <limits>
35
#include <lvgl/lvgl.h>
46
#include "displayapp/screens/Symbols.h"
57
#include "displayapp/screens/WeatherSymbols.h"
@@ -157,7 +159,7 @@ WatchFaceMixed::WatchFaceMixed(Controllers::DateTime& dateTimeController,
157159
lv_label_set_align(label_time_ampm, LV_LABEL_ALIGN_RIGHT);
158160

159161
label_date = lv_label_create(lv_scr_act(), nullptr);
160-
lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_CENTER, 0, 30);
162+
lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_CENTER, 0, 20);
161163
lv_label_set_align(label_date, LV_LABEL_ALIGN_CENTER);
162164

163165
// Notification
@@ -173,13 +175,13 @@ WatchFaceMixed::WatchFaceMixed(Controllers::DateTime& dateTimeController,
173175
lv_obj_set_style_local_text_color(weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999));
174176
lv_obj_set_style_local_text_font(weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &fontawesome_weathericons);
175177
lv_label_set_text(weatherIcon, "");
176-
lv_obj_align(weatherIcon, lv_scr_act(), LV_ALIGN_IN_TOP_MID, -20, 50);
178+
lv_obj_align(weatherIcon, lv_scr_act(), LV_ALIGN_CENTER, -23, 50);
177179
lv_obj_set_auto_realign(weatherIcon, true);
178180

179181
temperature = lv_label_create(lv_scr_act(), nullptr);
180182
lv_obj_set_style_local_text_color(temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999));
181183
lv_label_set_text(temperature, "");
182-
lv_obj_align(temperature, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 20, 50);
184+
lv_obj_align(temperature, lv_scr_act(), LV_ALIGN_CENTER, 22, 50);
183185

184186
// HeartBeat
185187

@@ -324,20 +326,89 @@ void WatchFaceMixed::UpdateSteps() {
324326
lv_obj_realign(stepIcon);
325327
}
326328

329+
uint32_t linear_color_gradient(uint32_t startingColor, uint32_t endingColor, uint8_t progress){
330+
constexpr decltype(progress) maxProgress = std::numeric_limits<decltype(progress)>::max();
331+
uint32_t res = 0;
332+
res += ((maxProgress-progress)*((startingColor&0xff0000) >> 16) + progress*((endingColor&0xff0000) >> 16)) / maxProgress;
333+
res <<= 8;
334+
res += ((maxProgress - progress) * ((startingColor&0x00ff00) >> 8) + progress * ((endingColor&0x00ff00) >> 8)) / maxProgress;
335+
res <<= 8;
336+
res += ((maxProgress - progress) * (startingColor&0x0000ff) + progress * (endingColor&0x0000ff)) / maxProgress;
337+
338+
return res;
339+
}
340+
327341
void WatchFaceMixed::UpdateWeather() {
328342
auto optCurrentWeather = currentWeather.Get();
329343
if (optCurrentWeather) {
330344
int16_t temp = optCurrentWeather->temperature.Celsius();
331345
char tempUnit = 'C';
346+
347+
enum TempColor : uint32_t {
348+
VeryCold = 0x6495ed,
349+
Freezing = 0x00ffff,
350+
Cold = 0x808080,
351+
Hot = 0xfafd0f,
352+
VeryHot = 0xff0000
353+
};
354+
if(temp < -30) {
355+
lv_obj_set_style_local_text_color(temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(TempColor::VeryCold));
356+
} else if(-30 <= temp && temp < 0) {
357+
lv_obj_set_style_local_text_color(temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(linear_color_gradient(TempColor::VeryCold, TempColor::Freezing, 255*(temp+30)/30)));
358+
} else if(0 <= temp && temp < 10) {
359+
lv_obj_set_style_local_text_color(temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(linear_color_gradient(TempColor::Freezing, TempColor::Cold, 255*temp/10)));
360+
} else if(10 <= temp && temp < 18) {
361+
lv_obj_set_style_local_text_color(temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(linear_color_gradient(TempColor::Cold, TempColor::Hot, 255*(temp-10)/8)));
362+
} else if(18 <= temp && temp < 50) {
363+
lv_obj_set_style_local_text_color(temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(linear_color_gradient(TempColor::Hot, TempColor::VeryHot, 255*(temp-18)/32)));
364+
} else if(temp >= 50) {
365+
lv_obj_set_style_local_text_color(temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(TempColor::VeryHot));
366+
}
332367
if (settingsController.GetWeatherFormat() == Controllers::Settings::WeatherFormat::Imperial) {
333368
temp = optCurrentWeather->temperature.Fahrenheit();
334369
tempUnit = 'F';
335370
}
336371
lv_label_set_text_fmt(temperature, "%d°%c", temp, tempUnit);
372+
337373
lv_label_set_text(weatherIcon, Symbols::GetSymbol(optCurrentWeather->iconId));
374+
using Icons = Pinetime::Controllers::SimpleWeatherService::Icons;
375+
switch(optCurrentWeather->iconId){
376+
case Icons::Sun:
377+
lv_obj_set_style_local_text_color(weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xfafd0f));
378+
break;
379+
case Icons::CloudsSun:
380+
lv_obj_set_style_local_text_color(weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xc4c745));
381+
break;
382+
case Icons::Clouds:
383+
lv_obj_set_style_local_text_color(weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xcbd0d2));
384+
break;
385+
case Icons::BrokenClouds:
386+
lv_obj_set_style_local_text_color(weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x7e8796));
387+
break;
388+
case Icons::CloudShowerHeavy:
389+
lv_obj_set_style_local_text_color(weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000080));
390+
break;
391+
case Icons::CloudSunRain:
392+
lv_obj_set_style_local_text_color(weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xbfddea));
393+
break;
394+
case Icons::Thunderstorm:
395+
lv_obj_set_style_local_text_color(weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xC4893D));
396+
break;
397+
case Icons::Snow:
398+
lv_obj_set_style_local_text_color(weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xffffff));
399+
break;
400+
case Icons::Smog:
401+
lv_obj_set_style_local_text_color(weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x697379));
402+
break;
403+
default:
404+
lv_obj_set_style_local_text_color(weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999));
405+
break;
406+
}
338407
} else {
339408
lv_label_set_text_static(temperature, "");
409+
lv_obj_set_style_local_text_color(temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999));
340410
lv_label_set_text(weatherIcon, "");
411+
lv_obj_set_style_local_text_color(weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999));
341412
}
342413
lv_obj_realign(temperature);
343414
lv_obj_realign(weatherIcon);

0 commit comments

Comments
 (0)