2021-01-20 21:34:09 +01:00
|
|
|
/* Copyright (C) 2021 Adam Pigg
|
|
|
|
|
|
|
|
This file is part of InfiniTime.
|
|
|
|
|
|
|
|
InfiniTime is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published
|
|
|
|
by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
InfiniTime is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2021-10-13 22:08:35 +02:00
|
|
|
#include "displayapp/screens/Navigation.h"
|
2021-01-20 21:34:09 +01:00
|
|
|
#include <cstdint>
|
2021-10-13 22:08:35 +02:00
|
|
|
#include "displayapp/DisplayApp.h"
|
2021-01-20 21:34:09 +01:00
|
|
|
#include "components/ble/NavigationService.h"
|
|
|
|
|
|
|
|
using namespace Pinetime::Applications::Screens;
|
|
|
|
|
2021-04-04 04:08:51 +02:00
|
|
|
LV_FONT_DECLARE(lv_font_navi_80)
|
2021-01-20 21:34:09 +01:00
|
|
|
|
2021-06-01 21:01:32 +02:00
|
|
|
namespace {
|
|
|
|
constexpr std::array<std::pair<const char*, const char*>, 86> m_iconMap = {{
|
|
|
|
{"arrive-left", "\xEE\xA4\x81"},
|
|
|
|
{"arrive-right", "\xEE\xA4\x82"},
|
|
|
|
{"arrive-straight", "\xEE\xA4\x80"},
|
|
|
|
{"arrive", "\xEE\xA4\x80"},
|
|
|
|
{"close", "\xEE\xA4\x83"},
|
|
|
|
{"continue-left", "\xEE\xA4\x85"},
|
|
|
|
{"continue-right", "\xEE\xA4\x86"},
|
|
|
|
{"continue-slight-left", "\xEE\xA4\x87"},
|
|
|
|
{"continue-slight-right", "\xEE\xA4\x88"},
|
|
|
|
{"continue-straight", "\xEE\xA4\x84"},
|
|
|
|
{"continue-uturn", "\xEE\xA4\x89"},
|
|
|
|
{"continue", "\xEE\xA4\x84"},
|
|
|
|
{"depart-left", "\xEE\xA4\x8B"},
|
|
|
|
{"depart-right", "\xEE\xA4\x8C"},
|
|
|
|
{"depart-straight", "\xEE\xA4\x8A"},
|
|
|
|
{"end-of-road-left", "\xEE\xA4\x8D"},
|
|
|
|
{"end-of-road-right", "\xEE\xA4\x8E"},
|
|
|
|
{"ferry", "\xEE\xA4\x8F"},
|
|
|
|
{"flag", "\xEE\xA4\x90"},
|
|
|
|
{"fork-left", "\xEE\xA4\x92"},
|
|
|
|
{"fork-right", "\xEE\xA4\x93"},
|
|
|
|
{"fork-slight-left", "\xEE\xA4\x94"},
|
|
|
|
{"fork-slight-right", "\xEE\xA4\x95"},
|
|
|
|
{"fork-straight", "\xEE\xA4\x96"},
|
|
|
|
{"invalid", "\xEE\xA4\x84"},
|
|
|
|
{"invalid-left", "\xEE\xA4\x85"},
|
|
|
|
{"invalid-right", "\xEE\xA4\x86"},
|
|
|
|
{"invalid-slight-left", "\xEE\xA4\x87"},
|
|
|
|
{"invalid-slight-right", "\xEE\xA4\x88"},
|
|
|
|
{"invalid-straight", "\xEE\xA4\x84"},
|
|
|
|
{"invalid-uturn", "\xEE\xA4\x89"},
|
|
|
|
{"merge-left", "\xEE\xA4\x97"},
|
|
|
|
{"merge-right", "\xEE\xA4\x98"},
|
|
|
|
{"merge-slight-left", "\xEE\xA4\x99"},
|
|
|
|
{"merge-slight-right", "\xEE\xA4\x9A"},
|
|
|
|
{"merge-straight", "\xEE\xA4\x84"},
|
|
|
|
{"new-name-left", "\xEE\xA4\x85"},
|
|
|
|
{"new-name-right", "\xEE\xA4\x86"},
|
|
|
|
{"new-name-sharp-left", "\xEE\xA4\x9B"},
|
|
|
|
{"new-name-sharp-right", "\xEE\xA4\x9C"},
|
|
|
|
{"new-name-slight-left", "\xEE\xA4\x87"},
|
|
|
|
{"new-name-slight-right", "\xEE\xA4\x88"},
|
|
|
|
{"new-name-straight", "\xEE\xA4\x84"},
|
|
|
|
{"notification-left", "\xEE\xA4\x85"},
|
|
|
|
{"notification-right", "\xEE\xA4\x86"},
|
|
|
|
{"notification-sharp-left", "\xEE\xA4\x9B"},
|
|
|
|
{"notification-sharp-right", "\xEE\xA4\xA5"},
|
|
|
|
{"notification-slight-left", "\xEE\xA4\x87"},
|
|
|
|
{"notification-slight-right", "\xEE\xA4\x88"},
|
|
|
|
{"notification-straight", "\xEE\xA4\x84"},
|
|
|
|
{"off-ramp-left", "\xEE\xA4\x9D"},
|
|
|
|
{"off-ramp-right", "\xEE\xA4\x9E"},
|
|
|
|
{"off-ramp-slight-left", "\xEE\xA4\x9F"},
|
|
|
|
{"off-ramp-slight-right", "\xEE\xA4\xA0"},
|
|
|
|
{"on-ramp-left", "\xEE\xA4\x85"},
|
|
|
|
{"on-ramp-right", "\xEE\xA4\x86"},
|
|
|
|
{"on-ramp-sharp-left", "\xEE\xA4\x9B"},
|
|
|
|
{"on-ramp-sharp-right", "\xEE\xA4\xA5"},
|
|
|
|
{"on-ramp-slight-left", "\xEE\xA4\x87"},
|
|
|
|
{"on-ramp-slight-right", "\xEE\xA4\x88"},
|
|
|
|
{"on-ramp-straight", "\xEE\xA4\x84"},
|
|
|
|
{"rotary", "\xEE\xA4\xA1"},
|
|
|
|
{"rotary-left", "\xEE\xA4\xA2"},
|
|
|
|
{"rotary-right", "\xEE\xA4\xA3"},
|
|
|
|
{"rotary-sharp-left", "\xEE\xA4\xA4"},
|
|
|
|
{"rotary-sharp-right", "\xEE\xA4\xA5"},
|
|
|
|
{"rotary-slight-left", "\xEE\xA4\xA6"},
|
|
|
|
{"rotary-slight-right", "\xEE\xA4\xA7"},
|
|
|
|
{"rotary-straight", "\xEE\xA4\xA8"},
|
|
|
|
{"roundabout", "\xEE\xA4\xA1"},
|
|
|
|
{"roundabout-left", "\xEE\xA4\xA2"},
|
|
|
|
{"roundabout-right", "\xEE\xA4\xA3"},
|
|
|
|
{"roundabout-sharp-left", "\xEE\xA4\xA4"},
|
|
|
|
{"roundabout-sharp-right", "\xEE\xA4\xA5"},
|
|
|
|
{"roundabout-slight-left", "\xEE\xA4\xA6"},
|
|
|
|
{"roundabout-slight-right", "\xEE\xA4\xA7"},
|
|
|
|
{"roundabout-straight", "\xEE\xA4\xA8"},
|
|
|
|
{"turn-left", "\xEE\xA4\x85"},
|
|
|
|
{"turn-right", "\xEE\xA4\x86"},
|
|
|
|
{"turn-sharp-left", "\xEE\xA4\x9B"},
|
|
|
|
{"turn-sharp-right", "\xEE\xA4\xA5"},
|
|
|
|
{"turn-slight-left", "\xEE\xA4\x87"},
|
|
|
|
{"turn-slight-right", "\xEE\xA4\x88"},
|
|
|
|
{"turn-straight", "\xEE\xA4\x84"},
|
|
|
|
{"updown", "\xEE\xA4\xA9"},
|
|
|
|
{"uturn", "\xEE\xA4\x89"},
|
|
|
|
}};
|
|
|
|
|
|
|
|
const char* iconForName(const std::string& icon) {
|
|
|
|
for (auto iter : m_iconMap) {
|
|
|
|
if (iter.first == icon) {
|
|
|
|
return iter.second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "\xEE\xA4\x90";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-20 21:34:09 +01:00
|
|
|
/**
|
|
|
|
* Navigation watchapp
|
|
|
|
*
|
|
|
|
*/
|
2021-04-18 19:28:14 +02:00
|
|
|
Navigation::Navigation(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::NavigationService& nav)
|
|
|
|
: Screen(app), navService(nav) {
|
2021-01-20 21:34:09 +01:00
|
|
|
|
2021-04-18 19:28:14 +02:00
|
|
|
imgFlag = lv_label_create(lv_scr_act(), nullptr);
|
2021-04-04 04:08:51 +02:00
|
|
|
lv_obj_set_style_local_text_font(imgFlag, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_navi_80);
|
|
|
|
lv_obj_set_style_local_text_color(imgFlag, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_CYAN);
|
2022-03-20 15:47:25 +01:00
|
|
|
lv_label_set_text_static(imgFlag, iconForName("flag"));
|
2021-04-04 04:08:51 +02:00
|
|
|
lv_obj_align(imgFlag, nullptr, LV_ALIGN_CENTER, 0, -60);
|
2021-01-20 21:34:09 +01:00
|
|
|
|
|
|
|
txtNarrative = lv_label_create(lv_scr_act(), nullptr);
|
2021-04-04 04:08:51 +02:00
|
|
|
lv_label_set_long_mode(txtNarrative, LV_LABEL_LONG_BREAK);
|
2021-01-20 21:34:09 +01:00
|
|
|
lv_obj_set_width(txtNarrative, LV_HOR_RES);
|
2022-03-20 15:47:25 +01:00
|
|
|
lv_label_set_text_static(txtNarrative, "Navigation");
|
2021-04-04 04:08:51 +02:00
|
|
|
lv_label_set_align(txtNarrative, LV_LABEL_ALIGN_CENTER);
|
|
|
|
lv_obj_align(txtNarrative, nullptr, LV_ALIGN_CENTER, 0, 10);
|
2021-01-20 21:34:09 +01:00
|
|
|
|
|
|
|
txtManDist = lv_label_create(lv_scr_act(), nullptr);
|
2021-04-04 04:08:51 +02:00
|
|
|
lv_label_set_long_mode(txtManDist, LV_LABEL_LONG_BREAK);
|
|
|
|
lv_obj_set_style_local_text_color(txtManDist, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN);
|
2021-01-20 21:34:09 +01:00
|
|
|
lv_obj_set_width(txtManDist, LV_HOR_RES);
|
2022-03-20 15:47:25 +01:00
|
|
|
lv_label_set_text_static(txtManDist, "--M");
|
2021-04-04 04:08:51 +02:00
|
|
|
lv_label_set_align(txtManDist, LV_LABEL_ALIGN_CENTER);
|
2021-04-18 19:28:14 +02:00
|
|
|
lv_obj_align(txtManDist, nullptr, LV_ALIGN_CENTER, 0, 60);
|
2021-01-20 21:34:09 +01:00
|
|
|
|
2021-04-18 19:28:14 +02:00
|
|
|
// Route Progress
|
2021-04-04 04:08:51 +02:00
|
|
|
barProgress = lv_bar_create(lv_scr_act(), nullptr);
|
2021-01-20 21:34:09 +01:00
|
|
|
lv_obj_set_size(barProgress, 200, 20);
|
2021-04-04 04:08:51 +02:00
|
|
|
lv_obj_align(barProgress, nullptr, LV_ALIGN_IN_BOTTOM_MID, 0, -10);
|
|
|
|
lv_obj_set_style_local_bg_color(barProgress, LV_BAR_PART_BG, LV_STATE_DEFAULT, lv_color_hex(0x222222));
|
2021-04-18 19:28:14 +02:00
|
|
|
lv_obj_set_style_local_bg_color(barProgress, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_ORANGE);
|
2021-01-20 21:34:09 +01:00
|
|
|
lv_bar_set_anim_time(barProgress, 500);
|
|
|
|
lv_bar_set_range(barProgress, 0, 100);
|
2021-04-04 04:08:51 +02:00
|
|
|
lv_bar_set_value(barProgress, 0, LV_ANIM_OFF);
|
2021-07-19 15:26:12 +02:00
|
|
|
|
|
|
|
taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
|
2021-01-20 21:34:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Navigation::~Navigation() {
|
2021-07-19 15:26:12 +02:00
|
|
|
lv_task_del(taskRefresh);
|
2021-01-20 21:34:09 +01:00
|
|
|
lv_obj_clean(lv_scr_act());
|
|
|
|
}
|
|
|
|
|
2021-07-19 15:26:12 +02:00
|
|
|
void Navigation::Refresh() {
|
2021-06-01 21:01:32 +02:00
|
|
|
if (flag != navService.getFlag()) {
|
|
|
|
flag = navService.getFlag();
|
2022-03-20 15:47:25 +01:00
|
|
|
lv_label_set_text_static(imgFlag, iconForName(flag));
|
2021-01-20 21:34:09 +01:00
|
|
|
}
|
|
|
|
|
2021-06-01 21:01:32 +02:00
|
|
|
if (narrative != navService.getNarrative()) {
|
|
|
|
narrative = navService.getNarrative();
|
|
|
|
lv_label_set_text(txtNarrative, narrative.data());
|
2021-01-20 21:34:09 +01:00
|
|
|
}
|
|
|
|
|
2021-06-01 21:01:32 +02:00
|
|
|
if (manDist != navService.getManDist()) {
|
|
|
|
manDist = navService.getManDist();
|
|
|
|
lv_label_set_text(txtManDist, manDist.data());
|
2021-01-20 21:34:09 +01:00
|
|
|
}
|
|
|
|
|
2021-06-01 21:01:32 +02:00
|
|
|
if (progress != navService.getProgress()) {
|
|
|
|
progress = navService.getProgress();
|
|
|
|
lv_bar_set_value(barProgress, progress, LV_ANIM_OFF);
|
|
|
|
if (progress > 90) {
|
2021-04-18 19:28:14 +02:00
|
|
|
lv_obj_set_style_local_bg_color(barProgress, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_RED);
|
2021-04-04 04:08:51 +02:00
|
|
|
} else {
|
2021-04-18 19:28:14 +02:00
|
|
|
lv_obj_set_style_local_bg_color(barProgress, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_ORANGE);
|
2021-04-04 04:08:51 +02:00
|
|
|
}
|
2021-01-20 21:34:09 +01:00
|
|
|
}
|
|
|
|
}
|