mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-05-08 17:55:00 -04:00
SYNC
This commit is contained in:
parent
29ec87a9ad
commit
44638e504b
166 changed files with 8700 additions and 3967 deletions
|
@ -21,48 +21,19 @@
|
|||
|
||||
#include "ui_receiver.hpp"
|
||||
|
||||
#include "ui_spectrum.hpp"
|
||||
#include "ui_console.hpp"
|
||||
|
||||
#include "ff.h"
|
||||
|
||||
#include "portapack.hpp"
|
||||
using namespace portapack;
|
||||
|
||||
#include "ais_baseband.hpp"
|
||||
#include "m4_startup.hpp"
|
||||
#include "string_format.hpp"
|
||||
|
||||
#include "analog_audio_app.hpp"
|
||||
#include "ais_app.hpp"
|
||||
#include "tpms_app.hpp"
|
||||
#include "ert_app.hpp"
|
||||
#include "spectrum_analysis_app.hpp"
|
||||
|
||||
namespace ui {
|
||||
|
||||
/* BasebandBandwidthField ************************************************/
|
||||
|
||||
BasebandBandwidthField::BasebandBandwidthField(
|
||||
Point parent_pos
|
||||
) : OptionsField {
|
||||
parent_pos,
|
||||
4,
|
||||
{
|
||||
{ " 1M8", 1750000 },
|
||||
{ " 2M5", 2500000 },
|
||||
{ " 3M5", 3500000 },
|
||||
{ " 5M ", 5000000 },
|
||||
{ " 5M5", 5500000 },
|
||||
{ " 6M ", 6000000 },
|
||||
{ " 7M ", 7000000 },
|
||||
{ " 8M ", 8000000 },
|
||||
{ " 9M ", 9000000 },
|
||||
{ "10M ", 10000000 },
|
||||
{ "12M ", 12000000 },
|
||||
{ "14M ", 14000000 },
|
||||
{ "15M ", 15000000 },
|
||||
{ "20M ", 20000000 },
|
||||
{ "24M ", 24000000 },
|
||||
{ "28M ", 28000000 },
|
||||
}
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
/* FrequencyField ********************************************************/
|
||||
|
||||
FrequencyField::FrequencyField(
|
||||
|
@ -127,25 +98,7 @@ bool FrequencyField::on_key(const ui::KeyEvent event) {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
/*
|
||||
bool FrequencyField::on_key(const ui::KeyEvent event) override {
|
||||
if( event == ui::KeyEvent::Select ) {
|
||||
|
||||
// NOTE: For testing sampling rate / decimation combinations
|
||||
turbo = !turbo;
|
||||
if( turbo ) {
|
||||
clock_manager.set_sampling_frequency(18432000);
|
||||
radio::set_baseband_decimation_by(6);
|
||||
} else {
|
||||
clock_manager.set_sampling_frequency(12288000);
|
||||
radio::set_baseband_decimation_by(4);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
bool FrequencyField::on_encoder(const EncoderEvent delta) {
|
||||
set_value(value() + (delta * step));
|
||||
return true;
|
||||
|
@ -165,13 +118,7 @@ void FrequencyField::on_focus() {
|
|||
}
|
||||
|
||||
rf::Frequency FrequencyField::clamp_value(rf::Frequency value) {
|
||||
if( value > range.max ) {
|
||||
value = range.max;
|
||||
}
|
||||
if( value < range.min ) {
|
||||
value = range.min;
|
||||
}
|
||||
return value;
|
||||
return range.clip(value);
|
||||
}
|
||||
|
||||
/* FrequencyKeypadView ***************************************************/
|
||||
|
@ -188,7 +135,7 @@ FrequencyKeypadView::FrequencyKeypadView(
|
|||
|
||||
const char* const key_caps = "123456789<0.";
|
||||
|
||||
size_t n = 0;
|
||||
int n = 0;
|
||||
for(auto& button : buttons) {
|
||||
add_child(&button);
|
||||
const std::string label {
|
||||
|
@ -196,8 +143,8 @@ FrequencyKeypadView::FrequencyKeypadView(
|
|||
};
|
||||
button.on_select = button_fn;
|
||||
button.set_parent_rect({
|
||||
static_cast<Coord>((n % 3) * button_w),
|
||||
static_cast<Coord>((n / 3) * button_h + button_h),
|
||||
(n % 3) * button_w,
|
||||
(n / 3) * button_h + button_h,
|
||||
button_w, button_h
|
||||
});
|
||||
button.set_text(label);
|
||||
|
@ -301,7 +248,6 @@ FrequencyOptionsView::FrequencyOptionsView(
|
|||
add_children({ {
|
||||
&text_step,
|
||||
&options_step,
|
||||
&text_correction,
|
||||
&field_ppm,
|
||||
&text_ppm,
|
||||
} });
|
||||
|
@ -339,19 +285,11 @@ RadioGainOptionsView::RadioGainOptionsView(
|
|||
add_children({ {
|
||||
&label_rf_amp,
|
||||
&field_rf_amp,
|
||||
//&label_agc,
|
||||
//&field_agc
|
||||
} });
|
||||
|
||||
field_rf_amp.on_change = [this](int32_t v) {
|
||||
this->on_rf_amp_changed(v);
|
||||
};
|
||||
/*
|
||||
field_agc.set_value(receiver_model.agc());
|
||||
field_agc.on_change = [this](int32_t v) {
|
||||
this->on_agc_changed(v);
|
||||
};
|
||||
*/
|
||||
}
|
||||
|
||||
void RadioGainOptionsView::set_rf_amp(int32_t v_db) {
|
||||
|
@ -363,19 +301,14 @@ void RadioGainOptionsView::on_rf_amp_changed(bool enable) {
|
|||
on_change_rf_amp(enable);
|
||||
}
|
||||
}
|
||||
/*
|
||||
void RadioGainOptionsView::on_agc_changed(bool v) {
|
||||
receiver_model.set_agc(v);
|
||||
}
|
||||
*/
|
||||
|
||||
/* LNAGainField **********************************************************/
|
||||
|
||||
LNAGainField::LNAGainField(
|
||||
Point parent_pos
|
||||
) : NumberField {
|
||||
{ parent_pos }, 2,
|
||||
{ max2837::lna::gain_db_min, max2837::lna::gain_db_max },
|
||||
parent_pos, 2,
|
||||
{ max2837::lna::gain_db_range.minimum, max2837::lna::gain_db_range.maximum },
|
||||
max2837::lna::gain_db_step,
|
||||
' ',
|
||||
}
|
||||
|
@ -392,30 +325,21 @@ void LNAGainField::on_focus() {
|
|||
/* ReceiverView **********************************************************/
|
||||
|
||||
ReceiverView::ReceiverView(
|
||||
NavigationView& nav,
|
||||
ReceiverModel& receiver_model
|
||||
) : receiver_model(receiver_model)
|
||||
{
|
||||
NavigationView& nav
|
||||
) {
|
||||
add_children({ {
|
||||
&rssi,
|
||||
&channel,
|
||||
&audio,
|
||||
&button_done,
|
||||
&field_frequency,
|
||||
&field_lna,
|
||||
//&options_baseband_bandwidth,
|
||||
&field_vga,
|
||||
&options_modulation,
|
||||
//&options_baseband_oversampling,
|
||||
&field_volume,
|
||||
&view_frequency_options,
|
||||
&view_rf_gain_options,
|
||||
} });
|
||||
|
||||
button_done.on_select = [&nav](Button&){
|
||||
nav.pop();
|
||||
};
|
||||
|
||||
field_frequency.set_value(receiver_model.tuning_frequency());
|
||||
field_frequency.set_step(receiver_model.frequency_step());
|
||||
field_frequency.on_change = [this](rf::Frequency f) {
|
||||
|
@ -423,12 +347,11 @@ ReceiverView::ReceiverView(
|
|||
};
|
||||
field_frequency.on_edit = [this, &nav]() {
|
||||
// TODO: Provide separate modal method/scheme?
|
||||
auto new_view = new FrequencyKeypadView { nav, this->receiver_model.tuning_frequency() };
|
||||
auto new_view = nav.push<FrequencyKeypadView>(receiver_model.tuning_frequency());
|
||||
new_view->on_changed = [this](rf::Frequency f) {
|
||||
this->on_tuning_frequency_changed(f);
|
||||
this->field_frequency.set_value(f);
|
||||
};
|
||||
nav.push(new_view);
|
||||
};
|
||||
field_frequency.on_show_options = [this]() {
|
||||
this->on_show_options_frequency();
|
||||
|
@ -441,13 +364,7 @@ ReceiverView::ReceiverView(
|
|||
field_lna.on_show_options = [this]() {
|
||||
this->on_show_options_rf_gain();
|
||||
};
|
||||
/*
|
||||
options_baseband_bandwidth.set_by_value(receiver_model.baseband_bandwidth());
|
||||
options_baseband_bandwidth.on_change = [this](size_t n, OptionsField::value_t v) {
|
||||
(void)n;
|
||||
this->on_baseband_bandwidth_changed(v);
|
||||
};
|
||||
*/
|
||||
|
||||
field_vga.set_value(receiver_model.vga());
|
||||
field_vga.on_change = [this](int32_t v_db) {
|
||||
this->on_vga_changed(v_db);
|
||||
|
@ -456,15 +373,9 @@ ReceiverView::ReceiverView(
|
|||
options_modulation.set_by_value(receiver_model.modulation());
|
||||
options_modulation.on_change = [this](size_t n, OptionsField::value_t v) {
|
||||
(void)n;
|
||||
this->on_modulation_changed((mode_type)v);
|
||||
this->on_modulation_changed(static_cast<ReceiverModel::Mode>(v));
|
||||
};
|
||||
/*
|
||||
options_baseband_oversampling.set_by_value(receiver_model.baseband_oversampling());
|
||||
options_baseband_oversampling.on_change = [this](size_t n, OptionsField::value_t v) {
|
||||
(void)n;
|
||||
this->on_baseband_oversampling_changed(v);
|
||||
};
|
||||
*/
|
||||
|
||||
field_volume.set_value((receiver_model.headphone_volume() - wolfson::wm8731::headphone_gain_range.max).decibel() + 99);
|
||||
field_volume.on_change = [this](int32_t v) {
|
||||
this->on_headphone_volume_changed(v);
|
||||
|
@ -499,110 +410,20 @@ ReceiverView::~ReceiverView() {
|
|||
}
|
||||
|
||||
void ReceiverView::on_show() {
|
||||
auto& message_map = context().message_map();
|
||||
message_map.register_handler(Message::ID::AISPacket,
|
||||
[this](Message* const p) {
|
||||
const auto message = static_cast<const AISPacketMessage*>(p);
|
||||
this->on_packet_ais(*message);
|
||||
}
|
||||
);
|
||||
message_map.register_handler(Message::ID::TPMSPacket,
|
||||
[this](Message* const p) {
|
||||
const auto message = static_cast<const TPMSPacketMessage*>(p);
|
||||
this->on_packet_tpms(*message);
|
||||
}
|
||||
);
|
||||
message_map.register_handler(Message::ID::SDCardStatus,
|
||||
[this](Message* const p) {
|
||||
const auto message = static_cast<const SDCardStatusMessage*>(p);
|
||||
this->on_sd_card_mounted(message->is_mounted);
|
||||
}
|
||||
);
|
||||
View::on_show();
|
||||
|
||||
// TODO: Separate concepts of baseband "modulation" and receiver "mode".
|
||||
on_modulation_changed(static_cast<ReceiverModel::Mode>(receiver_model.modulation()));
|
||||
}
|
||||
|
||||
void ReceiverView::on_hide() {
|
||||
auto& message_map = context().message_map();
|
||||
message_map.unregister_handler(Message::ID::SDCardStatus);
|
||||
message_map.unregister_handler(Message::ID::TPMSPacket);
|
||||
message_map.unregister_handler(Message::ID::AISPacket);
|
||||
}
|
||||
on_modulation_changed(static_cast<ReceiverModel::Mode>(-1));
|
||||
|
||||
void ReceiverView::on_packet_ais(const AISPacketMessage& message) {
|
||||
const auto result = baseband::ais::packet_decode(message.packet.payload, message.packet.bits_received);
|
||||
|
||||
auto console = reinterpret_cast<Console*>(widget_content.get());
|
||||
if( result.first == "OK" ) {
|
||||
console->writeln(result.second);
|
||||
}
|
||||
}
|
||||
|
||||
static FIL fil_tpms;
|
||||
|
||||
void ReceiverView::on_packet_tpms(const TPMSPacketMessage& message) {
|
||||
auto payload = message.packet.payload;
|
||||
auto payload_length = message.packet.bits_received;
|
||||
|
||||
std::string hex_data;
|
||||
std::string hex_error;
|
||||
uint8_t byte_data = 0;
|
||||
uint8_t byte_error = 0;
|
||||
for(size_t i=0; i<payload_length; i+=2) {
|
||||
const auto bit_data = payload[i+1];
|
||||
const auto bit_error = (payload[i+0] == payload[i+1]);
|
||||
|
||||
byte_data <<= 1;
|
||||
byte_data |= bit_data ? 1 : 0;
|
||||
|
||||
byte_error <<= 1;
|
||||
byte_error |= bit_error ? 1 : 0;
|
||||
|
||||
if( ((i >> 1) & 7) == 7 ) {
|
||||
hex_data += to_string_hex(byte_data, 2);
|
||||
hex_error += to_string_hex(byte_error, 2);
|
||||
}
|
||||
}
|
||||
|
||||
auto console = reinterpret_cast<Console*>(widget_content.get());
|
||||
console->writeln(hex_data.substr(0, 240 / 8));
|
||||
|
||||
if( !f_error(&fil_tpms) ) {
|
||||
rtc::RTC datetime;
|
||||
rtcGetTime(&RTCD1, &datetime);
|
||||
std::string timestamp =
|
||||
to_string_dec_uint(datetime.year(), 4) +
|
||||
to_string_dec_uint(datetime.month(), 2, '0') +
|
||||
to_string_dec_uint(datetime.day(), 2, '0') +
|
||||
to_string_dec_uint(datetime.hour(), 2, '0') +
|
||||
to_string_dec_uint(datetime.minute(), 2, '0') +
|
||||
to_string_dec_uint(datetime.second(), 2, '0');
|
||||
|
||||
const auto tuning_frequency = receiver_model.tuning_frequency();
|
||||
// TODO: function doesn't take uint64_t, so when >= 1<<32, weirdness will ensue!
|
||||
const auto tuning_frequency_str = to_string_dec_uint(tuning_frequency, 10);
|
||||
|
||||
std::string log = timestamp + " " + tuning_frequency_str + " FSK 38.4 19.2 " + hex_data + "/" + hex_error + "\r\n";
|
||||
f_puts(log.c_str(), &fil_tpms);
|
||||
f_sync(&fil_tpms);
|
||||
}
|
||||
}
|
||||
|
||||
void ReceiverView::on_sd_card_mounted(const bool is_mounted) {
|
||||
if( is_mounted ) {
|
||||
const auto open_result = f_open(&fil_tpms, "tpms.txt", FA_WRITE | FA_OPEN_ALWAYS);
|
||||
if( open_result == FR_OK ) {
|
||||
const auto fil_size = f_size(&fil_tpms);
|
||||
const auto seek_result = f_lseek(&fil_tpms, fil_size);
|
||||
if( seek_result != FR_OK ) {
|
||||
f_close(&fil_tpms);
|
||||
}
|
||||
} else {
|
||||
// TODO: Error, indicate somehow.
|
||||
}
|
||||
}
|
||||
View::on_hide();
|
||||
}
|
||||
|
||||
void ReceiverView::focus() {
|
||||
button_done.focus();
|
||||
field_frequency.focus();
|
||||
}
|
||||
|
||||
void ReceiverView::on_tuning_frequency_changed(rf::Frequency f) {
|
||||
|
@ -625,56 +446,27 @@ void ReceiverView::on_vga_changed(int32_t v_db) {
|
|||
receiver_model.set_vga(v_db);
|
||||
}
|
||||
|
||||
void ReceiverView::on_modulation_changed(mode_type modulation) {
|
||||
/* TODO: This is TERRIBLE!!! */
|
||||
switch(modulation) {
|
||||
case 3:
|
||||
case 5:
|
||||
receiver_model.set_baseband_configuration({
|
||||
.mode = modulation,
|
||||
.sampling_rate = 2457600,
|
||||
.decimation_factor = 4,
|
||||
});
|
||||
receiver_model.set_baseband_bandwidth(1750000);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
receiver_model.set_baseband_configuration({
|
||||
.mode = modulation,
|
||||
.sampling_rate = 20000000,
|
||||
.decimation_factor = 1,
|
||||
});
|
||||
receiver_model.set_baseband_bandwidth(12000000);
|
||||
break;
|
||||
|
||||
default:
|
||||
receiver_model.set_baseband_configuration({
|
||||
.mode = modulation,
|
||||
.sampling_rate = 3072000,
|
||||
.decimation_factor = 4,
|
||||
});
|
||||
receiver_model.set_baseband_bandwidth(1750000);
|
||||
break;
|
||||
}
|
||||
|
||||
void ReceiverView::on_modulation_changed(ReceiverModel::Mode mode) {
|
||||
remove_child(widget_content.get());
|
||||
widget_content.reset();
|
||||
|
||||
switch(modulation) {
|
||||
case 3:
|
||||
case 5:
|
||||
widget_content = std::make_unique<Console>();
|
||||
add_child(widget_content.get());
|
||||
switch(mode) {
|
||||
case ReceiverModel::Mode::AMAudio:
|
||||
case ReceiverModel::Mode::NarrowbandFMAudio:
|
||||
case ReceiverModel::Mode::WidebandFMAudio:
|
||||
widget_content = std::make_unique<AnalogAudioView>(mode);
|
||||
break;
|
||||
|
||||
case ReceiverModel::Mode::SpectrumAnalysis:
|
||||
widget_content = std::make_unique<SpectrumAnalysisView>();
|
||||
break;
|
||||
|
||||
default:
|
||||
widget_content = std::make_unique<spectrum::WaterfallWidget>();
|
||||
add_child(widget_content.get());
|
||||
break;
|
||||
}
|
||||
|
||||
if( widget_content ) {
|
||||
const ui::Dim header_height = 3 * 16;
|
||||
add_child(widget_content.get());
|
||||
const ui::Rect rect { 0, header_height, parent_rect.width(), static_cast<ui::Dim>(parent_rect.height() - header_height) };
|
||||
widget_content->set_parent_rect(rect);
|
||||
}
|
||||
|
@ -710,8 +502,4 @@ void ReceiverView::on_headphone_volume_changed(int32_t v) {
|
|||
receiver_model.set_headphone_volume(new_volume);
|
||||
}
|
||||
|
||||
// void ReceiverView::on_baseband_oversampling_changed(int32_t v) {
|
||||
// receiver_model.set_baseband_oversampling(v);
|
||||
// }
|
||||
|
||||
} /* namespace ui */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue