2017-07-22 14:30:20 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
|
|
|
* Copyright (C) 2017 Furrtek
|
|
|
|
*
|
|
|
|
* This file is part of PortaPack.
|
|
|
|
*
|
|
|
|
* This program 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 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program 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; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2017-08-27 17:06:11 -04:00
|
|
|
#ifndef __GEOMAP_H__
|
|
|
|
#define __GEOMAP_H__
|
|
|
|
|
2017-07-22 14:30:20 -04:00
|
|
|
#include "ui.hpp"
|
|
|
|
#include "file.hpp"
|
|
|
|
#include "ui_navigation.hpp"
|
|
|
|
#include "ui_font_fixed_8x16.hpp"
|
|
|
|
|
|
|
|
#include "portapack.hpp"
|
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
|
2017-08-12 02:07:21 -04:00
|
|
|
enum GeoMapMode {
|
|
|
|
DISPLAY,
|
|
|
|
PROMPT
|
|
|
|
};
|
|
|
|
|
2017-08-03 14:06:59 -04:00
|
|
|
class GeoPos : public View {
|
2017-07-22 14:30:20 -04:00
|
|
|
public:
|
2017-10-28 14:22:55 -04:00
|
|
|
enum alt_unit {
|
|
|
|
FEET = 0,
|
|
|
|
METERS
|
|
|
|
};
|
|
|
|
|
2017-08-12 02:07:21 -04:00
|
|
|
std::function<void(int32_t, float, float)> on_change { };
|
2017-08-03 14:06:59 -04:00
|
|
|
|
2017-10-28 14:22:55 -04:00
|
|
|
GeoPos(const Point pos, const alt_unit altitude_unit);
|
2017-08-03 14:06:59 -04:00
|
|
|
|
|
|
|
void focus() override;
|
|
|
|
|
|
|
|
void set_read_only(bool v);
|
|
|
|
void set_altitude(int32_t altitude);
|
|
|
|
void set_lat(float lat);
|
|
|
|
void set_lon(float lon);
|
2017-08-12 02:07:21 -04:00
|
|
|
int32_t altitude();
|
2017-08-03 14:06:59 -04:00
|
|
|
float lat();
|
|
|
|
float lon();
|
2017-08-12 02:07:21 -04:00
|
|
|
|
|
|
|
void set_report_change(bool v);
|
2017-08-03 14:06:59 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool read_only { false };
|
2017-08-12 02:07:21 -04:00
|
|
|
bool report_change { true };
|
2017-10-28 14:22:55 -04:00
|
|
|
alt_unit altitude_unit_ { };
|
2017-08-03 14:06:59 -04:00
|
|
|
|
|
|
|
Labels labels_position {
|
2017-10-28 14:22:55 -04:00
|
|
|
{ { 1 * 8, 0 * 16 }, "Alt:", Color::light_grey() },
|
2017-10-28 13:16:06 -04:00
|
|
|
{ { 1 * 8, 1 * 16 }, "Lat: * ' \"", Color::light_grey() }, // No ° symbol in 8x16 font
|
|
|
|
{ { 1 * 8, 2 * 16 }, "Lon: * ' \"", Color::light_grey() },
|
2017-08-03 14:06:59 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
NumberField field_altitude {
|
2017-10-28 13:16:06 -04:00
|
|
|
{ 6 * 8, 0 * 16 },
|
2017-08-03 14:06:59 -04:00
|
|
|
5,
|
|
|
|
{ -1000, 50000 },
|
|
|
|
250,
|
|
|
|
' '
|
|
|
|
};
|
2017-10-28 14:22:55 -04:00
|
|
|
Text text_alt_unit {
|
|
|
|
{ 12 * 8, 0 * 16, 2 * 8, 16 },
|
|
|
|
""
|
|
|
|
};
|
2017-08-03 14:06:59 -04:00
|
|
|
|
|
|
|
NumberField field_lat_degrees {
|
2017-10-28 13:16:06 -04:00
|
|
|
{ 5 * 8, 1 * 16 }, 4, { -90, 90 }, 1, ' '
|
2017-08-03 14:06:59 -04:00
|
|
|
};
|
|
|
|
NumberField field_lat_minutes {
|
2017-10-28 13:16:06 -04:00
|
|
|
{ 10 * 8, 1 * 16 }, 2, { 0, 59 }, 1, ' '
|
2017-08-03 14:06:59 -04:00
|
|
|
};
|
|
|
|
NumberField field_lat_seconds {
|
2017-10-28 13:16:06 -04:00
|
|
|
{ 13 * 8, 1 * 16 }, 2, { 0, 59 }, 1, ' '
|
|
|
|
};
|
|
|
|
Text text_lat_decimal {
|
|
|
|
{ 17 * 8, 1 * 16, 13 * 8, 1 * 16 },
|
|
|
|
""
|
2017-07-30 09:46:42 -04:00
|
|
|
};
|
|
|
|
|
2017-08-03 14:06:59 -04:00
|
|
|
NumberField field_lon_degrees {
|
2017-10-28 13:16:06 -04:00
|
|
|
{ 5 * 8, 2 * 16 }, 4, { -180, 180 }, 1, ' '
|
2017-08-03 14:06:59 -04:00
|
|
|
};
|
|
|
|
NumberField field_lon_minutes {
|
2017-10-28 13:16:06 -04:00
|
|
|
{ 10 * 8, 2 * 16 }, 2, { 0, 59 }, 1, ' '
|
2017-08-03 14:06:59 -04:00
|
|
|
};
|
|
|
|
NumberField field_lon_seconds {
|
2017-10-28 13:16:06 -04:00
|
|
|
{ 13 * 8, 2 * 16 }, 2, { 0, 59 }, 1, ' '
|
|
|
|
};
|
|
|
|
Text text_lon_decimal {
|
|
|
|
{ 17 * 8, 2 * 16, 13 * 8, 1 * 16 },
|
|
|
|
""
|
2017-08-03 14:06:59 -04:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-08-12 02:07:21 -04:00
|
|
|
class GeoMap : public Widget {
|
|
|
|
public:
|
|
|
|
std::function<void(float, float)> on_move { };
|
|
|
|
|
|
|
|
GeoMap(Rect parent_rect);
|
|
|
|
|
|
|
|
void paint(Painter& painter) override;
|
|
|
|
|
|
|
|
bool on_touch(const TouchEvent event) override;
|
|
|
|
|
|
|
|
bool init();
|
|
|
|
void set_mode(GeoMapMode mode);
|
|
|
|
void move(const float lon, const float lat);
|
2017-08-27 17:06:11 -04:00
|
|
|
void set_tag(std::string new_tag) {
|
|
|
|
tag_ = new_tag;
|
|
|
|
}
|
2017-08-12 02:07:21 -04:00
|
|
|
|
2020-07-25 11:23:46 -04:00
|
|
|
void set_angle(uint16_t new_angle){
|
|
|
|
angle_ = new_angle;
|
|
|
|
}
|
|
|
|
|
2017-08-12 02:07:21 -04:00
|
|
|
private:
|
2020-07-24 17:09:21 -04:00
|
|
|
void draw_bearing(const Point origin, const uint16_t angle, uint32_t size, const Color color);
|
2017-08-12 02:07:21 -04:00
|
|
|
|
|
|
|
GeoMapMode mode_ { };
|
|
|
|
File map_file { };
|
|
|
|
uint16_t map_width { }, map_height { };
|
|
|
|
int32_t map_center_x { }, map_center_y { };
|
|
|
|
float lon_ratio { }, lat_ratio { };
|
|
|
|
int32_t x_pos { }, y_pos { };
|
|
|
|
int32_t prev_x_pos { 0xFFFF }, prev_y_pos { 0xFFFF };
|
|
|
|
float lat_ { };
|
|
|
|
float lon_ { };
|
2020-07-24 17:09:21 -04:00
|
|
|
uint16_t angle_ { };
|
2017-08-27 17:06:11 -04:00
|
|
|
std::string tag_ { };
|
2017-08-12 02:07:21 -04:00
|
|
|
};
|
|
|
|
|
2017-08-03 14:06:59 -04:00
|
|
|
class GeoMapView : public View {
|
|
|
|
public:
|
2017-08-28 02:05:31 -04:00
|
|
|
GeoMapView(
|
|
|
|
NavigationView& nav,
|
|
|
|
const std::string& tag,
|
|
|
|
int32_t altitude,
|
2017-10-28 14:22:55 -04:00
|
|
|
GeoPos::alt_unit altitude_unit,
|
2017-08-28 02:05:31 -04:00
|
|
|
float lat,
|
|
|
|
float lon,
|
2020-07-24 17:09:21 -04:00
|
|
|
uint16_t angle,
|
2017-10-27 12:54:50 -04:00
|
|
|
const std::function<void(void)> on_close = nullptr
|
2017-08-28 02:05:31 -04:00
|
|
|
);
|
|
|
|
GeoMapView(NavigationView& nav,
|
|
|
|
int32_t altitude,
|
2017-10-28 14:22:55 -04:00
|
|
|
GeoPos::alt_unit altitude_unit,
|
2017-08-28 02:05:31 -04:00
|
|
|
float lat,
|
|
|
|
float lon,
|
|
|
|
const std::function<void(int32_t, float, float)> on_done
|
|
|
|
);
|
|
|
|
~GeoMapView();
|
2017-08-03 14:06:59 -04:00
|
|
|
|
|
|
|
GeoMapView(const GeoMapView&) = delete;
|
|
|
|
GeoMapView(GeoMapView&&) = delete;
|
|
|
|
GeoMapView& operator=(const GeoMapView&) = delete;
|
|
|
|
GeoMapView& operator=(GeoMapView&&) = delete;
|
|
|
|
|
2017-07-22 14:30:20 -04:00
|
|
|
void focus() override;
|
|
|
|
|
2020-07-24 17:09:21 -04:00
|
|
|
void update_position(float lat, float lon, uint16_t angle);
|
2017-08-27 17:06:11 -04:00
|
|
|
|
2017-07-22 14:30:20 -04:00
|
|
|
std::string title() const override { return "Map view"; };
|
|
|
|
|
|
|
|
private:
|
|
|
|
NavigationView& nav_;
|
2017-08-12 02:07:21 -04:00
|
|
|
|
|
|
|
void setup();
|
|
|
|
|
2017-08-03 14:06:59 -04:00
|
|
|
const std::function<void(int32_t, float, float)> on_done { };
|
2017-08-12 02:07:21 -04:00
|
|
|
|
|
|
|
const Dim banner_height = 3 * 16;
|
|
|
|
GeoMapMode mode_ { };
|
2017-08-03 14:06:59 -04:00
|
|
|
int32_t altitude_ { };
|
2017-10-28 14:22:55 -04:00
|
|
|
GeoPos::alt_unit altitude_unit_ { };
|
2017-08-03 14:06:59 -04:00
|
|
|
float lat_ { };
|
|
|
|
float lon_ { };
|
2020-07-24 17:09:21 -04:00
|
|
|
uint16_t angle_ { };
|
2017-08-28 02:05:31 -04:00
|
|
|
std::function<void(void)> on_close_ { nullptr };
|
2017-07-22 14:30:20 -04:00
|
|
|
|
2017-10-14 06:33:41 -04:00
|
|
|
bool map_opened { };
|
2017-07-22 14:30:20 -04:00
|
|
|
|
2017-08-03 14:06:59 -04:00
|
|
|
GeoPos geopos {
|
2017-10-28 14:22:55 -04:00
|
|
|
{ 0, 0 },
|
|
|
|
altitude_unit_
|
2017-07-22 14:30:20 -04:00
|
|
|
};
|
|
|
|
|
2017-08-12 02:07:21 -04:00
|
|
|
GeoMap geomap {
|
|
|
|
{ 0, banner_height, 240, 320 - 16 - banner_height }
|
|
|
|
};
|
|
|
|
|
2017-08-03 14:06:59 -04:00
|
|
|
Button button_ok {
|
|
|
|
{ 20 * 8, 8, 8 * 8, 2 * 16 },
|
|
|
|
"OK"
|
2017-07-22 14:30:20 -04:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
} /* namespace ui */
|
2017-08-27 17:06:11 -04:00
|
|
|
|
|
|
|
#endif
|