2015-09-04 18:37:27 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
2016-08-02 10:44:31 +00:00
|
|
|
* Copyright (C) 2016 Furrtek
|
2015-09-04 18:37:27 +00: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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ui_afsksetup.hpp"
|
|
|
|
#include "ui_receiver.hpp"
|
|
|
|
|
|
|
|
#include "ch.h"
|
|
|
|
|
|
|
|
#include "portapack.hpp"
|
2016-02-05 16:40:14 +00:00
|
|
|
#include "string_format.hpp"
|
2015-09-04 18:37:27 +00:00
|
|
|
|
|
|
|
#include "portapack_shared_memory.hpp"
|
|
|
|
#include "portapack_persistent_memory.hpp"
|
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2016-02-05 16:40:14 +00:00
|
|
|
using namespace portapack;
|
2016-08-02 10:44:31 +00:00
|
|
|
using namespace afsk;
|
2015-09-04 18:37:27 +00:00
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
|
|
|
|
void AFSKSetupView::focus() {
|
|
|
|
button_setfreq.focus();
|
|
|
|
}
|
|
|
|
|
2016-08-02 10:44:31 +00:00
|
|
|
void AFSKSetupView::update_freq(rf::Frequency f) {
|
2015-09-04 18:37:27 +00:00
|
|
|
char finalstr[9] = {0};
|
|
|
|
|
2015-11-18 21:01:48 +00:00
|
|
|
portapack::persistent_memory::set_tuned_frequency(f);
|
2015-09-04 18:37:27 +00:00
|
|
|
|
|
|
|
auto mhz = to_string_dec_int(f / 1000000, 3);
|
|
|
|
auto hz100 = to_string_dec_int((f / 100) % 10000, 4, '0');
|
|
|
|
|
|
|
|
strcat(finalstr, mhz.c_str());
|
|
|
|
strcat(finalstr, ".");
|
|
|
|
strcat(finalstr, hz100.c_str());
|
|
|
|
|
|
|
|
this->button_setfreq.set_text(finalstr);
|
|
|
|
}
|
|
|
|
|
|
|
|
AFSKSetupView::AFSKSetupView(
|
2016-02-04 09:27:53 +00:00
|
|
|
NavigationView& nav
|
|
|
|
)
|
2015-09-04 18:37:27 +00:00
|
|
|
{
|
2016-08-02 10:44:31 +00:00
|
|
|
using name_t = std::string;
|
|
|
|
using value_t = int32_t;
|
|
|
|
using option_t = std::pair<name_t, value_t>;
|
|
|
|
using options_t = std::vector<option_t>;
|
|
|
|
options_t format_options;
|
2015-09-16 13:43:43 +00:00
|
|
|
uint8_t rpt;
|
2016-08-02 10:44:31 +00:00
|
|
|
size_t i;
|
2015-09-04 18:37:27 +00:00
|
|
|
|
|
|
|
add_children({ {
|
2016-08-02 10:44:31 +00:00
|
|
|
&text_setfreq,
|
2015-09-04 18:37:27 +00:00
|
|
|
&button_setfreq,
|
2016-08-02 10:44:31 +00:00
|
|
|
&text_bps,
|
|
|
|
&options_bps,
|
2015-09-04 18:37:27 +00:00
|
|
|
&text_mark,
|
|
|
|
&field_mark,
|
|
|
|
&text_space,
|
|
|
|
&field_space,
|
2015-09-16 13:43:43 +00:00
|
|
|
&text_bw,
|
|
|
|
&field_bw,
|
2016-07-27 22:08:05 +00:00
|
|
|
&text_repeat,
|
|
|
|
&field_repeat,
|
2016-08-02 10:44:31 +00:00
|
|
|
&text_format,
|
|
|
|
&options_format,
|
|
|
|
&button_save
|
2015-09-04 18:37:27 +00:00
|
|
|
} });
|
|
|
|
|
2016-08-02 10:44:31 +00:00
|
|
|
for (i = 0; i < AFSK_MODES_COUNT; i++)
|
|
|
|
format_options.emplace_back(std::make_pair(afsk_formats[i].fullname, i));
|
|
|
|
|
|
|
|
options_format.set_options(format_options);
|
|
|
|
options_format.set_selected_index(portapack::persistent_memory::afsk_format());
|
2015-09-05 18:17:43 +00:00
|
|
|
|
2016-08-02 10:44:31 +00:00
|
|
|
update_freq(portapack::persistent_memory::tuned_frequency());
|
2015-09-04 18:37:27 +00:00
|
|
|
|
2016-08-02 10:44:31 +00:00
|
|
|
field_mark.set_value(portapack::persistent_memory::afsk_mark_freq() * 25);
|
|
|
|
field_space.set_value(portapack::persistent_memory::afsk_space_freq() * 25);
|
2015-11-18 21:01:48 +00:00
|
|
|
field_bw.set_value(portapack::persistent_memory::afsk_bw());
|
2016-08-02 10:44:31 +00:00
|
|
|
rpt = portapack::persistent_memory::afsk_repeats();
|
|
|
|
if ((rpt > 99) || (!rpt)) rpt = 5;
|
2015-09-16 13:43:43 +00:00
|
|
|
field_repeat.set_value(rpt);
|
|
|
|
|
2016-08-02 10:44:31 +00:00
|
|
|
button_setfreq.on_select = [this,&nav](Button&) {
|
2016-07-27 01:03:40 +00:00
|
|
|
auto new_view = nav.push<FrequencyKeypadView>(portapack::persistent_memory::tuned_frequency());
|
2015-09-04 18:37:27 +00:00
|
|
|
new_view->on_changed = [this](rf::Frequency f) {
|
2016-08-02 10:44:31 +00:00
|
|
|
update_freq(f);
|
2015-09-04 18:37:27 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2016-08-02 10:44:31 +00:00
|
|
|
options_bps.set_by_value(portapack::persistent_memory::afsk_bitrate());
|
2015-09-04 18:37:27 +00:00
|
|
|
|
2016-08-02 10:44:31 +00:00
|
|
|
button_save.on_select = [this,&nav](Button&) {
|
2015-09-16 13:43:43 +00:00
|
|
|
uint32_t afsk_config = 0;
|
2015-09-05 18:17:43 +00:00
|
|
|
|
2016-08-02 10:44:31 +00:00
|
|
|
portapack::persistent_memory::set_afsk_bitrate(options_bps.selected_index_value());
|
|
|
|
portapack::persistent_memory::set_afsk_mark(field_mark.value() / 25);
|
|
|
|
portapack::persistent_memory::set_afsk_space(field_space.value() / 25);
|
2015-11-18 21:01:48 +00:00
|
|
|
portapack::persistent_memory::set_afsk_bw(field_bw.value());
|
2015-09-05 18:17:43 +00:00
|
|
|
|
2016-08-02 10:44:31 +00:00
|
|
|
afsk_config |= (options_format.selected_index() << 16);
|
|
|
|
afsk_config |= (field_repeat.value() << 24);
|
2015-11-18 21:01:48 +00:00
|
|
|
portapack::persistent_memory::set_afsk_config(afsk_config);
|
2015-09-05 18:17:43 +00:00
|
|
|
|
2015-09-04 18:37:27 +00:00
|
|
|
nav.pop();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace ui */
|