2015-08-28 18:50:42 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
2016-05-27 23:59:13 +00:00
|
|
|
* Copyright (C) 2016 Furrtek
|
2015-08-28 18:50:42 +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_rds.hpp"
|
|
|
|
|
|
|
|
#include "portapack.hpp"
|
2016-07-27 01:03:40 +00:00
|
|
|
#include "baseband_api.hpp"
|
2015-08-28 18:50:42 +00:00
|
|
|
#include "portapack_shared_memory.hpp"
|
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
|
2016-02-04 09:27:53 +00:00
|
|
|
using namespace portapack;
|
2016-12-05 11:56:41 +00:00
|
|
|
using namespace rds;
|
2015-08-28 18:50:42 +00:00
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
|
2017-08-16 09:02:57 +00:00
|
|
|
RDSPSNView::RDSPSNView(
|
2023-05-18 20:16:05 +00:00
|
|
|
NavigationView& nav,
|
|
|
|
Rect parent_rect)
|
|
|
|
: OptionTabView(parent_rect) {
|
|
|
|
set_type("PSN");
|
|
|
|
|
|
|
|
add_children({&labels,
|
|
|
|
&text_psn,
|
|
|
|
&button_set,
|
|
|
|
&check_mono_stereo,
|
|
|
|
&check_TA,
|
|
|
|
&check_MS});
|
|
|
|
|
|
|
|
set_enabled(true);
|
|
|
|
|
|
|
|
check_TA.set_value(true);
|
|
|
|
|
|
|
|
check_mono_stereo.on_select = [this](Checkbox&, bool value) {
|
|
|
|
mono_stereo = value;
|
|
|
|
};
|
|
|
|
check_TA.on_select = [this](Checkbox&, bool value) {
|
|
|
|
TA = value;
|
|
|
|
};
|
|
|
|
check_MS.on_select = [this](Checkbox&, bool value) {
|
|
|
|
MS = value;
|
|
|
|
};
|
|
|
|
|
|
|
|
button_set.on_select = [this, &nav](Button&) {
|
|
|
|
text_prompt(
|
|
|
|
nav,
|
|
|
|
PSN,
|
|
|
|
8,
|
|
|
|
[this](std::string& s) {
|
|
|
|
text_psn.set(s);
|
|
|
|
});
|
|
|
|
};
|
2017-08-16 09:02:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RDSRadioTextView::RDSRadioTextView(
|
2023-05-18 20:16:05 +00:00
|
|
|
NavigationView& nav,
|
|
|
|
Rect parent_rect)
|
|
|
|
: OptionTabView(parent_rect) {
|
|
|
|
set_type("Radiotext");
|
|
|
|
|
|
|
|
add_children({&labels,
|
|
|
|
&button_set,
|
|
|
|
&text_radiotext});
|
|
|
|
|
|
|
|
button_set.on_select = [this, &nav](Button&) {
|
|
|
|
text_prompt(
|
|
|
|
nav,
|
|
|
|
radiotext,
|
|
|
|
28,
|
|
|
|
[this](std::string& s) {
|
|
|
|
text_radiotext.set(s);
|
|
|
|
});
|
|
|
|
};
|
2015-08-28 18:50:42 +00:00
|
|
|
}
|
|
|
|
|
2017-08-16 09:02:57 +00:00
|
|
|
RDSDateTimeView::RDSDateTimeView(
|
2023-05-18 20:16:05 +00:00
|
|
|
Rect parent_rect)
|
|
|
|
: OptionTabView(parent_rect) {
|
|
|
|
set_type("date & time");
|
|
|
|
|
|
|
|
add_children({&labels});
|
2017-08-16 09:02:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RDSAudioView::RDSAudioView(
|
2023-05-18 20:16:05 +00:00
|
|
|
Rect parent_rect)
|
|
|
|
: OptionTabView(parent_rect) {
|
|
|
|
set_type("audio");
|
|
|
|
|
|
|
|
add_children({&labels});
|
2017-08-16 09:02:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RDSThread::RDSThread(
|
2023-05-18 20:16:05 +00:00
|
|
|
std::vector<RDSGroup>** frames)
|
|
|
|
: frames_{std::move(frames)} {
|
|
|
|
thread = chThdCreateFromHeap(NULL, 1024, NORMALPRIO + 10, RDSThread::static_fn, this);
|
2017-08-16 09:02:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RDSThread::~RDSThread() {
|
2023-05-18 20:16:05 +00:00
|
|
|
if (thread) {
|
|
|
|
chThdTerminate(thread);
|
|
|
|
chThdWait(thread);
|
|
|
|
thread = nullptr;
|
|
|
|
}
|
2017-08-16 09:02:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
msg_t RDSThread::static_fn(void* arg) {
|
2023-05-18 20:16:05 +00:00
|
|
|
auto obj = static_cast<RDSThread*>(arg);
|
|
|
|
obj->run();
|
|
|
|
return 0;
|
2017-08-16 09:02:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RDSThread::run() {
|
2023-05-18 20:16:05 +00:00
|
|
|
std::vector<RDSGroup>* frame_ptr;
|
|
|
|
size_t block_count, c;
|
|
|
|
uint32_t* tx_data_u32 = (uint32_t*)shared_memory.bb_data.data;
|
|
|
|
uint32_t frame_index = 0;
|
|
|
|
|
|
|
|
while (!chThdShouldTerminate()) {
|
|
|
|
do {
|
|
|
|
frame_ptr = frames_[frame_index];
|
|
|
|
|
|
|
|
if (frame_index == 2) {
|
|
|
|
frame_index = 0;
|
|
|
|
} else {
|
|
|
|
frame_index++;
|
|
|
|
}
|
|
|
|
} while (!(block_count = frame_ptr->size() * 4));
|
|
|
|
|
|
|
|
for (c = 0; c < block_count; c++)
|
|
|
|
tx_data_u32[c] = frame_ptr->at(c >> 2).block[c & 3];
|
|
|
|
|
|
|
|
baseband::set_rds_data(block_count * 26);
|
|
|
|
|
|
|
|
chThdSleepMilliseconds(1000);
|
|
|
|
}
|
2017-08-16 09:02:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RDSView::focus() {
|
2023-05-18 20:16:05 +00:00
|
|
|
tab_view.focus();
|
2016-05-27 23:59:13 +00:00
|
|
|
}
|
|
|
|
|
2016-12-05 11:56:41 +00:00
|
|
|
RDSView::~RDSView() {
|
2023-05-18 20:16:05 +00:00
|
|
|
transmitter_model.disable();
|
2023-06-17 14:54:52 +00:00
|
|
|
baseband::shutdown();
|
2016-05-29 10:06:47 +00:00
|
|
|
}
|
2015-08-28 18:50:42 +00:00
|
|
|
|
2016-12-05 11:56:41 +00:00
|
|
|
void RDSView::start_tx() {
|
2023-05-18 20:16:05 +00:00
|
|
|
rds_flags.PI_code = sym_pi_code.value_hex_u64();
|
|
|
|
rds_flags.PTY = options_pty.selected_index_value();
|
|
|
|
rds_flags.DI = view_PSN.mono_stereo ? 1 : 0;
|
|
|
|
rds_flags.TP = check_TP.value();
|
|
|
|
rds_flags.TA = view_PSN.TA;
|
|
|
|
rds_flags.MS = view_PSN.MS;
|
|
|
|
|
|
|
|
if (view_PSN.is_enabled())
|
|
|
|
gen_PSN(frame_psn, view_PSN.PSN, &rds_flags);
|
|
|
|
else
|
|
|
|
frame_psn.clear();
|
|
|
|
|
|
|
|
if (view_radiotext.is_enabled())
|
|
|
|
gen_RadioText(frame_radiotext, view_radiotext.radiotext, 0, &rds_flags);
|
|
|
|
else
|
|
|
|
frame_radiotext.clear();
|
|
|
|
|
|
|
|
// DEBUG
|
|
|
|
if (view_datetime.is_enabled())
|
|
|
|
gen_ClockTime(frame_datetime, &rds_flags, 2016, 12, 1, 9, 23, 2);
|
|
|
|
else
|
|
|
|
frame_datetime.clear();
|
|
|
|
|
|
|
|
transmitter_model.enable();
|
|
|
|
|
|
|
|
tx_thread = std::make_unique<RDSThread>(frames);
|
2015-08-28 18:50:42 +00:00
|
|
|
}
|
|
|
|
|
2017-08-16 09:02:57 +00:00
|
|
|
RDSView::RDSView(
|
2023-05-18 20:16:05 +00:00
|
|
|
NavigationView& nav)
|
|
|
|
: nav_{nav} {
|
|
|
|
baseband::run_image(portapack::spi_flash::image_tag_rds);
|
|
|
|
|
|
|
|
add_children({
|
|
|
|
&tab_view,
|
|
|
|
&labels,
|
|
|
|
&sym_pi_code,
|
|
|
|
&check_TP,
|
|
|
|
&options_pty,
|
|
|
|
&view_PSN,
|
|
|
|
&view_radiotext,
|
|
|
|
&view_datetime,
|
|
|
|
&view_audio,
|
|
|
|
&tx_view,
|
|
|
|
});
|
|
|
|
|
|
|
|
check_TP.set_value(true);
|
|
|
|
|
|
|
|
sym_pi_code.set_sym(0, 0xF);
|
|
|
|
sym_pi_code.set_sym(1, 0x3);
|
|
|
|
sym_pi_code.set_sym(2, 0xE);
|
|
|
|
sym_pi_code.set_sym(3, 0x0);
|
|
|
|
sym_pi_code.on_change = [this]() {
|
|
|
|
rds_flags.PI_code = sym_pi_code.value_hex_u64();
|
|
|
|
};
|
|
|
|
|
|
|
|
options_pty.set_selected_index(0); // None
|
|
|
|
|
|
|
|
tx_view.on_edit_frequency = [this, &nav]() {
|
2023-06-11 18:47:13 +00:00
|
|
|
auto new_view = nav.push<FrequencyKeypadView>(transmitter_model.target_frequency());
|
2023-05-18 20:16:05 +00:00
|
|
|
new_view->on_changed = [this](rf::Frequency f) {
|
2023-06-11 18:47:13 +00:00
|
|
|
transmitter_model.set_target_frequency(f);
|
2023-05-18 20:16:05 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
tx_view.on_start = [this]() {
|
|
|
|
start_tx();
|
|
|
|
tx_view.set_transmitting(true);
|
|
|
|
txing = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
tx_view.on_stop = [this]() {
|
|
|
|
// Kill tx_thread here ?
|
|
|
|
tx_view.set_transmitting(false);
|
|
|
|
transmitter_model.disable();
|
|
|
|
txing = false;
|
|
|
|
};
|
2015-08-28 18:50:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace ui */
|