mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2026-09-14 02:29:29 +00:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| de81156223 | |||
| e7e1bedcad | |||
| d8930db8af | |||
| 014db9e233 | |||
| 933920edfd | |||
| cf25d85d51 | |||
| 9af1308e29 | |||
| f4496d8f45 | |||
| 966d1c938b | |||
| f537c7896e | |||
| 4a1479957c | |||
| dc9a16c54b |
@@ -44,7 +44,7 @@ if(cpp20_supported)
|
||||
else()
|
||||
set(USE_CPPOPT "-std=c++17")
|
||||
endif()
|
||||
set(USE_CPPOPT "${USE_CPPOPT} -fno-rtti -fno-exceptions -Weffc++ -Wuninitialized -Wno-volatile")
|
||||
set(USE_CPPOPT "${USE_CPPOPT} -flto -fno-rtti -fno-exceptions -Weffc++ -Wuninitialized -Wno-volatile")
|
||||
|
||||
# Enable this if you want the linker to remove unused code and data
|
||||
set(USE_LINK_GC yes)
|
||||
|
||||
@@ -82,6 +82,12 @@ CaptureAppView::CaptureAppView(NavigationView& nav)
|
||||
auto anti_alias_filter_bandwidth = filter_bandwidth_for_sampling_rate(actual_sample_rate);
|
||||
receiver_model.set_baseband_bandwidth(anti_alias_filter_bandwidth);
|
||||
|
||||
// Automatically switch default capture format to C8 when bandwidth setting is increased to >=1.5MHz
|
||||
if ((bandwidth >= 1500000) && (previous_bandwidth < 1500000)) {
|
||||
option_format.set_selected_index(1);
|
||||
}
|
||||
previous_bandwidth = bandwidth;
|
||||
|
||||
waterfall.start();
|
||||
};
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ class CaptureAppView : public View {
|
||||
|
||||
private:
|
||||
static constexpr ui::Dim header_height = 3 * 16;
|
||||
uint32_t previous_bandwidth{500000};
|
||||
|
||||
NavigationView& nav_;
|
||||
RxRadioState radio_state_{ReceiverModel::Mode::Capture};
|
||||
|
||||
@@ -69,7 +69,7 @@ void LGEView::generate_frame_touche() {
|
||||
// 0D 96 02 12 0E 00 46 28 01 45 27 01 44 23 66 30
|
||||
std::vector<uint8_t> data{0x46, 0x28, 0x01, 0x45, 0x27, 0x01, 0x44, 0x23};
|
||||
|
||||
console.write("\n\x1B\x07Touche:\x1B\x10");
|
||||
console.write("\n" STR_COLOR_LIGHT_GREY "Touche:");
|
||||
generate_lge_frame(0x96, (field_player.value() << 8) | field_room.value(), 0x0001, data);
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ void LGEView::generate_frame_nickname() {
|
||||
|
||||
data.insert(data.end(), data_footer.begin(), data_footer.end());
|
||||
|
||||
console.write("\n\x1B\x0ESet nickname:\x1B\x10");
|
||||
console.write("\n" STR_COLOR_YELLOW "Set nickname:");
|
||||
|
||||
generate_lge_frame(0x02, 0x001A, field_player.value(), data);
|
||||
}
|
||||
@@ -141,7 +141,7 @@ void LGEView::generate_frame_team() {
|
||||
|
||||
data.push_back(field_team.value() - 1); // Color ?
|
||||
|
||||
console.write("\n\x1B\x0ASet team:\x1B\x10");
|
||||
console.write("\n" STR_COLOR_GREEN "Set team:");
|
||||
|
||||
generate_lge_frame(0x03, data);
|
||||
}
|
||||
@@ -173,9 +173,7 @@ void LGEView::generate_frame_broadcast_nickname() {
|
||||
|
||||
data.push_back(field_team.value());
|
||||
|
||||
console.write(
|
||||
"\n\x1B\x09"
|
||||
"Broadcast nickname:\x1B\x10");
|
||||
console.write("\n" STR_COLOR_BLUE "Broadcast nickname:");
|
||||
|
||||
generate_lge_frame(0x04, data);
|
||||
}
|
||||
@@ -187,14 +185,14 @@ void LGEView::generate_frame_start() {
|
||||
|
||||
// data[0] = field_room.value(); // ?
|
||||
|
||||
console.write("\n\x1B\x0DStart:\x1B\x10");
|
||||
console.write("\n" STR_COLOR_MAGENTA "Start:");
|
||||
generate_lge_frame(0x05, data);
|
||||
}
|
||||
|
||||
void LGEView::generate_frame_gameover() {
|
||||
std::vector<uint8_t> data{(uint8_t)field_room.value()};
|
||||
|
||||
console.write("\n\x1B\x0CGameover:\x1B\x10");
|
||||
console.write("\n" STR_COLOR_RED "Gameover:");
|
||||
generate_lge_frame(0x0D, data);
|
||||
}
|
||||
|
||||
@@ -229,9 +227,7 @@ void LGEView::generate_frame_collier() {
|
||||
|
||||
data.push_back(checksum - id);
|
||||
|
||||
console.write(
|
||||
"\n\x1B\x06"
|
||||
"Config:\x1B\x10");
|
||||
console.write("\n" STR_COLOR_DARK_YELLOW "Config:");
|
||||
generate_lge_frame(0x00, 0x3713, 0x3713, data);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,15 +22,15 @@
|
||||
|
||||
#include "pocsag_app.hpp"
|
||||
|
||||
#include "audio.hpp"
|
||||
#include "baseband_api.hpp"
|
||||
#include "portapack_persistent_memory.hpp"
|
||||
#include "string_format.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
using namespace portapack;
|
||||
using namespace pocsag;
|
||||
|
||||
#include "string_format.hpp"
|
||||
#include "utility.hpp"
|
||||
#include "audio.hpp"
|
||||
namespace pmem = portapack::persistent_memory;
|
||||
|
||||
void POCSAGLogger::log_raw_data(const pocsag::POCSAGPacket& packet, const uint32_t frequency) {
|
||||
std::string entry = "Raw: F:" + to_string_dec_uint(frequency) + "Hz " +
|
||||
@@ -43,53 +43,93 @@ void POCSAGLogger::log_raw_data(const pocsag::POCSAGPacket& packet, const uint32
|
||||
log_file.write_entry(packet.timestamp(), entry);
|
||||
}
|
||||
|
||||
void POCSAGLogger::log_decoded(
|
||||
const pocsag::POCSAGPacket& packet,
|
||||
const std::string text) {
|
||||
log_file.write_entry(packet.timestamp(), text);
|
||||
void POCSAGLogger::log_decoded(Timestamp timestamp, const std::string& text) {
|
||||
log_file.write_entry(timestamp, text);
|
||||
}
|
||||
|
||||
namespace ui {
|
||||
|
||||
POCSAGSettingsView::POCSAGSettingsView(
|
||||
NavigationView& nav,
|
||||
POCSAGSettings& settings)
|
||||
: settings_{settings} {
|
||||
add_children(
|
||||
{&check_log,
|
||||
&check_log_raw,
|
||||
&check_small_font,
|
||||
&check_hide_bad,
|
||||
&check_hide_addr_only,
|
||||
&check_ignore,
|
||||
&field_ignore,
|
||||
&button_save});
|
||||
|
||||
check_log.set_value(settings_.enable_logging);
|
||||
check_log_raw.set_value(settings_.enable_raw_log);
|
||||
check_small_font.set_value(settings_.enable_small_font);
|
||||
check_hide_bad.set_value(settings_.hide_bad_data);
|
||||
check_hide_addr_only.set_value(settings_.hide_addr_only);
|
||||
check_ignore.set_value(settings_.enable_ignore);
|
||||
field_ignore.set_value(settings_.address_to_ignore);
|
||||
|
||||
button_save.on_select = [this, &nav](Button&) {
|
||||
settings_.enable_logging = check_log.value();
|
||||
settings_.enable_raw_log = check_log_raw.value();
|
||||
settings_.enable_small_font = check_small_font.value();
|
||||
settings_.hide_bad_data = check_hide_bad.value();
|
||||
settings_.hide_addr_only = check_hide_addr_only.value();
|
||||
settings_.enable_ignore = check_ignore.value();
|
||||
settings_.address_to_ignore = field_ignore.value();
|
||||
|
||||
nav.pop();
|
||||
};
|
||||
}
|
||||
|
||||
POCSAGAppView::POCSAGAppView(NavigationView& nav)
|
||||
: nav_{nav} {
|
||||
baseband::run_image(portapack::spi_flash::image_tag_pocsag);
|
||||
|
||||
add_children({&rssi,
|
||||
&channel,
|
||||
&audio,
|
||||
&field_rf_amp,
|
||||
&field_lna,
|
||||
&field_vga,
|
||||
&field_frequency,
|
||||
&check_log,
|
||||
&field_volume,
|
||||
&check_ignore,
|
||||
&sym_ignore,
|
||||
&console});
|
||||
add_children(
|
||||
{&rssi,
|
||||
&audio,
|
||||
&field_rf_amp,
|
||||
&field_lna,
|
||||
&field_vga,
|
||||
&field_frequency,
|
||||
&field_squelch,
|
||||
&field_volume,
|
||||
&image_status,
|
||||
&text_packet_count,
|
||||
&button_ignore_last,
|
||||
&button_config,
|
||||
&console});
|
||||
|
||||
if (!settings_.loaded())
|
||||
// No app settings, use fallbacks.
|
||||
if (!app_settings_.loaded()) {
|
||||
field_frequency.set_value(initial_target_frequency);
|
||||
|
||||
check_log.set_value(enable_logging);
|
||||
|
||||
receiver_model.enable();
|
||||
|
||||
// TODO: app setting instead?
|
||||
uint32_t ignore_address;
|
||||
ignore_address = persistent_memory::pocsag_ignore_address();
|
||||
|
||||
// TODO: is this common enough for a helper?
|
||||
for (size_t c = 0; c < 7; c++) {
|
||||
sym_ignore.set_sym(6 - c, ignore_address % 10);
|
||||
ignore_address /= 10;
|
||||
settings_.address_to_ignore = pmem::pocsag_ignore_address();
|
||||
settings_.enable_ignore = settings_.address_to_ignore > 0;
|
||||
}
|
||||
|
||||
logger = std::make_unique<POCSAGLogger>();
|
||||
if (logger)
|
||||
logger->append(LOG_ROOT_DIR "/POCSAG.TXT");
|
||||
logger.append(LOG_ROOT_DIR "/POCSAG.TXT");
|
||||
|
||||
field_squelch.set_value(receiver_model.squelch_level());
|
||||
field_squelch.on_change = [this](int32_t v) {
|
||||
receiver_model.set_squelch_level(v);
|
||||
};
|
||||
|
||||
button_ignore_last.on_select = [this](Button&) {
|
||||
settings_.enable_ignore = true;
|
||||
settings_.address_to_ignore = last_address;
|
||||
};
|
||||
|
||||
button_config.on_select = [this](Button&) {
|
||||
nav_.push<POCSAGSettingsView>(settings_);
|
||||
nav_.set_on_pop([this]() { refresh_ui(); });
|
||||
};
|
||||
|
||||
refresh_ui();
|
||||
audio::output::start();
|
||||
receiver_model.enable();
|
||||
baseband::set_pocsag();
|
||||
}
|
||||
|
||||
@@ -99,82 +139,133 @@ void POCSAGAppView::focus() {
|
||||
|
||||
POCSAGAppView::~POCSAGAppView() {
|
||||
audio::output::stop();
|
||||
|
||||
// Save settings.
|
||||
persistent_memory::set_pocsag_ignore_address(sym_ignore.value_dec_u32());
|
||||
enable_logging = check_log.value();
|
||||
|
||||
receiver_model.disable();
|
||||
baseband::shutdown();
|
||||
|
||||
// Save pmem settings. TODO: Even needed anymore?
|
||||
pmem::set_pocsag_ignore_address(settings_.address_to_ignore);
|
||||
pmem::set_pocsag_last_address(pocsag_state.address); // For POCSAG TX.
|
||||
}
|
||||
|
||||
void POCSAGAppView::refresh_ui() {
|
||||
console.set_style(
|
||||
settings_.enable_small_font
|
||||
? &Styles::white_small
|
||||
: &Styles::white);
|
||||
}
|
||||
|
||||
void POCSAGAppView::handle_decoded(Timestamp timestamp, const std::string& prefix) {
|
||||
bool bad_data = pocsag_state.errors >= 3;
|
||||
|
||||
// Too many errors for reliable decode.
|
||||
if (bad_data && hide_bad_data()) {
|
||||
console.write("\n" STR_COLOR_MAGENTA + prefix + " Too many decode errors.");
|
||||
last_address = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
// Ignored address.
|
||||
if (ignore() && pocsag_state.address == settings_.address_to_ignore) {
|
||||
console.write("\n" STR_COLOR_CYAN + prefix + " Ignored: " + to_string_dec_uint(pocsag_state.address));
|
||||
last_address = pocsag_state.address;
|
||||
return;
|
||||
}
|
||||
|
||||
// Color indicates the message has a lot of decoding errors.
|
||||
std::string color = bad_data ? STR_COLOR_MAGENTA : STR_COLOR_WHITE;
|
||||
|
||||
std::string console_info = "\n" + color + prefix;
|
||||
console_info += " #" + to_string_dec_uint(pocsag_state.address);
|
||||
console_info += " F" + to_string_dec_uint(pocsag_state.function);
|
||||
|
||||
if (pocsag_state.out_type == ADDRESS) {
|
||||
last_address = pocsag_state.address;
|
||||
|
||||
if (!hide_addr_only()) {
|
||||
console.write(console_info);
|
||||
|
||||
if (logging()) {
|
||||
logger.log_decoded(
|
||||
timestamp,
|
||||
to_string_dec_uint(pocsag_state.address) +
|
||||
" F" + to_string_dec_uint(pocsag_state.function));
|
||||
}
|
||||
}
|
||||
|
||||
} else if (pocsag_state.out_type == MESSAGE) {
|
||||
if (pocsag_state.address != last_address) {
|
||||
// New message
|
||||
last_address = pocsag_state.address;
|
||||
console.writeln(console_info);
|
||||
console.write(color + pocsag_state.output);
|
||||
} else {
|
||||
// Message continues...
|
||||
console.write(color + pocsag_state.output);
|
||||
}
|
||||
|
||||
if (logging()) {
|
||||
logger.log_decoded(
|
||||
timestamp,
|
||||
to_string_dec_uint(pocsag_state.address) +
|
||||
" F" + to_string_dec_uint(pocsag_state.function) +
|
||||
" " + pocsag_state.output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static Color get_status_color(const POCSAGState& state) {
|
||||
if (state.out_type == IDLE)
|
||||
return Color::white();
|
||||
|
||||
switch (state.mode) {
|
||||
case STATE_CLEAR:
|
||||
return Color::cyan();
|
||||
case STATE_HAVE_ADDRESS:
|
||||
return Color::yellow();
|
||||
case STATE_GETTING_MSG:
|
||||
return Color::green();
|
||||
}
|
||||
|
||||
// Shouldn't get here...
|
||||
return Color::red();
|
||||
}
|
||||
|
||||
void POCSAGAppView::on_packet(const POCSAGPacketMessage* message) {
|
||||
std::string alphanum_text = "";
|
||||
const uint32_t roundVal = 50;
|
||||
const uint32_t bitrate_rounded = roundVal * ((message->packet.bitrate() + (roundVal / 2)) / roundVal);
|
||||
auto bitrate = to_string_dec_uint(bitrate_rounded);
|
||||
auto timestamp = to_string_datetime(message->packet.timestamp(), HM);
|
||||
auto prefix = timestamp + " " + bitrate;
|
||||
|
||||
if (message->packet.flag() != NORMAL)
|
||||
console.writeln("\n\x1B\x0CRC ERROR: " + pocsag::flag_str(message->packet.flag()));
|
||||
else {
|
||||
pocsag_decode_batch(message->packet, &pocsag_state);
|
||||
// Display packet count to be able to tell whether baseband sent a packet for a tone.
|
||||
++packet_count;
|
||||
text_packet_count.set(to_string_dec_uint(packet_count));
|
||||
|
||||
if ((ignore()) && (pocsag_state.address == sym_ignore.value_dec_u32())) {
|
||||
// Ignore (inform, but no log)
|
||||
// console.write("\n\x1B\x03" + to_string_time(message->packet.timestamp()) +
|
||||
// " Ignored address " + to_string_dec_uint(pocsag_state.address));
|
||||
return;
|
||||
}
|
||||
// Too many errors for reliable decode
|
||||
if ((ignore()) && (pocsag_state.errors >= 3)) {
|
||||
return;
|
||||
}
|
||||
if (logging_raw())
|
||||
logger.log_raw_data(message->packet, receiver_model.target_frequency());
|
||||
|
||||
std::string console_info;
|
||||
const uint32_t roundVal = 50;
|
||||
const uint32_t bitrate = roundVal * ((message->packet.bitrate() + (roundVal / 2)) / roundVal);
|
||||
console_info = "\n" + to_string_datetime(message->packet.timestamp(), HM);
|
||||
console_info += " " + to_string_dec_uint(bitrate);
|
||||
console_info += " ADDR:" + to_string_dec_uint(pocsag_state.address);
|
||||
console_info += " F" + to_string_dec_uint(pocsag_state.function);
|
||||
if (message->packet.flag() != NORMAL) {
|
||||
console.writeln("\n" STR_COLOR_RED + prefix + " CRC ERROR: " + pocsag::flag_str(message->packet.flag()));
|
||||
last_address = 0;
|
||||
} else {
|
||||
// Set color before to be able to see if decode gets stuck.
|
||||
image_status.set_foreground(Color::magenta());
|
||||
pocsag_state.codeword_index = 0;
|
||||
pocsag_state.errors = 0;
|
||||
|
||||
// Store last received address for POCSAG TX
|
||||
persistent_memory::set_pocsag_last_address(pocsag_state.address);
|
||||
// Handle multiple messages (if any).
|
||||
while (pocsag_decode_batch(message->packet, pocsag_state))
|
||||
handle_decoded(message->packet.timestamp(), prefix);
|
||||
|
||||
if (pocsag_state.out_type == ADDRESS) {
|
||||
// Address only
|
||||
|
||||
console.write(console_info);
|
||||
|
||||
if (logger && logging()) {
|
||||
logger->log_decoded(
|
||||
message->packet, to_string_dec_uint(pocsag_state.address) +
|
||||
" F" + to_string_dec_uint(pocsag_state.function) +
|
||||
" Address only");
|
||||
}
|
||||
|
||||
last_address = pocsag_state.address;
|
||||
} else if (pocsag_state.out_type == MESSAGE) {
|
||||
if (pocsag_state.address != last_address) {
|
||||
// New message
|
||||
console.writeln(console_info);
|
||||
console.write(pocsag_state.output);
|
||||
|
||||
last_address = pocsag_state.address;
|
||||
} else {
|
||||
// Message continues...
|
||||
console.write(pocsag_state.output);
|
||||
}
|
||||
|
||||
if (logger && logging())
|
||||
logger->log_decoded(
|
||||
message->packet, to_string_dec_uint(pocsag_state.address) +
|
||||
" F" + to_string_dec_uint(pocsag_state.function) +
|
||||
" Alpha: " + pocsag_state.output);
|
||||
}
|
||||
// Handle the remainder.
|
||||
handle_decoded(message->packet.timestamp(), prefix);
|
||||
}
|
||||
|
||||
// TODO: make setting.
|
||||
// Log raw data whatever it contains
|
||||
/*if (logger && logging())
|
||||
logger->log_raw_data(message->packet, receiver_model.target_frequency());*/
|
||||
// Set status icon color to indicate state machine state.
|
||||
image_status.set_foreground(get_status_color(pocsag_state));
|
||||
}
|
||||
|
||||
void POCSAGAppView::on_stats(const POCSAGStatsMessage*) {
|
||||
}
|
||||
|
||||
} /* namespace ui */
|
||||
|
||||
@@ -27,12 +27,15 @@
|
||||
#include "ui_freq_field.hpp"
|
||||
#include "ui_receiver.hpp"
|
||||
#include "ui_rssi.hpp"
|
||||
#include "ui_styles.hpp"
|
||||
|
||||
#include "log_file.hpp"
|
||||
#include "app_settings.hpp"
|
||||
#include "radio_state.hpp"
|
||||
#include "log_file.hpp"
|
||||
#include "pocsag.hpp"
|
||||
#include "pocsag_packet.hpp"
|
||||
#include "radio_state.hpp"
|
||||
|
||||
#include <functional>
|
||||
|
||||
class POCSAGLogger {
|
||||
public:
|
||||
@@ -41,7 +44,7 @@ class POCSAGLogger {
|
||||
}
|
||||
|
||||
void log_raw_data(const pocsag::POCSAGPacket& packet, const uint32_t frequency);
|
||||
void log_decoded(const pocsag::POCSAGPacket& packet, const std::string text);
|
||||
void log_decoded(Timestamp timestamp, const std::string& text);
|
||||
|
||||
private:
|
||||
LogFile log_file{};
|
||||
@@ -49,6 +52,73 @@ class POCSAGLogger {
|
||||
|
||||
namespace ui {
|
||||
|
||||
struct POCSAGSettings {
|
||||
bool enable_small_font = false;
|
||||
bool enable_logging = false;
|
||||
bool enable_raw_log = false;
|
||||
bool enable_ignore = false;
|
||||
bool hide_bad_data = false;
|
||||
bool hide_addr_only = false;
|
||||
uint32_t address_to_ignore = 0;
|
||||
};
|
||||
|
||||
class POCSAGSettingsView : public View {
|
||||
public:
|
||||
POCSAGSettingsView(NavigationView& nav, POCSAGSettings& settings);
|
||||
|
||||
std::string title() const override { return "POCSAG Config"; };
|
||||
|
||||
private:
|
||||
POCSAGSettings& settings_;
|
||||
|
||||
Checkbox check_log{
|
||||
{2 * 8, 2 * 16},
|
||||
10,
|
||||
"Enable Log",
|
||||
false};
|
||||
|
||||
Checkbox check_log_raw{
|
||||
{2 * 8, 4 * 16},
|
||||
12,
|
||||
"Log Raw Data",
|
||||
false};
|
||||
|
||||
Checkbox check_small_font{
|
||||
{2 * 8, 6 * 16},
|
||||
4,
|
||||
"Use Small Font",
|
||||
false};
|
||||
|
||||
Checkbox check_hide_bad{
|
||||
{2 * 8, 8 * 16},
|
||||
22,
|
||||
"Hide Bad Data",
|
||||
false};
|
||||
|
||||
Checkbox check_hide_addr_only{
|
||||
{2 * 8, 10 * 16},
|
||||
22,
|
||||
"Hide Addr Only",
|
||||
false};
|
||||
|
||||
Checkbox check_ignore{
|
||||
{2 * 8, 12 * 16},
|
||||
22,
|
||||
"Enable Ignored Address",
|
||||
false};
|
||||
|
||||
NumberField field_ignore{
|
||||
{7 * 8, 13 * 16 + 8},
|
||||
7,
|
||||
{0, 9999999},
|
||||
1,
|
||||
'0'};
|
||||
|
||||
Button button_save{
|
||||
{12 * 8, 16 * 16, 10 * 8, 2 * 16},
|
||||
"Save"};
|
||||
};
|
||||
|
||||
class POCSAGAppView : public View {
|
||||
public:
|
||||
POCSAGAppView(NavigationView& nav);
|
||||
@@ -58,64 +128,86 @@ class POCSAGAppView : public View {
|
||||
void focus() override;
|
||||
|
||||
private:
|
||||
static constexpr uint32_t initial_target_frequency = 466175000;
|
||||
bool logging() const { return check_log.value(); };
|
||||
bool ignore() const { return check_ignore.value(); };
|
||||
static constexpr uint32_t initial_target_frequency = 466'175'000;
|
||||
bool logging() const { return settings_.enable_logging; };
|
||||
bool logging_raw() const { return settings_.enable_raw_log; };
|
||||
bool ignore() const { return settings_.enable_ignore; };
|
||||
bool hide_bad_data() const { return settings_.hide_bad_data; };
|
||||
bool hide_addr_only() const { return settings_.hide_addr_only; };
|
||||
|
||||
NavigationView& nav_;
|
||||
RxRadioState radio_state_{};
|
||||
|
||||
// Settings
|
||||
bool enable_logging = false;
|
||||
app_settings::SettingsManager settings_{
|
||||
POCSAGSettings settings_{};
|
||||
app_settings::SettingsManager app_settings_{
|
||||
"rx_pocsag"sv,
|
||||
app_settings::Mode::RX,
|
||||
{{"enable_logging"sv, &enable_logging}}};
|
||||
{
|
||||
{"small_font"sv, &settings_.enable_small_font},
|
||||
{"enable_logging"sv, &settings_.enable_logging},
|
||||
{"enable_ignore"sv, &settings_.enable_ignore},
|
||||
{"address_to_ignore"sv, &settings_.address_to_ignore},
|
||||
{"hide_bad_data"sv, &settings_.hide_bad_data},
|
||||
{"hide_addr_only"sv, &settings_.hide_addr_only},
|
||||
}};
|
||||
|
||||
void refresh_ui();
|
||||
void handle_decoded(Timestamp timestamp, const std::string& prefix);
|
||||
void on_packet(const POCSAGPacketMessage* message);
|
||||
void on_stats(const POCSAGStatsMessage* stats);
|
||||
|
||||
uint32_t last_address = 0xFFFFFFFF;
|
||||
pocsag::POCSAGState pocsag_state{};
|
||||
|
||||
RFAmpField field_rf_amp{
|
||||
{13 * 8, 0 * 16}};
|
||||
LNAGainField field_lna{
|
||||
{15 * 8, 0 * 16}};
|
||||
VGAGainField field_vga{
|
||||
{18 * 8, 0 * 16}};
|
||||
RSSI rssi{
|
||||
{21 * 8, 0, 6 * 8, 4}};
|
||||
Channel channel{
|
||||
{21 * 8, 5, 6 * 8, 4}};
|
||||
Audio audio{
|
||||
{21 * 8, 10, 6 * 8, 4}};
|
||||
pocsag::EccContainer ecc{};
|
||||
pocsag::POCSAGState pocsag_state{&ecc};
|
||||
POCSAGLogger logger{};
|
||||
uint16_t packet_count = 0;
|
||||
|
||||
RxFrequencyField field_frequency{
|
||||
{0 * 8, 0 * 8},
|
||||
nav_};
|
||||
|
||||
RFAmpField field_rf_amp{
|
||||
{11 * 8, 0 * 16}};
|
||||
LNAGainField field_lna{
|
||||
{13 * 8, 0 * 16}};
|
||||
VGAGainField field_vga{
|
||||
{16 * 8, 0 * 16}};
|
||||
|
||||
RSSI rssi{
|
||||
{19 * 8 - 4, 3, 6 * 8, 4}};
|
||||
Audio audio{
|
||||
{19 * 8 - 4, 8, 6 * 8, 4}};
|
||||
|
||||
NumberField field_squelch{
|
||||
{25 * 8, 0 * 16},
|
||||
2,
|
||||
{0, 99},
|
||||
1,
|
||||
' '};
|
||||
AudioVolumeField field_volume{
|
||||
{28 * 8, 0 * 16}};
|
||||
|
||||
Checkbox check_ignore{
|
||||
{0 * 8, 21},
|
||||
8,
|
||||
"Ign addr",
|
||||
false};
|
||||
SymField sym_ignore{
|
||||
{13 * 8, 25},
|
||||
7,
|
||||
SymField::SYMFIELD_DEC};
|
||||
Image image_status{
|
||||
{0 * 8 + 4, 1 * 16 + 2, 16, 16},
|
||||
&bitmap_icon_pocsag,
|
||||
Color::white(),
|
||||
Color::black()};
|
||||
|
||||
Checkbox check_log{
|
||||
{240 - 8 * 8, 21},
|
||||
3,
|
||||
"Log",
|
||||
false};
|
||||
Text text_packet_count{
|
||||
{3 * 8, 1 * 16 + 2, 5 * 8, 16},
|
||||
"0"};
|
||||
|
||||
Button button_ignore_last{
|
||||
{10 * 8, 1 * 16, 12 * 8, 20},
|
||||
"Ignore Last"};
|
||||
|
||||
Button button_config{
|
||||
{22 * 8, 1 * 16, 8 * 8, 20},
|
||||
"Config"};
|
||||
|
||||
Console console{
|
||||
{0, 3 * 16, 240, 256}};
|
||||
|
||||
std::unique_ptr<POCSAGLogger> logger{};
|
||||
|
||||
void on_packet(const POCSAGPacketMessage* message);
|
||||
{0, 2 * 16 + 6, screen_width, screen_height - 56}};
|
||||
|
||||
MessageHandlerRegistration message_handler_packet{
|
||||
Message::ID::POCSAGPacket,
|
||||
@@ -123,6 +215,13 @@ class POCSAGAppView : public View {
|
||||
const auto message = static_cast<const POCSAGPacketMessage*>(p);
|
||||
this->on_packet(message);
|
||||
}};
|
||||
|
||||
MessageHandlerRegistration message_handler_stats{
|
||||
Message::ID::POCSAGStats,
|
||||
[this](Message* const p) {
|
||||
const auto stats = static_cast<const POCSAGStatsMessage*>(p);
|
||||
this->on_stats(stats);
|
||||
}};
|
||||
};
|
||||
|
||||
} /* namespace ui */
|
||||
|
||||
@@ -8,7 +8,7 @@ AboutView::AboutView(NavigationView& nav) {
|
||||
nav.pop();
|
||||
};
|
||||
|
||||
console.writeln("\x1B\x07List of contributors:\x1B\x10");
|
||||
console.writeln(STR_COLOR_LIGHT_GREY "List of contributors:");
|
||||
console.writeln("");
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ void AboutView::update() {
|
||||
case 1:
|
||||
// TODO: Generate this automatically from github
|
||||
// https://github.com/eried/portapack-mayhem/graphs/contributors?to=2022-01-01&from=2020-04-12&type=c
|
||||
console.writeln("\x1B\x06Mayhem:\x1B\x10");
|
||||
console.writeln(STR_COLOR_DARK_YELLOW "Mayhem:");
|
||||
console.writeln("eried,euquiq,gregoryfenton");
|
||||
console.writeln("johnelder,jwetzell,nnemanjan00");
|
||||
console.writeln("N0vaPixel,klockee,GullCode");
|
||||
@@ -34,13 +34,15 @@ void AboutView::update() {
|
||||
console.writeln("notpike,jLynx,zigad");
|
||||
console.writeln("MichalLeonBorsuk,jimilinuxguy");
|
||||
console.writeln("kallanreed,bernd-herzog");
|
||||
break;
|
||||
case 2:
|
||||
console.writeln("NotherNgineer,zxkmm,u-foka");
|
||||
console.writeln("");
|
||||
break;
|
||||
|
||||
case 2:
|
||||
case 3:
|
||||
// https://github.com/eried/portapack-mayhem/graphs/contributors?to=2020-04-12&from=2015-07-31&type=c
|
||||
console.writeln("\x1B\x06Havoc:\x1B\x10");
|
||||
console.writeln(STR_COLOR_DARK_YELLOW "Havoc:");
|
||||
console.writeln("furrtek,mrmookie,NotPike");
|
||||
console.writeln("mjwaxios,ImDroided,Giorgiofox");
|
||||
console.writeln("F4GEV,z4ziggy,xmycroftx");
|
||||
@@ -51,16 +53,16 @@ void AboutView::update() {
|
||||
console.writeln("");
|
||||
break;
|
||||
|
||||
case 3:
|
||||
case 4:
|
||||
// https://github.com/eried/portapack-mayhem/graphs/contributors?from=2014-07-05&to=2015-07-31&type=c
|
||||
console.writeln("\x1B\x06PortaPack:\x1B\x10");
|
||||
console.writeln(STR_COLOR_DARK_YELLOW "PortaPack:");
|
||||
console.writeln("jboone,argilo");
|
||||
console.writeln("");
|
||||
break;
|
||||
|
||||
case 4:
|
||||
case 5:
|
||||
// https://github.com/mossmann/hackrf/graphs/contributors
|
||||
console.writeln("\x1B\x06HackRF:\x1B\x10");
|
||||
console.writeln(STR_COLOR_DARK_YELLOW "HackRF:");
|
||||
console.writeln("mossmann,dominicgs,bvernoux");
|
||||
console.writeln("bgamari,schneider42,miek");
|
||||
console.writeln("willcode,hessu,Sec42");
|
||||
|
||||
@@ -40,24 +40,22 @@ void RecentEntriesTable<AircraftRecentEntries>::draw(
|
||||
const Rect& target_rect,
|
||||
Painter& painter,
|
||||
const Style& style) {
|
||||
char aged_color;
|
||||
Color target_color;
|
||||
auto entry_age = entry.age;
|
||||
std::string entry_string;
|
||||
|
||||
// Color decay for flights not being updated anymore
|
||||
if (entry_age < ADSB_CURRENT) {
|
||||
aged_color = 0x10;
|
||||
entry_string = "";
|
||||
target_color = Color::green();
|
||||
} else if (entry_age < ADSB_RECENT) {
|
||||
aged_color = 0x07;
|
||||
entry_string = STR_COLOR_LIGHT_GREY;
|
||||
target_color = Color::light_grey();
|
||||
} else {
|
||||
aged_color = 0x08;
|
||||
entry_string = STR_COLOR_DARK_GREY;
|
||||
target_color = Color::grey();
|
||||
}
|
||||
|
||||
std::string entry_string = "\x1B";
|
||||
entry_string += aged_color;
|
||||
entry_string +=
|
||||
(entry.callsign[0] != ' ' ? entry.callsign + " " : entry.icaoStr + " ") +
|
||||
to_string_dec_uint((unsigned int)(entry.pos.altitude / 100), 4) +
|
||||
|
||||
@@ -42,15 +42,12 @@ void RecentEntriesTable<APRSRecentEntries>::draw(
|
||||
const Rect& target_rect,
|
||||
Painter& painter,
|
||||
const Style& style) {
|
||||
char aged_color;
|
||||
Color target_color;
|
||||
// auto entry_age = entry.age;
|
||||
|
||||
target_color = Color::green();
|
||||
|
||||
aged_color = 0x10;
|
||||
std::string entry_string = "\x1B";
|
||||
entry_string += aged_color;
|
||||
std::string entry_string = "";
|
||||
|
||||
entry_string += entry.source_formatted;
|
||||
entry_string.append(10 - entry.source_formatted.size(), ' ');
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
*/
|
||||
|
||||
#include "ui_debug.hpp"
|
||||
#include "debug.hpp"
|
||||
|
||||
#include "ch.h"
|
||||
|
||||
@@ -406,6 +407,7 @@ DebugMenuView::DebugMenuView(NavigationView& nav) {
|
||||
{"Touch Test", ui::Color::dark_cyan(), &bitmap_icon_notepad, [&nav]() { nav.push<DebugScreenTest>(); }},
|
||||
{"P.Memory", ui::Color::dark_cyan(), &bitmap_icon_memory, [&nav]() { nav.push<DebugPmemView>(); }},
|
||||
{"Debug Dump", ui::Color::dark_cyan(), &bitmap_icon_memory, [&nav]() { portapack::persistent_memory::debug_dump(); }},
|
||||
{"M0 Stack Dump", ui::Color::dark_cyan(), &bitmap_icon_memory, [&nav]() { stack_dump(); }},
|
||||
//{"Fonts Viewer", ui::Color::dark_cyan(), &bitmap_icon_notepad, [&nav]() { nav.push<DebugFontsView>(); }}, // temporarily disabled to conserve ROM space
|
||||
});
|
||||
set_max_rows(2); // allow wider buttons
|
||||
|
||||
@@ -74,8 +74,8 @@ rf::Frequency GlassView::get_freq_from_bin_pos(uint8_t pos) {
|
||||
|
||||
void GlassView::on_marker_change() {
|
||||
marker = get_freq_from_bin_pos(marker_pixel_index);
|
||||
button_marker.set_text(to_string_short_freq(marker));
|
||||
PlotMarker(marker_pixel_index); // Refresh marker on screen
|
||||
field_marker.set_text(to_string_short_freq(marker));
|
||||
plot_marker(marker_pixel_index); // Refresh marker on screen
|
||||
}
|
||||
|
||||
void GlassView::retune() {
|
||||
@@ -87,23 +87,13 @@ void GlassView::retune() {
|
||||
baseband::spectrum_streaming_start(); // Do the RX
|
||||
}
|
||||
|
||||
void GlassView::on_lna_changed(int32_t v_db) {
|
||||
receiver_model.set_lna(v_db);
|
||||
}
|
||||
|
||||
void GlassView::on_vga_changed(int32_t v_db) {
|
||||
receiver_model.set_vga(v_db);
|
||||
}
|
||||
|
||||
void GlassView::reset_live_view(bool clear_screen) {
|
||||
void GlassView::reset_live_view() {
|
||||
max_freq_hold = 0;
|
||||
max_freq_power = -1000;
|
||||
if (clear_screen) {
|
||||
// only clear screen in peak mode
|
||||
if (live_frequency_view == 2) {
|
||||
display.fill_rectangle({{0, 108 + 16}, {SCREEN_W, 320 - (108 + 16)}}, {0, 0, 0});
|
||||
}
|
||||
}
|
||||
|
||||
// Clear screen in peak mode.
|
||||
if (live_frequency_view == 2)
|
||||
display.fill_rectangle({{0, 108 + 16}, {SCREEN_W, SCREEN_H - (108 + 16)}}, {0, 0, 0});
|
||||
}
|
||||
|
||||
void GlassView::add_spectrum_pixel(uint8_t power) {
|
||||
@@ -134,15 +124,15 @@ void GlassView::add_spectrum_pixel(uint8_t power) {
|
||||
uint8_t color_gradient = (point * 255) / 212;
|
||||
// clear if not in peak view
|
||||
if (live_frequency_view != 2) {
|
||||
display.fill_rectangle({{xpos, 108 + 16}, {1, 320 - point}}, {0, 0, 0});
|
||||
display.fill_rectangle({{xpos, 108 + 16}, {1, SCREEN_H - point}}, {0, 0, 0});
|
||||
}
|
||||
display.fill_rectangle({{xpos, 320 - point}, {1, point}}, {color_gradient, 0, uint8_t(255 - color_gradient)});
|
||||
display.fill_rectangle({{xpos, SCREEN_H - point}, {1, point}}, {color_gradient, 0, uint8_t(255 - color_gradient)});
|
||||
}
|
||||
if (last_max_freq != max_freq_hold) {
|
||||
last_max_freq = max_freq_hold;
|
||||
freq_stats.set("MAX HOLD: " + to_string_short_freq(max_freq_hold));
|
||||
}
|
||||
PlotMarker(marker_pixel_index);
|
||||
plot_marker(marker_pixel_index);
|
||||
} else {
|
||||
display.draw_pixels({{0, display.scroll(1)}, {SCREEN_W, 1}}, spectrum_row); // new line at top, one less var, speedier
|
||||
}
|
||||
@@ -151,8 +141,8 @@ void GlassView::add_spectrum_pixel(uint8_t power) {
|
||||
}
|
||||
|
||||
bool GlassView::process_bins(uint8_t* powerlevel) {
|
||||
bins_Hz_size += each_bin_size; // add pixel to fulfilled bag of Hz
|
||||
if (bins_Hz_size >= marker_pixel_step) // new pixel fullfilled
|
||||
bins_hz_size += each_bin_size; // add pixel to fulfilled bag of Hz
|
||||
if (bins_hz_size >= marker_pixel_step) // new pixel fullfilled
|
||||
{
|
||||
if (*powerlevel > min_color_power)
|
||||
add_spectrum_pixel(*powerlevel); // Pixel will represent max_power
|
||||
@@ -162,7 +152,7 @@ bool GlassView::process_bins(uint8_t* powerlevel) {
|
||||
|
||||
if (!pixel_index) // Received indication that a waterfall line has been completed
|
||||
{
|
||||
bins_Hz_size = 0; // Since this is an entire pixel line, we don't carry "Pixels into next bin"
|
||||
bins_hz_size = 0; // Since this is an entire pixel line, we don't carry "Pixels into next bin"
|
||||
if (mode != LOOKING_GLASS_SINGLEPASS) {
|
||||
f_center = f_center_ini;
|
||||
retune();
|
||||
@@ -170,18 +160,18 @@ bool GlassView::process_bins(uint8_t* powerlevel) {
|
||||
baseband::spectrum_streaming_start();
|
||||
return true; // signal a new line
|
||||
}
|
||||
bins_Hz_size -= marker_pixel_step; // reset bins size, but carrying the eventual excess Hz into next pixel
|
||||
bins_hz_size -= marker_pixel_step; // reset bins size, but carrying the eventual excess Hz into next pixel
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Apparently, the spectrum object returns an array of SPEC_NB_BINS (256) bins
|
||||
// Each having the radio signal power for it's corresponding frequency slot
|
||||
// Each having the radio signal power for its corresponding frequency slot
|
||||
void GlassView::on_channel_spectrum(const ChannelSpectrum& spectrum) {
|
||||
baseband::spectrum_streaming_stop();
|
||||
// Convert bins of this spectrum slice into a representative max_power and when enough, into pixels
|
||||
// we actually need SCREEN_W (240) of those bins
|
||||
for (bin = 0; bin < bin_length; bin++) {
|
||||
for (uint8_t bin = 0; bin < bin_length; bin++) {
|
||||
get_max_power(spectrum, bin, max_power);
|
||||
// process dc spike if enable
|
||||
if (bin == 119) {
|
||||
@@ -215,7 +205,7 @@ void GlassView::on_show() {
|
||||
}
|
||||
|
||||
void GlassView::on_range_changed() {
|
||||
reset_live_view(true);
|
||||
reset_live_view();
|
||||
f_min = field_frequency_min.value();
|
||||
f_max = field_frequency_max.value();
|
||||
f_min = f_min * MHZ_DIV; // Transpose into full frequency realm
|
||||
@@ -231,8 +221,7 @@ void GlassView::on_range_changed() {
|
||||
looking_glass_sampling_rate = looking_glass_bandwidth;
|
||||
each_bin_size = looking_glass_bandwidth / SCREEN_W;
|
||||
looking_glass_step = looking_glass_bandwidth;
|
||||
f_center_ini = f_min + (looking_glass_bandwidth / 2); // Initial center frequency for sweep
|
||||
portapack::display.fill_rectangle({17 * 8, 4 * 16, 2 * 8, 16}, Color::black()); // Clear old marker and whole marker rectangle btw
|
||||
f_center_ini = f_min + (looking_glass_bandwidth / 2); // Initial center frequency for sweep
|
||||
} else {
|
||||
// view is made in multiple pass, use original bin picking
|
||||
mode = scan_type.selected_index_value();
|
||||
@@ -253,19 +242,13 @@ void GlassView::on_range_changed() {
|
||||
}
|
||||
search_span = looking_glass_range / MHZ_DIV;
|
||||
marker_pixel_step = looking_glass_range / SCREEN_W; // Each pixel value in Hz
|
||||
//
|
||||
button_range.set_text(" "); // clear up to 6 chars
|
||||
if (locked_range) {
|
||||
button_range.set_text(">" + to_string_dec_uint(search_span) + "<");
|
||||
} else {
|
||||
button_range.set_text(" " + to_string_dec_uint(search_span) + " ");
|
||||
}
|
||||
|
||||
pixel_index = 0; // reset pixel counter
|
||||
max_power = 0; // reset save max power level
|
||||
bins_Hz_size = 0; // reset amount of Hz filled up by pixels
|
||||
//
|
||||
pixel_index = 0;
|
||||
max_power = 0;
|
||||
bins_hz_size = 0;
|
||||
|
||||
on_marker_change();
|
||||
update_range_field();
|
||||
|
||||
// set the sample rate and bandwidth
|
||||
receiver_model.set_sampling_rate(looking_glass_sampling_rate);
|
||||
@@ -273,11 +256,11 @@ void GlassView::on_range_changed() {
|
||||
|
||||
receiver_model.set_squelch_level(0);
|
||||
f_center = f_center_ini; // Reset sweep into first slice
|
||||
baseband::set_spectrum(looking_glass_bandwidth, field_trigger.value());
|
||||
baseband::set_spectrum(looking_glass_bandwidth, trigger);
|
||||
receiver_model.set_target_frequency(f_center); // tune rx for this slice
|
||||
}
|
||||
|
||||
void GlassView::PlotMarker(uint8_t pos) {
|
||||
void GlassView::plot_marker(uint8_t pos) {
|
||||
uint8_t shift_y = 0;
|
||||
if (live_frequency_view > 0) // plot one line down when in live view
|
||||
{
|
||||
@@ -289,7 +272,7 @@ void GlassView::PlotMarker(uint8_t pos) {
|
||||
portapack::display.fill_rectangle({pos, 106 + shift_y, 1, 2}, Color::red()); // Red marker bottom
|
||||
}
|
||||
|
||||
void GlassView::clip_min(int32_t v) {
|
||||
void GlassView::update_min(int32_t v) {
|
||||
int32_t min_size = steps;
|
||||
if (locked_range)
|
||||
min_size = search_span;
|
||||
@@ -299,15 +282,14 @@ void GlassView::clip_min(int32_t v) {
|
||||
v = 7200 - min_size;
|
||||
}
|
||||
if (v > (field_frequency_max.value() - min_size))
|
||||
field_frequency_max.set_value(v + min_size);
|
||||
field_frequency_max.set_value(v + min_size, false);
|
||||
if (locked_range)
|
||||
field_frequency_max.set_value(v + min_size);
|
||||
field_frequency_max.set_value(v + min_size, false);
|
||||
else
|
||||
field_frequency_min.set_value(v);
|
||||
on_range_changed();
|
||||
field_frequency_min.set_value(v, false);
|
||||
}
|
||||
|
||||
void GlassView::clip_max(int32_t v) {
|
||||
void GlassView::update_max(int32_t v) {
|
||||
int32_t min_size = steps;
|
||||
if (locked_range)
|
||||
min_size = search_span;
|
||||
@@ -317,12 +299,21 @@ void GlassView::clip_max(int32_t v) {
|
||||
v = min_size;
|
||||
}
|
||||
if (v < (field_frequency_min.value() + min_size))
|
||||
field_frequency_min.set_value(v - min_size);
|
||||
field_frequency_min.set_value(v - min_size, false);
|
||||
if (locked_range)
|
||||
field_frequency_min.set_value(v - min_size);
|
||||
field_frequency_min.set_value(v - min_size, false);
|
||||
else
|
||||
field_frequency_max.set_value(v);
|
||||
on_range_changed();
|
||||
field_frequency_max.set_value(v, false);
|
||||
}
|
||||
|
||||
void GlassView::update_range_field() {
|
||||
if (!locked_range) {
|
||||
field_range.set_style(&Styles::white);
|
||||
field_range.set_text(" " + to_string_dec_uint(search_span) + " ");
|
||||
} else {
|
||||
field_range.set_style(&Styles::red);
|
||||
field_range.set_text(">" + to_string_dec_uint(search_span) + "<");
|
||||
}
|
||||
}
|
||||
|
||||
GlassView::GlassView(
|
||||
@@ -335,7 +326,7 @@ GlassView::GlassView(
|
||||
&field_frequency_max,
|
||||
&field_lna,
|
||||
&field_vga,
|
||||
&button_range,
|
||||
&field_range,
|
||||
&steps_config,
|
||||
&scan_type,
|
||||
&view_config,
|
||||
@@ -343,175 +334,156 @@ GlassView::GlassView(
|
||||
&filter_config,
|
||||
&field_rf_amp,
|
||||
&range_presets,
|
||||
&button_marker,
|
||||
&field_marker,
|
||||
&field_trigger,
|
||||
&button_jump,
|
||||
&button_rst,
|
||||
&freq_stats});
|
||||
|
||||
load_Presets(); // Load available presets from TXT files (or default)
|
||||
load_presets(); // Load available presets from TXT files (or default).
|
||||
preset_index = clip<uint8_t>(preset_index, 0, presets_db.size());
|
||||
|
||||
field_frequency_min.set_value(f_min / MHZ_DIV);
|
||||
field_frequency_min.on_change = [this](int32_t v) {
|
||||
clip_min(v);
|
||||
range_presets.set_selected_index(0); // Manual
|
||||
update_min(v);
|
||||
on_range_changed();
|
||||
};
|
||||
field_frequency_min.set_value(presets_db[0].min); // Defaults to first preset
|
||||
field_frequency_min.set_step(steps);
|
||||
|
||||
field_frequency_min.on_select = [this, &nav](NumberField& field) {
|
||||
auto new_view = nav_.push<FrequencyKeypadView>(field_frequency_min.value() * MHZ_DIV);
|
||||
new_view->on_changed = [this, &field](rf::Frequency f) {
|
||||
clip_min(f / MHZ_DIV);
|
||||
field_frequency_min.set_value(f / MHZ_DIV);
|
||||
};
|
||||
};
|
||||
|
||||
field_frequency_max.set_value(f_max / MHZ_DIV);
|
||||
field_frequency_max.on_change = [this](int32_t v) {
|
||||
clip_max(v);
|
||||
range_presets.set_selected_index(0); // Manual
|
||||
update_max(v);
|
||||
on_range_changed();
|
||||
};
|
||||
field_frequency_max.set_value(presets_db[0].max); // Defaults to first preset
|
||||
field_frequency_max.set_step(steps);
|
||||
|
||||
field_frequency_max.on_select = [this, &nav](NumberField& field) {
|
||||
auto new_view = nav_.push<FrequencyKeypadView>(field_frequency_max.value() * MHZ_DIV);
|
||||
new_view->on_changed = [this, &field](rf::Frequency f) {
|
||||
clip_max(f / MHZ_DIV);
|
||||
field_frequency_max.set_value(f / MHZ_DIV);
|
||||
};
|
||||
};
|
||||
|
||||
field_lna.on_change = [this](int32_t v) {
|
||||
reset_live_view(true);
|
||||
this->on_lna_changed(v);
|
||||
};
|
||||
field_lna.set_value(receiver_model.lna());
|
||||
|
||||
field_vga.on_change = [this](int32_t v_db) {
|
||||
reset_live_view(true);
|
||||
this->on_vga_changed(v_db);
|
||||
};
|
||||
field_vga.set_value(receiver_model.vga());
|
||||
|
||||
steps_config.on_change = [this](size_t n, OptionsField::value_t v) {
|
||||
(void)n;
|
||||
steps_config.on_change = [this](size_t, OptionsField::value_t v) {
|
||||
field_frequency_min.set_step(v);
|
||||
field_frequency_max.set_step(v);
|
||||
steps = v;
|
||||
};
|
||||
steps_config.set_selected_index(0); // default of 1 Mhz steps
|
||||
steps_config.set_selected_index(0); // 1 Mhz step.
|
||||
|
||||
scan_type.on_change = [this](size_t n, OptionsField::value_t v) {
|
||||
(void)n;
|
||||
scan_type.on_change = [this](size_t, OptionsField::value_t v) {
|
||||
mode = v;
|
||||
on_range_changed();
|
||||
};
|
||||
scan_type.set_selected_index(0); // default legacy fast scan
|
||||
scan_type.set_selected_index(mode);
|
||||
|
||||
view_config.on_change = [this](size_t n, OptionsField::value_t v) {
|
||||
(void)n;
|
||||
// clear between changes
|
||||
reset_live_view(true);
|
||||
if (v == 0) {
|
||||
live_frequency_view = 0;
|
||||
level_integration.hidden(true);
|
||||
freq_stats.hidden(true);
|
||||
button_jump.hidden(true);
|
||||
button_rst.hidden(true);
|
||||
display.scroll_set_area(109, 319); // Restart scroll on the correct coordinates
|
||||
} else if (v == 1) {
|
||||
display.fill_rectangle({{0, 108}, {SCREEN_W, 24}}, {0, 0, 0});
|
||||
live_frequency_view = 1;
|
||||
display.scroll_disable();
|
||||
level_integration.hidden(false);
|
||||
freq_stats.hidden(false);
|
||||
button_jump.hidden(false);
|
||||
button_rst.hidden(false);
|
||||
} else if (v == 2) {
|
||||
display.fill_rectangle({{0, 108}, {SCREEN_W, 24}}, {0, 0, 0});
|
||||
live_frequency_view = 2;
|
||||
display.scroll_disable();
|
||||
level_integration.hidden(false);
|
||||
freq_stats.hidden(false);
|
||||
button_jump.hidden(false);
|
||||
button_rst.hidden(false);
|
||||
view_config.on_change = [this](size_t, OptionsField::value_t v) {
|
||||
reset_live_view(); // Clear between changes.
|
||||
live_frequency_view = v;
|
||||
|
||||
switch (v) {
|
||||
case 0: // SPEC
|
||||
level_integration.hidden(true);
|
||||
freq_stats.hidden(true);
|
||||
button_jump.hidden(true);
|
||||
button_rst.hidden(true);
|
||||
display.scroll_set_area(109, 319); // Restart scroll on the correct coordinates.
|
||||
break;
|
||||
|
||||
case 1: // LEVEL
|
||||
display.fill_rectangle({{0, 108}, {SCREEN_W, 24}}, {0, 0, 0});
|
||||
display.scroll_disable();
|
||||
level_integration.hidden(false);
|
||||
freq_stats.hidden(false);
|
||||
button_jump.hidden(false);
|
||||
button_rst.hidden(false);
|
||||
break;
|
||||
|
||||
case 2: // PEAK
|
||||
default:
|
||||
display.fill_rectangle({{0, 108}, {SCREEN_W, 24}}, {0, 0, 0});
|
||||
display.scroll_disable();
|
||||
level_integration.hidden(false);
|
||||
freq_stats.hidden(false);
|
||||
button_jump.hidden(false);
|
||||
button_rst.hidden(false);
|
||||
break;
|
||||
}
|
||||
|
||||
set_dirty();
|
||||
};
|
||||
view_config.set_selected_index(0); // default spectrum
|
||||
view_config.set_selected_index(live_frequency_view);
|
||||
|
||||
level_integration.on_change = [this](size_t n, OptionsField::value_t v) {
|
||||
(void)n;
|
||||
reset_live_view(true);
|
||||
level_integration.on_change = [this](size_t, OptionsField::value_t v) {
|
||||
reset_live_view();
|
||||
live_frequency_integrate = v;
|
||||
};
|
||||
level_integration.set_selected_index(3); // default integration of ( 3 * old value + new_value ) / 4
|
||||
level_integration.set_selected_index(live_frequency_integrate);
|
||||
|
||||
filter_config.on_change = [this](size_t n, OptionsField::value_t v) {
|
||||
(void)n;
|
||||
reset_live_view(true);
|
||||
filter_config.on_change = [this](size_t ix, OptionsField::value_t v) {
|
||||
reset_live_view();
|
||||
min_color_power = v;
|
||||
filter_index = ix;
|
||||
};
|
||||
filter_config.set_selected_index(0);
|
||||
filter_config.set_selected_index(filter_index);
|
||||
|
||||
range_presets.on_change = [this](size_t n, OptionsField::value_t v) {
|
||||
(void)n;
|
||||
range_presets.on_change = [this](size_t ix, OptionsField::value_t v) {
|
||||
preset_index = ix;
|
||||
if (ix == 0) return; // Don't update range for "Manual".
|
||||
|
||||
// NB: Don't trigger updates, presets directly set the range
|
||||
// values without applying step or range lock.
|
||||
field_frequency_min.set_value(presets_db[v].min, false);
|
||||
field_frequency_max.set_value(presets_db[v].max, false);
|
||||
on_range_changed();
|
||||
};
|
||||
range_presets.set_selected_index(preset_index);
|
||||
|
||||
button_marker.on_change = [this]() {
|
||||
if (((int)marker_pixel_index + button_marker.get_encoder_delta()) < 0) {
|
||||
marker_pixel_index = 0;
|
||||
} else if (((int)marker_pixel_index + button_marker.get_encoder_delta()) > SCREEN_W) {
|
||||
marker_pixel_index = SCREEN_W;
|
||||
} else {
|
||||
marker_pixel_index = marker_pixel_index + button_marker.get_encoder_delta();
|
||||
}
|
||||
field_marker.on_encoder_change = [this](TextField&, EncoderEvent delta) {
|
||||
marker_pixel_index = clip<uint8_t>(marker_pixel_index + delta, 0, SCREEN_W);
|
||||
on_marker_change();
|
||||
button_marker.set_encoder_delta(0);
|
||||
};
|
||||
|
||||
button_marker.on_select = [this](ButtonWithEncoder&) {
|
||||
receiver_model.set_target_frequency(marker); // Center tune rx in marker freq.
|
||||
auto settings = receiver_model.settings();
|
||||
settings.frequency_step = MHZ_DIV; // Preset a 1 MHz frequency step into RX -> AUDIO
|
||||
nav_.replace<AnalogAudioView>(settings); // Jump into audio view
|
||||
field_marker.on_select = [this](TextField&) {
|
||||
// Launch Audio with marker frequency.
|
||||
launch_audio(marker);
|
||||
};
|
||||
|
||||
field_trigger.on_change = [this](int32_t v) {
|
||||
baseband::set_spectrum(looking_glass_bandwidth, v);
|
||||
trigger = v;
|
||||
baseband::set_spectrum(looking_glass_bandwidth, trigger);
|
||||
};
|
||||
field_trigger.set_value(32); // Defaults to 32, as normal triggering resolution
|
||||
field_trigger.set_value(trigger);
|
||||
|
||||
button_range.on_select = [this](Button&) {
|
||||
if (locked_range) {
|
||||
locked_range = false;
|
||||
button_range.set_style(&Styles::white);
|
||||
button_range.set_text(" " + to_string_dec_uint(search_span) + " ");
|
||||
} else {
|
||||
locked_range = true;
|
||||
button_range.set_style(&Styles::red);
|
||||
button_range.set_text(">" + to_string_dec_uint(search_span) + "<");
|
||||
}
|
||||
field_range.on_select = [this](TextField&) {
|
||||
locked_range = !locked_range;
|
||||
update_range_field();
|
||||
};
|
||||
|
||||
button_jump.on_select = [this](Button&) {
|
||||
receiver_model.set_target_frequency(max_freq_hold); // Center tune rx in marker freq.
|
||||
auto settings = receiver_model.settings();
|
||||
settings.frequency_step = MHZ_DIV; // Preset a 1 MHz frequency step into RX -> AUDIO
|
||||
nav_.replace<AnalogAudioView>(settings); // Jump into audio view
|
||||
// Launch Audio with peak frequency.
|
||||
launch_audio(max_freq_hold);
|
||||
};
|
||||
|
||||
button_rst.on_select = [this](Button&) {
|
||||
reset_live_view(true);
|
||||
reset_live_view();
|
||||
};
|
||||
|
||||
display.scroll_set_area(109, 319);
|
||||
baseband::set_spectrum(looking_glass_bandwidth, field_trigger.value()); // trigger:
|
||||
// Discord User jteich: WidebandSpectrum::on_message to set the trigger value. In WidebandSpectrum::execute ,
|
||||
// it keeps adding the output of the fft to the buffer until "trigger" number of calls are made,
|
||||
// at which time it pushes the buffer up with channel_spectrum.feed
|
||||
|
||||
marker_pixel_index = 120;
|
||||
on_range_changed();
|
||||
// trigger:
|
||||
// Discord User jteich: WidebandSpectrum::on_message to set the trigger value. In WidebandSpectrum::execute,
|
||||
// it keeps adding the output of the fft to the buffer until "trigger" number of calls are made,
|
||||
// at which time it pushes the buffer up with channel_spectrum.feed
|
||||
baseband::set_spectrum(looking_glass_bandwidth, trigger);
|
||||
|
||||
marker_pixel_index = SCREEN_W / 2;
|
||||
on_range_changed(); // Force a UI update.
|
||||
|
||||
receiver_model.set_sampling_rate(looking_glass_sampling_rate); // 20mhz
|
||||
receiver_model.set_baseband_bandwidth(looking_glass_bandwidth); // possible values: 1.75/2.5/3.5/5/5.5/6/7/8/9/10/12/14/15/20/24/28MHz
|
||||
@@ -519,11 +491,14 @@ GlassView::GlassView(
|
||||
receiver_model.enable();
|
||||
}
|
||||
|
||||
void GlassView::load_Presets() {
|
||||
void GlassView::load_presets() {
|
||||
File presets_file;
|
||||
auto error = presets_file.open("LOOKINGGLASS/PRESETS.TXT");
|
||||
presets_db.clear();
|
||||
|
||||
// Add the "Manual" entry.
|
||||
presets_db.push_back({0, 0, "Manual"});
|
||||
|
||||
if (!error) {
|
||||
auto reader = FileLineReader(presets_file);
|
||||
for (const auto& line : reader) {
|
||||
@@ -546,14 +521,10 @@ void GlassView::load_Presets() {
|
||||
}
|
||||
}
|
||||
|
||||
// Couldn't load any from the file, load a default instead.
|
||||
if (presets_db.empty())
|
||||
presets_Default();
|
||||
|
||||
populate_Presets();
|
||||
populate_presets();
|
||||
}
|
||||
|
||||
void GlassView::populate_Presets() {
|
||||
void GlassView::populate_presets() {
|
||||
using option_t = std::pair<std::string, int32_t>;
|
||||
using options_t = std::vector<option_t>;
|
||||
options_t entries;
|
||||
@@ -561,12 +532,14 @@ void GlassView::populate_Presets() {
|
||||
for (const auto& preset : presets_db)
|
||||
entries.emplace_back(preset.label, entries.size());
|
||||
|
||||
range_presets.set_options(entries);
|
||||
range_presets.set_options(std::move(entries));
|
||||
}
|
||||
|
||||
void GlassView::presets_Default() {
|
||||
presets_db.clear();
|
||||
presets_db.push_back({2320, 2560, "DEFAULT WIFI 2.4GHz"});
|
||||
void GlassView::launch_audio(rf::Frequency center_freq) {
|
||||
receiver_model.set_target_frequency(center_freq);
|
||||
auto settings = receiver_model.settings();
|
||||
settings.frequency_step = MHZ_DIV; // Preset a 1 MHz frequency step into RX -> AUDIO
|
||||
nav_.replace<AnalogAudioView>(settings); // Jump into audio view
|
||||
}
|
||||
|
||||
} // namespace ui
|
||||
|
||||
@@ -72,8 +72,28 @@ class GlassView : public View {
|
||||
private:
|
||||
NavigationView& nav_;
|
||||
RxRadioState radio_state_{ReceiverModel::Mode::SpectrumAnalysis};
|
||||
// Settings
|
||||
rf::Frequency f_min = 260 * MHZ_DIV; // Default to 315/433 remote range.
|
||||
rf::Frequency f_max = 500 * MHZ_DIV;
|
||||
uint8_t preset_index = 0; // Manual
|
||||
uint8_t filter_index = 0; // OFF
|
||||
uint8_t trigger = 32;
|
||||
uint8_t mode = LOOKING_GLASS_FASTSCAN;
|
||||
uint8_t live_frequency_view = 0; // Spectrum
|
||||
uint8_t live_frequency_integrate = 3; // Default (3 * old value + new_value) / 4
|
||||
app_settings::SettingsManager settings_{
|
||||
"rx_glass", app_settings::Mode::RX};
|
||||
"rx_glass"sv,
|
||||
app_settings::Mode::RX,
|
||||
{
|
||||
{"min"sv, &f_min},
|
||||
{"max"sv, &f_max},
|
||||
{"preset"sv, &preset_index},
|
||||
{"filter"sv, &filter_index},
|
||||
{"trigger"sv, &trigger},
|
||||
{"scan_mode"sv, &mode},
|
||||
{"freq_view"sv, &live_frequency_view},
|
||||
{"freq_integrate"sv, &live_frequency_integrate},
|
||||
}};
|
||||
|
||||
struct preset_entry {
|
||||
rf::Frequency min{};
|
||||
@@ -82,8 +102,9 @@ class GlassView : public View {
|
||||
};
|
||||
|
||||
std::vector<preset_entry> presets_db{};
|
||||
void clip_min(int32_t v);
|
||||
void clip_max(int32_t v);
|
||||
void update_min(int32_t v);
|
||||
void update_max(int32_t v);
|
||||
void update_range_field();
|
||||
void get_max_power(const ChannelSpectrum& spectrum, uint8_t bin, uint8_t& max_power);
|
||||
rf::Frequency get_freq_from_bin_pos(uint8_t pos);
|
||||
void on_marker_change();
|
||||
@@ -94,57 +115,52 @@ class GlassView : public View {
|
||||
int64_t next_mult_of(int64_t num, int64_t multiplier);
|
||||
void adjust_range(int64_t* f_min, int64_t* f_max, int64_t width);
|
||||
void on_range_changed();
|
||||
void on_lna_changed(int32_t v_db);
|
||||
void on_vga_changed(int32_t v_db);
|
||||
void reset_live_view(bool clear_screen);
|
||||
void reset_live_view();
|
||||
void add_spectrum_pixel(uint8_t power);
|
||||
void PlotMarker(uint8_t pos);
|
||||
void load_Presets();
|
||||
void txtline_process(std::string& line);
|
||||
void populate_Presets();
|
||||
void presets_Default();
|
||||
void plot_marker(uint8_t pos);
|
||||
void load_presets();
|
||||
void populate_presets();
|
||||
void launch_audio(rf::Frequency center_freq);
|
||||
|
||||
rf::Frequency f_min{0}, f_max{0};
|
||||
rf::Frequency search_span{0};
|
||||
rf::Frequency f_center{0};
|
||||
rf::Frequency f_center_ini{0};
|
||||
|
||||
rf::Frequency marker{0};
|
||||
uint8_t marker_pixel_index{0};
|
||||
rf::Frequency marker_pixel_step{0};
|
||||
// size of one spectrum bin in Hz
|
||||
|
||||
// Size of one spectrum bin in Hz.
|
||||
rf::Frequency each_bin_size{0};
|
||||
// consumed number of Hz, used to know if we have filled a 'bag' , a corresponding pixel length on screen
|
||||
rf::Frequency bins_Hz_size{0};
|
||||
// Bandwidth of a single spectrum bin.
|
||||
rf::Frequency bins_hz_size{0};
|
||||
rf::Frequency looking_glass_sampling_rate{0};
|
||||
rf::Frequency looking_glass_bandwidth{0};
|
||||
rf::Frequency looking_glass_range{0};
|
||||
rf::Frequency looking_glass_step{0};
|
||||
uint8_t min_color_power{0};
|
||||
uint8_t min_color_power{0}; // Filter cutoff level.
|
||||
uint32_t pixel_index{0};
|
||||
std::array<Color, SCREEN_W> spectrum_row = {0};
|
||||
std::array<uint8_t, SCREEN_W> spectrum_data = {0};
|
||||
ChannelSpectrumFIFO* fifo{nullptr};
|
||||
uint8_t max_power = 0;
|
||||
int32_t steps = 0;
|
||||
uint8_t live_frequency_view = 0;
|
||||
int16_t live_frequency_integrate = 3;
|
||||
int64_t max_freq_hold = 0;
|
||||
int16_t max_freq_power = -1000;
|
||||
|
||||
std::array<Color, SCREEN_W> spectrum_row{};
|
||||
std::array<uint8_t, SCREEN_W> spectrum_data{};
|
||||
ChannelSpectrumFIFO* fifo{};
|
||||
|
||||
int32_t steps = 1;
|
||||
bool locked_range = false;
|
||||
|
||||
uint8_t max_power = 0;
|
||||
rf::Frequency max_freq_hold = 0;
|
||||
rf::Frequency last_max_freq = 0;
|
||||
int16_t max_freq_power = -1000;
|
||||
uint8_t bin_length = SCREEN_W;
|
||||
uint8_t real_bin_length = SCREEN_W;
|
||||
uint8_t offset = 0;
|
||||
uint8_t tune_offset = 0;
|
||||
uint8_t bin = 0;
|
||||
int64_t last_max_freq = 0;
|
||||
uint8_t mode = LOOKING_GLASS_FASTSCAN;
|
||||
uint8_t ignore_dc = 0;
|
||||
|
||||
Labels labels{
|
||||
{{0, 0}, "MIN: MAX: LNA VGA ", Color::light_grey()},
|
||||
{{0, 1 * 16}, "RANGE: FILTER: AMP:", Color::light_grey()},
|
||||
{{0, 0 * 16}, "MIN: MAX: LNA VGA ", Color::light_grey()},
|
||||
{{0, 1 * 16}, "RANGE: FILTER: AMP:", Color::light_grey()},
|
||||
{{0, 2 * 16}, "PRESET:", Color::light_grey()},
|
||||
{{0, 3 * 16}, "MARKER: MHz", Color::light_grey()},
|
||||
{{0, 3 * 16}, "MARKER: MHz", Color::light_grey()},
|
||||
{{0, 4 * 16}, "RES: STEP:", Color::light_grey()}};
|
||||
|
||||
NumberField field_frequency_min{
|
||||
@@ -167,8 +183,8 @@ class GlassView : public View {
|
||||
VGAGainField field_vga{
|
||||
{27 * 8, 0 * 16}};
|
||||
|
||||
Button button_range{
|
||||
{7 * 8, 1 * 16, 4 * 8, 16},
|
||||
TextField field_range{
|
||||
{6 * 8, 1 * 16, 6 * 8, 16},
|
||||
""};
|
||||
|
||||
OptionsField filter_config{
|
||||
@@ -176,23 +192,21 @@ class GlassView : public View {
|
||||
4,
|
||||
{
|
||||
{"OFF ", 0},
|
||||
{"MID ", 118}, // 85 +25 (110) + a bit more to kill all blue
|
||||
{"MID ", 118}, // 85 + 25 (110) + a bit more to kill all blue
|
||||
{"HIGH", 202}, // 168 + 25 (193)
|
||||
}};
|
||||
|
||||
RFAmpField field_rf_amp{
|
||||
{29 * 8, 1 * 16}};
|
||||
{28 * 8, 1 * 16}};
|
||||
|
||||
OptionsField range_presets{
|
||||
{7 * 8, 2 * 16},
|
||||
20,
|
||||
{
|
||||
{" NONE (WIFI 2.4GHz)", 0},
|
||||
}};
|
||||
{}};
|
||||
|
||||
ButtonWithEncoder button_marker{
|
||||
{7 * 8, 3 * 16, 10 * 8, 16},
|
||||
" "};
|
||||
TextField field_marker{
|
||||
{7 * 8, 3 * 16, 9 * 8, 16},
|
||||
""};
|
||||
|
||||
NumberField field_trigger{
|
||||
{4 * 8, 4 * 16},
|
||||
|
||||
@@ -31,8 +31,6 @@ namespace fs = std::filesystem;
|
||||
|
||||
namespace ui {
|
||||
|
||||
static const fs::path default_scan_file{u"FREQMAN/SCANNER.TXT"};
|
||||
|
||||
ScannerThread::ScannerThread(std::vector<rf::Frequency> frequency_list)
|
||||
: frequency_list_{std::move(frequency_list)} {
|
||||
_manual_search = false;
|
||||
@@ -234,7 +232,7 @@ void ScannerView::handle_retune(int64_t freq, uint32_t freq_idx) {
|
||||
|
||||
if (!manual_search) {
|
||||
if (entries.size() > 0)
|
||||
text_current_index.set(to_string_dec_uint(freq_idx + 1, 3));
|
||||
field_current_index.set_text(to_string_dec_uint(freq_idx + 1, 3));
|
||||
|
||||
if (freq_idx < entries.size() && entries[freq_idx].description.size() > 1)
|
||||
text_current_desc.set(entries[freq_idx].description); // Show description from file
|
||||
@@ -243,9 +241,20 @@ void ScannerView::handle_retune(int64_t freq, uint32_t freq_idx) {
|
||||
}
|
||||
}
|
||||
|
||||
void ScannerView::handle_encoder(EncoderEvent delta) {
|
||||
auto index_step = delta > 0 ? 1 : -1;
|
||||
|
||||
if (scan_thread)
|
||||
scan_thread->set_index_stepper(index_step);
|
||||
|
||||
// Restart browse timer when frequency changes.
|
||||
if (browse_timer != 0)
|
||||
browse_timer = 1;
|
||||
}
|
||||
|
||||
std::string ScannerView::loaded_filename() const {
|
||||
auto filename = loaded_path.filename().string();
|
||||
if (filename.length() > 23) { // Truncate and add ellipses if long file name
|
||||
auto filename = freqman_file;
|
||||
if (filename.length() > 23) { // Truncate long file name.
|
||||
filename.resize(22);
|
||||
filename = filename + "+";
|
||||
}
|
||||
@@ -266,7 +275,7 @@ ScannerView::~ScannerView() {
|
||||
}
|
||||
|
||||
void ScannerView::show_max_index() { // show total number of freqs to scan
|
||||
text_current_index.set("---");
|
||||
field_current_index.set_text("---");
|
||||
|
||||
if (entries.size() == FREQMAN_MAX_PER_FILE) {
|
||||
text_max_index.set_style(&Styles::red);
|
||||
@@ -293,7 +302,7 @@ ScannerView::ScannerView(
|
||||
&button_load,
|
||||
&button_clear,
|
||||
&rssi,
|
||||
&text_current_index,
|
||||
&field_current_index,
|
||||
&text_max_index,
|
||||
&text_current_desc,
|
||||
&big_display,
|
||||
@@ -336,14 +345,14 @@ ScannerView::ScannerView(
|
||||
};
|
||||
};
|
||||
|
||||
// Button to clear in-memory frequency list
|
||||
// Button to clear in-memory frequency list.
|
||||
button_clear.on_select = [this, &nav](Button&) {
|
||||
if (scan_thread && entries.size()) {
|
||||
scan_thread->stop(); // STOP SCANNER THREAD
|
||||
entries.clear();
|
||||
|
||||
show_max_index(); // UPDATE new list size on screen
|
||||
text_current_index.set("");
|
||||
field_current_index.set_text("");
|
||||
text_current_desc.set(loaded_filename());
|
||||
scan_thread->set_freq_lock(0); // Reset the scanner lock
|
||||
|
||||
@@ -351,7 +360,7 @@ ScannerView::ScannerView(
|
||||
}
|
||||
};
|
||||
|
||||
// Button to configure starting frequency for a manual range search
|
||||
// Button to configure starting frequency for a manual range search.
|
||||
button_manual_start.on_select = [this, &nav](Button& button) {
|
||||
auto new_view = nav_.push<FrequencyKeypadView>(frequency_range.min);
|
||||
new_view->on_changed = [this, &button](rf::Frequency f) {
|
||||
@@ -360,7 +369,7 @@ ScannerView::ScannerView(
|
||||
};
|
||||
};
|
||||
|
||||
// Button to configure ending frequency for a manual range search
|
||||
// Button to configure ending frequency for a manual range search.
|
||||
button_manual_end.on_select = [this, &nav](Button& button) {
|
||||
auto new_view = nav.push<FrequencyKeypadView>(frequency_range.max);
|
||||
new_view->on_changed = [this, &button](rf::Frequency f) {
|
||||
@@ -369,7 +378,7 @@ ScannerView::ScannerView(
|
||||
};
|
||||
};
|
||||
|
||||
// Button to pause/resume scan (note that some other buttons will trigger resume also)
|
||||
// Button to pause/resume scan (note that some other buttons will trigger resume also).
|
||||
button_pause.on_select = [this](ButtonWithEncoder&) {
|
||||
if (userpause)
|
||||
user_resume();
|
||||
@@ -380,19 +389,14 @@ ScannerView::ScannerView(
|
||||
}
|
||||
};
|
||||
|
||||
// Encoder dial causes frequency change when focus is on pause button
|
||||
// Encoder dial causes frequency change when focus is on pause button or current index.
|
||||
button_pause.on_change = [this]() {
|
||||
int32_t encoder_delta{(button_pause.get_encoder_delta() > 0) ? 1 : -1};
|
||||
|
||||
if (scan_thread)
|
||||
scan_thread->set_index_stepper(encoder_delta);
|
||||
|
||||
// Restart browse timer when frequency changes
|
||||
if (browse_timer != 0)
|
||||
browse_timer = 1;
|
||||
|
||||
handle_encoder(button_pause.get_encoder_delta());
|
||||
button_pause.set_encoder_delta(0);
|
||||
};
|
||||
field_current_index.on_encoder_change = [this](TextField&, EncoderEvent delta) {
|
||||
handle_encoder(delta);
|
||||
};
|
||||
|
||||
// Button to switch to Audio app
|
||||
button_audio_app.on_select = [this](Button&) {
|
||||
@@ -485,7 +489,7 @@ ScannerView::ScannerView(
|
||||
// Button to add current frequency (found during Search) to the Scan Frequency List
|
||||
button_add.on_select = [this](Button&) {
|
||||
FreqmanDB db;
|
||||
if (db.open(loaded_path, /*create*/ true)) {
|
||||
if (db.open(get_freqman_path(freqman_file), /*create*/ true)) {
|
||||
freqman_entry entry{
|
||||
.frequency_a = current_frequency,
|
||||
.type = freqman_type::Single,
|
||||
@@ -511,7 +515,7 @@ ScannerView::ScannerView(
|
||||
}
|
||||
}
|
||||
} else {
|
||||
nav_.display_modal("Error", "Cannot open " + loaded_path.filename().string() + "\nfor appending freq.");
|
||||
nav_.display_modal("Error", "Cannot open " + freqman_file + ".TXT\nfor appending freq.");
|
||||
bigdisplay_update(-1); // Need to poke this control after displaying modal?
|
||||
}
|
||||
};
|
||||
@@ -531,7 +535,7 @@ ScannerView::ScannerView(
|
||||
receiver_model.set_squelch_level(0);
|
||||
|
||||
// LOAD FREQUENCIES
|
||||
frequency_file_load(default_scan_file);
|
||||
frequency_file_load(get_freqman_path(freqman_file));
|
||||
}
|
||||
|
||||
void ScannerView::frequency_file_load(const fs::path& path) {
|
||||
@@ -542,12 +546,11 @@ void ScannerView::frequency_file_load(const fs::path& path) {
|
||||
FreqmanDB db;
|
||||
if (!db.open(path)) {
|
||||
text_current_desc.set("NO " + path.filename().string());
|
||||
loaded_path = default_scan_file;
|
||||
return;
|
||||
}
|
||||
|
||||
entries.clear();
|
||||
loaded_path = path;
|
||||
freqman_file = path.stem().string();
|
||||
Optional<scanner_range_t> range;
|
||||
|
||||
for (auto entry : db) {
|
||||
|
||||
@@ -110,6 +110,8 @@ class ScannerView : public View {
|
||||
std::string title() const override { return "Scanner"; };
|
||||
|
||||
private:
|
||||
static constexpr const char* default_freqman_file = "SCANNER";
|
||||
|
||||
RxRadioState radio_state_{};
|
||||
|
||||
// Settings
|
||||
@@ -117,6 +119,7 @@ class ScannerView : public View {
|
||||
uint32_t lock_wait{2};
|
||||
int32_t squelch{-30};
|
||||
scanner_range_t frequency_range{0, MAX_UFREQ};
|
||||
std::string freqman_file{default_freqman_file};
|
||||
app_settings::SettingsManager settings_{
|
||||
"rx_scanner"sv,
|
||||
app_settings::Mode::RX,
|
||||
@@ -126,6 +129,7 @@ class ScannerView : public View {
|
||||
{"scanner_squelch"sv, &squelch},
|
||||
{"range_min"sv, &frequency_range.min},
|
||||
{"range_max"sv, &frequency_range.max},
|
||||
{"file"sv, &freqman_file},
|
||||
}};
|
||||
|
||||
NavigationView& nav_;
|
||||
@@ -142,7 +146,7 @@ class ScannerView : public View {
|
||||
void update_squelch_while_paused(int32_t max_db);
|
||||
void on_statistics_update(const ChannelStatistics& statistics);
|
||||
void handle_retune(int64_t freq, uint32_t freq_idx);
|
||||
|
||||
void handle_encoder(EncoderEvent delta);
|
||||
std::string loaded_filename() const;
|
||||
|
||||
uint32_t browse_timer{0};
|
||||
@@ -151,7 +155,6 @@ class ScannerView : public View {
|
||||
int32_t bigdisplay_current_color{-2};
|
||||
rf::Frequency bigdisplay_current_frequency{0};
|
||||
|
||||
std::filesystem::path loaded_path{};
|
||||
std::vector<scanner_entry_t> entries{};
|
||||
uint32_t current_index{0};
|
||||
rf::Frequency current_frequency{0};
|
||||
@@ -223,8 +226,9 @@ class ScannerView : public View {
|
||||
{0 * 16, 2 * 16, 15 * 16, 8},
|
||||
};
|
||||
|
||||
Text text_current_index{
|
||||
TextField field_current_index{
|
||||
{0, 3 * 16, 3 * 8, 16},
|
||||
{},
|
||||
};
|
||||
|
||||
Text text_max_index{
|
||||
@@ -235,9 +239,9 @@ class ScannerView : public View {
|
||||
{0, 4 * 16, 240 - 6 * 8, 16},
|
||||
};
|
||||
|
||||
BigFrequency big_display{// Show frequency in glamour
|
||||
{4, 6 * 16, 28 * 8, 52},
|
||||
0};
|
||||
BigFrequency big_display{
|
||||
{4, 6 * 16, 28 * 8, 52},
|
||||
0};
|
||||
|
||||
Button button_manual_start{
|
||||
{0 * 8, 11 * 16, 11 * 8, 28},
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "portapack.hpp"
|
||||
#include "string_format.hpp"
|
||||
#include "ui_styles.hpp"
|
||||
#include "irq_controls.hpp"
|
||||
|
||||
using namespace ui;
|
||||
|
||||
@@ -46,7 +47,7 @@ void __debug_log(const std::string& msg) {
|
||||
pg_debug_log->write_entry(msg);
|
||||
}
|
||||
|
||||
void runtime_error(LED);
|
||||
void runtime_error(uint8_t source);
|
||||
std::string number_to_hex_string(uint32_t);
|
||||
void draw_line(int32_t, const char*, regarm_t);
|
||||
static bool error_shown = false;
|
||||
@@ -67,8 +68,10 @@ void draw_guru_meditation_header(uint8_t source, const char* hint) {
|
||||
painter.draw_string({48, 24}, Styles::white, "M? Guru");
|
||||
painter.draw_string({48 + 8 * 8, 24}, Styles::white, "Meditation");
|
||||
|
||||
if (source == CORTEX_M0)
|
||||
if (source == CORTEX_M0) {
|
||||
painter.draw_string({48 + 8, 24}, Styles::white, "0");
|
||||
painter.draw_string({12, 320 - 32}, Styles::white, "Press DFU to try Stack Dump");
|
||||
}
|
||||
|
||||
if (source == CORTEX_M4)
|
||||
painter.draw_string({48 + 8, 24}, Styles::white, "4");
|
||||
@@ -83,11 +86,7 @@ void draw_guru_meditation(uint8_t source, const char* hint) {
|
||||
draw_guru_meditation_header(source, hint);
|
||||
}
|
||||
|
||||
if (source == CORTEX_M0)
|
||||
runtime_error(hackrf::one::led_rx);
|
||||
|
||||
if (source == CORTEX_M4)
|
||||
runtime_error(hackrf::one::led_tx);
|
||||
runtime_error(source);
|
||||
}
|
||||
|
||||
void draw_guru_meditation(uint8_t source, const char* hint, struct extctx* ctxp, uint32_t cfsr = 0) {
|
||||
@@ -117,11 +116,7 @@ void draw_guru_meditation(uint8_t source, const char* hint, struct extctx* ctxp,
|
||||
}
|
||||
}
|
||||
|
||||
if (source == CORTEX_M0)
|
||||
runtime_error(hackrf::one::led_rx);
|
||||
|
||||
if (source == CORTEX_M4)
|
||||
runtime_error(hackrf::one::led_tx);
|
||||
runtime_error(source);
|
||||
}
|
||||
|
||||
void draw_line(int32_t y_offset, const char* label, regarm_t value) {
|
||||
@@ -131,7 +126,10 @@ void draw_line(int32_t y_offset, const char* label, regarm_t value) {
|
||||
painter.draw_string({15 + 8 * 8, y_offset}, Styles::white, to_string_hex((uint32_t)value, 8));
|
||||
}
|
||||
|
||||
void runtime_error(LED led) {
|
||||
void runtime_error(uint8_t source) {
|
||||
bool dumped{false};
|
||||
LED led = (source == CORTEX_M0) ? hackrf::one::led_rx : hackrf::one::led_tx;
|
||||
|
||||
led.off();
|
||||
|
||||
while (true) {
|
||||
@@ -139,9 +137,70 @@ void runtime_error(LED led) {
|
||||
while (n--)
|
||||
;
|
||||
led.toggle();
|
||||
|
||||
// Stack dump is not guaranteed to work in this state, so wait for DFU button press to attempt it
|
||||
if (!dumped && (swizzled_switches() & (1 << (int)Switch::Dfu))) {
|
||||
dumped = true;
|
||||
stack_dump();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Fix this function to work after a fault; might need to write to screen instead or to Flash memory.
|
||||
// Using the stack while dumping the stack isn't ideal, but hopefully anything imporant is still on the call stack.
|
||||
bool stack_dump() {
|
||||
ui::Painter painter{};
|
||||
std::string debug_dir = "DEBUG";
|
||||
std::filesystem::path filename{};
|
||||
File stack_dump_file{};
|
||||
bool error;
|
||||
std::string str;
|
||||
uint32_t* p;
|
||||
int n;
|
||||
bool data_found;
|
||||
|
||||
make_new_directory(debug_dir);
|
||||
filename = next_filename_matching_pattern(debug_dir + "/STACK_DUMP_????.TXT");
|
||||
error = filename.empty();
|
||||
if (!error)
|
||||
error = stack_dump_file.create(filename) != 0;
|
||||
if (error) {
|
||||
painter.draw_string({16, 320 - 32}, ui::Styles::red, "ERROR DUMPING " + filename.filename().string() + "!");
|
||||
return false;
|
||||
}
|
||||
|
||||
for (p = &__process_stack_base__, n = 0, data_found = false; p < &__process_stack_end__; p++) {
|
||||
if (!data_found) {
|
||||
if (*p == CRT0_STACKS_FILL_PATTERN)
|
||||
continue;
|
||||
else {
|
||||
data_found = true;
|
||||
auto stack_space_left = p - &__process_stack_base__;
|
||||
stack_dump_file.write_line(to_string_hex((uint32_t)&__process_stack_base__, 8) + ": Unused bytes " + to_string_dec_uint(stack_space_left * sizeof(uint32_t)));
|
||||
|
||||
// align subsequent lines to start on 16-byte boundaries
|
||||
p -= (stack_space_left & 3);
|
||||
}
|
||||
}
|
||||
|
||||
if (n++ == 0) {
|
||||
str = to_string_hex((uint32_t)p, 8) + ":";
|
||||
stack_dump_file.write(str.data(), 9);
|
||||
}
|
||||
|
||||
str = " " + to_string_hex(*p, 8);
|
||||
stack_dump_file.write(str.data(), 9);
|
||||
|
||||
if (n == 4) {
|
||||
stack_dump_file.write("\r\n", 2);
|
||||
n = 0;
|
||||
}
|
||||
}
|
||||
|
||||
painter.draw_string({16, 320 - 32}, ui::Styles::green, filename.filename().string() + " dumped!");
|
||||
return true;
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
#if CH_DBG_ENABLED
|
||||
void port_halt(void) {
|
||||
|
||||
@@ -47,4 +47,6 @@ inline uint32_t get_free_stack_space() {
|
||||
return stack_space_left;
|
||||
}
|
||||
|
||||
bool stack_dump();
|
||||
|
||||
#endif /*__DEBUG_H__*/
|
||||
|
||||
@@ -83,16 +83,22 @@ options_t freqman_bandwidths[4] = {
|
||||
{"100k", 100000},
|
||||
{"150k", 150000},
|
||||
{"250k", 250000},
|
||||
{"500k", 500000}, /* Previous Limit bandwith Option with perfect micro SD write .C16 format operaton.*/
|
||||
{"600k", 600000}, /* We doubled x2 previous REC BW limit , now extended BW from 600k to 1M with fast enough SD card in C16 or C8 format .*/
|
||||
{"650k", 650000},
|
||||
{"500k", 500000},
|
||||
{"600k", 600000},
|
||||
{"750k", 750000},
|
||||
{"1000k", 1000000}, /* New limit bandwith option for recording in C16 (in fast SD card) or in C8 */
|
||||
{"1500k", 1500000}, /* From this BW onwards, the LCD is ok, but M4 CPU is having periodical sample rec dropps, (not real file size, accelerated replay) */
|
||||
{"1000k", 1000000}, // Max bandwith for recording in C16 (with fast SD card).
|
||||
{"1250k", 1250000},
|
||||
{"1500k", 1500000},
|
||||
{"1750k", 1750000},
|
||||
{"2000k", 2000000},
|
||||
{"2500k", 2500000},
|
||||
{"2750k", 2750000}, // That is our max Capture option, to keep using later / 8 decimation (22Mhz sampling ADC)
|
||||
{"2250k", 2250000}, // Max bandwith for recording in C8 (with fast SD card).
|
||||
{"2500k", 2500000}, // Here and up, LCD is ok, but M4 CPU drops samples.
|
||||
{"3000k", 3000000},
|
||||
{"3500k", 3500000},
|
||||
{"4000k", 4000000},
|
||||
{"4500k", 4500000},
|
||||
{"5000k", 5500000},
|
||||
{"5500k", 5500000}, // Max capture, needs /4 decimation, (22Mhz sampling ADC).
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -139,7 +139,9 @@ static uint8_t switches_raw = 0;
|
||||
// uint8_t rot_b() const { return (raw_ >> 6) & 1; }
|
||||
// uint8_t dfu() const { return (raw_ >> 7) & 1; }};
|
||||
|
||||
static uint8_t swizzle_raw(uint8_t raw) {
|
||||
uint8_t swizzled_switches() {
|
||||
uint8_t raw = io.io_update(touch_pins_configs[touch_phase]);
|
||||
|
||||
return (raw & 0x1F) | // Keep the bottom 5 bits the same.
|
||||
((raw >> 2) & 0x20) | // Shift the DFU bit down to bit 6.
|
||||
((raw << 1) & 0xC0); // Shift the encoder bits up to be 7 & 8.
|
||||
@@ -183,7 +185,7 @@ void timer0_callback(GPTDriver* const) {
|
||||
eventmask_t event_mask = 0;
|
||||
if (touch_update()) event_mask |= EVT_MASK_TOUCH;
|
||||
|
||||
switches_raw = swizzle_raw(io.io_update(touch_pins_configs[touch_phase]));
|
||||
switches_raw = swizzled_switches();
|
||||
if (switches_update(switches_raw))
|
||||
event_mask |= EVT_MASK_SWITCHES;
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ using SwitchesState = std::bitset<6>;
|
||||
using EncoderPosition = uint32_t;
|
||||
|
||||
void controls_init();
|
||||
uint8_t swizzled_switches();
|
||||
SwitchesState get_switches_state();
|
||||
EncoderPosition get_encoder_position();
|
||||
touch::Frame get_touch_frame();
|
||||
|
||||
@@ -383,33 +383,33 @@ void WaterfallView::on_audio_spectrum() {
|
||||
// TODO: Comments below refer to a fixed oversample rate (8x), cleanup.
|
||||
uint32_t filter_bandwidth_for_sampling_rate(int32_t sampling_rate) {
|
||||
switch (sampling_rate) { // Use the var fs (sampling_rate) to set up BPF aprox < fs_max / 2 by Nyquist theorem.
|
||||
case 0 ... 3'500'000: // BW Captured range (0 <= 250kHz max) fs = 8x250 kHz =2000., 16x150 khz =2400, 32x100 khz =3200, (32x75k = 2400), (future 64x40 khz =2400)
|
||||
case 0 ... 3'500'000: // BW Captured range (0 <= 250kHz max) fs = 8x250k = 2000, 16x150k = 2400, 32x100k = 3200, 32x75k = 2400, (future 64x40 khz = 2400)
|
||||
return 1'750'000; // Minimum BPF MAX2837 for all those lower BW options.
|
||||
|
||||
case 4'000'000 ... 6'000'000: // BW capture range (500k...750kHz max) fs_max = 8 x 750kHz = 6Mhz
|
||||
case 4'000'000 ... 7'000'000: // OVS x8, BW capture range (500k...750kHz max) fs_max = 8 x 750k = 6Mhz
|
||||
// BW 500k...750kHz, ex. 500kHz (fs = 8 x BW = 4Mhz), BW 600kHz (fs = 4,8Mhz), BW 750 kHz (fs = 6Mhz).
|
||||
return 2'500'000; // In some IC, MAX2837 appears as 2250000, but both work similarly.
|
||||
|
||||
case 8'000'000: // BW capture 1Mhz fs = 8 x 1Mhz = 8Mhz. (1Mhz showed slightly higher noise background).
|
||||
return 3'500'000; // some low SD cards, if not showing avg. writting speed >4MB/sec, they will produce sammples drop at REC with 1MB and C16 format.
|
||||
case 7'000'001 ... 10'000'000: // OVS x8 and x4, BW capture 1Mhz fs = 8 x 1Mhz = 8Mhz. (1Mhz showed slightly higher noise background).
|
||||
return 3'500'000; // some low SD cards, if not showing avg. writing speed >4MB/sec, they will produce sammples drop at REC with 1MB and C16 format.
|
||||
|
||||
case 12'000'000: // BW capture 1,5Mhz, fs = 8 x 1,5Mhz = 12Mhz
|
||||
// Good BPF, good matching, we have some periodical M4 % samples drop.
|
||||
case 12'000'000 ... 14'000'000: // OVS x4, BW capture 3Mhz, fs = 4 x 3Mhz = 12Mhz
|
||||
// Good BPF, good matching, we have some periodical M4 % samples drop.
|
||||
return 5'000'000;
|
||||
|
||||
case 14'000'000: // BW capture 1,75Mhz, fs = 8 x 1,75Mhz = 14Mhz
|
||||
case 16'000'000: // OVS x4, BW capture 4Mhz, fs = 4 x 4Mhz = 16Mhz
|
||||
// Good BPF, good matching, we have some periodical M4 % samples drop.
|
||||
return 5'000'000;
|
||||
return 5'500'000;
|
||||
|
||||
case 16'000'000: // BW capture 2Mhz, fs = 8 x 2Mhz = 16Mhz
|
||||
case 18'000'000: // OVS x4, BW capture 4,5Mhz, fs = 4 x 4,5Mhz = 18Mhz
|
||||
// Good BPF, good matching, we have some periodical M4 % samples drop.
|
||||
return 6'000'000;
|
||||
|
||||
case 20'000'000: // BW capture 2,5Mhz, fs = 8 x 2,5 Mhz = 20Mhz
|
||||
case 20'000'000: // OVS x4, BW capture 5Mhz, fs = 4 x 5Mhz = 20Mhz
|
||||
// Good BPF, good matching, we have some periodical M4 % samples drop.
|
||||
return 7'000'000;
|
||||
|
||||
default: // BW capture 2,75Mhz, fs = 8 x 2,75Mhz = 22Mhz max ADC sampling and others.
|
||||
default: // BW capture 5,5Mhz, fs = 4 x 5,5Mhz = 22Mhz max ADC sampling and others.
|
||||
// We tested also 9Mhz FPB slightly too much noise floor, better at 8Mhz.
|
||||
return 8'000'000;
|
||||
}
|
||||
|
||||
@@ -107,13 +107,9 @@ uint32_t RecordView::set_sampling_rate(uint32_t new_sampling_rate) {
|
||||
auto oversample_rate = get_oversample_rate(new_sampling_rate);
|
||||
auto actual_sampling_rate = new_sampling_rate * toUType(oversample_rate);
|
||||
|
||||
/* We are changing "REC" icon background to yellow in BW rec Options >1Mhz
|
||||
* > 1Mhz BW options , we are NOT recording full IQ .C16 files (those files has some periodical missing dropped samples).
|
||||
* Those recorded files, has not the full IQ samples information, looks like decimated in file size.
|
||||
* They are ok as recorded spectrum indication, but they should not be used by Replay app. (the voice speed will be accelerated)
|
||||
|
||||
* We keep original black background in all the correct IQ .C16 files BW's Options. */
|
||||
if (actual_sampling_rate > 8'000'000) { // yellow REC button means not ok for REC, BW >1Mhz (BW from 12k5 till 1Mhz OK for REC and Replay)
|
||||
// Change the "REC" icon background to yellow when the selected rate exceeds hardware limits.
|
||||
// Above this threshold, samples will be dropped resulting incomplete capture files.
|
||||
if (new_sampling_rate > 1'250'000) {
|
||||
button_record.set_background(ui::Color::yellow());
|
||||
} else {
|
||||
button_record.set_background(ui::Color::black());
|
||||
@@ -142,15 +138,7 @@ OversampleRate RecordView::get_oversample_rate(uint32_t sample_rate) {
|
||||
if (file_type == FileType::WAV)
|
||||
return OversampleRate::None;
|
||||
|
||||
auto rate = ::get_oversample_rate(sample_rate);
|
||||
|
||||
// Currently proc_capture only supports /8, /16, /32 for decimation.
|
||||
if (rate < OversampleRate::x8) // clipping while /4 is not implemented yet (it will be used >1Mhz onwards when available)
|
||||
rate = OversampleRate::x8;
|
||||
else if (rate > OversampleRate::x64) // clipping while /128 is not implemented yet , (but it is not necessary for 12k5)
|
||||
rate = OversampleRate::x64;
|
||||
|
||||
return rate;
|
||||
return ::get_oversample_rate(sample_rate);
|
||||
}
|
||||
|
||||
// Setter for datetime and frequency filename
|
||||
|
||||
@@ -69,29 +69,22 @@ class BlockDecimator {
|
||||
|
||||
set_input_sampling_rate(src.sampling_rate);
|
||||
|
||||
while (src_i < src.count) {
|
||||
for (size_t src_i = 0; src_i < src.count; src_i += factor()) {
|
||||
buffer[dst_i++] = src.p[src_i];
|
||||
if (dst_i == buffer.size()) {
|
||||
callback({buffer.data(), buffer.size(), output_sampling_rate()});
|
||||
reset_state();
|
||||
dst_i = 0;
|
||||
}
|
||||
|
||||
src_i += factor();
|
||||
}
|
||||
|
||||
src_i -= src.count;
|
||||
}
|
||||
|
||||
private:
|
||||
std::array<T, N> buffer{};
|
||||
uint32_t input_sampling_rate_{0};
|
||||
size_t factor_{1};
|
||||
size_t src_i{0};
|
||||
size_t dst_i{0};
|
||||
|
||||
void reset_state() {
|
||||
src_i = 0;
|
||||
dst_i = 0;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -202,8 +202,8 @@ buffer_c16_t FIRC8xR16x24FS4Decim4::execute(
|
||||
uint32_t* const d = static_cast<uint32_t*>(__builtin_assume_aligned(dst.p, 4));
|
||||
|
||||
const auto k = output_scale;
|
||||
|
||||
const size_t count = src.count / decimation_factor;
|
||||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
const vec4_s8* const in = static_cast<const vec4_s8*>(__builtin_assume_aligned(&src.p[i * decimation_factor], 4));
|
||||
|
||||
|
||||
@@ -26,48 +26,32 @@
|
||||
#include "event_m4.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
using namespace dsp::decimate;
|
||||
|
||||
CaptureProcessor::CaptureProcessor() {
|
||||
decim_0_4.configure(taps_200k_decim_0.taps, 33554432); // to be used with decim1 (/2), then total two stages decim (/8)
|
||||
decim_0_8.configure(taps_200k_decim_0.taps, 33554432); // to be used with decim1 (/2), then total two stages decim (/16)
|
||||
decim_0_8_180k.configure(taps_180k_wfm_decim_0.taps, 33554432); // to be used alone - no additional decim1 (/2), then total single stage decim (/8)
|
||||
|
||||
decim_1_2.configure(taps_200k_decim_1.taps, 131072);
|
||||
decim_1_8.configure(taps_16k0_decim_1.taps, 131072); // tentative decim1 /8 and taps, pending to be optimized.
|
||||
|
||||
channel_spectrum.set_decimation_factor(1);
|
||||
baseband_thread.start();
|
||||
}
|
||||
|
||||
void CaptureProcessor::execute(const buffer_c8_t& buffer) {
|
||||
/* 2.4576MHz, 2048 samples */
|
||||
const auto decim_0_out = decim_0_execute(buffer, dst_buffer); // selectable 3 possible decim_0, (/4. /8 200k soft filter , /8 180k sharp )
|
||||
const auto decim_1_out = decim_1_execute(decim_0_out, dst_buffer); // selectable 3 possible decim_1, (/8. /2 200k or bypassed /1 )
|
||||
|
||||
/* this code was valid when we had only 2 decim1 cases.
|
||||
const auto decim_1_out = baseband_fs < 4800'000
|
||||
? decim_1_2.execute(decim_0_out, dst_buffer) // < 600khz double decim. stage , means 500khz and lower bit rates.
|
||||
// ? decim_1_8.execute(decim_0_out, dst_buffer) // < 600khz double decim. stage , means 500khz and lower bit rates.
|
||||
: decim_0_out; // >= 600khz single decim. stage , means 600khz and upper bit rates.
|
||||
|
||||
} */
|
||||
|
||||
const auto& decimator_out = decim_1_out;
|
||||
const auto& channel = decimator_out;
|
||||
auto decim_0_out = decim_0.execute(buffer, dst_buffer);
|
||||
auto out_buffer = decim_1.execute(decim_0_out, dst_buffer);
|
||||
|
||||
if (stream) {
|
||||
const size_t bytes_to_write = sizeof(*decimator_out.p) * decimator_out.count;
|
||||
const size_t written = stream->write(decimator_out.p, bytes_to_write);
|
||||
const size_t bytes_to_write = sizeof(*out_buffer.p) * out_buffer.count;
|
||||
const size_t written = stream->write(out_buffer.p, bytes_to_write);
|
||||
if (written != bytes_to_write) {
|
||||
// TODO eventually report error somewhere
|
||||
// TODO: Send an error message to the app?
|
||||
}
|
||||
}
|
||||
|
||||
feed_channel_stats(channel);
|
||||
feed_channel_stats(out_buffer);
|
||||
|
||||
spectrum_samples += channel.count;
|
||||
spectrum_samples += out_buffer.count;
|
||||
if (spectrum_samples >= spectrum_interval_samples) {
|
||||
spectrum_samples -= spectrum_interval_samples;
|
||||
channel_spectrum.feed(channel, channel_filter_low_f, channel_filter_high_f, channel_filter_transition);
|
||||
channel_spectrum.feed(out_buffer, channel_filter_low_f,
|
||||
channel_filter_high_f, channel_filter_transition);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,120 +76,88 @@ void CaptureProcessor::on_message(const Message* const message) {
|
||||
}
|
||||
|
||||
void CaptureProcessor::sample_rate_config(const SampleRateConfigMessage& message) {
|
||||
baseband_fs = message.sample_rate * toUType(message.oversample_rate);
|
||||
oversample_rate = message.oversample_rate;
|
||||
const auto sample_rate = message.sample_rate;
|
||||
|
||||
// The actual sample rate is the requested rate * the oversample rate.
|
||||
// See oversample.hpp for more details on oversampling.
|
||||
baseband_fs = sample_rate * toUType(message.oversample_rate);
|
||||
baseband_thread.set_sampling_rate(baseband_fs);
|
||||
|
||||
// Current fw , we are using only 2 decim_0 modes, /4 , /8
|
||||
auto decim_0_factor = oversample_rate == OversampleRate::x8
|
||||
? decim_0_4.decimation_factor
|
||||
: decim_0_8.decimation_factor;
|
||||
// TODO: Do we need to use the taps that the decimators get configured with?
|
||||
channel_filter_low_f = taps_200k_decim_1.low_frequency_normalized * sample_rate;
|
||||
channel_filter_high_f = taps_200k_decim_1.high_frequency_normalized * sample_rate;
|
||||
channel_filter_transition = taps_200k_decim_1.transition_normalized * sample_rate;
|
||||
|
||||
size_t decim_0_output_fs = baseband_fs / decim_0_factor;
|
||||
size_t decim_1_input_fs = decim_0_output_fs;
|
||||
// Compute the scalar that corrects the oversample_rate to be x8 when computing
|
||||
// the spectrum update interval. The original implementation only supported x8.
|
||||
// TODO: Why is this needed here but not in proc_replay? There must be some other
|
||||
// assumption about x8 oversampling in some component that makes this necessary.
|
||||
const auto oversample_correction = toUType(message.oversample_rate) / 8.0;
|
||||
|
||||
// The spectrum update interval controls how often the waterfall is fed new samples.
|
||||
spectrum_interval_samples = sample_rate / (spectrum_rate_hz * oversample_correction);
|
||||
spectrum_samples = 0;
|
||||
|
||||
// For high sample rates, the M4 is busy collecting samples so the
|
||||
// waterfall runs slower. Reduce the update interval so it runs faster.
|
||||
// NB: Trade off: looks nicer, but more frequent updates == more CPU.
|
||||
if (sample_rate >= 1'500'000)
|
||||
spectrum_interval_samples /= (sample_rate / 500'000);
|
||||
|
||||
// Mystery scalars for decimator configuration.
|
||||
// TODO: figure these out and add a real comment.
|
||||
constexpr int decim_0_scale = 0x2000000;
|
||||
constexpr int decim_1_scale = 0x20000;
|
||||
|
||||
switch (message.oversample_rate) {
|
||||
case OversampleRate::x4:
|
||||
// M4 can't handle 2 decimation passes for sample rates needing x4.
|
||||
decim_0.set<FIRC8xR16x24FS4Decim4>().configure(taps_200k_decim_0.taps, decim_0_scale);
|
||||
decim_1.set<NoopDecim>();
|
||||
break;
|
||||
|
||||
size_t decim_1_factor;
|
||||
switch (oversample_rate) { // we are using 3 decim_1 modes, /1 , /2 , /8
|
||||
case OversampleRate::x8:
|
||||
if (baseband_fs < 4800'000) {
|
||||
decim_1_factor = decim_1_2.decimation_factor; // /8 = /4x2
|
||||
// M4 can't handle 2 decimation passes for sample rates <= 600k.
|
||||
if (message.sample_rate < 600'000) {
|
||||
decim_0.set<FIRC8xR16x24FS4Decim4>().configure(taps_200k_decim_0.taps, decim_0_scale);
|
||||
decim_1.set<FIRC16xR16x16Decim2>().configure(taps_200k_decim_1.taps, decim_1_scale);
|
||||
} else {
|
||||
decim_1_factor = 2 * 1; // 600khz and onwards, single decim /8 = /8x1 (we applied additional *2 correction to speed up waterfall, no effect to scale spectrum)
|
||||
// Using 180k taps to provide better filtering with a single pass.
|
||||
decim_0.set<FIRC8xR16x24FS4Decim8>().configure(taps_180k_wfm_decim_0.taps, decim_0_scale);
|
||||
decim_1.set<NoopDecim>();
|
||||
}
|
||||
break;
|
||||
|
||||
case OversampleRate::x16:
|
||||
decim_1_factor = 2 * decim_1_2.decimation_factor; // /16 = /8x2 (we applied additional *2 correction to increase waterfall spped >=600k and smooth & avoid abnormal motion >1M5 )
|
||||
decim_0.set<FIRC8xR16x24FS4Decim8>().configure(taps_200k_decim_0.taps, decim_0_scale);
|
||||
decim_1.set<FIRC16xR16x16Decim2>().configure(taps_200k_decim_1.taps, decim_1_scale);
|
||||
break;
|
||||
|
||||
case OversampleRate::x32:
|
||||
decim_1_factor = 2 * decim_1_8.decimation_factor; // /32 = /4x8 (we applied additional *2 correction to speed up waterfall, no effect to scale spectrum)
|
||||
decim_0.set<FIRC8xR16x24FS4Decim4>().configure(taps_200k_decim_0.taps, decim_0_scale);
|
||||
decim_1.set<FIRC16xR16x32Decim8>().configure(taps_16k0_decim_1.taps, decim_1_scale);
|
||||
break;
|
||||
|
||||
case OversampleRate::x64:
|
||||
decim_1_factor = 8 * decim_1_8.decimation_factor; // /64 = /8x8 (we applied additional *8 correction to speed up waterfall, no effect to scale spectrum)
|
||||
decim_0.set<FIRC8xR16x24FS4Decim8>().configure(taps_200k_decim_0.taps, decim_0_scale);
|
||||
decim_1.set<FIRC16xR16x32Decim8>().configure(taps_16k0_decim_1.taps, decim_1_scale);
|
||||
break;
|
||||
|
||||
default:
|
||||
decim_1_factor = 2; // just default initial value to remove compile warning.
|
||||
chDbgPanic("Unhandled OversampleRate");
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
auto decim_1_factor = oversample_rate == OversampleRate::x32 // that was ok, when we had only 2 oversampling x8 , x16
|
||||
? decim_1_8.decimation_factor
|
||||
: decim_1_2.decimation_factor;
|
||||
|
||||
*/
|
||||
size_t decim_1_output_fs = decim_1_input_fs / decim_1_factor;
|
||||
|
||||
channel_filter_low_f = taps_200k_decim_1.low_frequency_normalized * decim_1_input_fs;
|
||||
channel_filter_high_f = taps_200k_decim_1.high_frequency_normalized * decim_1_input_fs;
|
||||
channel_filter_transition = taps_200k_decim_1.transition_normalized * decim_1_input_fs;
|
||||
|
||||
spectrum_interval_samples = decim_1_output_fs / spectrum_rate_hz;
|
||||
spectrum_samples = 0;
|
||||
}
|
||||
|
||||
void CaptureProcessor::capture_config(const CaptureConfigMessage& message) {
|
||||
if (message.config) {
|
||||
if (message.config)
|
||||
stream = std::make_unique<StreamInput>(message.config);
|
||||
} else {
|
||||
else
|
||||
stream.reset();
|
||||
}
|
||||
}
|
||||
|
||||
buffer_c16_t CaptureProcessor::decim_0_execute(const buffer_c8_t& src, const buffer_c16_t& dst) {
|
||||
switch (oversample_rate) {
|
||||
case OversampleRate::x8: // we can get /8 by two means , decim0 (/4) + decim1 (/2) . or just decim0 (/8)
|
||||
if (baseband_fs < 4800'000) { // 600khz (600k x 8)
|
||||
return decim_0_4.execute(src, dst); // decim_0 , /4 with double decim stage
|
||||
} else {
|
||||
return decim_0_8_180k.execute(src, dst); // decim_0 /8 with single decim stage
|
||||
}
|
||||
|
||||
case OversampleRate::x16:
|
||||
return decim_0_8.execute(src, dst); // decim_0 , /8 with double decim stage
|
||||
|
||||
case OversampleRate::x32:
|
||||
return decim_0_4.execute(src, dst); // decim_0 , /4 with double decim stage
|
||||
|
||||
case OversampleRate::x64:
|
||||
return decim_0_8.execute(src, dst); // decim_0 , /8 with double decim stage
|
||||
|
||||
default:
|
||||
chDbgPanic("Unhandled OversampleRate");
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
buffer_c16_t CaptureProcessor::decim_1_execute(const buffer_c16_t& src, const buffer_c16_t& dst) {
|
||||
switch (oversample_rate) {
|
||||
case OversampleRate::x8: // we can get /8 by two means , decim0 (/4) + decim1 (/2) . or just decim0 (/8)
|
||||
if (baseband_fs < 4800'000) { // 600khz (600k x 8)
|
||||
return decim_1_2.execute(src, dst);
|
||||
} else {
|
||||
return src;
|
||||
}
|
||||
|
||||
case OversampleRate::x16:
|
||||
return decim_1_2.execute(src, dst); // total decim /16 = /8x2, applied to 100khz and 150khz
|
||||
|
||||
case OversampleRate::x32:
|
||||
return decim_1_8.execute(src, dst); // total decim /32 = /4x8, appled to 75k , 50k, 32k
|
||||
|
||||
case OversampleRate::x64:
|
||||
return decim_1_8.execute(src, dst); // total decim /64 = /8x8, appled to 16k and 12k5
|
||||
|
||||
default:
|
||||
chDbgPanic("Unhandled OversampleRate");
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
EventDispatcher event_dispatcher{std::make_unique<CaptureProcessor>()};
|
||||
event_dispatcher.run();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,56 @@
|
||||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <tuple>
|
||||
#include <variant>
|
||||
|
||||
/* A decimator that just returns the source buffer. */
|
||||
class NoopDecim {
|
||||
public:
|
||||
static constexpr int decimation_factor = 1;
|
||||
|
||||
template <typename Buffer>
|
||||
Buffer execute(const Buffer& src, const Buffer&) {
|
||||
// TODO: should this copy to 'dst'?
|
||||
return {src.p, src.count, src.sampling_rate};
|
||||
}
|
||||
};
|
||||
|
||||
/* Decimator wrapper that can hold one of a set of decimators and dispatch at runtime. */
|
||||
template <typename... Args>
|
||||
class MultiDecimator {
|
||||
public:
|
||||
/* Dispatches to the underlying type's execute. */
|
||||
template <typename Source, typename Destination>
|
||||
Destination execute(
|
||||
const Source& src,
|
||||
const Destination& dst) {
|
||||
return std::visit(
|
||||
[&src, &dst](auto&& arg) -> Destination {
|
||||
return arg.execute(src, dst);
|
||||
},
|
||||
decimator_);
|
||||
}
|
||||
|
||||
size_t decimation_factor() const {
|
||||
return std::visit(
|
||||
[](auto&& arg) -> size_t {
|
||||
return arg.decimation_factor;
|
||||
},
|
||||
decimator_);
|
||||
}
|
||||
|
||||
/* Sets this decimator to a new instance of the specified decimator type.
|
||||
* NB: The instance is returned by-ref so 'configure' can easily be called. */
|
||||
template <typename Decimator>
|
||||
Decimator& set() {
|
||||
decimator_ = Decimator{};
|
||||
return std::get<Decimator>(decimator_);
|
||||
}
|
||||
|
||||
private:
|
||||
std::variant<Args...> decimator_{};
|
||||
};
|
||||
|
||||
class CaptureProcessor : public BasebandProcessor {
|
||||
public:
|
||||
@@ -50,15 +100,16 @@ class CaptureProcessor : public BasebandProcessor {
|
||||
dst.data(),
|
||||
dst.size()};
|
||||
|
||||
/* NB: There are two decimation passes: 0 and 1. In pass 0, one of
|
||||
* the following will be selected based on the oversample rate.
|
||||
* use decim_0_4 for an overall decimation factor of 8.
|
||||
* use decim_0_8 for an overall decimation factor of 16. */
|
||||
dsp::decimate::FIRC8xR16x24FS4Decim4 decim_0_4{};
|
||||
dsp::decimate::FIRC8xR16x24FS4Decim8 decim_0_8{};
|
||||
dsp::decimate::FIRC8xR16x24FS4Decim8 decim_0_8_180k{};
|
||||
dsp::decimate::FIRC16xR16x16Decim2 decim_1_2{};
|
||||
dsp::decimate::FIRC16xR16x32Decim8 decim_1_8{};
|
||||
/* The actual type will be configured depending on the sample rate. */
|
||||
MultiDecimator<
|
||||
dsp::decimate::FIRC8xR16x24FS4Decim4,
|
||||
dsp::decimate::FIRC8xR16x24FS4Decim8>
|
||||
decim_0{};
|
||||
MultiDecimator<
|
||||
dsp::decimate::FIRC16xR16x16Decim2,
|
||||
dsp::decimate::FIRC16xR16x32Decim8,
|
||||
NoopDecim>
|
||||
decim_1{};
|
||||
|
||||
int32_t channel_filter_low_f = 0;
|
||||
int32_t channel_filter_high_f = 0;
|
||||
@@ -69,7 +120,6 @@ class CaptureProcessor : public BasebandProcessor {
|
||||
SpectrumCollector channel_spectrum{};
|
||||
size_t spectrum_interval_samples = 0;
|
||||
size_t spectrum_samples = 0;
|
||||
OversampleRate oversample_rate{OversampleRate::x8};
|
||||
|
||||
/* NB: Threads should be the last members in the class definition. */
|
||||
BasebandThread baseband_thread{
|
||||
@@ -78,12 +128,6 @@ class CaptureProcessor : public BasebandProcessor {
|
||||
|
||||
void sample_rate_config(const SampleRateConfigMessage& message);
|
||||
void capture_config(const CaptureConfigMessage& message);
|
||||
|
||||
/* Dispatch to the correct decim_0 based on oversample rate. */
|
||||
buffer_c16_t decim_0_execute(const buffer_c8_t& src, const buffer_c16_t& dst);
|
||||
|
||||
/* Dispatch to the correct decim_1 based on oversample rate. */
|
||||
buffer_c16_t decim_1_execute(const buffer_c16_t& src, const buffer_c16_t& dst);
|
||||
};
|
||||
|
||||
#endif /*__PROC_CAPTURE_HPP__*/
|
||||
|
||||
@@ -24,12 +24,13 @@
|
||||
|
||||
#include "proc_pocsag.hpp"
|
||||
|
||||
#include "dsp_iir_config.hpp"
|
||||
#include "event_m4.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
#include <algorithm> // std::max
|
||||
#include <cmath>
|
||||
|
||||
void POCSAGProcessor::execute(const buffer_c8_t& buffer) {
|
||||
// This is called at 1500Hz
|
||||
@@ -41,9 +42,13 @@ void POCSAGProcessor::execute(const buffer_c8_t& buffer) {
|
||||
const auto decim_1_out = decim_1.execute(decim_0_out, dst_buffer);
|
||||
const auto channel_out = channel_filter.execute(decim_1_out, dst_buffer);
|
||||
auto audio = demod.execute(channel_out, audio_buffer);
|
||||
smooth.Process(audio.p, audio.count); // Smooth the data to make decoding more accurate
|
||||
|
||||
// Output audio pre-smoothing so squelch actually works.
|
||||
// NB: It's useful to output *after* when debugging the smoothing filter.
|
||||
audio_output.write(audio);
|
||||
|
||||
// Smooth the data to make decoding more accurate.
|
||||
smooth.Process(audio.p, audio.count);
|
||||
processDemodulatedSamples(audio.p, 16);
|
||||
extractFrames();
|
||||
}
|
||||
@@ -71,8 +76,23 @@ int POCSAGProcessor::OnDataFrame(int len, int baud) {
|
||||
}
|
||||
|
||||
void POCSAGProcessor::on_message(const Message* const message) {
|
||||
if (message->id == Message::ID::POCSAGConfigure)
|
||||
configure();
|
||||
switch (message->id) {
|
||||
case Message::ID::POCSAGConfigure:
|
||||
configure();
|
||||
break;
|
||||
|
||||
case Message::ID::NBFMConfigure: {
|
||||
auto config = reinterpret_cast<const NBFMConfigureMessage*>(message);
|
||||
audio_output.configure(
|
||||
audio_24k_hpf_300hz_config,
|
||||
audio_8k_deemph_300_6_config,
|
||||
config->squelch_level / 100.0);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void POCSAGProcessor::configure() {
|
||||
@@ -90,11 +110,11 @@ void POCSAGProcessor::configure() {
|
||||
decim_0.configure(taps_11k0_decim_0.taps, 33554432);
|
||||
decim_1.configure(taps_11k0_decim_1.taps, 131072);
|
||||
channel_filter.configure(taps_11k0_channel.taps, 2);
|
||||
demod.configure(demod_input_fs, 4500);
|
||||
demod.configure(demod_input_fs, 4'500); // FSK +/- 4k5Hz.
|
||||
|
||||
// Smoothing should be roughly sample rate over max baud
|
||||
// 24k / 3.2k is 7.5
|
||||
// 24k / 3.2k = 7.5
|
||||
smooth.SetSize(8);
|
||||
audio_output.configure(false);
|
||||
|
||||
// Set up the frame extraction, limits of baud
|
||||
setFrameExtractParams(demod_input_fs, 4000, 300, 32);
|
||||
|
||||
@@ -48,7 +48,7 @@ using namespace std;
|
||||
template <class ValType, class CalcType>
|
||||
class SmoothVals {
|
||||
protected:
|
||||
ValType* m_lastVals; // Previoius N values
|
||||
ValType* m_lastVals; // Previous N values
|
||||
int m_size; // The size N
|
||||
CalcType m_sumVal; // Running sum of lastVals
|
||||
int m_pos; // Current position in last vals ring buffer
|
||||
@@ -106,10 +106,10 @@ class SmoothVals {
|
||||
|
||||
// Use a rolling smoothed value while processing the buffer
|
||||
for (int buffPos = 0; buffPos < numVals; ++buffPos) {
|
||||
m_pos = (m_pos + 1); // Increment the position in the stored values
|
||||
m_pos++;
|
||||
if (m_pos >= m_size) {
|
||||
m_pos = 0;
|
||||
} // loop if reached the end of the stored values
|
||||
}
|
||||
|
||||
m_sumVal -= (CalcType)m_lastVals[m_pos]; // Subtract the oldest value
|
||||
m_lastVals[m_pos] = valBuff[buffPos]; // Store the new value
|
||||
|
||||
@@ -69,7 +69,7 @@ void ReplayProcessor::execute(const buffer_c8_t& buffer) {
|
||||
chDbgPanic("Output not div.");
|
||||
|
||||
// Is the input smaple buffer big enough?
|
||||
if (samples_to_read > iq_buffer.size())
|
||||
if (samples_to_read > iq_buffer.count)
|
||||
chDbgPanic("IQ buf ovf.");
|
||||
#endif
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ class ReplayProcessor : public BasebandProcessor {
|
||||
static constexpr auto spectrum_rate_hz = 50.0f;
|
||||
|
||||
// Holds the read IQ data chunk from the file to send.
|
||||
std::array<complex16_t, 256> iq{};
|
||||
std::array<complex16_t, 512> iq{};
|
||||
|
||||
int32_t channel_filter_low_f = 0;
|
||||
int32_t channel_filter_high_f = 0;
|
||||
|
||||
@@ -38,9 +38,7 @@ constexpr iir_biquad_config_t audio_48k_hpf_300hz_config{
|
||||
// scipy.signal.butter(2, 300 / 12000.0, 'highpass', analog=False)
|
||||
constexpr iir_biquad_config_t audio_24k_hpf_300hz_config{
|
||||
{0.94597686f, -1.89195371f, 0.94597686f},
|
||||
{1.00000000f, -1.88903308f, 0.89487434f}
|
||||
|
||||
};
|
||||
{1.00000000f, -1.88903308f, 0.89487434f}};
|
||||
|
||||
// scipy.signal.butter(2, 30 / 12000.0, 'highpass', analog=False)
|
||||
constexpr iir_biquad_config_t audio_24k_hpf_30hz_config{
|
||||
|
||||
@@ -111,6 +111,7 @@ class Message {
|
||||
APRSRxConfigure = 54,
|
||||
SpectrumPainterBufferRequestConfigure = 55,
|
||||
SpectrumPainterBufferResponseConfigure = 56,
|
||||
POCSAGStats = 57,
|
||||
MAX
|
||||
};
|
||||
|
||||
@@ -340,6 +341,17 @@ class POCSAGPacketMessage : public Message {
|
||||
pocsag::POCSAGPacket packet;
|
||||
};
|
||||
|
||||
class POCSAGStatsMessage : public Message {
|
||||
public:
|
||||
constexpr POCSAGStatsMessage(
|
||||
uint16_t baud_rate)
|
||||
: Message{ID::POCSAGStats},
|
||||
baud_rate_{baud_rate} {
|
||||
}
|
||||
|
||||
uint16_t baud_rate_;
|
||||
};
|
||||
|
||||
class ACARSPacketMessage : public Message {
|
||||
public:
|
||||
constexpr ACARSPacketMessage(
|
||||
@@ -804,8 +816,8 @@ enum class OversampleRate : uint8_t {
|
||||
None = 1,
|
||||
x1 = None,
|
||||
|
||||
// 4x would make sense to have, but need to ensure it doesn't
|
||||
// overrun the IQ read buffer in proc_replay.
|
||||
/* Oversample rate of 4 times the sample rate. */
|
||||
x4 = 4,
|
||||
|
||||
/* Oversample rate of 8 times the sample rate. */
|
||||
x8 = 8,
|
||||
@@ -818,9 +830,6 @@ enum class OversampleRate : uint8_t {
|
||||
|
||||
/* Oversample rate of 64 times the sample rate. */
|
||||
x64 = 64,
|
||||
|
||||
/* Oversample rate of 128 times the sample rate. */
|
||||
x128 = 128,
|
||||
};
|
||||
|
||||
class SampleRateConfigMessage : public Message {
|
||||
|
||||
@@ -42,26 +42,27 @@
|
||||
* In testing, a minimum rate of 400kHz seems to the functional minimum.
|
||||
*
|
||||
* There are several different concepts or terms related to Capture and Replay,
|
||||
* (1) oversampling (x8, x16 ,...) / decimation (/8, /16...)
|
||||
* In Capture App , when ADC can not handle directly a requiered low sample rates ,
|
||||
* we need to apply oversampling (x8. x16 ex) , getting more real samples than needed) by "x_number" ,
|
||||
* and later to write it to SD card with the proper needed real sample rate , we apply Decimation , "/ number" .
|
||||
* (1) Oversampling (x8, x16, ...) and Decimation (/8, /16...)
|
||||
* In Capture App, the ADC can not directly handle low sample rates.
|
||||
* We need to apply oversampling (x8, x16, ...), collecting more "x number" additional real samples.
|
||||
* To write it to SD card with the desired sample rate, we apply Decimation ("/ number").
|
||||
*
|
||||
* (2) up-sampling or re-escale or interpolation. (x8, x16, ...)
|
||||
* In Replay-list App, when we got too low bit rate data for Hackrf ,
|
||||
* we need to upsampling or interpolate or resampling to increase those low bit rates
|
||||
* to a proper sample rate higher than the min. to be able to be transmitted by Hackrf.
|
||||
* (2) Up-sampling or re-scale or interpolation. (x8, x16, ...).
|
||||
* In Replay-list App, when the bit rate data is too low for HackRF.
|
||||
* We need to upsample or interpolate to increase those low bit rates
|
||||
* to a rate higher than the hardware nminimum to be transmitted by Hackrf.
|
||||
*/
|
||||
|
||||
/* Gets the oversample rate for a given sample rate.
|
||||
* The oversample rate is used to increase the sample rate to improve SNR and quality.
|
||||
* This is also used as the interpolation rate when replaying captures. */
|
||||
inline OversampleRate get_oversample_rate(uint32_t sample_rate) {
|
||||
if (sample_rate < 30'000) return OversampleRate::x64; // 25k, 16k, 12k5.
|
||||
if (sample_rate < 80'000) return OversampleRate::x32; // 75k, 50k, 32k.
|
||||
if (sample_rate < 250'000) return OversampleRate::x16; // 100k and 150k.
|
||||
if (sample_rate < 30'000) return OversampleRate::x64; // 25k, 16k, 12k5.
|
||||
if (sample_rate < 80'000) return OversampleRate::x32; // 75k, 50k, 32k.
|
||||
if (sample_rate < 250'000) return OversampleRate::x16; // 100k, 150k.
|
||||
if (sample_rate < 1'250'000) return OversampleRate::x8; // 250k, 500k, 600k, 650k, 750k, 1Mhz.
|
||||
|
||||
return OversampleRate::x8; // 250k .. 1Mhz, that decim x8 , is already applied.(OVerSampling and decim OK)
|
||||
return OversampleRate::x4; // Top range (1.25Mhz ... 5.5Mhz).
|
||||
}
|
||||
|
||||
/* Gets the actual sample rate for a given sample rate.
|
||||
|
||||
+77
-94
@@ -225,27 +225,14 @@ void pocsag_encode(const MessageType type, BCHCode& BCH_code, const uint32_t fun
|
||||
} while (char_idx < message_size);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
// -------------------------------------------------------------------------------
|
||||
inline int bitsDiff(unsigned long left, unsigned long right) {
|
||||
unsigned long xord = left ^ right;
|
||||
int count = 0;
|
||||
for (int i = 0; i < 32; i++) {
|
||||
if ((xord & 0x01) != 0) ++count;
|
||||
xord = xord >> 1;
|
||||
}
|
||||
return (count);
|
||||
// ----------------------------------------------------------------------------
|
||||
// EccContainer
|
||||
// ----------------------------------------------------------------------------
|
||||
EccContainer::EccContainer() {
|
||||
setup_ecc();
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
// -------------------------------------------------------------------------------
|
||||
static uint32_t ecs[32]; /* error correction sequence */
|
||||
static uint32_t bch[1025];
|
||||
static int eccSetup = 0;
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
// -------------------------------------------------------------------------------
|
||||
void setupecc() {
|
||||
void EccContainer::setup_ecc() {
|
||||
unsigned int srr = 0x3b4;
|
||||
unsigned int i, n, j, k;
|
||||
|
||||
@@ -308,36 +295,24 @@ void setupecc() {
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
// -------------------------------------------------------------------------------
|
||||
inline int errorCorrection(uint32_t* val) {
|
||||
// Set up the tables the first time
|
||||
if (eccSetup == 0) {
|
||||
setupecc();
|
||||
eccSetup = 1;
|
||||
}
|
||||
|
||||
int EccContainer::error_correct(uint32_t& val) {
|
||||
int i, synd, errl, acc, pari, ecc, b1, b2;
|
||||
|
||||
errl = 0;
|
||||
pari = 0;
|
||||
|
||||
/* run through error detection and correction routine */
|
||||
|
||||
// for (i=0; i<=20; i++)
|
||||
ecc = 0;
|
||||
for (i = 31; i >= 11; --i) {
|
||||
if ((*val & (1 << i))) {
|
||||
if (val & (1 << i)) {
|
||||
ecc = ecc ^ ecs[31 - i];
|
||||
pari = pari ^ 0x01;
|
||||
}
|
||||
}
|
||||
|
||||
// for (i=21; i<=30; i++)
|
||||
acc = 0;
|
||||
for (i = 10; i >= 1; --i) {
|
||||
acc = acc << 1;
|
||||
if ((*val & (1 << i))) {
|
||||
if (val & (1 << i)) {
|
||||
acc = acc ^ 0x01;
|
||||
}
|
||||
}
|
||||
@@ -355,12 +330,12 @@ inline int errorCorrection(uint32_t* val) {
|
||||
b2 = b2 & 0x1f;
|
||||
|
||||
if (b2 != 0x1f) {
|
||||
*val ^= 0x01 << (31 - b2);
|
||||
val ^= 0x01 << (31 - b2);
|
||||
ecc = ecc ^ ecs[b2];
|
||||
}
|
||||
|
||||
if (b1 != 0x1f) {
|
||||
*val ^= 0x01 << (31 - b1);
|
||||
val ^= 0x01 << (31 - b1);
|
||||
ecc = ecc ^ ecs[b1];
|
||||
}
|
||||
|
||||
@@ -377,78 +352,86 @@ inline int errorCorrection(uint32_t* val) {
|
||||
return errl;
|
||||
}
|
||||
|
||||
void pocsag_decode_batch(const POCSAGPacket& batch, POCSAGState* const state) {
|
||||
int errors = 0;
|
||||
uint32_t codeword;
|
||||
char ascii_char;
|
||||
std::string output_text = "";
|
||||
bool pocsag_decode_batch(const POCSAGPacket& batch, POCSAGState& state) {
|
||||
constexpr uint8_t codeword_max = 16;
|
||||
state.output.clear();
|
||||
|
||||
state->out_type = EMPTY;
|
||||
while (state.codeword_index < codeword_max) {
|
||||
auto codeword = batch[state.codeword_index];
|
||||
bool is_address = (codeword & 0x80000000U) == 0;
|
||||
|
||||
// For each codeword...
|
||||
for (size_t i = 0; i < 16; i++) {
|
||||
codeword = batch[i];
|
||||
// Error correct twice. First time to fix any errors it can,
|
||||
// second time to count number of errors that couldn't be fixed.
|
||||
state.ecc->error_correct(codeword);
|
||||
auto error_count = state.ecc->error_correct(codeword);
|
||||
|
||||
errorCorrection(&codeword);
|
||||
errors = errorCorrection(&codeword);
|
||||
switch (state.mode) {
|
||||
case STATE_CLEAR:
|
||||
if (is_address && codeword != POCSAG_IDLEWORD) {
|
||||
state.function = (codeword >> 11) & 3;
|
||||
state.address = (codeword >> 10) & 0x1FFFF8U; // 18 MSBs are transmitted
|
||||
state.mode = STATE_HAVE_ADDRESS;
|
||||
state.out_type = ADDRESS;
|
||||
state.errors = error_count;
|
||||
|
||||
if (!(codeword & 0x80000000U)) {
|
||||
// Address codeword
|
||||
if (state->mode == STATE_CLEAR) {
|
||||
// if (codeword != POCSAG_IDLEWORD) {
|
||||
if (!(bitsDiff(codeword, POCSAG_IDLEWORD) < 1)) {
|
||||
state->function = (codeword >> 11) & 3;
|
||||
state->address = (codeword >> 10) & 0x1FFFF8U; // 18 MSBs are transmitted
|
||||
state->mode = STATE_HAVE_ADDRESS;
|
||||
state->out_type = ADDRESS;
|
||||
state->errors = errors;
|
||||
|
||||
state->ascii_idx = 0;
|
||||
state->ascii_data = 0;
|
||||
state.ascii_idx = 0;
|
||||
state.ascii_data = 0;
|
||||
} else if (codeword == POCSAG_IDLEWORD) {
|
||||
state.out_type = IDLE;
|
||||
}
|
||||
} else {
|
||||
state->mode = STATE_CLEAR; // New address = new message
|
||||
}
|
||||
} else {
|
||||
state->errors += errors;
|
||||
// Message codeword
|
||||
if (state->mode == STATE_HAVE_ADDRESS) {
|
||||
// First message codeword: complete address
|
||||
state->address |= (i >> 1); // Add in the 3 LSBs (frame #)
|
||||
state->mode = STATE_GETTING_MSG;
|
||||
}
|
||||
break;
|
||||
|
||||
state->out_type = MESSAGE;
|
||||
case STATE_HAVE_ADDRESS:
|
||||
if (is_address) {
|
||||
// Got another address, return the current state.
|
||||
state.mode = STATE_CLEAR;
|
||||
return true;
|
||||
}
|
||||
|
||||
state->ascii_data |= ((codeword >> 11) & 0xFFFFF); // Get 20 message bits
|
||||
state->ascii_idx += 20;
|
||||
// First message codeword, complete the address.
|
||||
state.address |= (state.codeword_index >> 1); // Add in the 3 LSBs (frame #).
|
||||
state.mode = STATE_GETTING_MSG;
|
||||
[[fallthrough]];
|
||||
|
||||
// Raw 20 bits to 7 bit reversed ASCII
|
||||
while (state->ascii_idx >= 7) {
|
||||
state->ascii_idx -= 7;
|
||||
ascii_char = ((state->ascii_data) >> (state->ascii_idx)) & 0x7F;
|
||||
case STATE_GETTING_MSG:
|
||||
if (is_address) {
|
||||
// Codeword isn't a message, return the current state.
|
||||
state.mode = STATE_CLEAR;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Bottom's up
|
||||
ascii_char = (ascii_char & 0xF0) >> 4 | (ascii_char & 0x0F) << 4; // 01234567 -> 45670123
|
||||
ascii_char = (ascii_char & 0xCC) >> 2 | (ascii_char & 0x33) << 2; // 45670123 -> 67452301
|
||||
ascii_char = (ascii_char & 0xAA) >> 2 | (ascii_char & 0x55); // 67452301 -> *7654321
|
||||
state.out_type = MESSAGE;
|
||||
state.errors += error_count;
|
||||
state.ascii_data |= (codeword >> 11) & 0xFFFFF; // Get 20 message bits.
|
||||
state.ascii_idx += 20;
|
||||
|
||||
// Translate non-printable chars
|
||||
if ((ascii_char < 32) || (ascii_char > 126)) {
|
||||
// output_text += "[" + to_string_dec_uint(ascii_char) + "]";
|
||||
output_text += ".";
|
||||
} else
|
||||
output_text += ascii_char;
|
||||
}
|
||||
// Raw 20 bits to 7 bit reversed ASCII.
|
||||
// NB: This is processed MSB first, any remaining bits are shifted
|
||||
// up so a whole 7 bits are processed with the next codeword.
|
||||
while (state.ascii_idx >= 7) {
|
||||
state.ascii_idx -= 7;
|
||||
char ascii_char = (state.ascii_data >> state.ascii_idx) & 0x7F;
|
||||
|
||||
state->ascii_data <<= 20; // Remaining bits are for next time...
|
||||
// Bottom's up (reverse the bits).
|
||||
ascii_char = (ascii_char & 0xF0) >> 4 | (ascii_char & 0x0F) << 4; // 01234567 -> 45670123
|
||||
ascii_char = (ascii_char & 0xCC) >> 2 | (ascii_char & 0x33) << 2; // 45670123 -> 67452301
|
||||
ascii_char = (ascii_char & 0xAA) >> 2 | (ascii_char & 0x55); // 67452301 -> 76543210
|
||||
|
||||
// Translate non-printable chars. TODO: Leave CRLF?
|
||||
if (ascii_char < 32 || ascii_char > 126)
|
||||
state.output += ".";
|
||||
else
|
||||
state.output += ascii_char;
|
||||
}
|
||||
|
||||
state.ascii_data <<= 20; // Remaining bits are for next iteration...
|
||||
break;
|
||||
}
|
||||
|
||||
state.codeword_index++;
|
||||
}
|
||||
|
||||
state->output = output_text;
|
||||
|
||||
if (state->mode == STATE_HAVE_ADDRESS)
|
||||
state->mode = STATE_CLEAR;
|
||||
return false;
|
||||
}
|
||||
|
||||
} /* namespace pocsag */
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
|
||||
namespace pocsag {
|
||||
|
||||
// Todo: these enums suck, make a better decode_batch
|
||||
// TODO: these enums suck, make a better decode_batch
|
||||
|
||||
enum Mode : uint32_t {
|
||||
STATE_CLEAR,
|
||||
@@ -45,6 +45,7 @@ enum Mode : uint32_t {
|
||||
|
||||
enum OutputType : uint32_t {
|
||||
EMPTY,
|
||||
IDLE,
|
||||
ADDRESS,
|
||||
MESSAGE
|
||||
};
|
||||
@@ -55,22 +56,46 @@ enum MessageType : uint32_t {
|
||||
ALPHANUMERIC
|
||||
};
|
||||
|
||||
/* Holds error correction arrays. This allows the arrays to
|
||||
* be freed when POCSAG is not running, saving ~4kb of RAM. */
|
||||
class EccContainer {
|
||||
public:
|
||||
EccContainer();
|
||||
|
||||
EccContainer(const EccContainer&) = delete;
|
||||
EccContainer(EccContainer&&) = delete;
|
||||
EccContainer& operator=(const EccContainer&) = delete;
|
||||
EccContainer& operator=(EccContainer&&) = delete;
|
||||
|
||||
int error_correct(uint32_t& val);
|
||||
|
||||
private:
|
||||
void setup_ecc();
|
||||
|
||||
/* error correction sequence */
|
||||
uint32_t ecs[32];
|
||||
uint32_t bch[1025];
|
||||
};
|
||||
|
||||
struct POCSAGState {
|
||||
uint32_t function;
|
||||
uint32_t address;
|
||||
EccContainer* ecc = nullptr;
|
||||
uint8_t codeword_index = 0;
|
||||
uint32_t function = 0;
|
||||
uint32_t address = 0;
|
||||
Mode mode = STATE_CLEAR;
|
||||
OutputType out_type = EMPTY;
|
||||
uint32_t ascii_data;
|
||||
uint32_t ascii_idx;
|
||||
uint32_t errors;
|
||||
std::string output;
|
||||
uint32_t ascii_data = 0;
|
||||
uint32_t ascii_idx = 0;
|
||||
uint32_t errors = 0;
|
||||
std::string output{};
|
||||
};
|
||||
|
||||
const pocsag::BitRate pocsag_bitrates[4] = {
|
||||
pocsag::BitRate::FSK512,
|
||||
pocsag::BitRate::FSK1200,
|
||||
pocsag::BitRate::FSK2400,
|
||||
pocsag::BitRate::FSK3200};
|
||||
pocsag::BitRate::FSK3200,
|
||||
};
|
||||
|
||||
std::string bitrate_str(BitRate bitrate);
|
||||
std::string flag_str(PacketFlag packetflag);
|
||||
@@ -78,7 +103,9 @@ std::string flag_str(PacketFlag packetflag);
|
||||
void insert_BCH(BCHCode& BCH_code, uint32_t* codeword);
|
||||
uint32_t get_digit_code(char code);
|
||||
void pocsag_encode(const MessageType type, BCHCode& BCH_code, const uint32_t function, const std::string message, const uint32_t address, std::vector<uint32_t>& codewords);
|
||||
void pocsag_decode_batch(const POCSAGPacket& batch, POCSAGState* const state);
|
||||
|
||||
// Returns true if the batch has more to process.
|
||||
bool pocsag_decode_batch(const POCSAGPacket& batch, POCSAGState& state);
|
||||
|
||||
} /* namespace pocsag */
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
namespace ui {
|
||||
|
||||
// CGA palette
|
||||
// Index into this table should match STR_COLOR_ escape string in ui.hpp
|
||||
Color term_colors[16] = {
|
||||
Color::black(),
|
||||
Color::dark_blue(),
|
||||
|
||||
@@ -26,6 +26,25 @@
|
||||
|
||||
namespace ui {
|
||||
|
||||
// Escape sequences for colored text; second character is index into term_colors[]
|
||||
#define STR_COLOR_BLACK "\x1B\x00"
|
||||
#define STR_COLOR_DARK_BLUE "\x1B\x01"
|
||||
#define STR_COLOR_DARK_GREEN "\x1B\x02"
|
||||
#define STR_COLOR_DARK_CYAN "\x1B\x03"
|
||||
#define STR_COLOR_DARK_RED "\x1B\x04"
|
||||
#define STR_COLOR_DARK_MAGENTA "\x1B\x05"
|
||||
#define STR_COLOR_DARK_YELLOW "\x1B\x06"
|
||||
#define STR_COLOR_LIGHT_GREY "\x1B\x07"
|
||||
#define STR_COLOR_DARK_GREY "\x1B\x08"
|
||||
#define STR_COLOR_BLUE "\x1B\x09"
|
||||
#define STR_COLOR_GREEN "\x1B\x0A"
|
||||
#define STR_COLOR_CYAN "\x1B\x0B"
|
||||
#define STR_COLOR_RED "\x1B\x0C"
|
||||
#define STR_COLOR_MAGENTA "\x1B\x0D"
|
||||
#define STR_COLOR_YELLOW "\x1B\x0E"
|
||||
#define STR_COLOR_WHITE "\x1B\x0F"
|
||||
#define STR_COLOR_FOREGROUND "\x1B\x10"
|
||||
|
||||
#define DEG_TO_RAD(d) (d * (2 * pi) / 360.0)
|
||||
|
||||
using Coord = int16_t;
|
||||
|
||||
@@ -57,8 +57,8 @@ int Painter::draw_string(
|
||||
|
||||
for (auto c : text) {
|
||||
if (escape) {
|
||||
if (c <= 15)
|
||||
pen = term_colors[c & 15];
|
||||
if (c < std::size(term_colors))
|
||||
pen = term_colors[(uint8_t)c];
|
||||
else
|
||||
pen = foreground;
|
||||
escape = false;
|
||||
|
||||
@@ -366,16 +366,17 @@ void Text::paint(Painter& painter) {
|
||||
const auto rect = screen_rect();
|
||||
auto s = has_focus() ? style().invert() : style();
|
||||
auto max_len = (unsigned)rect.width() / s.font.char_width();
|
||||
auto text_view = std::string_view{text};
|
||||
|
||||
painter.fill_rectangle(rect, s.background);
|
||||
|
||||
if (text.length() > max_len)
|
||||
text.resize(max_len);
|
||||
if (text_view.length() > max_len)
|
||||
text_view = text_view.substr(0, max_len);
|
||||
|
||||
painter.draw_string(
|
||||
rect.location(),
|
||||
s,
|
||||
text);
|
||||
text_view);
|
||||
}
|
||||
|
||||
/* Labels ****************************************************************/
|
||||
@@ -616,7 +617,7 @@ void Console::write(std::string message) {
|
||||
|
||||
for (const auto c : message) {
|
||||
if (escape) {
|
||||
if (c <= 15)
|
||||
if (c < std::size(term_colors))
|
||||
pen_color = term_colors[(uint8_t)c];
|
||||
else
|
||||
pen_color = s.foreground;
|
||||
@@ -1764,6 +1765,24 @@ bool TextField::on_key(KeyEvent key) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TextField::on_encoder(EncoderEvent delta) {
|
||||
if (on_encoder_change) {
|
||||
on_encoder_change(*this, delta);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TextField::on_touch(TouchEvent event) {
|
||||
if (event.type == TouchEvent::Type::Start) {
|
||||
focus();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* NumberField ***********************************************************/
|
||||
|
||||
NumberField::NumberField(
|
||||
|
||||
@@ -208,6 +208,10 @@ class Text : public Widget {
|
||||
void paint(Painter& painter) override;
|
||||
|
||||
protected:
|
||||
// NB: Don't truncate this string. The UI will only render
|
||||
// as many characters as will fit in its rectange.
|
||||
// Apps expect to be able to retrieve this string to avoid
|
||||
// needing to hold additional copies in memory.
|
||||
std::string text;
|
||||
};
|
||||
|
||||
@@ -694,6 +698,7 @@ class TextField : public Text {
|
||||
public:
|
||||
std::function<void(TextField&)> on_select{};
|
||||
std::function<void(TextField&)> on_change{};
|
||||
std::function<void(TextField&, EncoderEvent)> on_encoder_change{};
|
||||
|
||||
TextField(Rect parent_rect, std::string text);
|
||||
|
||||
@@ -701,6 +706,8 @@ class TextField : public Text {
|
||||
void set_text(std::string_view value);
|
||||
|
||||
bool on_key(KeyEvent key) override;
|
||||
bool on_encoder(EncoderEvent delta) override;
|
||||
bool on_touch(TouchEvent event) override;
|
||||
|
||||
private:
|
||||
using Text::set;
|
||||
|
||||
Reference in New Issue
Block a user