2017-10-05 00:38:45 -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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ui_sonde.hpp"
|
|
|
|
#include "baseband_api.hpp"
|
2021-06-08 18:07:37 -04:00
|
|
|
#include "audio.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-05 00:38:45 -04:00
|
|
|
|
2017-10-28 13:16:06 -04:00
|
|
|
void SondeLogger::on_packet(const sonde::Packet& packet) {
|
2017-10-05 00:38:45 -04:00
|
|
|
const auto formatted = packet.symbols_formatted();
|
2017-10-28 13:16:06 -04:00
|
|
|
log_file.write_entry(packet.received_at(), formatted.data);
|
|
|
|
}
|
2017-10-05 00:38:45 -04:00
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
|
2022-01-02 05:56:55 -05:00
|
|
|
|
2017-10-05 00:38:45 -04:00
|
|
|
SondeView::SondeView(NavigationView& nav) {
|
|
|
|
baseband::run_image(portapack::spi_flash::image_tag_sonde);
|
|
|
|
|
|
|
|
add_children({
|
2017-10-27 12:54:50 -04:00
|
|
|
&labels,
|
2017-10-28 13:16:06 -04:00
|
|
|
&field_frequency,
|
2017-10-05 00:38:45 -04:00
|
|
|
&field_rf_amp,
|
|
|
|
&field_lna,
|
|
|
|
&field_vga,
|
2017-10-27 12:54:50 -04:00
|
|
|
&rssi,
|
2021-06-08 18:07:37 -04:00
|
|
|
&field_volume,
|
|
|
|
&check_beep,
|
2017-10-28 13:16:06 -04:00
|
|
|
&check_log,
|
2020-08-24 16:31:27 -04:00
|
|
|
&check_crc,
|
2017-10-27 12:54:50 -04:00
|
|
|
&text_signature,
|
2017-10-28 13:16:06 -04:00
|
|
|
&text_serial,
|
2020-08-24 16:31:27 -04:00
|
|
|
&text_timestamp,
|
2017-10-28 13:16:06 -04:00
|
|
|
&text_voltage,
|
2020-08-24 16:31:27 -04:00
|
|
|
&text_frame,
|
|
|
|
&text_temp,
|
|
|
|
&text_humid,
|
2017-10-27 12:54:50 -04:00
|
|
|
&geopos,
|
2022-01-02 05:56:55 -05:00
|
|
|
&button_see_qr,
|
2017-10-27 12:54:50 -04:00
|
|
|
&button_see_map
|
2017-10-05 00:38:45 -04:00
|
|
|
});
|
|
|
|
|
2021-06-13 18:35:33 -04:00
|
|
|
// start from the frequency currently stored in the receiver_model:
|
|
|
|
target_frequency_ = receiver_model.tuning_frequency();
|
|
|
|
|
2017-10-27 12:54:50 -04:00
|
|
|
field_frequency.set_value(target_frequency_);
|
2020-08-14 14:51:12 -04:00
|
|
|
field_frequency.set_step(500); //euquiq: was 10000, but we are using this for fine-tunning
|
2017-10-05 00:38:45 -04:00
|
|
|
field_frequency.on_change = [this](rf::Frequency f) {
|
2017-10-06 00:35:25 -04:00
|
|
|
set_target_frequency(f);
|
2017-10-05 00:38:45 -04:00
|
|
|
field_frequency.set_value(f);
|
|
|
|
};
|
|
|
|
field_frequency.on_edit = [this, &nav]() {
|
|
|
|
// TODO: Provide separate modal method/scheme?
|
|
|
|
auto new_view = nav.push<FrequencyKeypadView>(receiver_model.tuning_frequency());
|
|
|
|
new_view->on_changed = [this](rf::Frequency f) {
|
2017-10-06 00:35:25 -04:00
|
|
|
set_target_frequency(f);
|
2017-10-05 00:38:45 -04:00
|
|
|
field_frequency.set_value(f);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-10-27 12:54:50 -04:00
|
|
|
geopos.set_read_only(true);
|
|
|
|
|
2021-06-08 18:07:37 -04:00
|
|
|
check_beep.on_select = [this](Checkbox&, bool v) {
|
|
|
|
beep = v;
|
|
|
|
};
|
|
|
|
|
2017-10-28 13:16:06 -04:00
|
|
|
check_log.on_select = [this](Checkbox&, bool v) {
|
|
|
|
logging = v;
|
|
|
|
};
|
2020-08-24 16:31:27 -04:00
|
|
|
|
|
|
|
check_crc.on_select = [this](Checkbox&, bool v) {
|
|
|
|
use_crc = v;
|
|
|
|
};
|
2017-10-28 13:16:06 -04:00
|
|
|
|
2022-01-30 05:37:46 -05:00
|
|
|
receiver_model.set_tuning_frequency(tuning_frequency());
|
|
|
|
receiver_model.set_sampling_rate(sampling_rate);
|
|
|
|
receiver_model.set_baseband_bandwidth(baseband_bandwidth);
|
|
|
|
receiver_model.enable(); // Before using radio::enable(), but not updating Ant.DC-Bias.
|
|
|
|
|
|
|
|
/* radio::enable({ // this can be removed, previous version, no DC-bias ant. control.
|
2017-10-27 12:54:50 -04:00
|
|
|
tuning_frequency(),
|
2017-10-05 00:38:45 -04:00
|
|
|
sampling_rate,
|
|
|
|
baseband_bandwidth,
|
|
|
|
rf::Direction::Receive,
|
|
|
|
receiver_model.rf_amp(),
|
|
|
|
static_cast<int8_t>(receiver_model.lna()),
|
|
|
|
static_cast<int8_t>(receiver_model.vga()),
|
2022-01-30 05:37:46 -05:00
|
|
|
}); */
|
2017-10-05 00:38:45 -04:00
|
|
|
|
2022-01-02 05:56:55 -05:00
|
|
|
|
|
|
|
// QR code with geo URI
|
|
|
|
button_see_qr.on_select = [this, &nav](Button&) {
|
|
|
|
nav.push<QRCodeView>(geo_uri);
|
|
|
|
};
|
|
|
|
|
2017-10-27 12:54:50 -04:00
|
|
|
button_see_map.on_select = [this, &nav](Button&) {
|
|
|
|
nav.push<GeoMapView>(
|
2020-08-14 14:51:12 -04:00
|
|
|
sonde_id,
|
|
|
|
gps_info.alt,
|
2017-10-28 14:22:55 -04:00
|
|
|
GeoPos::alt_unit::METERS,
|
2020-08-14 14:51:12 -04:00
|
|
|
gps_info.lat,
|
|
|
|
gps_info.lon,
|
|
|
|
999); //set a dummy heading out of range to draw a cross...probably not ideal?
|
2017-10-27 12:54:50 -04:00
|
|
|
};
|
2021-06-08 18:07:37 -04:00
|
|
|
|
2017-10-28 13:16:06 -04:00
|
|
|
logger = std::make_unique<SondeLogger>();
|
|
|
|
if (logger)
|
2017-10-05 00:38:45 -04:00
|
|
|
logger->append(u"sonde.txt");
|
2021-06-08 18:07:37 -04:00
|
|
|
|
|
|
|
// initialize audio:
|
|
|
|
|
|
|
|
field_volume.set_value((receiver_model.headphone_volume() - audio::headphone::volume_range().max).decibel() + 99);
|
2017-10-28 13:16:06 -04:00
|
|
|
|
2021-06-08 18:07:37 -04:00
|
|
|
field_volume.on_change = [this](int32_t v) {
|
|
|
|
this->on_headphone_volume_changed(v);
|
|
|
|
};
|
|
|
|
|
|
|
|
audio::output::start();
|
|
|
|
audio::output::speaker_unmute();
|
|
|
|
|
2021-06-09 04:10:01 -04:00
|
|
|
// 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);
|
|
|
|
|
2021-06-08 18:07:37 -04:00
|
|
|
baseband::set_pitch_rssi(0, true);
|
2017-10-05 00:38:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
SondeView::~SondeView() {
|
2021-06-08 18:07:37 -04:00
|
|
|
baseband::set_pitch_rssi(0, false);
|
2022-01-30 05:37:46 -05:00
|
|
|
/* radio::disable(); */
|
|
|
|
receiver_model.disable(); // to switch off all, including DC bias.
|
2017-10-05 00:38:45 -04:00
|
|
|
baseband::shutdown();
|
2021-06-08 18:07:37 -04:00
|
|
|
audio::output::stop();
|
2017-10-05 00:38:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void SondeView::focus() {
|
|
|
|
field_vga.focus();
|
|
|
|
}
|
|
|
|
|
2022-01-02 05:56:55 -05:00
|
|
|
|
|
|
|
// used to convert float to character pointer, since unfortunately function like
|
|
|
|
// sprintf and c_str aren't supported.
|
|
|
|
char * SondeView::float_to_char(float x, char *p)
|
|
|
|
{
|
|
|
|
|
|
|
|
char *s = p + 9; // go to end of buffer
|
|
|
|
uint16_t decimals; // variable to store the decimals
|
|
|
|
int units; // variable to store the units (part to left of decimal place)
|
|
|
|
if (x < 0) { // take care of negative numbers
|
|
|
|
decimals = (int)(x * -100000) % 100000; // make 1000 for 3 decimals etc.
|
|
|
|
units = (int)(-1 * x);
|
|
|
|
} else { // positive numbers
|
|
|
|
decimals = (int)(x * 100000) % 100000;
|
|
|
|
units = (int)x;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: more elegant solution (loop?)
|
|
|
|
*--s = (decimals % 10) + '0';
|
|
|
|
decimals /= 10;
|
|
|
|
*--s = (decimals % 10) + '0';
|
|
|
|
decimals /= 10;
|
|
|
|
*--s = (decimals % 10) + '0';
|
|
|
|
decimals /= 10;
|
|
|
|
*--s = (decimals % 10) + '0';
|
|
|
|
decimals /= 10;
|
|
|
|
*--s = (decimals % 10) + '0';
|
|
|
|
*--s = '.';
|
|
|
|
|
|
|
|
while (units > 0) {
|
|
|
|
*--s = (units % 10) + '0';
|
|
|
|
units /= 10;
|
|
|
|
}
|
|
|
|
if (x < 0) *--s = '-'; // unary minus sign for negative numbers
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2020-08-24 16:31:27 -04:00
|
|
|
void SondeView::on_packet(const sonde::Packet &packet)
|
|
|
|
{
|
|
|
|
if (!use_crc || packet.crc_ok()) //euquiq: Reject bad packet if crc is on
|
|
|
|
{
|
2022-01-02 05:56:55 -05:00
|
|
|
|
|
|
|
char buffer_lat[10] = {};
|
|
|
|
char buffer_lon[10] = {};
|
|
|
|
|
|
|
|
strcpy(geo_uri, "geo:");
|
|
|
|
strcat(geo_uri, float_to_char(gps_info.lat, buffer_lat));
|
|
|
|
strcat(geo_uri, ",");
|
|
|
|
strcat(geo_uri, float_to_char(gps_info.lon, buffer_lon));
|
|
|
|
|
2020-08-24 16:31:27 -04:00
|
|
|
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));
|
|
|
|
//if (decimals < 0)
|
|
|
|
// decimals = -decimals;
|
|
|
|
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));
|
|
|
|
// if (decimals < 0)
|
|
|
|
// decimals = -decimals;
|
|
|
|
text_temp.set(to_string_dec_int((int)temp_humid_info.temp) + "." + to_string_dec_uint(decimals, 1) + "C");
|
|
|
|
}
|
|
|
|
|
|
|
|
gps_info = packet.get_GPS_data();
|
2021-06-08 18:07:37 -04:00
|
|
|
|
2020-08-24 16:31:27 -04:00
|
|
|
geopos.set_altitude(gps_info.alt);
|
|
|
|
geopos.set_lat(gps_info.lat);
|
|
|
|
geopos.set_lon(gps_info.lon);
|
|
|
|
|
2021-06-08 18:07:37 -04:00
|
|
|
if (logger && logging) {
|
2020-08-24 16:31:27 -04:00
|
|
|
logger->on_packet(packet);
|
2021-06-08 18:07:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if(beep) {
|
|
|
|
baseband::request_beep();
|
|
|
|
}
|
2017-10-28 13:16:06 -04:00
|
|
|
}
|
2017-10-05 00:38:45 -04:00
|
|
|
}
|
|
|
|
|
2021-06-08 18:07:37 -04:00
|
|
|
void SondeView::on_headphone_volume_changed(int32_t v) {
|
|
|
|
const auto new_volume = volume_t::decibel(v - 99) + audio::headphone::volume_range().max;
|
|
|
|
receiver_model.set_headphone_volume(new_volume);
|
|
|
|
}
|
|
|
|
|
2017-10-06 00:35:25 -04:00
|
|
|
void SondeView::set_target_frequency(const uint32_t new_value) {
|
|
|
|
target_frequency_ = new_value;
|
2021-06-13 18:35:33 -04:00
|
|
|
//radio::set_tuning_frequency(tuning_frequency());
|
|
|
|
// we better remember the tuned frequency, by using this function instead:
|
2021-06-16 18:23:47 -04:00
|
|
|
receiver_model.set_tuning_frequency(target_frequency_);
|
2017-10-06 00:35:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t SondeView::tuning_frequency() const {
|
|
|
|
return target_frequency_ - (sampling_rate / 4);
|
|
|
|
}
|
|
|
|
|
2017-10-05 00:38:45 -04:00
|
|
|
} /* namespace ui */
|