Compare commits

...

9 Commits

Author SHA1 Message Date
jLynx e2ad0a1b1a Stable 1.7.4 release (#1340)
* Update version.txt

* Update past_version.txt
2023-08-02 10:24:23 +12:00
Mark Thompson 96cdb2e9e0 Keyboard tweaks (#1338)
* Disallow 1-time shift in digits/symbols mode

* Slightly wider "123" button and smaller OK button

* Slightly wider "123" button and smaller OK button
2023-08-01 14:25:26 -05:00
Mark Thompson 002ef720ee Fixed waterfall frequency scale in Replay app (#1337)
* Fix waterfall frequency scale in Replay

* Fix waterfall frequency scale in Replay
2023-08-01 20:20:19 +02:00
Kyle Reed 2214533894 Keyboard Shift Mode (#1333)
* Add "shift" concept to keyboard

* Better shift colors

* Better keybaord layout for symbols

* Start ShiftLocked for consistency with previous UX.

* Fix number layout

* PR and test-drive feedback
2023-07-31 21:44:05 -07:00
Mark Thompson 06b7a0419e Fixed Select button responsiveness when updating frequency field during heavy CPU activity (e.g. WFM Audio) (#1335)
* Resolve button responsiveness

* Resolve button responsiveness

* Clang

* Clang

* Clang try again

* Removed unnecessary lines

* Address review comments

* Add comments per reviewer suggestion

* Clang test

* Clang retry
2023-07-31 23:27:15 -05:00
Kyle Reed d24ff7b3bc Oversample capturing for low bandwidths (#1332)
* draft_low_bit_rate_solution_Capture_App

* second_draft_dynamic_decim

* Add support for Oversample Rate to capture.

---------

Co-authored-by: Brumi-2021 <ea3hqj@gmail.com>
2023-07-31 17:46:07 +02:00
Mark Thompson a24b3ad3de Correct estimated capture time in C8 format (#1330)
* Correct capture time remaining for C8 format

* Removed unsupported RawS32 type

* Clang
2023-07-31 08:02:11 -07:00
Mark Thompson 91c6e3fc30 Display error message when trying to delete non-empty directory (#1321)
* Non-empty directory check

* Non-empty directory check

* Display error when attempting to delete non-empty directory

* Clang

Delete white-space that the friggin editor added

* is_empty_directory

* is_empty_directory

* is_empty_directory

* Now need to check if it's a directory first
2023-07-30 15:46:59 -05:00
Kyle Reed 411f6c0a34 Progress bar for Notepad IO (#1322) 2023-07-30 09:36:57 +02:00
29 changed files with 457 additions and 162 deletions
+1 -1
View File
@@ -1 +1 @@
v1.7.2
v1.7.3
+1 -1
View File
@@ -1 +1 @@
v1.7.3
v1.7.4
+9 -3
View File
@@ -64,13 +64,19 @@ CaptureAppView::CaptureAppView(NavigationView& nav)
/* base_rate is used for FFT calculation and display LCD, and also in recording writing SD Card rate. */
/* ex. sampling_rate values, 4Mhz, when recording 500 kHz (BW) and fs 8 Mhz, when selected 1 Mhz BW ... */
/* ex. recording 500kHz BW to .C16 file, base_rate clock 500kHz x2(I,Q) x 2 bytes (int signed) =2MB/sec rate SD Card */
auto sampling_rate = 8 * base_rate; // Decimation by 8 done on baseband side.
/* Set up proper anti aliasing BPF bandwith in MAX2837 before ADC sampling according to the new added BW Options. */
// For lower bandwidths, (12k5, 16k, 20k), increase the oversample rate to get a higher sample rate.
OversampleRate oversample_rate = base_rate >= 25'000 ? OversampleRate::Rate8x : OversampleRate::Rate16x;
// HackRF suggests a minimum sample rate of 2M.
// Oversampling helps get to higher sample rates when recording lower bandwidths.
uint32_t sampling_rate = toUType(oversample_rate) * base_rate;
// Set up proper anti aliasing BPF bandwidth in MAX2837 before ADC sampling according to the new added BW Options.
auto anti_alias_baseband_bandwidth_filter = filter_bandwidth_for_sampling_rate(sampling_rate);
waterfall.stop();
record_view.set_sampling_rate(sampling_rate);
record_view.set_sampling_rate(sampling_rate, oversample_rate); // NB: Actually updates the baseband.
receiver_model.set_sampling_rate(sampling_rate);
receiver_model.set_baseband_bandwidth(anti_alias_baseband_bandwidth_filter);
waterfall.start();
+5
View File
@@ -440,6 +440,11 @@ void FileManagerView::on_rename(std::string_view hint) {
}
void FileManagerView::on_delete() {
if (is_directory(get_selected_full_path()) && !is_empty_directory(get_selected_full_path())) {
nav_.display_modal("Delete", "Directory not empty!");
return;
}
auto name = get_selected_entry().path.filename().string();
nav_.push<ModalMessageView>(
"Delete", "Delete " + name + "\nAre you sure?", YESNO,
+2 -1
View File
@@ -1251,8 +1251,9 @@ size_t ReconView::change_mode(freqman_index_t new_mod) {
}
if (new_mod != SPEC_MODULATION) {
button_audio_app.set_text("AUDIO");
// TODO: Oversampling.
record_view->set_sampling_rate(recording_sampling_rate);
// reset receiver model to fix bug when going from SPEC to audio, the sound is distorded
// reset receiver model to fix bug when going from SPEC to audio, the sound is distorted
receiver_model.set_sampling_rate(3072000);
receiver_model.set_baseband_bandwidth(1750000);
} else {
+12 -2
View File
@@ -341,7 +341,7 @@ static void show_save_prompt(
std::function<void()> on_save,
std::function<void()> continuation) {
nav.display_modal(
"Save?", "Save changes?", YESNO,
"Save?", " Save changes?", YESNO,
[on_save](bool choice) {
if (choice && on_save)
on_save();
@@ -474,7 +474,13 @@ void TextEditorView::open_file(const fs::path& path) {
path_ = {};
file_dirty_ = false;
has_temp_file_ = false;
auto result = FileWrapper::open(path);
auto result = FileWrapper::open(
path, false, [](uint32_t value, uint32_t total) {
Painter p;
auto percent = (value * 100) / total;
auto width = (percent * screen_width) / 100;
p.draw_hline({0, 16}, width, Color::yellow());
});
if (!result) {
nav_.display_modal("Read Error", "Cannot open file:\n" + result.error().what());
@@ -582,6 +588,10 @@ void TextEditorView::prepare_for_write() {
if (has_temp_file_)
return;
// TODO: This would be nice to have but it causes a stack overflow in an ISR?
// Painter p;
// p.draw_string({2, 48}, Styles::yellow, "Creating temporary file...");
// Copy to temp file on write.
has_temp_file_ = true;
delete_temp_file(path_);
+5
View File
@@ -352,6 +352,11 @@ void set_sample_rate(const uint32_t sample_rate) {
send_message(&message);
}
void set_oversample_rate(OversampleRate oversample_rate) {
OversampleRateConfigMessage message{oversample_rate};
send_message(&message);
}
void capture_start(CaptureConfig* const config) {
CaptureConfigMessage message{config};
send_message(&message);
+1
View File
@@ -95,6 +95,7 @@ void spectrum_streaming_start();
void spectrum_streaming_stop();
void set_sample_rate(const uint32_t sample_rate);
void set_oversample_rate(OversampleRate oversample_rate);
void capture_start(CaptureConfig* const config);
void capture_stop();
void replay_start(ReplayConfig* const config);
+38
View File
@@ -5607,6 +5607,44 @@ static constexpr Bitmap bitmap_icon_speaker_and_headphones_mute{
{16, 16},
bitmap_icon_speaker_and_headphones_mute_data};
static constexpr uint8_t bitmap_icon_shift_data[] = {
0x00,
0x00,
0x80,
0x00,
0xC0,
0x01,
0xE0,
0x03,
0xF0,
0x07,
0xF8,
0x0F,
0xFC,
0x1F,
0xE0,
0x03,
0xE0,
0x03,
0xE0,
0x03,
0x20,
0x02,
0xE0,
0x03,
0x20,
0x02,
0xE0,
0x03,
0x00,
0x00,
0x00,
0x00,
};
static constexpr Bitmap bitmap_icon_shift{
{16, 16},
bitmap_icon_shift_data};
} /* namespace ui */
#endif /*__BITMAP_HPP__*/
+11
View File
@@ -568,6 +568,17 @@ bool is_directory(const path& file_path) {
return fr == FR_OK && is_directory(static_cast<file_status>(filinfo.fattrib));
}
bool is_empty_directory(const path& file_path) {
DIR dir;
FILINFO filinfo;
if (!is_directory(file_path))
return false;
auto result = f_findfirst(&dir, &filinfo, reinterpret_cast<const TCHAR*>(file_path.c_str()), (const TCHAR*)u"*");
return !((result == FR_OK) && (filinfo.fname[0] != (TCHAR)'\0'));
}
space_info space(const path& p) {
DWORD free_clusters{0};
FATFS* fs;
+1
View File
@@ -248,6 +248,7 @@ bool is_directory(const file_status s);
bool is_regular_file(const file_status s);
bool file_exists(const path& file_path);
bool is_directory(const path& file_path);
bool is_empty_directory(const path& file_path);
space_info space(const path& p);
+36 -1
View File
@@ -26,6 +26,7 @@
#include "file.hpp"
#include "optional.hpp"
#include <functional>
#include <memory>
#include <string_view>
@@ -75,6 +76,8 @@ class BufferWrapper {
}
virtual ~BufferWrapper() {}
std::function<void(Size, Size)> on_read_progress{};
/* Prevent copies */
BufferWrapper(const BufferWrapper&) = delete;
BufferWrapper& operator=(const BufferWrapper&) = delete;
@@ -234,13 +237,23 @@ class BufferWrapper {
line_count_ = start_line_;
Offset offset = start_offset_;
// Report progress every N lines.
constexpr auto report_interval = 100u;
auto result = next_newline(offset);
auto next_report = report_interval;
while (result) {
++line_count_;
if (newlines_.size() < max_newlines)
newlines_.push_back(*result);
offset = *result + 1;
if (on_read_progress && line_count_ > next_report) {
on_read_progress(offset, size());
next_report = line_count_ + report_interval;
}
result = next_newline(offset);
}
}
@@ -397,6 +410,9 @@ class BufferWrapper {
// Number of bytes left to shift.
Offset remaining = size() - src;
Offset offset = size();
Size report_total = remaining;
Size report_interval = report_total / 8;
Size next_report = remaining - report_interval;
while (remaining > 0) {
offset -= std::min(remaining, buffer_size);
@@ -413,6 +429,11 @@ class BufferWrapper {
break;
remaining -= *result;
if (on_read_progress && remaining <= next_report) {
on_read_progress(report_total - remaining, report_total);
next_report = remaining > report_interval ? remaining - report_interval : 0;
}
}
}
@@ -424,6 +445,9 @@ class BufferWrapper {
char buffer[buffer_size];
auto offset = src;
Size report_total = size();
Size report_interval = report_total / 8;
Size next_report = offset + report_interval;
while (true) {
wrapped_->seek(offset);
@@ -438,6 +462,11 @@ class BufferWrapper {
break;
offset += *result;
if (on_read_progress && offset >= next_report) {
on_read_progress(offset, report_total);
next_report = offset + report_interval;
}
}
// Delete the extra bytes at the end of the file.
@@ -463,13 +492,19 @@ class FileWrapper : public BufferWrapper<File, 64> {
template <typename T>
using Result = File::Result<T>;
using Error = File::Error;
static Result<std::unique_ptr<FileWrapper>> open(const std::filesystem::path& path, bool create = false) {
static Result<std::unique_ptr<FileWrapper>> open(
const std::filesystem::path& path,
bool create = false,
std::function<void(Size, Size)> on_read_progress = nullptr) {
auto fw = std::unique_ptr<FileWrapper>(new FileWrapper());
auto error = fw->file_.open(path, /*read_only*/ false, create);
if (error)
return *error;
if (on_read_progress)
fw->on_read_progress = on_read_progress;
fw->initialize();
return fw;
}
+2 -2
View File
@@ -74,9 +74,9 @@ options_t freqman_bandwidths[4] = {
},
{
// SPEC -- TODO: these should be indexes.
{"8k5", 8500},
{"11k", 11000},
{"12k5", 12500},
{"16k", 16000},
{"20k", 20000},
{"25k", 25000},
{"50k", 50000},
{"100k", 100000},
+77 -61
View File
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
* Copyright (C) 2023 Mark Thompson
*
* This file is part of PortaPack.
*
@@ -24,9 +25,8 @@
#include "utility.hpp"
uint8_t Debounce::state() {
bool v = !pulse_upon_release_ && (state_ || simulated_pulse_);
if (simulated_pulse_)
simulated_pulse_ = false;
bool v = state_to_report_;
simulated_pulse_ = false;
return v;
}
@@ -52,84 +52,100 @@ bool Debounce::long_press_occurred() {
bool Debounce::feed(const uint8_t bit) {
history_ = (history_ << 1) | (bit & 1);
// "Repeat" handling - simulated button release
if (repeat_ctr_) {
// Make sure the button is still being held continuously
if ((history_ == 0xFF) && !long_press_enabled_) {
// Simulate button press every REPEAT_SUBSEQUENT_DELAY ticks
if (--repeat_ctr_ == 0) {
state_ = !state_;
repeat_ctr_ = REPEAT_SUBSEQUENT_DELAY / 2;
return true;
}
} else {
// It's a real button release; stop simulating
repeat_ctr_ = 0;
}
}
if (state_ == 0) {
// Previous button state was 0 (released);
// Has button been held for DEBOUNCE_COUNT ticks?
if ((history_ & DEBOUNCE_MASK) == DEBOUNCE_MASK) {
// Has button been held for DEBOUNCE_COUNT ticks?
if ((history_ & DEBOUNCE_MASK) == DEBOUNCE_MASK) {
//
// Button is currently pressed;
// Was previous button state 0 (released)?
//
if (state_ == 0) {
//
// Button has been pressed (after filtering glitches), transition 0->1
//
state_ = 1;
held_time_ = 0;
// If long_press_enabled_, state() function masks the button press until it's released
// or until LONG_PRESS_DELAY is reached
if (long_press_enabled_) {
pulse_upon_release_ = true;
state_to_report_ = 0;
return false;
}
state_to_report_ = 1;
return true;
}
} else {
// Previous button state was 1 (pressed);
// Has button been released for DEBOUNCE_COUNT ticks?
if ((history_ & DEBOUNCE_MASK) == 0) {
// Button has been released when long_press_enabled_ and before LONG_PRESS_DELAY was reached;
// "Repeat" handling - simulated button release
if (repeat_ctr_ && !long_press_enabled_) {
// Simulate button press every REPEAT_SUBSEQUENT_DELAY ticks
// (by toggling reported state every 1/2 of the delay time)
if (--repeat_ctr_ == 0) {
state_to_report_ = !state_to_report_;
repeat_ctr_ = REPEAT_SUBSEQUENT_DELAY / 2;
return true;
}
}
// Keep track of how long button has been held
held_time_++;
if (pulse_upon_release_) {
// Button is being held down and long_press support is enabled for this key:
// if LONG_PRESS_DELAY is reached then finally report that switch is pressed and set flag
// indicating it was a LONG press
// (note that repeat_support and long_press support are mutually exclusive)
if (held_time_ >= LONG_PRESS_DELAY) {
pulse_upon_release_ = false;
long_press_occurred_ = true;
state_to_report_ = 1;
return true;
}
} else if (repeat_enabled_ && !long_press_enabled_) {
// Repeat support -- 4 directional buttons only (unless long_press is enabled)
if (held_time_ >= REPEAT_INITIAL_DELAY) {
// Delay reached; trigger repeat code on NEXT tick
repeat_ctr_ = 1;
held_time_ = 0;
}
}
} else if ((history_ & DEBOUNCE_MASK) == 0) { // Has button been released for at least DEBOUNCE_COUNT ticks?
//
// Button is released;
// Was previous button state 1 (pressed)?
//
if (state_ == 1) {
//
// Button has been released (after filtering glitches), transition 1->0
//
state_ = 0;
long_press_occurred_ = false;
// If button released when long_press_enabled_ and before LONG_PRESS_DELAY was reached;
// allow state() function to finally return a single press indication (simulated pulse).
// Note: In long press mode, apps won't see button press until the button is released.
if (pulse_upon_release_) {
// force state() function (called by EventDispatcher) to return simulated press for one cycle
simulated_pulse_ = true;
pulse_upon_release_ = false;
} else {
state_ = 0;
simulated_pulse_ = true;
state_to_report_ = 1;
return true;
}
// Reset long_press_occurred_ flag after button is released
long_press_occurred_ = false;
state_to_report_ = 0;
return true;
}
// Has button been held continuously?
if (history_ == 0xFF) {
held_time_++;
if (pulse_upon_release_) {
// Button is being held down and long_press support is enabled for this key:
// if LONG_PRESS_DELAY is reached then finally report that switch is pressed and set flag
// indicating it was a LONG press
// (note that repeat_support and long_press support are mutually exclusive)
if (held_time_ >= LONG_PRESS_DELAY) {
long_press_occurred_ = true;
simulated_pulse_ = true;
pulse_upon_release_ = false;
held_time_ = 0;
return true;
}
} else if (repeat_enabled_ && !long_press_enabled_) {
// Repeat support -- 4 directional buttons only (unless long_press is enabled)
if (held_time_ == REPEAT_INITIAL_DELAY) {
// Delay reached; trigger repeat code on NEXT tick
repeat_ctr_ = 1;
held_time_ = 0;
}
}
} else {
// Button not continuously pressed; reset counter
held_time_ = 0;
// Reset reported state after application/event has cleared simulated_pulse_
if (state_to_report_ == 1 && !simulated_pulse_) {
state_to_report_ = 0;
return true;
}
} else {
//
// Button is in transition between states;
// Reset counters until button inputs are stable.
//
held_time_ = 0;
repeat_ctr_ = 0;
}
return false;
}
+19 -9
View File
@@ -43,15 +43,25 @@ class Debounce {
bool long_press_occurred();
private:
uint8_t history_{0};
uint8_t state_{0};
bool repeat_enabled_{false};
uint16_t repeat_ctr_{0};
uint16_t held_time_{0};
bool pulse_upon_release_{false};
bool simulated_pulse_{false};
bool long_press_enabled_{false};
bool long_press_occurred_{false};
uint8_t history_{0}; // shift register of last 8 reads from button hardware state bit
uint8_t state_{0}; // actual button hardware state (after debounce logic), 1=pressed
uint8_t state_to_report_{0}; // pseudo button state reported by state() function (may be masked off or simulated presses)
bool repeat_enabled_{false}; // TRUE if this button is enabled to auto-repeat when held down (ignored if long_press_enabled)
uint16_t repeat_ctr_{0}; // used for timing auto-repeat simulated button presses when button is held down and repeat_enabled
uint16_t held_time_{0}; // number of ticks that the button has been held down (compared against REPEAT and LONG_PRESS delays)
bool pulse_upon_release_{false}; // TRUE when button is being held down when long_press_enabled and LONG_PRESS_DELAY hasn't been reached yet
bool simulated_pulse_{false}; // TRUE if a simulated button press is active following a short button press (only when long_press_enabled)
bool long_press_enabled_{false}; // TRUE when button is in long-press mode (takes precedence over the repeat_enabled flag)
bool long_press_occurred_{false}; // TRUE when button is being held down and LONG_PRESS_DELAY has been reached (only when long_press_enabled)
};
#endif /*__DEBOUNCE_H__*/
+52 -18
View File
@@ -22,11 +22,10 @@
#include "ui_alphanum.hpp"
#include "portapack.hpp"
#include "hackrf_hal.hpp"
#include "portapack.hpp"
#include "portapack_shared_memory.hpp"
#include <algorithm>
#include "utility.hpp"
namespace ui {
@@ -38,6 +37,7 @@ AlphanumView::AlphanumView(
size_t n;
add_children({
&button_shift,
&labels,
&field_raw,
&text_raw_to_char,
@@ -49,6 +49,19 @@ AlphanumView::AlphanumView(
this->on_button(button);
};
button_shift.set_vertical_center(true);
button_shift.on_select = [this]() {
incr(shift_mode);
// Disallow one-time shift in digits/symbols mode
if ((mode == 1) && (shift_mode == ShiftMode::Shift))
shift_mode = ShiftMode::ShiftLock;
else if (shift_mode > ShiftMode::ShiftLock)
shift_mode = ShiftMode::None;
refresh_keys();
};
n = 0;
for (auto& button : buttons) {
button.id = n;
@@ -56,9 +69,9 @@ AlphanumView::AlphanumView(
focused_button = button.id;
};
button.on_select = button_fn;
button.set_parent_rect({static_cast<Coord>((n % 5) * (240 / 5)),
button.set_parent_rect({static_cast<Coord>((n % 5) * (screen_width / 5)),
static_cast<Coord>((n / 5) * 38 + 24),
240 / 5, 38});
screen_width / 5, 38});
add_child(&button);
n++;
}
@@ -78,38 +91,59 @@ AlphanumView::AlphanumView(
char_add(field_raw.value());
};
// make text_raw_to_char widget display the char value from field_raw
field_raw.on_change = [this](auto) {
text_raw_to_char.set(std::string{static_cast<char>(field_raw.value())});
};
}
void AlphanumView::set_mode(const uint32_t new_mode) {
size_t n = 0;
if (new_mode < 3)
void AlphanumView::set_mode(uint32_t new_mode, ShiftMode new_shift_mode) {
if (new_mode < std::size(key_sets))
mode = new_mode;
else
mode = 0;
const char* key_list = key_sets[mode].second;
shift_mode = new_shift_mode;
refresh_keys();
if (mode + 1 < std::size(key_sets))
button_mode.set_text(key_sets[mode + 1].name);
else
button_mode.set_text(key_sets[0].name);
}
void AlphanumView::refresh_keys() {
auto key_list = shift_mode == ShiftMode::None
? key_sets[mode].normal
: key_sets[mode].shifted;
size_t n = 0;
for (auto& button : buttons) {
const std::string label{
key_list[n]};
button.set_text(label);
button.set_text(std::string{key_list[n]});
n++;
}
if (mode < 2)
button_mode.set_text(key_sets[mode + 1].first);
else
button_mode.set_text(key_sets[0].first);
switch (shift_mode) {
case ShiftMode::None:
button_shift.set_color(Color::dark_grey());
break;
case ShiftMode::Shift:
button_shift.set_color(Color::black());
break;
case ShiftMode::ShiftLock:
button_shift.set_color(Color::dark_blue());
break;
}
}
void AlphanumView::on_button(Button& button) {
const auto c = button.text()[0];
char_add(c);
// TODO: Consolidate shift handling.
if (shift_mode == ShiftMode::Shift) {
shift_mode = ShiftMode::None;
refresh_keys();
}
}
bool AlphanumView::on_encoder(const EncoderEvent delta) {
+36 -12
View File
@@ -29,6 +29,10 @@
#include "ui_textentry.hpp"
#include "ui_menu.hpp"
// TODO: Building this as a custom widget instead of using
// all the Button controls would save a considerable amount of RAM.
// The Buttons each have a backing string but these only need one char.
namespace ui {
class AlphanumView : public TextEntryView {
@@ -43,22 +47,42 @@ class AlphanumView : public TextEntryView {
bool on_encoder(const EncoderEvent delta) override;
private:
const char* const keys_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ, ._";
const char* const keys_lower = "abcdefghijklmnopqrstuvwxyz, ._";
const char* const keys_digit = "0123456789!\"#'()*+-/:;=<>@[\\]?";
enum class ShiftMode : uint8_t {
None,
Shift,
ShiftLock,
};
const std::pair<std::string, const char*> key_sets[3] = {
{"ABC", keys_upper},
{"abc", keys_lower},
{"123", keys_digit}};
const char* const keys_lower = "abcdefghijklmnopqrstuvwxyz, .";
const char* const keys_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ, .";
const char* const keys_digit = "1234567890()'`\"+-*/=<>_\\!?, .";
const char* const keys_symbl = "!@#$%^&*()[]'`\"{}|:;<>-_~?, .";
struct key_set_t {
const char* name;
const char* normal;
const char* shifted;
};
const key_set_t key_sets[2] = {
{"abc", keys_lower, keys_upper},
{"123", keys_digit, keys_symbl}};
int16_t focused_button = 0;
uint32_t mode = 0; // Uppercase
uint32_t mode = 0; // Letters.
ShiftMode shift_mode = ShiftMode::None;
void set_mode(const uint32_t new_mode);
void set_mode(uint32_t new_mode, ShiftMode new_shift_mode = ShiftMode::None);
void refresh_keys();
void on_button(Button& button);
std::array<Button, 30> buttons{};
std::array<Button, 29> buttons{};
NewButton button_shift{
{192, 214, screen_width / 5, 38},
{},
&bitmap_icon_shift,
Color::dark_grey()};
Labels labels{
{{1 * 8, 33 * 8}, "Raw:", Color::light_grey()},
@@ -76,11 +100,11 @@ class AlphanumView : public TextEntryView {
"0"};
Button button_delete{
{9 * 8, 33 * 8, 6 * 8, 32},
{9 * 8, 32 * 8 - 3, 7 * 8, 3 * 16 + 3},
"<DEL"};
Button button_mode{
{16 * 8, 33 * 8, 5 * 8, 32},
{16 * 8, 32 * 8 - 3, 6 * 8, 3 * 16 + 3},
""};
};
-2
View File
@@ -21,9 +21,7 @@
*/
#include "ui_textentry.hpp"
//#include "portapack_persistent_memory.hpp"
#include "ui_alphanum.hpp"
//#include "ui_handwrite.hpp"
using namespace portapack;
+1 -1
View File
@@ -50,7 +50,7 @@ class TextEntryView : public View {
TextEdit text_input;
Button button_ok{
{22 * 8, 33 * 8, 7 * 8, 32},
{22 * 8, 32 * 8 - 3, 8 * 8, 3 * 16 + 3},
"OK"};
};
+36 -22
View File
@@ -101,24 +101,27 @@ void RecordView::focus() {
button_record.focus();
}
void RecordView::set_sampling_rate(const size_t new_sampling_rate) {
/* We are changing "REC" icon background to yellow in BW rec Options >600kHz
void RecordView::set_sampling_rate(size_t new_sampling_rate, OversampleRate new_oversample_rate) {
/* We are changing "REC" icon background to yellow in BW rec Options >600kHz
where we are NOT recording full IQ .C16 files (recorded files are decimated ones).
Those decimated recorded files,has not the full IQ samples .
are ok as recorded spectrum indication, but they should not be used by Replay app.
Those decimated recorded files, has not the full IQ samples.
are ok as recorded spectrum indication, but they should not be used by Replay app.
We keep original black background in all the correct IQ .C16 files BW's Options */
if (new_sampling_rate > 4800000) { // > BW >600kHz (fs=8*BW), (750kHz ...2750kHz)
We keep original black background in all the correct IQ .C16 files BW's Options */
if (new_sampling_rate > 4'800'000) { // > BW >600kHz (fs=8*BW), (750kHz...2750kHz)
button_record.set_background(ui::Color::yellow());
} else {
button_record.set_background(ui::Color::black());
}
if (new_sampling_rate != sampling_rate) {
if (new_sampling_rate != sampling_rate ||
new_oversample_rate != oversample_rate) {
stop();
sampling_rate = new_sampling_rate;
oversample_rate = new_oversample_rate;
baseband::set_sample_rate(sampling_rate);
baseband::set_oversample_rate(oversample_rate);
button_record.hidden(sampling_rate == 0);
text_record_filename.hidden(sampling_rate == 0);
@@ -162,12 +165,13 @@ void RecordView::start() {
rtcGetTime(&RTCD1, &datetime);
// ISO 8601
std::string date_time = to_string_dec_uint(datetime.year(), 4, '0') +
to_string_dec_uint(datetime.month(), 2, '0') +
to_string_dec_uint(datetime.day(), 2, '0') + "T" +
to_string_dec_uint(datetime.hour()) +
to_string_dec_uint(datetime.minute()) +
to_string_dec_uint(datetime.second());
std::string date_time =
to_string_dec_uint(datetime.year(), 4, '0') +
to_string_dec_uint(datetime.month(), 2, '0') +
to_string_dec_uint(datetime.day(), 2, '0') + "T" +
to_string_dec_uint(datetime.hour()) +
to_string_dec_uint(datetime.minute()) +
to_string_dec_uint(datetime.second());
base_path = filename_stem_pattern.string() + "_" + date_time + "_" +
trim(to_string_freq(receiver_model.target_frequency())) + "Hz";
@@ -197,10 +201,9 @@ void RecordView::start() {
case FileType::RawS8:
case FileType::RawS16: {
const auto metadata_file_error =
write_metadata_file(get_metadata_path(base_path),
{receiver_model.target_frequency(), sampling_rate / 8});
// Not sure why sample_rate is div. 8, but stored value matches rate settings.
const auto metadata_file_error = write_metadata_file(
get_metadata_path(base_path),
{receiver_model.target_frequency(), sampling_rate / toUType(oversample_rate)});
if (metadata_file_error.is_valid()) {
handle_error(metadata_file_error.value());
return;
@@ -263,13 +266,24 @@ void RecordView::update_status_display() {
text_record_dropped.set(s);
}
/*if (pitch_rssi_enabled) {
button_pitch_rssi.invert_colors();
}*/
/*
if (pitch_rssi_enabled) {
button_pitch_rssi.invert_colors();
}
*/
if (sampling_rate) {
if (sampling_rate > 0) {
const auto space_info = std::filesystem::space(u"");
const uint32_t bytes_per_second = file_type == FileType::WAV ? (sampling_rate * 2) : (sampling_rate / 8 * 4); // TODO: Why 8/4??
// - Audio is 1 int16_t per sample or '2' bytes per sample.
// - C8 captures 2 (I,Q) int8_t per sample or '2' bytes per sample.
// - C16 captures 2 (I,Q) int16_t per sample or '4' bytes per sample.
const auto bytes_per_sample = file_type == FileType::RawS16 ? 4 : 2;
// WAV files are not oversampled, but C8 and C16 are. Divide by the
// oversample rate to get the effective sample rate.
const auto effective_sampling_rate = file_type == FileType::WAV
? sampling_rate
: sampling_rate / toUType(oversample_rate);
const uint32_t bytes_per_second = effective_sampling_rate * bytes_per_sample;
const uint32_t available_seconds = space_info.free / bytes_per_second;
const uint32_t seconds = available_seconds % 60;
const uint32_t available_minutes = available_seconds / 60;
+12 -3
View File
@@ -42,8 +42,7 @@ class RecordView : public View {
enum FileType {
RawS8 = 1,
RawS16 = 2,
RawS32 = 3,
WAV = 4,
WAV = 3,
};
RecordView(
@@ -57,7 +56,16 @@ class RecordView : public View {
void focus() override;
void set_sampling_rate(const size_t new_sampling_rate);
/* Sets the sampling rate and the oversampling "decimation" rate.
* These values are passed down to the baseband proc_capture. For
* Audio (WAV) recording, the OversampleRate should not be
* specified and the default will be used. */
/* TODO: Currently callers are expected to have already multiplied the
* sample_rate with the oversample rate. It would be better move that
* logic to a single place. */
void set_sampling_rate(
size_t new_sampling_rate,
OversampleRate new_oversample_rate = OversampleRate::Rate8x);
void set_file_type(const FileType v) { file_type = v; }
@@ -91,6 +99,7 @@ class RecordView : public View {
const size_t write_size;
const size_t buffer_count;
size_t sampling_rate{0};
OversampleRate oversample_rate{OversampleRate::Rate8x};
SignalToken signal_token_tick_second{};
Rectangle rect_background{
+35 -7
View File
@@ -27,7 +27,8 @@
#include "utility.hpp"
CaptureProcessor::CaptureProcessor() {
decim_0.configure(taps_200k_decim_0.taps, 33554432);
decim_0_4.configure(taps_200k_decim_0.taps, 33554432);
decim_0_8.configure(taps_200k_decim_0.taps, 33554432);
decim_1.configure(taps_200k_decim_1.taps, 131072);
channel_spectrum.set_decimation_factor(1);
@@ -36,7 +37,7 @@ CaptureProcessor::CaptureProcessor() {
void CaptureProcessor::execute(const buffer_c8_t& buffer) {
/* 2.4576MHz, 2048 samples */
const auto decim_0_out = decim_0.execute(buffer, dst_buffer);
const auto decim_0_out = decim_0_execute(buffer, dst_buffer);
const auto decim_1_out = decim_1.execute(decim_0_out, dst_buffer);
const auto& decimator_out = decim_1_out;
const auto& channel = decimator_out;
@@ -65,9 +66,19 @@ void CaptureProcessor::on_message(const Message* const message) {
channel_spectrum.on_message(message);
break;
case Message::ID::SamplerateConfig:
samplerate_config(*reinterpret_cast<const SamplerateConfigMessage*>(message));
case Message::ID::SamplerateConfig: {
auto config = reinterpret_cast<const SamplerateConfigMessage*>(message);
baseband_fs = config->sample_rate;
update_for_rate_change();
break;
}
case Message::ID::OversampleRateConfig: {
auto config = reinterpret_cast<const OversampleRateConfigMessage*>(message);
oversample_rate = config->oversample_rate;
update_for_rate_change();
break;
}
case Message::ID::CaptureConfig:
capture_config(*reinterpret_cast<const CaptureConfigMessage*>(message));
@@ -78,11 +89,14 @@ void CaptureProcessor::on_message(const Message* const message) {
}
}
void CaptureProcessor::samplerate_config(const SamplerateConfigMessage& message) {
baseband_fs = message.sample_rate;
void CaptureProcessor::update_for_rate_change() {
baseband_thread.set_sampling_rate(baseband_fs);
size_t decim_0_output_fs = baseband_fs / decim_0.decimation_factor;
auto decim_0_factor = oversample_rate == OversampleRate::Rate8x
? decim_0_4.decimation_factor
: decim_0_8.decimation_factor;
size_t decim_0_output_fs = baseband_fs / decim_0_factor;
size_t decim_1_input_fs = decim_0_output_fs;
size_t decim_1_output_fs = decim_1_input_fs / decim_1.decimation_factor;
@@ -103,6 +117,20 @@ void CaptureProcessor::capture_config(const CaptureConfigMessage& message) {
}
}
buffer_c16_t CaptureProcessor::decim_0_execute(const buffer_c8_t& src, const buffer_c16_t& dst) {
switch (oversample_rate) {
case OversampleRate::Rate8x:
return decim_0_4.execute(src, dst);
case OversampleRate::Rate16x:
return decim_0_8.execute(src, dst);
default:
chDbgPanic("Unhandled OversampleRate");
return {};
}
}
int main() {
EventDispatcher event_dispatcher{std::make_unique<CaptureProcessor>()};
event_dispatcher.run();
+13 -2
View File
@@ -50,7 +50,13 @@ class CaptureProcessor : public BasebandProcessor {
dst.data(),
dst.size()};
dsp::decimate::FIRC8xR16x24FS4Decim4 decim_0{};
/* 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::FIRC16xR16x16Decim2 decim_1{};
int32_t channel_filter_low_f = 0;
int32_t channel_filter_high_f = 0;
@@ -61,14 +67,19 @@ class CaptureProcessor : public BasebandProcessor {
SpectrumCollector channel_spectrum{};
size_t spectrum_interval_samples = 0;
size_t spectrum_samples = 0;
OversampleRate oversample_rate{OversampleRate::Rate8x};
/* NB: Threads should be the last members in the class definition. */
BasebandThread baseband_thread{
baseband_fs, this, baseband::Direction::Receive, /*auto_start*/ false};
RSSIThread rssi_thread{};
void samplerate_config(const SamplerateConfigMessage& message);
/* Called to update members when the sample rate or oversample rate is changed. */
void update_for_rate_change();
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);
};
#endif /*__PROC_CAPTURE_HPP__*/
+2
View File
@@ -46,6 +46,8 @@ void ReplayProcessor::execute(const buffer_c8_t& buffer) {
if (!configured || !stream) return;
buffer_c16_t iq_buffer{iq.data(), iq.size(), baseband_fs / 8};
// File data is in C16 format, we need C8
// File samplerate is 500kHz, we're at 4MHz
// iq_buffer can only be 512 C16 samples (RAM limitation)
-4
View File
@@ -45,10 +45,6 @@ class ReplayProcessor : public BasebandProcessor {
static constexpr auto spectrum_rate_hz = 50.0f;
std::array<complex16_t, 256> iq{};
const buffer_c16_t iq_buffer{
iq.data(),
iq.size(),
baseband_fs / 8};
int32_t channel_filter_low_f = 0;
int32_t channel_filter_high_f = 0;
+18
View File
@@ -111,6 +111,7 @@ class Message {
APRSRxConfigure = 54,
SpectrumPainterBufferRequestConfigure = 55,
SpectrumPainterBufferResponseConfigure = 56,
OversampleRateConfig = 57,
MAX
};
@@ -809,6 +810,23 @@ class SamplerateConfigMessage : public Message {
const uint32_t sample_rate = 0;
};
/* Controls decimation handling in proc_capture. */
enum class OversampleRate : uint8_t {
Rate8x = 8,
Rate16x = 16,
};
class OversampleRateConfigMessage : public Message {
public:
constexpr OversampleRateConfigMessage(
OversampleRate oversample_rate)
: Message{ID::OversampleRateConfig},
oversample_rate(oversample_rate) {
}
const OversampleRate oversample_rate{OversampleRate::Rate8x};
};
class AudioLevelReportMessage : public Message {
public:
constexpr AudioLevelReportMessage()
+7 -10
View File
@@ -1188,7 +1188,7 @@ void NewButton::paint(Painter& painter) {
painter.draw_bitmap(
bmp_pos,
*bitmap_,
color_, // Color::green(), //fg,
color_,
bg);
}
@@ -1667,8 +1667,6 @@ void TextEdit::char_delete() {
}
void TextEdit::paint(Painter& painter) {
constexpr int char_width = 8;
auto rect = screen_rect();
auto text_style = has_focus() ? style().invert() : style();
auto offset = 0;
@@ -1677,15 +1675,14 @@ void TextEdit::paint(Painter& painter) {
if (cursor_pos_ >= char_count_)
offset = cursor_pos_ - char_count_ + 1;
// Clear the control.
painter.fill_rectangle(rect, text_style.background);
// Draw the text starting at the offset.
for (uint32_t i = 0; i < char_count_ && i + offset < text_.length(); i++) {
for (uint32_t i = 0; i < char_count_; i++) {
// Using draw_char to blank the rest of the line with spaces produces less flicker.
auto c = (i + offset < text_.length()) ? text_[i + offset] : ' ';
painter.draw_char(
{rect.location().x() + (static_cast<int>(i) * char_width), rect.location().y()},
text_style,
text_[i + offset]);
text_style, c);
}
// Determine cursor position on screen (either the cursor position or the last char).
@@ -1698,7 +1695,7 @@ void TextEdit::paint(Painter& painter) {
painter.draw_char(cursor_point, cursor_style, text_[cursor_pos_]);
// Draw the cursor.
Rect cursor_box{cursor_point, {char_width, 16}};
Rect cursor_box{cursor_point, {char_width, char_height}};
painter.draw_rectangle(cursor_box, cursor_style.background);
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 267 B

@@ -435,4 +435,29 @@ SCENARIO("Delete line.") {
}
}
SCENARIO("It calls on_read_progress while reading.") {
GIVEN("A file larger than internal buffer_size (512)") {
std::string content = std::string(599, 'a');
content.push_back('x');
MockFile f{content};
auto w = wrap_buffer(f);
auto init_line_count = w.line_count();
auto init_size = w.size();
auto called = false;
w.on_read_progress = [&called](auto, auto) {
called = true;
};
WHEN("Replacing range with larger size") {
w.replace_range({0, 2}, "bbb");
THEN("callback should be called.") {
CHECK(called);
}
}
}
}
TEST_SUITE_END();