2017-01-30 13:10:30 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
|
|
|
* Copyright (C) 2016 Furrtek
|
|
|
|
*
|
|
|
|
* 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_transmitter.hpp"
|
|
|
|
|
2017-04-07 05:20:24 +00:00
|
|
|
#include "audio.hpp"
|
|
|
|
#include "baseband_api.hpp"
|
2017-01-30 13:10:30 +00:00
|
|
|
#include "portapack.hpp"
|
|
|
|
using namespace portapack;
|
|
|
|
|
|
|
|
#include "string_format.hpp"
|
|
|
|
|
|
|
|
#include "max2837.hpp"
|
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
|
|
|
|
/* TransmitterView *******************************************************/
|
|
|
|
|
2017-02-07 22:12:20 +00:00
|
|
|
void TransmitterView::paint(Painter& painter) {
|
|
|
|
size_t c;
|
|
|
|
Point pos = { 0, screen_pos().y() };
|
|
|
|
|
|
|
|
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() + 32 + 8 };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-30 13:10:30 +00:00
|
|
|
void TransmitterView::on_tuning_frequency_changed(rf::Frequency f) {
|
2017-08-27 21:06:11 +00:00
|
|
|
transmitter_model.set_tuning_frequency(f);
|
2017-01-30 13:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-08-12 18:28:57 +00:00
|
|
|
void TransmitterView::on_channel_bandwidth_changed(uint32_t channel_bandwidth) {
|
|
|
|
transmitter_model.set_channel_bandwidth(channel_bandwidth);
|
2017-01-30 13:10:30 +00:00
|
|
|
}
|
|
|
|
|
2020-04-16 21:58:06 +00:00
|
|
|
void TransmitterView::on_tx_gain_changed(int32_t tx_gain) {
|
|
|
|
transmitter_model.set_tx_gain(tx_gain);
|
|
|
|
update_gainlevel_styles();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransmitterView::on_tx_amp_changed(bool rf_amp) {
|
|
|
|
transmitter_model.set_rf_amp(rf_amp);
|
|
|
|
update_gainlevel_styles();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransmitterView::update_gainlevel_styles() {
|
|
|
|
const Style *new_style_ptr = NULL;
|
|
|
|
int8_t tot_gain = transmitter_model.tx_gain() + (transmitter_model.rf_amp() ? 14 : 0);
|
|
|
|
|
|
|
|
if(tot_gain > POWER_THRESHOLD_HIGH) {
|
|
|
|
new_style_ptr = &style_power_high;
|
|
|
|
} else if(tot_gain > POWER_THRESHOLD_MED) {
|
|
|
|
new_style_ptr = &style_power_med;
|
|
|
|
} else if(tot_gain > POWER_THRESHOLD_LOW) {
|
|
|
|
new_style_ptr = &style_power_low;
|
|
|
|
}
|
|
|
|
|
|
|
|
field_gain.set_style(new_style_ptr);
|
|
|
|
text_gain.set_style(new_style_ptr);
|
|
|
|
field_amp.set_style(new_style_ptr);
|
|
|
|
text_amp.set_style(new_style_ptr);
|
|
|
|
}
|
|
|
|
|
2017-01-30 13:10:30 +00:00
|
|
|
void TransmitterView::set_transmitting(const bool transmitting) {
|
|
|
|
if (transmitting) {
|
|
|
|
button_start.set_text("STOP");
|
|
|
|
button_start.set_style(&style_stop);
|
|
|
|
} else {
|
|
|
|
button_start.set_text("START");
|
|
|
|
button_start.set_style(&style_start);
|
|
|
|
}
|
|
|
|
|
|
|
|
transmitting_ = transmitting;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransmitterView::on_show() {
|
2017-08-27 21:06:11 +00:00
|
|
|
field_frequency.set_value(transmitter_model.tuning_frequency());
|
2021-05-14 19:57:25 +00:00
|
|
|
field_frequency_step.set_by_value(receiver_model.frequency_step());
|
2020-04-16 21:58:06 +00:00
|
|
|
|
|
|
|
field_gain.set_value(transmitter_model.tx_gain());
|
|
|
|
field_amp.set_value(transmitter_model.rf_amp() ? 14 : 0);
|
|
|
|
|
|
|
|
update_gainlevel_styles();
|
2017-01-30 13:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-02-07 17:48:17 +00:00
|
|
|
void TransmitterView::focus() {
|
|
|
|
button_start.focus();
|
|
|
|
}
|
|
|
|
|
2017-01-30 13:10:30 +00:00
|
|
|
TransmitterView::TransmitterView(
|
2017-08-12 18:28:57 +00:00
|
|
|
const Coord y, const uint64_t frequency_step, const uint32_t channel_bandwidth, const bool lock
|
2017-02-12 04:05:21 +00:00
|
|
|
) : lock_ { lock }
|
|
|
|
{
|
2017-07-30 08:39:01 +00:00
|
|
|
set_parent_rect({ 0, y, 30 * 8, 6 * 8 });
|
2017-01-30 13:10:30 +00:00
|
|
|
|
|
|
|
add_children({
|
|
|
|
&field_frequency,
|
2021-05-14 19:57:25 +00:00
|
|
|
&field_frequency_step,
|
2017-02-12 04:05:21 +00:00
|
|
|
&text_gain,
|
2017-01-30 13:10:30 +00:00
|
|
|
&field_gain,
|
2020-04-16 21:58:06 +00:00
|
|
|
&button_start,
|
|
|
|
&text_amp,
|
|
|
|
&field_amp,
|
2017-01-30 13:10:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
set_transmitting(false);
|
2017-02-12 04:05:21 +00:00
|
|
|
|
|
|
|
if (lock_) {
|
|
|
|
field_frequency.set_focusable(false);
|
|
|
|
field_frequency.set_style(&style_locked);
|
|
|
|
} else {
|
2017-08-12 18:28:57 +00:00
|
|
|
if (channel_bandwidth) {
|
2017-07-30 08:39:01 +00:00
|
|
|
add_children({
|
|
|
|
&text_bw,
|
|
|
|
&field_bw
|
|
|
|
});
|
|
|
|
|
2017-08-12 18:28:57 +00:00
|
|
|
field_bw.on_change = [this](int32_t v) {
|
|
|
|
on_channel_bandwidth_changed(v * 1000);
|
2017-07-30 08:39:01 +00:00
|
|
|
};
|
2017-08-12 18:28:57 +00:00
|
|
|
field_bw.set_value(channel_bandwidth);
|
2017-07-30 08:39:01 +00:00
|
|
|
}
|
2017-02-12 04:05:21 +00:00
|
|
|
}
|
2017-01-30 13:10:30 +00:00
|
|
|
|
2017-08-27 21:06:11 +00:00
|
|
|
//field_frequency.set_value(transmitter_model.tuning_frequency());
|
2017-01-30 13:10:30 +00:00
|
|
|
field_frequency.set_step(frequency_step);
|
|
|
|
field_frequency.on_change = [this](rf::Frequency f) {
|
2017-02-12 04:05:21 +00:00
|
|
|
on_tuning_frequency_changed(f);
|
2017-01-30 13:10:30 +00:00
|
|
|
};
|
|
|
|
field_frequency.on_edit = [this]() {
|
|
|
|
if (on_edit_frequency)
|
|
|
|
on_edit_frequency();
|
|
|
|
};
|
2021-05-14 19:57:25 +00:00
|
|
|
|
|
|
|
field_frequency_step.on_change = [this](size_t, OptionsField::value_t v) {
|
|
|
|
this->field_frequency.set_step(v);
|
|
|
|
};
|
2020-04-16 21:58:06 +00:00
|
|
|
|
|
|
|
field_gain.on_change = [this](uint32_t tx_gain) {
|
|
|
|
on_tx_gain_changed(tx_gain);
|
2017-02-15 03:05:38 +00:00
|
|
|
};
|
2017-01-30 13:10:30 +00:00
|
|
|
|
2020-04-16 21:58:06 +00:00
|
|
|
field_amp.on_change = [this](uint32_t rf_amp) {
|
|
|
|
on_tx_amp_changed((bool) rf_amp);
|
|
|
|
};
|
|
|
|
|
2017-01-30 13:10:30 +00:00
|
|
|
button_start.on_select = [this](Button&){
|
|
|
|
if (transmitting_) {
|
|
|
|
if (on_stop)
|
|
|
|
on_stop();
|
|
|
|
} else {
|
|
|
|
if (on_start)
|
|
|
|
on_start();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
TransmitterView::~TransmitterView() {
|
2017-04-07 05:20:24 +00:00
|
|
|
audio::output::stop();
|
2017-01-30 13:10:30 +00:00
|
|
|
transmitter_model.disable();
|
2017-04-07 05:20:24 +00:00
|
|
|
baseband::shutdown();
|
2017-01-30 13:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace ui */
|