2016-12-09 12:21:47 -05:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 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_bht_tx.hpp"
|
2017-09-21 04:18:17 -04:00
|
|
|
#include "string_format.hpp"
|
2016-12-09 12:21:47 -05:00
|
|
|
|
|
|
|
#include "baseband_api.hpp"
|
|
|
|
#include "portapack_persistent_memory.hpp"
|
|
|
|
|
|
|
|
using namespace portapack;
|
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
|
|
|
|
void BHTView::focus() {
|
2017-08-11 19:27:05 -04:00
|
|
|
tx_view.focus();
|
2016-12-09 12:21:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void BHTView::start_tx() {
|
2017-09-21 04:18:17 -04:00
|
|
|
baseband::shutdown();
|
2016-12-09 12:21:47 -05:00
|
|
|
|
2018-01-09 16:12:19 -05:00
|
|
|
transmitter_model.set_baseband_bandwidth(1750000);
|
|
|
|
|
|
|
|
if (target_system == XYLOS) {
|
2017-09-21 04:18:17 -04:00
|
|
|
|
|
|
|
baseband::run_image(portapack::spi_flash::image_tag_tones);
|
|
|
|
|
|
|
|
view_xylos.generate_message();
|
|
|
|
|
2018-01-09 16:12:19 -05:00
|
|
|
//if (tx_mode == SINGLE) {
|
|
|
|
progressbar.set_max(XY_TONE_COUNT);
|
|
|
|
/*} else if (tx_mode == SCAN) {
|
|
|
|
progressbar.set_max(XY_TONE_COUNT * view_xylos.get_scan_remaining());
|
|
|
|
}*/
|
2017-09-21 04:18:17 -04:00
|
|
|
|
|
|
|
transmitter_model.set_sampling_rate(TONES_SAMPLERATE);
|
|
|
|
transmitter_model.enable();
|
|
|
|
|
|
|
|
// Setup tones
|
|
|
|
for (size_t c = 0; c < ccir_deltas.size(); c++)
|
2018-01-09 16:12:19 -05:00
|
|
|
baseband::set_tone(c, ccir_deltas[c], XY_TONE_DURATION);
|
2017-09-21 04:18:17 -04:00
|
|
|
|
|
|
|
baseband::set_tones_config(transmitter_model.channel_bandwidth(), XY_SILENCE, XY_TONE_COUNT, false, false);
|
|
|
|
|
2018-01-09 16:12:19 -05:00
|
|
|
} else if (target_system == EPAR) {
|
2017-09-21 04:18:17 -04:00
|
|
|
|
|
|
|
baseband::run_image(portapack::spi_flash::image_tag_ook);
|
|
|
|
|
2018-01-09 16:12:19 -05:00
|
|
|
auto bitstream_length = view_EPAR.generate_message();
|
2017-09-21 04:18:17 -04:00
|
|
|
|
2018-01-09 16:12:19 -05:00
|
|
|
//if (tx_mode == SINGLE) {
|
|
|
|
progressbar.set_max(2 * EPAR_REPEAT_COUNT);
|
|
|
|
/*} else if (tx_mode == SCAN) {
|
|
|
|
progressbar.set_max(2 * EPAR_REPEAT_COUNT * view_EPAR.get_scan_remaining());
|
|
|
|
}*/
|
2017-09-21 04:18:17 -04:00
|
|
|
|
|
|
|
transmitter_model.set_sampling_rate(OOK_SAMPLERATE);
|
|
|
|
transmitter_model.enable();
|
|
|
|
|
|
|
|
baseband::set_ook_data(
|
|
|
|
bitstream_length,
|
2018-01-09 16:12:19 -05:00
|
|
|
EPAR_BIT_DURATION,
|
|
|
|
EPAR_REPEAT_COUNT,
|
2017-09-21 04:18:17 -04:00
|
|
|
encoder_defs[ENCODER_UM3750].pause_symbols
|
|
|
|
);
|
|
|
|
}
|
2016-12-09 12:21:47 -05:00
|
|
|
}
|
|
|
|
|
2018-01-09 16:12:19 -05:00
|
|
|
void BHTView::stop_tx() {
|
|
|
|
transmitter_model.disable();
|
|
|
|
baseband::shutdown();
|
|
|
|
tx_mode = IDLE;
|
|
|
|
tx_view.set_transmitting(false);
|
|
|
|
progressbar.set_value(0);
|
|
|
|
}
|
|
|
|
|
2017-09-24 15:05:42 -04:00
|
|
|
void BHTView::on_tx_progress(const uint32_t progress, const bool done) {
|
2018-01-09 16:12:19 -05:00
|
|
|
if (target_system == XYLOS) {
|
2016-12-09 12:21:47 -05:00
|
|
|
if (done) {
|
2018-01-09 16:12:19 -05:00
|
|
|
if (tx_mode == SINGLE) {
|
|
|
|
if (checkbox_cligno.value()) {
|
|
|
|
// TODO: Thread !
|
|
|
|
chThdSleepMilliseconds(field_tempo.value() * 1000); // Dirty :(
|
|
|
|
view_xylos.flip_relays();
|
|
|
|
start_tx();
|
|
|
|
} else
|
|
|
|
stop_tx();
|
|
|
|
} else if (tx_mode == SCAN) {
|
|
|
|
if (view_xylos.increment_address())
|
|
|
|
start_tx();
|
|
|
|
else
|
|
|
|
stop_tx(); // Reached end of scan range
|
2016-12-09 12:21:47 -05:00
|
|
|
}
|
2017-09-21 04:18:17 -04:00
|
|
|
} else
|
2016-12-09 12:21:47 -05:00
|
|
|
progressbar.set_value(progress);
|
2018-01-09 16:12:19 -05:00
|
|
|
} else if (target_system == EPAR) {
|
2017-09-21 04:18:17 -04:00
|
|
|
if (done) {
|
2018-01-09 16:12:19 -05:00
|
|
|
|
2017-09-21 04:18:17 -04:00
|
|
|
if (!view_EPAR.half) {
|
2018-01-09 16:12:19 -05:00
|
|
|
view_EPAR.half = true;
|
2017-09-21 04:18:17 -04:00
|
|
|
start_tx(); // Start second half of transmission
|
|
|
|
} else {
|
2018-01-09 16:12:19 -05:00
|
|
|
view_EPAR.half = false;
|
|
|
|
if (tx_mode == SINGLE) {
|
|
|
|
if (checkbox_cligno.value()) {
|
|
|
|
// TODO: Thread !
|
|
|
|
chThdSleepMilliseconds(field_tempo.value() * 1000); // Dirty :(
|
|
|
|
view_EPAR.flip_relays();
|
|
|
|
start_tx();
|
|
|
|
} else
|
|
|
|
stop_tx();
|
|
|
|
} else if (tx_mode == SCAN) {
|
|
|
|
if (view_EPAR.increment_address())
|
|
|
|
start_tx();
|
|
|
|
else
|
|
|
|
stop_tx(); // Reached end of scan range
|
2017-09-21 04:18:17 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else
|
2018-01-09 16:12:19 -05:00
|
|
|
progressbar.set_value(progress);
|
2017-09-21 04:18:17 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BHTView::~BHTView() {
|
|
|
|
transmitter_model.disable();
|
|
|
|
}
|
|
|
|
|
|
|
|
BHTView::BHTView(NavigationView& nav) {
|
|
|
|
add_children({
|
|
|
|
&tab_view,
|
|
|
|
&labels,
|
|
|
|
&view_xylos,
|
|
|
|
&view_EPAR,
|
2018-01-09 16:12:19 -05:00
|
|
|
&checkbox_scan,
|
2017-09-21 04:18:17 -04:00
|
|
|
&checkbox_cligno,
|
|
|
|
&field_tempo,
|
|
|
|
&progressbar,
|
|
|
|
&tx_view
|
|
|
|
});
|
|
|
|
|
|
|
|
field_tempo.set_value(1);
|
|
|
|
|
|
|
|
tx_view.on_edit_frequency = [this, &nav]() {
|
|
|
|
auto new_view = nav.push<FrequencyKeypadView>(receiver_model.tuning_frequency());
|
|
|
|
new_view->on_changed = [this](rf::Frequency f) {
|
|
|
|
transmitter_model.set_tuning_frequency(f);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
tx_view.on_start = [this]() {
|
2018-01-09 16:12:19 -05:00
|
|
|
if (tx_mode == IDLE) {
|
|
|
|
if (checkbox_scan.value()) {
|
|
|
|
tx_mode = SCAN;
|
|
|
|
} else {
|
|
|
|
tx_mode = SINGLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
progressbar.set_value(0);
|
2017-09-21 04:18:17 -04:00
|
|
|
tx_view.set_transmitting(true);
|
2018-01-09 16:12:19 -05:00
|
|
|
target_system = (target_system_t)tab_view.selected();
|
|
|
|
view_EPAR.half = false;
|
|
|
|
|
2017-09-21 04:18:17 -04:00
|
|
|
start_tx();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
tx_view.on_stop = [this]() {
|
2018-01-09 16:12:19 -05:00
|
|
|
stop_tx();
|
2017-09-21 04:18:17 -04:00
|
|
|
};
|
2016-12-09 12:21:47 -05:00
|
|
|
}
|
|
|
|
|
2018-01-09 16:12:19 -05:00
|
|
|
bool EPARView::increment_address() {
|
|
|
|
auto city_code = field_city.value();
|
|
|
|
|
|
|
|
if (city_code < EPAR_MAX_CITY) {
|
|
|
|
field_city.set_value(city_code + 1);
|
|
|
|
return true;
|
|
|
|
} else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t EPARView::get_scan_remaining() {
|
|
|
|
return EPAR_MAX_CITY - field_city.value();
|
|
|
|
}
|
|
|
|
|
2017-08-11 19:27:05 -04:00
|
|
|
void EPARView::flip_relays() {
|
|
|
|
// Invert first relay's state
|
|
|
|
relay_states[0].set_selected_index(relay_states[0].selected_index() ^ 1);
|
|
|
|
}
|
|
|
|
|
2017-09-21 04:18:17 -04:00
|
|
|
size_t EPARView::generate_message() {
|
|
|
|
// R2, then R1
|
|
|
|
return gen_message_ep(field_city.value(), field_group.selected_index_value(),
|
2018-01-09 16:12:19 -05:00
|
|
|
half ? 0 : 1, relay_states[half].selected_index());
|
2017-08-11 19:27:05 -04:00
|
|
|
}
|
|
|
|
|
2017-09-21 04:18:17 -04:00
|
|
|
EPARView::EPARView(
|
|
|
|
Rect parent_rect
|
|
|
|
) : View(parent_rect) {
|
2016-12-09 12:21:47 -05:00
|
|
|
|
2017-08-11 19:27:05 -04:00
|
|
|
hidden(true);
|
|
|
|
|
|
|
|
add_children({
|
|
|
|
&labels,
|
|
|
|
&field_city,
|
2018-01-09 16:12:19 -05:00
|
|
|
&field_group
|
2017-08-11 19:27:05 -04:00
|
|
|
});
|
|
|
|
|
2018-01-09 16:12:19 -05:00
|
|
|
field_city.set_value(0);
|
2017-08-11 19:27:05 -04:00
|
|
|
field_group.set_selected_index(2);
|
|
|
|
|
|
|
|
field_city.on_change = [this](int32_t) { generate_message(); };
|
|
|
|
field_group.on_change = [this](size_t, int32_t) { generate_message(); };
|
|
|
|
|
|
|
|
const auto relay_state_fn = [this](size_t, OptionsField::value_t) {
|
2018-01-09 16:12:19 -05:00
|
|
|
generate_message();
|
2017-08-11 19:27:05 -04:00
|
|
|
};
|
|
|
|
|
2017-09-21 04:18:17 -04:00
|
|
|
size_t n = 0;
|
2017-08-11 19:27:05 -04:00
|
|
|
for (auto& relay_state : relay_states) {
|
|
|
|
relay_state.on_change = relay_state_fn;
|
|
|
|
relay_state.set_parent_rect({
|
|
|
|
static_cast<Coord>(90 + (n * 36)),
|
|
|
|
80,
|
|
|
|
24, 24
|
|
|
|
});
|
|
|
|
relay_state.set_options(relay_options);
|
|
|
|
add_child(&relay_state);
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EPARView::focus() {
|
|
|
|
field_city.focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
void XylosView::flip_relays() {
|
2017-09-21 04:18:17 -04:00
|
|
|
// Invert first relay's state if not ignored
|
|
|
|
size_t rs = relay_states[0].selected_index();
|
2017-08-11 19:27:05 -04:00
|
|
|
|
2017-09-21 04:18:17 -04:00
|
|
|
if (rs > 0)
|
|
|
|
relay_states[0].set_selected_index(rs ^ 3);
|
2017-08-11 19:27:05 -04:00
|
|
|
}
|
|
|
|
|
2018-01-09 16:12:19 -05:00
|
|
|
bool XylosView::increment_address() {
|
|
|
|
auto city_code = field_city.value();
|
|
|
|
|
|
|
|
if (city_code < XY_MAX_CITY) {
|
|
|
|
field_city.set_value(city_code + 1);
|
|
|
|
return true;
|
|
|
|
} else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t XylosView::get_scan_remaining() {
|
|
|
|
return XY_MAX_CITY - field_city.value();
|
|
|
|
}
|
|
|
|
|
2017-08-11 19:27:05 -04:00
|
|
|
void XylosView::generate_message() {
|
2018-01-09 16:12:19 -05:00
|
|
|
gen_message_xy(field_header_a.value(), field_header_b.value(), field_city.value(), field_family.value(),
|
|
|
|
checkbox_wcsubfamily.value(), field_subfamily.value(), checkbox_wcid.value(), field_receiver.value(),
|
|
|
|
relay_states[0].selected_index(), relay_states[1].selected_index(),
|
|
|
|
relay_states[2].selected_index(), relay_states[3].selected_index());
|
2017-08-11 19:27:05 -04:00
|
|
|
}
|
|
|
|
|
2017-09-21 04:18:17 -04:00
|
|
|
XylosView::XylosView(
|
|
|
|
Rect parent_rect
|
|
|
|
) : View(parent_rect) {
|
2017-08-11 19:27:05 -04:00
|
|
|
|
|
|
|
hidden(true);
|
|
|
|
|
2017-01-15 22:45:44 -05:00
|
|
|
add_children({
|
2017-02-13 00:35:13 -05:00
|
|
|
&labels,
|
2017-08-11 19:27:05 -04:00
|
|
|
&field_header_a,
|
|
|
|
&field_header_b,
|
|
|
|
&field_city,
|
|
|
|
&field_family,
|
|
|
|
&field_subfamily,
|
2016-12-09 12:21:47 -05:00
|
|
|
&checkbox_wcsubfamily,
|
2017-08-11 19:27:05 -04:00
|
|
|
&field_receiver,
|
2016-12-09 12:21:47 -05:00
|
|
|
&checkbox_wcid,
|
2017-09-21 04:18:17 -04:00
|
|
|
//&button_seq,
|
2017-01-15 22:45:44 -05:00
|
|
|
});
|
2017-08-11 19:27:05 -04:00
|
|
|
|
|
|
|
field_header_a.set_value(0);
|
|
|
|
field_header_b.set_value(0);
|
|
|
|
field_city.set_value(10);
|
|
|
|
field_family.set_value(1);
|
|
|
|
field_subfamily.set_value(1);
|
|
|
|
field_receiver.set_value(1);
|
2016-12-09 12:21:47 -05:00
|
|
|
|
2018-01-09 16:12:19 -05:00
|
|
|
const auto field_fn = [this](int32_t) {
|
|
|
|
generate_message();
|
|
|
|
};
|
|
|
|
|
|
|
|
field_header_a.on_change = field_fn;
|
2017-08-11 19:27:05 -04:00
|
|
|
field_header_b.on_change = [this](int32_t) { generate_message(); };
|
|
|
|
field_city.on_change = [this](int32_t) { generate_message(); };
|
|
|
|
field_family.on_change = [this](int32_t) { generate_message(); };
|
|
|
|
field_subfamily.on_change = [this](int32_t) { generate_message(); };
|
|
|
|
field_receiver.on_change = [this](int32_t) { generate_message(); };
|
2016-12-09 12:21:47 -05:00
|
|
|
|
2017-01-17 09:27:37 -05:00
|
|
|
checkbox_wcsubfamily.on_select = [this](Checkbox&, bool v) {
|
2017-08-11 19:27:05 -04:00
|
|
|
field_subfamily.set_focusable(!v);
|
2016-12-09 12:21:47 -05:00
|
|
|
generate_message();
|
|
|
|
};
|
|
|
|
|
2017-01-17 09:27:37 -05:00
|
|
|
checkbox_wcid.on_select = [this](Checkbox&, bool v) {
|
2017-08-11 19:27:05 -04:00
|
|
|
field_receiver.set_focusable(!v);
|
2016-12-09 12:21:47 -05:00
|
|
|
generate_message();
|
|
|
|
};
|
|
|
|
|
|
|
|
checkbox_wcsubfamily.set_value(true);
|
|
|
|
checkbox_wcid.set_value(true);
|
|
|
|
|
|
|
|
const auto relay_state_fn = [this](size_t, OptionsField::value_t) {
|
2018-01-09 16:12:19 -05:00
|
|
|
generate_message();
|
2016-12-09 12:21:47 -05:00
|
|
|
};
|
|
|
|
|
2017-09-21 04:18:17 -04:00
|
|
|
size_t n = 0;
|
2016-12-09 12:21:47 -05:00
|
|
|
for (auto& relay_state : relay_states) {
|
|
|
|
relay_state.on_change = relay_state_fn;
|
|
|
|
relay_state.set_parent_rect({
|
2017-08-11 19:27:05 -04:00
|
|
|
static_cast<Coord>(54 + (n * 36)),
|
|
|
|
134,
|
2016-12-09 12:21:47 -05:00
|
|
|
24, 24
|
|
|
|
});
|
|
|
|
relay_state.set_options(relay_options);
|
|
|
|
add_child(&relay_state);
|
|
|
|
n++;
|
|
|
|
}
|
2017-08-11 19:27:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void XylosView::focus() {
|
|
|
|
field_city.focus();
|
|
|
|
}
|
|
|
|
|
2016-12-09 12:21:47 -05:00
|
|
|
} /* namespace ui */
|