2015-07-08 11:39:24 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
|
|
|
*
|
|
|
|
* 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_receiver.hpp"
|
2016-12-06 07:31:38 -05:00
|
|
|
#include "ui_freqman.hpp"
|
2015-07-08 11:39:24 -04:00
|
|
|
|
2015-08-01 16:42:27 -04:00
|
|
|
#include "portapack.hpp"
|
|
|
|
using namespace portapack;
|
2015-07-08 11:39:24 -04:00
|
|
|
|
2015-12-02 16:38:17 -05:00
|
|
|
#include "string_format.hpp"
|
|
|
|
|
2016-01-31 12:13:44 -05:00
|
|
|
#include "max2837.hpp"
|
2015-11-10 18:31:46 -05:00
|
|
|
|
2015-07-08 11:39:24 -04:00
|
|
|
namespace ui {
|
|
|
|
|
|
|
|
/* FrequencyField ********************************************************/
|
|
|
|
|
|
|
|
FrequencyField::FrequencyField(
|
|
|
|
const Point parent_pos
|
|
|
|
) : Widget { { parent_pos, { 8 * 10, 16 } } },
|
|
|
|
length_ { 11 },
|
|
|
|
range(rf::tuning_range)
|
|
|
|
{
|
2016-02-07 13:32:38 -05:00
|
|
|
set_focusable(true);
|
2015-07-08 11:39:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
rf::Frequency FrequencyField::value() const {
|
|
|
|
return value_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FrequencyField::set_value(rf::Frequency new_value) {
|
|
|
|
new_value = clamp_value(new_value);
|
|
|
|
|
|
|
|
if( new_value != value_ ) {
|
|
|
|
value_ = new_value;
|
|
|
|
if( on_change ) {
|
|
|
|
on_change(value_);
|
|
|
|
}
|
|
|
|
set_dirty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FrequencyField::set_step(rf::Frequency new_value) {
|
|
|
|
step = new_value;
|
|
|
|
// TODO: Quantize current frequency to a step of the new size?
|
|
|
|
}
|
|
|
|
|
|
|
|
void FrequencyField::paint(Painter& painter) {
|
|
|
|
const auto mhz = to_string_dec_int(value_ / 1000000, 4);
|
|
|
|
const auto hz100 = to_string_dec_int((value_ / 100) % 10000, 4, '0');
|
|
|
|
|
|
|
|
const auto paint_style = has_focus() ? style().invert() : style();
|
|
|
|
|
|
|
|
painter.draw_string(
|
|
|
|
screen_pos(),
|
|
|
|
paint_style,
|
|
|
|
mhz
|
|
|
|
);
|
|
|
|
painter.draw_string(
|
|
|
|
screen_pos() + Point { 4 * 8, 0 },
|
|
|
|
paint_style,
|
|
|
|
"."
|
|
|
|
);
|
|
|
|
painter.draw_string(
|
|
|
|
screen_pos() + Point { 5 * 8, 0 },
|
|
|
|
paint_style,
|
|
|
|
hz100
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FrequencyField::on_key(const ui::KeyEvent event) {
|
|
|
|
if( event == ui::KeyEvent::Select ) {
|
|
|
|
if( on_edit ) {
|
|
|
|
on_edit();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FrequencyField::on_encoder(const EncoderEvent delta) {
|
|
|
|
set_value(value() + (delta * step));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FrequencyField::on_touch(const TouchEvent event) {
|
|
|
|
if( event.type == TouchEvent::Type::Start ) {
|
|
|
|
focus();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FrequencyField::on_focus() {
|
|
|
|
if( on_show_options ) {
|
|
|
|
on_show_options();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rf::Frequency FrequencyField::clamp_value(rf::Frequency value) {
|
2016-01-27 17:46:45 -05:00
|
|
|
return range.clip(value);
|
2015-07-08 11:39:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* FrequencyKeypadView ***************************************************/
|
|
|
|
|
|
|
|
FrequencyKeypadView::FrequencyKeypadView(
|
|
|
|
NavigationView& nav,
|
|
|
|
const rf::Frequency value
|
|
|
|
) {
|
|
|
|
add_child(&text_value);
|
|
|
|
|
|
|
|
const auto button_fn = [this](Button& button) {
|
|
|
|
this->on_button(button);
|
|
|
|
};
|
|
|
|
|
|
|
|
const char* const key_caps = "123456789<0.";
|
|
|
|
|
2016-01-23 20:53:16 -05:00
|
|
|
int n = 0;
|
2015-07-08 11:39:24 -04:00
|
|
|
for(auto& button : buttons) {
|
|
|
|
add_child(&button);
|
|
|
|
const std::string label {
|
|
|
|
key_caps[n]
|
|
|
|
};
|
|
|
|
button.on_select = button_fn;
|
|
|
|
button.set_parent_rect({
|
2016-01-23 20:02:16 -05:00
|
|
|
(n % 3) * button_w,
|
2016-12-06 07:31:38 -05:00
|
|
|
(n / 3) * button_h + 24,
|
2015-07-08 11:39:24 -04:00
|
|
|
button_w, button_h
|
|
|
|
});
|
|
|
|
button.set_text(label);
|
|
|
|
n++;
|
|
|
|
}
|
2016-12-06 07:31:38 -05:00
|
|
|
|
|
|
|
add_children({ {
|
|
|
|
&button_save,
|
|
|
|
&button_close
|
|
|
|
} });
|
|
|
|
|
|
|
|
button_save.on_select = [this, &nav](Button&) {
|
|
|
|
nav.push<FrequencySaveView>(this->value());
|
|
|
|
};
|
2015-07-08 11:39:24 -04:00
|
|
|
|
|
|
|
button_close.on_select = [this, &nav](Button&) {
|
|
|
|
if( on_changed ) {
|
|
|
|
on_changed(this->value());
|
|
|
|
}
|
|
|
|
nav.pop();
|
|
|
|
};
|
|
|
|
|
|
|
|
set_value(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FrequencyKeypadView::focus() {
|
|
|
|
button_close.focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
rf::Frequency FrequencyKeypadView::value() const {
|
|
|
|
return mhz.as_int() * 1000000ULL + submhz.as_int() * submhz_base;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FrequencyKeypadView::set_value(const rf::Frequency new_value) {
|
|
|
|
mhz.set(new_value / 1000000);
|
|
|
|
mhz.remove_leading_zeros();
|
|
|
|
|
|
|
|
submhz.set((new_value % 1000000) / submhz_base);
|
|
|
|
submhz.remove_trailing_zeros();
|
|
|
|
|
|
|
|
update_text();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FrequencyKeypadView::on_button(Button& button) {
|
|
|
|
const auto s = button.text();
|
|
|
|
if( s == "." ) {
|
|
|
|
field_toggle();
|
|
|
|
} else if( s == "<" ) {
|
|
|
|
digit_delete();
|
|
|
|
} else {
|
|
|
|
digit_add(s[0]);
|
|
|
|
}
|
|
|
|
update_text();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FrequencyKeypadView::digit_add(const char c) {
|
|
|
|
if( state == State::DigitMHz ) {
|
|
|
|
if( clear_field_if_digits_entered ) {
|
|
|
|
mhz.clear();
|
|
|
|
}
|
|
|
|
mhz.add_digit(c);
|
|
|
|
} else {
|
|
|
|
submhz.add_digit(c);
|
|
|
|
}
|
|
|
|
clear_field_if_digits_entered = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FrequencyKeypadView::digit_delete() {
|
|
|
|
if( state == State::DigitMHz ) {
|
|
|
|
mhz.delete_digit();
|
|
|
|
} else {
|
|
|
|
submhz.delete_digit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FrequencyKeypadView::field_toggle() {
|
|
|
|
if( state == State::DigitMHz ) {
|
|
|
|
state = State::DigitSubMHz;
|
|
|
|
submhz.clear();
|
|
|
|
} else {
|
|
|
|
state = State::DigitMHz;
|
|
|
|
clear_field_if_digits_entered = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FrequencyKeypadView::update_text() {
|
|
|
|
const auto s = mhz.as_string() + "." + submhz.as_string();
|
|
|
|
text_value.set(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FrequencyOptionsView **************************************************/
|
|
|
|
|
|
|
|
FrequencyOptionsView::FrequencyOptionsView(
|
|
|
|
const Rect parent_rect,
|
|
|
|
const Style* const style
|
|
|
|
) : View { parent_rect }
|
|
|
|
{
|
|
|
|
set_style(style);
|
|
|
|
|
2016-07-19 13:47:15 -04:00
|
|
|
field_step.on_change = [this](size_t n, OptionsField::value_t v) {
|
2015-07-08 11:39:24 -04:00
|
|
|
(void)n;
|
|
|
|
this->on_step_changed(v);
|
|
|
|
};
|
|
|
|
|
2015-07-29 19:09:00 -04:00
|
|
|
field_ppm.on_change = [this](int32_t v) {
|
|
|
|
this->on_reference_ppm_correction_changed(v);
|
|
|
|
};
|
|
|
|
|
2015-07-08 11:39:24 -04:00
|
|
|
add_children({ {
|
|
|
|
&text_step,
|
2016-07-19 13:47:15 -04:00
|
|
|
&field_step,
|
2015-07-26 17:32:37 -04:00
|
|
|
&field_ppm,
|
|
|
|
&text_ppm,
|
2015-07-08 11:39:24 -04:00
|
|
|
} });
|
|
|
|
}
|
|
|
|
|
|
|
|
void FrequencyOptionsView::set_step(rf::Frequency f) {
|
2016-07-19 13:47:15 -04:00
|
|
|
field_step.set_by_value(f);
|
2015-07-08 11:39:24 -04:00
|
|
|
}
|
|
|
|
|
2015-07-29 19:09:00 -04:00
|
|
|
void FrequencyOptionsView::set_reference_ppm_correction(int32_t v) {
|
|
|
|
field_ppm.set_value(v);
|
|
|
|
}
|
2015-07-08 11:39:24 -04:00
|
|
|
|
|
|
|
void FrequencyOptionsView::on_step_changed(rf::Frequency v) {
|
|
|
|
if( on_change_step ) {
|
|
|
|
on_change_step(v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-29 19:09:00 -04:00
|
|
|
void FrequencyOptionsView::on_reference_ppm_correction_changed(int32_t v) {
|
|
|
|
if( on_change_reference_ppm_correction ) {
|
|
|
|
on_change_reference_ppm_correction(v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-06 13:13:36 -04:00
|
|
|
/* RFAmpField ************************************************************/
|
|
|
|
|
|
|
|
RFAmpField::RFAmpField(
|
|
|
|
Point parent_pos
|
|
|
|
) : NumberField {
|
|
|
|
parent_pos,
|
|
|
|
1,
|
|
|
|
{ 0, 1 },
|
|
|
|
1,
|
|
|
|
' ',
|
|
|
|
}
|
|
|
|
{
|
|
|
|
set_value(receiver_model.rf_amp());
|
|
|
|
|
|
|
|
on_change = [](int32_t v) {
|
|
|
|
receiver_model.set_rf_amp(v);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2015-07-08 11:39:24 -04:00
|
|
|
/* RadioGainOptionsView **************************************************/
|
|
|
|
|
|
|
|
RadioGainOptionsView::RadioGainOptionsView(
|
|
|
|
const Rect parent_rect,
|
|
|
|
const Style* const style
|
|
|
|
) : View { parent_rect }
|
|
|
|
{
|
|
|
|
set_style(style);
|
|
|
|
|
|
|
|
add_children({ {
|
|
|
|
&label_rf_amp,
|
|
|
|
&field_rf_amp,
|
|
|
|
} });
|
|
|
|
}
|
|
|
|
|
|
|
|
/* LNAGainField **********************************************************/
|
|
|
|
|
|
|
|
LNAGainField::LNAGainField(
|
|
|
|
Point parent_pos
|
|
|
|
) : NumberField {
|
2015-12-17 13:30:40 -05:00
|
|
|
parent_pos, 2,
|
2016-01-27 17:55:03 -05:00
|
|
|
{ max2837::lna::gain_db_range.minimum, max2837::lna::gain_db_range.maximum },
|
2015-07-08 11:39:24 -04:00
|
|
|
max2837::lna::gain_db_step,
|
|
|
|
' ',
|
|
|
|
}
|
|
|
|
{
|
2016-06-06 13:27:33 -04:00
|
|
|
set_value(receiver_model.lna());
|
|
|
|
|
|
|
|
on_change = [](int32_t v) {
|
|
|
|
receiver_model.set_lna(v);
|
|
|
|
};
|
2015-07-08 11:39:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void LNAGainField::on_focus() {
|
|
|
|
//Widget::on_focus();
|
|
|
|
if( on_show_options ) {
|
|
|
|
on_show_options();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-12 13:48:24 -04:00
|
|
|
/* VGAGainField **********************************************************/
|
|
|
|
|
|
|
|
VGAGainField::VGAGainField(
|
|
|
|
Point parent_pos
|
|
|
|
) : NumberField {
|
|
|
|
parent_pos, 2,
|
|
|
|
{ max2837::vga::gain_db_range.minimum, max2837::vga::gain_db_range.maximum },
|
|
|
|
max2837::vga::gain_db_step,
|
|
|
|
' ',
|
|
|
|
}
|
|
|
|
{
|
2016-06-06 13:27:33 -04:00
|
|
|
set_value(receiver_model.vga());
|
|
|
|
|
|
|
|
on_change = [](int32_t v) {
|
|
|
|
receiver_model.set_vga(v);
|
|
|
|
};
|
2016-04-12 13:48:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void VGAGainField::on_focus() {
|
|
|
|
//Widget::on_focus();
|
|
|
|
if( on_show_options ) {
|
|
|
|
on_show_options();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-08 11:39:24 -04:00
|
|
|
} /* namespace ui */
|