2023-05-14 17:09:43 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2023 Bernd Herzog
|
|
|
|
*
|
|
|
|
* This file is part of PortaPack.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ui_spectrum_painter.hpp"
|
2023-07-17 14:43:37 -04:00
|
|
|
|
2023-05-14 17:09:43 -04:00
|
|
|
#include "bmp.hpp"
|
|
|
|
#include "baseband_api.hpp"
|
|
|
|
#include "file.hpp"
|
2023-07-17 14:43:37 -04:00
|
|
|
#include "io_file.hpp"
|
2023-05-14 17:09:43 -04:00
|
|
|
#include "portapack_persistent_memory.hpp"
|
2023-07-17 14:43:37 -04:00
|
|
|
#include "ui_fileman.hpp"
|
|
|
|
#include "ui_freqman.hpp"
|
2023-05-14 17:09:43 -04:00
|
|
|
|
2023-06-11 14:47:13 -04:00
|
|
|
using namespace portapack;
|
|
|
|
|
2023-05-14 17:09:43 -04:00
|
|
|
namespace ui {
|
|
|
|
|
|
|
|
SpectrumPainterView::SpectrumPainterView(
|
2023-05-18 16:16:05 -04:00
|
|
|
NavigationView& nav)
|
|
|
|
: nav_(nav) {
|
2023-06-11 14:47:13 -04:00
|
|
|
baseband::run_image(spi_flash::image_tag_spectrum_painter);
|
2023-05-18 16:16:05 -04:00
|
|
|
|
|
|
|
add_children({
|
|
|
|
&labels,
|
|
|
|
&tab_view,
|
|
|
|
&input_image,
|
|
|
|
&input_text,
|
|
|
|
&progressbar,
|
|
|
|
&field_frequency,
|
|
|
|
&field_rfgain,
|
|
|
|
&field_rfamp,
|
|
|
|
&check_loop,
|
|
|
|
&button_play,
|
|
|
|
&option_bandwidth,
|
|
|
|
&field_duration,
|
|
|
|
&field_pause,
|
|
|
|
});
|
|
|
|
|
|
|
|
Rect view_rect = {0, 3 * 8, 240, 80};
|
|
|
|
input_image.set_parent_rect(view_rect);
|
|
|
|
input_text.set_parent_rect(view_rect);
|
|
|
|
|
2023-06-25 05:33:44 -04:00
|
|
|
freqman_set_bandwidth_option(SPEC_MODULATION, option_bandwidth);
|
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
field_frequency.set_step(5000);
|
|
|
|
|
2023-06-11 14:47:13 -04:00
|
|
|
tx_gain = transmitter_model.tx_gain();
|
2023-05-18 16:16:05 -04:00
|
|
|
field_rfgain.set_value(tx_gain); // Initial default value (-12 dB's max ).
|
|
|
|
field_rfgain.on_change = [this](int32_t v) { // allow initial value change just after opened file.
|
|
|
|
tx_gain = v;
|
2023-06-11 14:47:13 -04:00
|
|
|
transmitter_model.set_tx_gain(tx_gain);
|
2023-05-18 16:16:05 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
field_rfamp.set_value(rf_amp ? 14 : 0); // Initial default value True. (TX RF amp on , +14dB's)
|
|
|
|
field_rfamp.on_change = [this](int32_t v) { // allow initial value change just after opened file.
|
|
|
|
rf_amp = (bool)v;
|
2023-06-11 14:47:13 -04:00
|
|
|
transmitter_model.set_rf_amp(rf_amp);
|
2023-05-18 16:16:05 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
input_image.on_input_avaliable = [this]() {
|
|
|
|
image_input_avaliable = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
button_play.on_select = [this](ImageButton&) {
|
|
|
|
if (tx_active == false) {
|
|
|
|
tx_mode = tab_view.selected();
|
|
|
|
|
|
|
|
if (tx_mode == 0 && image_input_avaliable == false)
|
|
|
|
return;
|
|
|
|
|
2023-06-11 14:47:13 -04:00
|
|
|
transmitter_model.enable();
|
2023-05-18 16:16:05 -04:00
|
|
|
|
2023-06-11 14:47:13 -04:00
|
|
|
if (persistent_memory::stealth_mode()) {
|
2023-05-18 16:16:05 -04:00
|
|
|
DisplaySleepMessage message;
|
|
|
|
EventDispatcher::send_message(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
button_play.set_bitmap(&bitmap_stop);
|
|
|
|
|
|
|
|
if (tx_mode == 0) {
|
|
|
|
tx_current_max_lines = input_image.get_height();
|
|
|
|
tx_current_width = input_image.get_width();
|
|
|
|
} else {
|
|
|
|
tx_current_max_lines = input_text.get_height();
|
|
|
|
tx_current_width = input_text.get_width();
|
|
|
|
}
|
|
|
|
|
|
|
|
progressbar.set_max(tx_current_max_lines);
|
|
|
|
progressbar.set_value(0);
|
|
|
|
|
|
|
|
baseband::set_spectrum_painter_config(tx_current_width, tx_current_max_lines, false, option_bandwidth.selected_index_value());
|
|
|
|
} else {
|
|
|
|
stop_tx();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
option_bandwidth.on_change = [this](size_t, ui::OptionsField::value_t value) {
|
|
|
|
baseband::set_spectrum_painter_config(tx_current_width, tx_current_max_lines, true, value);
|
|
|
|
};
|
|
|
|
|
|
|
|
field_duration.set_value(10);
|
|
|
|
field_pause.set_value(5);
|
2023-05-14 17:09:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void SpectrumPainterView::start_tx() {
|
2023-05-18 16:16:05 -04:00
|
|
|
tx_current_line = 0;
|
|
|
|
tx_active = true;
|
|
|
|
tx_timestamp_start = chTimeNow();
|
2023-05-14 17:09:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void SpectrumPainterView::stop_tx() {
|
2023-05-18 16:16:05 -04:00
|
|
|
button_play.set_bitmap(&bitmap_play);
|
2023-06-11 14:47:13 -04:00
|
|
|
transmitter_model.disable();
|
2023-05-18 16:16:05 -04:00
|
|
|
tx_active = false;
|
|
|
|
tx_current_line = 0;
|
2023-05-14 17:09:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void SpectrumPainterView::frame_sync() {
|
2023-05-18 16:16:05 -04:00
|
|
|
if (tx_active) {
|
|
|
|
if (fifo->is_empty()) {
|
|
|
|
int32_t sequence_duration = (field_duration.value() + (check_loop.value() ? field_pause.value() : 0)) * 1000;
|
|
|
|
int32_t sequence_time = tx_time_elapsed() % sequence_duration;
|
|
|
|
bool is_pausing = sequence_time > field_duration.value() * 1000;
|
|
|
|
|
|
|
|
if (is_pausing) {
|
|
|
|
fifo->in(std::vector<uint8_t>(tx_current_width));
|
|
|
|
} else {
|
|
|
|
auto current_time_line = sequence_time * tx_current_max_lines / (field_duration.value() * 1000);
|
|
|
|
|
|
|
|
if (tx_current_line > current_time_line && !check_loop.value()) {
|
|
|
|
fifo->in(std::vector<uint8_t>(tx_current_width));
|
|
|
|
stop_tx();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
tx_current_line = current_time_line;
|
|
|
|
progressbar.set_value(current_time_line);
|
|
|
|
|
|
|
|
if (tx_mode == 0) {
|
|
|
|
std::vector<uint8_t> line = input_image.get_line(current_time_line);
|
|
|
|
fifo->in(line);
|
|
|
|
} else {
|
|
|
|
std::vector<uint8_t> line = input_text.get_line(current_time_line);
|
|
|
|
fifo->in(line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-05-14 17:09:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
SpectrumPainterView::~SpectrumPainterView() {
|
2023-06-11 14:47:13 -04:00
|
|
|
transmitter_model.disable();
|
2023-05-18 16:16:05 -04:00
|
|
|
baseband::shutdown();
|
2023-05-14 17:09:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void SpectrumPainterView::focus() {
|
2023-05-18 16:16:05 -04:00
|
|
|
tab_view.focus();
|
2023-05-14 17:09:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void SpectrumPainterView::paint(Painter& painter) {
|
2023-05-18 16:16:05 -04:00
|
|
|
View::paint(painter);
|
|
|
|
|
|
|
|
size_t c;
|
|
|
|
Point pos = {0, screen_pos().y() + 8 + footer_location};
|
|
|
|
|
|
|
|
for (c = 0; c < 20; c++) {
|
|
|
|
painter.draw_bitmap(
|
|
|
|
pos,
|
|
|
|
bitmap_stripes,
|
|
|
|
ui::Color(191, 191, 0),
|
|
|
|
ui::Color::black());
|
|
|
|
if (c != 9)
|
|
|
|
pos += {24, 0};
|
|
|
|
else
|
|
|
|
pos = {0, screen_pos().y() + 8 + footer_location + 32 + 8};
|
|
|
|
}
|
2023-05-14 17:09:43 -04:00
|
|
|
}
|
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
} // namespace ui
|