2017-10-05 00:38:45 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
|
|
|
* Copyright (C) 2017 Furrtek
|
2024-03-21 05:14:54 -04:00
|
|
|
* Copyright (C) 2024 Mark Thompson
|
2017-10-05 00:38:45 -04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ui_sonde.hpp"
|
|
|
|
#include "baseband_api.hpp"
|
2021-06-08 18:07:37 -04:00
|
|
|
#include "audio.hpp"
|
2022-04-15 08:43:44 -04:00
|
|
|
#include "app_settings.hpp"
|
2024-03-25 03:44:49 -04:00
|
|
|
#include "file_path.hpp"
|
2017-10-05 00:38:45 -04:00
|
|
|
|
|
|
|
#include "portapack.hpp"
|
2020-08-24 16:31:27 -04:00
|
|
|
#include <cstring>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2017-10-05 00:38:45 -04:00
|
|
|
using namespace portapack;
|
|
|
|
|
|
|
|
#include "string_format.hpp"
|
2020-08-24 16:31:27 -04:00
|
|
|
#include "complex.hpp"
|
|
|
|
|
2017-10-28 13:16:06 -04:00
|
|
|
void SondeLogger::on_packet(const sonde::Packet& packet) {
|
2023-05-18 16:16:05 -04:00
|
|
|
const auto formatted = packet.symbols_formatted();
|
|
|
|
log_file.write_entry(packet.received_at(), formatted.data);
|
2017-10-28 13:16:06 -04:00
|
|
|
}
|
2017-10-05 00:38:45 -04:00
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
|
2023-06-18 15:11:04 -04:00
|
|
|
SondeView::SondeView(NavigationView& nav)
|
|
|
|
: nav_{nav} {
|
2023-05-18 16:16:05 -04:00
|
|
|
baseband::run_image(portapack::spi_flash::image_tag_sonde);
|
|
|
|
|
|
|
|
add_children({&labels,
|
|
|
|
&field_frequency,
|
|
|
|
&field_rf_amp,
|
|
|
|
&field_lna,
|
|
|
|
&field_vga,
|
|
|
|
&rssi,
|
|
|
|
&field_volume,
|
|
|
|
&check_beep,
|
|
|
|
&check_log,
|
|
|
|
&check_crc,
|
|
|
|
&text_signature,
|
|
|
|
&text_serial,
|
|
|
|
&text_timestamp,
|
|
|
|
&text_voltage,
|
|
|
|
&text_frame,
|
|
|
|
&text_temp,
|
|
|
|
&text_humid,
|
|
|
|
&geopos,
|
|
|
|
&button_see_qr,
|
|
|
|
&button_see_map});
|
|
|
|
|
|
|
|
field_frequency.set_step(500); // euquiq: was 10000, but we are using this for fine-tunning
|
|
|
|
|
|
|
|
geopos.set_read_only(true);
|
|
|
|
|
2024-03-21 05:14:54 -04:00
|
|
|
check_beep.set_value(beep);
|
2023-05-18 16:16:05 -04:00
|
|
|
check_beep.on_select = [this](Checkbox&, bool v) {
|
|
|
|
beep = v;
|
2024-03-21 05:14:54 -04:00
|
|
|
if (beep)
|
2024-03-23 03:21:35 -04:00
|
|
|
baseband::request_audio_beep(1000, 24000, 60); // 1khz tone for 60ms to acknowledge enablement
|
2023-05-18 16:16:05 -04:00
|
|
|
};
|
|
|
|
|
2024-03-21 05:14:54 -04:00
|
|
|
check_log.set_value(logging);
|
2023-05-18 16:16:05 -04:00
|
|
|
check_log.on_select = [this](Checkbox&, bool v) {
|
|
|
|
logging = v;
|
|
|
|
};
|
|
|
|
|
2024-03-21 05:14:54 -04:00
|
|
|
check_crc.set_value(use_crc);
|
2023-05-18 16:16:05 -04:00
|
|
|
check_crc.on_select = [this](Checkbox&, bool v) {
|
|
|
|
use_crc = v;
|
|
|
|
};
|
|
|
|
|
2023-05-24 00:22:30 -04:00
|
|
|
receiver_model.enable();
|
2023-05-18 16:16:05 -04:00
|
|
|
|
|
|
|
// QR code with geo URI
|
|
|
|
button_see_qr.on_select = [this, &nav](Button&) {
|
2024-03-21 11:56:06 -04:00
|
|
|
std::string geo_uri = "geo:" + to_string_decimal(geopos.lat(), 5) + "," + to_string_decimal(geopos.lon(), 5); // 5 decimal digits for ~1 meter accuracy
|
|
|
|
nav.push<QRCodeView>(geo_uri.data());
|
2023-05-18 16:16:05 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
button_see_map.on_select = [this, &nav](Button&) {
|
2024-01-11 16:17:06 -05:00
|
|
|
geomap_view_ = nav.push<GeoMapView>(
|
2023-05-18 16:16:05 -04:00
|
|
|
sonde_id,
|
2024-03-21 11:56:06 -04:00
|
|
|
geopos.altitude(),
|
2023-05-18 16:16:05 -04:00
|
|
|
GeoPos::alt_unit::METERS,
|
2024-01-05 07:44:30 -05:00
|
|
|
GeoPos::spd_unit::HIDDEN,
|
2024-03-21 11:56:06 -04:00
|
|
|
geopos.lat(),
|
|
|
|
geopos.lon(),
|
2023-05-18 16:16:05 -04:00
|
|
|
999); // set a dummy heading out of range to draw a cross...probably not ideal?
|
2024-01-11 16:17:06 -05:00
|
|
|
nav.set_on_pop([this]() {
|
|
|
|
geomap_view_ = nullptr;
|
|
|
|
});
|
2023-05-18 16:16:05 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
logger = std::make_unique<SondeLogger>();
|
|
|
|
if (logger)
|
2024-03-25 03:44:49 -04:00
|
|
|
logger->append(logs_dir / u"SONDE.TXT");
|
2023-05-18 16:16:05 -04:00
|
|
|
|
|
|
|
audio::output::start();
|
|
|
|
|
|
|
|
// inject a PitchRSSIConfigureMessage in order to arm
|
|
|
|
// the pitch rssi events that will be used by the
|
|
|
|
// processor:
|
|
|
|
const PitchRSSIConfigureMessage message{true, 0};
|
|
|
|
|
|
|
|
shared_memory.application_queue.push(message);
|
|
|
|
|
|
|
|
baseband::set_pitch_rssi(0, true);
|
2017-10-05 00:38:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
SondeView::~SondeView() {
|
2023-05-18 16:16:05 -04:00
|
|
|
baseband::set_pitch_rssi(0, false);
|
2022-04-15 08:43:44 -04:00
|
|
|
|
2023-05-24 00:22:30 -04:00
|
|
|
receiver_model.disable();
|
2023-05-18 16:16:05 -04:00
|
|
|
baseband::shutdown();
|
|
|
|
audio::output::stop();
|
2017-10-05 00:38:45 -04:00
|
|
|
}
|
|
|
|
|
2024-01-11 16:17:06 -05:00
|
|
|
void SondeView::on_gps(const GPSPosDataMessage* msg) {
|
|
|
|
if (!geomap_view_)
|
|
|
|
return;
|
|
|
|
geomap_view_->update_my_position(msg->lat, msg->lon, msg->altitude);
|
|
|
|
}
|
|
|
|
void SondeView::on_orientation(const OrientationDataMessage* msg) {
|
|
|
|
if (!geomap_view_)
|
|
|
|
return;
|
|
|
|
geomap_view_->update_my_orientation(msg->angle, true);
|
|
|
|
}
|
|
|
|
|
2017-10-05 00:38:45 -04:00
|
|
|
void SondeView::focus() {
|
2023-06-18 02:14:29 -04:00
|
|
|
field_frequency.focus();
|
2017-10-05 00:38:45 -04:00
|
|
|
}
|
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
void SondeView::on_packet(const sonde::Packet& packet) {
|
|
|
|
if (!use_crc || packet.crc_ok()) // euquiq: Reject bad packet if crc is on
|
|
|
|
{
|
|
|
|
text_signature.set(packet.type_string());
|
|
|
|
|
|
|
|
sonde_id = packet.serial_number(); // used also as tag on the geomap
|
|
|
|
text_serial.set(sonde_id);
|
|
|
|
|
|
|
|
text_timestamp.set(to_string_timestamp(packet.received_at()));
|
|
|
|
|
|
|
|
text_voltage.set(unit_auto_scale(packet.battery_voltage(), 2, 2) + "V");
|
|
|
|
|
|
|
|
text_frame.set(to_string_dec_uint(packet.frame(), 0)); // euquiq: integrate frame #, temp & humid.
|
|
|
|
|
|
|
|
temp_humid_info = packet.get_temp_humid();
|
|
|
|
if (temp_humid_info.humid != 0) {
|
|
|
|
double decimals = abs(get_decimals(temp_humid_info.humid, 10, true));
|
|
|
|
text_humid.set(to_string_dec_int((int)temp_humid_info.humid) + "." + to_string_dec_uint(decimals, 1) + "%");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (temp_humid_info.temp != 0) {
|
|
|
|
double decimals = abs(get_decimals(temp_humid_info.temp, 10, true));
|
2023-08-20 05:14:22 -04:00
|
|
|
text_temp.set(to_string_dec_int((int)temp_humid_info.temp) + "." + to_string_dec_uint(decimals, 1) + STR_DEGREES_C);
|
2023-05-18 16:16:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
gps_info = packet.get_GPS_data();
|
|
|
|
|
|
|
|
geopos.set_altitude(gps_info.alt);
|
|
|
|
geopos.set_lat(gps_info.lat);
|
|
|
|
geopos.set_lon(gps_info.lon);
|
|
|
|
|
|
|
|
if (logger && logging) {
|
|
|
|
logger->on_packet(packet);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (beep) {
|
2024-03-21 05:14:54 -04:00
|
|
|
baseband::request_rssi_beep();
|
2023-05-18 16:16:05 -04:00
|
|
|
}
|
|
|
|
}
|
2017-10-05 00:38:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace ui */
|