Skip to content

Commit

Permalink
Extend model
Browse files Browse the repository at this point in the history
Refs: #20
  • Loading branch information
orontee committed Sep 5, 2023
1 parent 1f861a0 commit 9f69f62
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 17 deletions.
24 changes: 12 additions & 12 deletions src/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ class MenuButton : public Widget {
imenu{ITEM_ACTIVE, taranis::MENU_ITEM_QUIT,
const_cast<char *>(T("Quit")), nullptr},
imenu{0, 0, nullptr, nullptr}},
model{model},
icon{BitmapStretchProportionally(
icons->get("menu"), MenuButton::icon_size, MenuButton::icon_size)},
model{model}, icon{BitmapStretchProportionally(icons->get("menu"),
MenuButton::icon_size,
MenuButton::icon_size)},
font{fonts->get_normal_font()} {
const int width = MenuButton::icon_size + 2 * MenuButton::padding;
const int height = MenuButton::icon_size + 2 * MenuButton::padding;
Expand Down Expand Up @@ -184,17 +184,17 @@ class MenuButton : public Widget {

void update_unit_system_bullet() const {
if (this->model->unit_system == UnitSystem::standard) {
const_cast<imenu*>(&this->unit_system_items[0])->type = ITEM_BULLET;
const_cast<imenu*>(&this->unit_system_items[1])->type = ITEM_ACTIVE;
const_cast<imenu*>(&this->unit_system_items[2])->type = ITEM_ACTIVE;
const_cast<imenu *>(&this->unit_system_items[0])->type = ITEM_BULLET;
const_cast<imenu *>(&this->unit_system_items[1])->type = ITEM_ACTIVE;
const_cast<imenu *>(&this->unit_system_items[2])->type = ITEM_ACTIVE;
} else if (this->model->unit_system == UnitSystem::metric) {
const_cast<imenu*>(&this->unit_system_items[0])->type = ITEM_ACTIVE;
const_cast<imenu*>(&this->unit_system_items[1])->type = ITEM_BULLET;
const_cast<imenu*>(&this->unit_system_items[2])->type = ITEM_ACTIVE;
const_cast<imenu *>(&this->unit_system_items[0])->type = ITEM_ACTIVE;
const_cast<imenu *>(&this->unit_system_items[1])->type = ITEM_BULLET;
const_cast<imenu *>(&this->unit_system_items[2])->type = ITEM_ACTIVE;
} else if (this->model->unit_system == UnitSystem::imperial) {
const_cast<imenu*>(&this->unit_system_items[0])->type = ITEM_ACTIVE;
const_cast<imenu*>(&this->unit_system_items[1])->type = ITEM_ACTIVE;
const_cast<imenu*>(&this->unit_system_items[2])->type = ITEM_BULLET;
const_cast<imenu *>(&this->unit_system_items[0])->type = ITEM_ACTIVE;
const_cast<imenu *>(&this->unit_system_items[1])->type = ITEM_ACTIVE;
const_cast<imenu *>(&this->unit_system_items[2])->type = ITEM_BULLET;
}
}
};
Expand Down
4 changes: 4 additions & 0 deletions src/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,17 @@ struct Condition {
int pressure;
int humidity;
long double uv_index;
int clouds;
int visibility;
long double probability_of_precipitation;
long double wind_speed;
int wind_degree;
long double wind_gust;
Weather weather{CLEAR_SKY};
std::string weather_description;
std::string weather_icon_name;
long double rain;
long double snow;
};

struct Model {
Expand Down
30 changes: 26 additions & 4 deletions src/service.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,27 @@ class Service {
const auto pressure = value.get("pressure", NAN).asInt();
const auto humidity = value.get("humidity", NAN).asInt();
const auto uv_index = value.get("uvi", NAN).asDouble();
const auto clouds = value.get("clouds", NAN).asInt();
const auto visibility = value.get("visibility", NAN).asInt();
const auto probability_of_precipitation = value.get("pop", NAN).asDouble();
const auto wind_speed = value.get("wind_speed", NAN).asDouble();
const auto wind_degree = value.get("wind_deg", NAN).asInt();
const auto wind_gust = value.get("wind_gust", NAN).asDouble();

Condition condition{date, sunrise, sunset,
temperature, felt_temperature, pressure,
humidity, uv_index, visibility,
wind_speed, wind_degree, wind_gust};
Condition condition{date,
sunrise,
sunset,
temperature,
felt_temperature,
pressure,
humidity,
uv_index,
clouds,
visibility,
probability_of_precipitation,
wind_speed,
wind_degree,
wind_gust};

if (value.isMember("weather") and value["weather"].isArray() and
value["weather"].isValidIndex(0)) {
Expand All @@ -167,6 +179,16 @@ class Service {
weather_value.get("description", "").asString();
condition.weather_icon_name = weather_value.get("icon", "").asString();
}

if (value.isMember("rain") and value["rain"].isMember("1h")) {
const auto rain_value = value["rain"];
condition.rain = rain_value.get("1h", NAN).asDouble();
}

if (value.isMember("snow") and value["snow"].isMember("1h")) {
const auto snow_value = value["snow"];
condition.snow = snow_value.get("1h", NAN).asDouble();
}
return condition;
}
};
Expand Down
3 changes: 2 additions & 1 deletion src/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ class Ui {
current_condition_box->get_height(),
ScreenWidth(), remaining_height, this->model, this->icons, this->fonts);

auto menu_button = std::make_shared<MenuButton>(this->model, this->icons, this->fonts);
auto menu_button =
std::make_shared<MenuButton>(this->model, this->icons, this->fonts);
menu_button->set_menu_handler(handle_menu_item_selected);

this->children.push_back(location_box);
Expand Down

0 comments on commit 9f69f62

Please sign in to comment.