2023-09-21 11:43:10 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2023 Kyle Reed
|
2024-02-10 10:56:50 -05:00
|
|
|
* Copyright (C) 2024 Mark Thompson
|
2023-09-21 11:43:10 -04:00
|
|
|
*
|
|
|
|
* This file is part of PortaPack.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __UI_IQ_TRIM_H__
|
|
|
|
#define __UI_IQ_TRIM_H__
|
|
|
|
|
|
|
|
#include "file.hpp"
|
|
|
|
#include "iq_trim.hpp"
|
2023-09-23 15:56:37 -04:00
|
|
|
#include "optional.hpp"
|
2023-09-21 11:43:10 -04:00
|
|
|
#include "ui.hpp"
|
|
|
|
#include "ui_navigation.hpp"
|
|
|
|
#include "ui_styles.hpp"
|
|
|
|
#include "ui_widget.hpp"
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
|
|
|
|
/* Helper for drawing progress related to IQ trimming. */
|
|
|
|
/* TODO: Ideally this would all be done on second thread. */
|
|
|
|
class TrimProgressUI {
|
|
|
|
public:
|
|
|
|
void show_reading() {
|
|
|
|
clear();
|
|
|
|
p.draw_string({6 * 8, 5 * 16}, Styles::yellow, "Reading Capture...");
|
|
|
|
}
|
|
|
|
|
|
|
|
void show_trimming() {
|
|
|
|
clear();
|
|
|
|
p.draw_string({5 * 8, 5 * 16}, Styles::yellow, "Trimming Capture...");
|
|
|
|
}
|
|
|
|
|
|
|
|
void show_progress(uint8_t percent) {
|
|
|
|
auto width = percent * screen_width / 100;
|
2023-09-23 15:56:37 -04:00
|
|
|
p.draw_hline({0, 6 * 16 + 2}, width, Color::yellow());
|
2023-09-21 11:43:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void clear() {
|
|
|
|
p.fill_rectangle({0 * 8, 4 * 16, screen_width, 3 * 16}, Color::black());
|
|
|
|
}
|
|
|
|
|
|
|
|
auto get_callback() {
|
|
|
|
return [this](uint8_t percent) { show_progress(percent); };
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Painter p{};
|
|
|
|
};
|
|
|
|
|
|
|
|
class IQTrimView : public View {
|
|
|
|
public:
|
|
|
|
IQTrimView(NavigationView& nav);
|
2023-10-08 15:57:59 -04:00
|
|
|
IQTrimView(NavigationView& nav, const std::filesystem::path& path);
|
2023-09-21 11:43:10 -04:00
|
|
|
|
|
|
|
std::string title() const override { return "IQ Trim"; }
|
|
|
|
void paint(Painter& painter) override;
|
|
|
|
void focus() override;
|
|
|
|
|
|
|
|
private:
|
2023-10-08 15:57:59 -04:00
|
|
|
void open_file(const std::filesystem::path& path);
|
|
|
|
|
2023-09-23 15:56:37 -04:00
|
|
|
/* Update controls with latest values. */
|
2023-09-21 11:43:10 -04:00
|
|
|
void refresh_ui();
|
2023-09-23 15:56:37 -04:00
|
|
|
|
|
|
|
/* Update the start/end controls with trim range info. */
|
|
|
|
void update_range_controls(iq::TrimRange trim_range);
|
|
|
|
|
|
|
|
/* Collect capture info and samples to draw the UI. */
|
|
|
|
void profile_capture();
|
|
|
|
|
|
|
|
/* Determine the start and end buckets based on the cutoff. */
|
|
|
|
void compute_range();
|
|
|
|
|
|
|
|
/* Trims the capture file based on the settings. */
|
|
|
|
bool trim_capture();
|
|
|
|
|
|
|
|
NavigationView& nav_;
|
2023-09-21 11:43:10 -04:00
|
|
|
|
|
|
|
std::filesystem::path path_{};
|
2023-09-23 15:56:37 -04:00
|
|
|
Optional<iq::CaptureInfo> info_{};
|
|
|
|
std::array<iq::PowerBuckets::Bucket, screen_width> power_buckets_{};
|
2023-09-21 11:43:10 -04:00
|
|
|
TrimProgressUI progress_ui{};
|
|
|
|
|
|
|
|
Labels labels{
|
|
|
|
{{0 * 8, 0 * 16}, "Capture File:", Color::light_grey()},
|
2023-09-23 15:56:37 -04:00
|
|
|
{{0 * 8, 6 * 16}, "Start :", Color::light_grey()},
|
|
|
|
{{0 * 8, 7 * 16}, "End :", Color::light_grey()},
|
|
|
|
{{0 * 8, 8 * 16}, "Samples:", Color::light_grey()},
|
|
|
|
{{0 * 8, 9 * 16}, "Max Pwr:", Color::light_grey()},
|
|
|
|
{{0 * 8, 10 * 16}, "Cutoff :", Color::light_grey()},
|
|
|
|
{{12 * 8, 10 * 16}, "%", Color::light_grey()},
|
2023-10-19 14:14:25 -04:00
|
|
|
{{0 * 8, 12 * 16}, "Amplify:", Color::light_grey()},
|
|
|
|
{{10 * 8, 12 * 16}, "x", Color::light_grey()},
|
2023-09-21 11:43:10 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
TextField field_path{
|
|
|
|
{0 * 8, 1 * 16, 30 * 8, 1 * 16},
|
|
|
|
"Open File..."};
|
|
|
|
|
|
|
|
Point pos_lines{0 * 8, 4 * 16};
|
|
|
|
Dim height_lines{2 * 16};
|
|
|
|
|
2023-09-23 15:56:37 -04:00
|
|
|
NumberField field_start{
|
|
|
|
{9 * 8, 6 * 16},
|
|
|
|
10,
|
|
|
|
{0, 0},
|
|
|
|
1,
|
|
|
|
' '};
|
|
|
|
|
|
|
|
NumberField field_end{
|
|
|
|
{9 * 8, 7 * 16},
|
|
|
|
10,
|
|
|
|
{0, 0},
|
|
|
|
1,
|
|
|
|
' '};
|
|
|
|
|
|
|
|
Text text_samples{
|
|
|
|
{9 * 8, 8 * 16, 10 * 8, 1 * 16},
|
|
|
|
"0"};
|
|
|
|
|
|
|
|
Text text_max{
|
2023-10-19 14:14:25 -04:00
|
|
|
{9 * 8, 9 * 16, 20 * 8, 1 * 16},
|
2023-09-23 15:56:37 -04:00
|
|
|
"0"};
|
|
|
|
|
|
|
|
NumberField field_cutoff{
|
|
|
|
{9 * 8, 10 * 16},
|
|
|
|
3,
|
|
|
|
{1, 100},
|
|
|
|
1,
|
|
|
|
' '};
|
2023-09-21 11:43:10 -04:00
|
|
|
|
2023-10-19 14:14:25 -04:00
|
|
|
NumberField field_amplify{
|
|
|
|
{9 * 8, 12 * 16},
|
|
|
|
1,
|
|
|
|
{1, 9},
|
|
|
|
1,
|
|
|
|
' '};
|
|
|
|
|
2023-09-21 11:43:10 -04:00
|
|
|
Button button_trim{
|
2023-09-23 15:56:37 -04:00
|
|
|
{20 * 8, 16 * 16, 8 * 8, 2 * 16},
|
2023-09-21 11:43:10 -04:00
|
|
|
"Trim"};
|
|
|
|
};
|
|
|
|
|
|
|
|
} /* namespace ui */
|
|
|
|
|
|
|
|
#endif /*__UI_IQ_TRIM_H__*/
|