2016-12-09 17:21:47 +00: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_morse.hpp"
|
|
|
|
|
|
|
|
#include "portapack.hpp"
|
|
|
|
#include "baseband_api.hpp"
|
2017-02-14 17:16:59 +00:00
|
|
|
#include "hackrf_gpio.hpp"
|
|
|
|
#include "portapack_shared_memory.hpp"
|
|
|
|
#include "ui_textentry.hpp"
|
2017-02-15 04:27:51 +00:00
|
|
|
#include "string_format.hpp"
|
2016-12-09 17:21:47 +00:00
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
using namespace portapack;
|
2017-02-13 23:24:42 +00:00
|
|
|
using namespace morse;
|
2017-02-14 17:16:59 +00:00
|
|
|
using namespace hackrf::one;
|
2016-12-09 17:21:47 +00:00
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
|
2017-02-14 17:16:59 +00:00
|
|
|
static WORKING_AREA(ookthread_wa, 256);
|
2017-02-15 03:05:38 +00:00
|
|
|
|
2023-05-18 20:16:05 +00:00
|
|
|
static msg_t ookthread_fn(void* arg) {
|
|
|
|
uint32_t v = 0, delay = 0;
|
|
|
|
uint8_t* message_symbols = shared_memory.bb_data.tones_data.message;
|
|
|
|
uint8_t symbol;
|
|
|
|
MorseView* arg_c = (MorseView*)arg;
|
|
|
|
|
|
|
|
chRegSetThreadName("ookthread");
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < arg_c->symbol_count; i++) {
|
|
|
|
if (chThdShouldTerminate()) break;
|
|
|
|
|
|
|
|
symbol = message_symbols[i];
|
|
|
|
|
|
|
|
v = (symbol < 2) ? 1 : 0; // TX on for dot or dash, off for pause
|
|
|
|
delay = morse_symbols[symbol];
|
|
|
|
|
2023-11-25 00:01:52 +00:00
|
|
|
if (hackrf_r9) { // r9 has a common PIN 54 for MODE CONTROL TX / RX, <=r6 has two independent MODE CONTROL pins (TX and RX)
|
|
|
|
gpio_r9_rx.write(!v); // in hackrf r9 opposite logic "0" means tx , "1" rx = no tx)
|
|
|
|
} else {
|
|
|
|
gpio_og_tx.write(v); // in hackrf <=r6, "1" means tx , "0" no tx.
|
|
|
|
}
|
|
|
|
|
2023-05-18 20:16:05 +00:00
|
|
|
arg_c->on_tx_progress(i, false);
|
|
|
|
|
|
|
|
chThdSleepMilliseconds(delay * arg_c->time_unit_ms);
|
|
|
|
}
|
|
|
|
|
2023-11-25 00:01:52 +00:00
|
|
|
if (hackrf_r9) { // r9 has a common PIN 54 for MODE CONTROL TX / RX, <=r6 has two independent MODE CONTROL pins (TX and RX)
|
|
|
|
gpio_r9_rx.write(1); // Hackrf_r9 , common pin, rx="1" (we ensure TX is off) / tx="0"
|
|
|
|
} else {
|
|
|
|
gpio_og_tx.write(0); // Hackrf <=r6 independent TX / RX pins ,now touching the tx pin ==> Ensure TX is off
|
|
|
|
}
|
|
|
|
|
2023-05-18 20:16:05 +00:00
|
|
|
arg_c->on_tx_progress(0, true);
|
|
|
|
chThdExit(0);
|
|
|
|
|
|
|
|
return 0;
|
2017-02-14 17:16:59 +00:00
|
|
|
}
|
|
|
|
|
2023-05-18 20:16:05 +00:00
|
|
|
static msg_t loopthread_fn(void* arg) {
|
|
|
|
MorseView* arg_c = (MorseView*)arg;
|
|
|
|
uint32_t wait = arg_c->loop;
|
|
|
|
|
|
|
|
chRegSetThreadName("loopthread");
|
2020-09-22 13:12:46 +00:00
|
|
|
|
2023-05-18 20:16:05 +00:00
|
|
|
for (uint32_t i = 0; i < wait; i++) {
|
|
|
|
if (chThdShouldTerminate()) break;
|
2020-09-22 13:12:46 +00:00
|
|
|
|
2023-05-18 20:16:05 +00:00
|
|
|
arg_c->on_loop_progress(i, false);
|
|
|
|
chThdSleepMilliseconds(1000);
|
|
|
|
}
|
2020-09-22 13:12:46 +00:00
|
|
|
|
2023-05-18 20:16:05 +00:00
|
|
|
arg_c->on_loop_progress(0, true);
|
|
|
|
chThdExit(0);
|
2020-09-22 13:12:46 +00:00
|
|
|
|
2023-05-18 20:16:05 +00:00
|
|
|
return 0;
|
2020-09-22 13:12:46 +00:00
|
|
|
}
|
|
|
|
|
2017-03-03 08:06:11 +00:00
|
|
|
void MorseView::on_set_text(NavigationView& nav) {
|
2023-05-18 20:16:05 +00:00
|
|
|
text_prompt(nav, buffer, 28);
|
2017-03-03 08:06:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MorseView::focus() {
|
2023-05-18 20:16:05 +00:00
|
|
|
button_message.focus();
|
2017-03-03 08:06:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MorseView::~MorseView() {
|
2023-05-18 20:16:05 +00:00
|
|
|
transmitter_model.disable();
|
2023-06-17 14:54:52 +00:00
|
|
|
baseband::shutdown();
|
2017-03-03 08:06:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MorseView::paint(Painter&) {
|
2023-05-18 20:16:05 +00:00
|
|
|
message = buffer;
|
|
|
|
text_message.set(message);
|
|
|
|
update_tx_duration();
|
2017-03-03 08:06:11 +00:00
|
|
|
}
|
|
|
|
|
2017-02-14 17:16:59 +00:00
|
|
|
bool MorseView::start_tx() {
|
2023-05-18 20:16:05 +00:00
|
|
|
// Re-generate message, just in case
|
|
|
|
update_tx_duration();
|
|
|
|
|
|
|
|
if (!symbol_count) {
|
2023-05-19 20:39:35 +00:00
|
|
|
nav_.display_modal("Error", "Message too long,\nmust be < 256 symbols.");
|
2023-05-18 20:16:05 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
progressbar.set_max(symbol_count);
|
2023-10-12 16:02:38 +00:00
|
|
|
// By experimental spectrum measurment, we left exactly same TX LPF settings as previous fw 1.7.4, TX LPF= 1M75 (min).
|
|
|
|
transmitter_model.set_baseband_bandwidth(1'750'000); // Min TX LPF .already tested in FM morse max tone 9,999k , max dev 150khz
|
2023-05-18 20:16:05 +00:00
|
|
|
transmitter_model.enable();
|
|
|
|
|
2023-12-08 18:20:59 +00:00
|
|
|
baseband::set_tones_config(transmitter_model.channel_bandwidth(), 0, symbol_count, false, false);
|
|
|
|
|
2023-11-26 11:17:23 +00:00
|
|
|
if (mode_cw) {
|
2023-05-18 20:16:05 +00:00
|
|
|
ookthread = chThdCreateStatic(ookthread_wa, sizeof(ookthread_wa), NORMALPRIO + 10, ookthread_fn, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2016-12-09 17:21:47 +00:00
|
|
|
}
|
|
|
|
|
2017-02-15 04:27:51 +00:00
|
|
|
void MorseView::update_tx_duration() {
|
2023-05-18 20:16:05 +00:00
|
|
|
uint32_t duration_ms;
|
|
|
|
|
2023-11-26 11:17:23 +00:00
|
|
|
time_unit_ms = 1200 / speed;
|
|
|
|
symbol_count = morse_encode(message, time_unit_ms, tone, &time_units);
|
2023-05-18 20:16:05 +00:00
|
|
|
|
|
|
|
if (symbol_count) {
|
|
|
|
duration_ms = time_units * time_unit_ms;
|
|
|
|
text_tx_duration.set(to_string_dec_uint(duration_ms / 1000) + "." + to_string_dec_uint((duration_ms / 100) % 10, 1) + "s ");
|
|
|
|
} else {
|
|
|
|
text_tx_duration.set("-"); // Error
|
|
|
|
}
|
2017-02-15 04:27:51 +00:00
|
|
|
}
|
|
|
|
|
2017-09-24 19:05:42 +00:00
|
|
|
void MorseView::on_tx_progress(const uint32_t progress, const bool done) {
|
2023-05-18 20:16:05 +00:00
|
|
|
if (done) {
|
|
|
|
transmitter_model.disable();
|
|
|
|
progressbar.set_value(0);
|
|
|
|
|
|
|
|
if (loop && run) {
|
|
|
|
text_tx_duration.set("wait");
|
|
|
|
progressbar.set_max(loop);
|
|
|
|
progressbar.set_value(0);
|
|
|
|
|
|
|
|
if (loopthread) {
|
|
|
|
chThdRelease(loopthread);
|
|
|
|
loopthread = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
loopthread = chThdCreateFromHeap(NULL, 1024, NORMALPRIO, loopthread_fn, this);
|
|
|
|
} else {
|
|
|
|
tx_view.set_transmitting(false);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
progressbar.set_value(progress);
|
2020-09-22 13:12:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MorseView::on_loop_progress(const uint32_t progress, const bool done) {
|
2023-05-18 20:16:05 +00:00
|
|
|
if (done) {
|
|
|
|
start_tx();
|
|
|
|
} else
|
|
|
|
progressbar.set_value(progress);
|
2017-01-09 02:45:29 +00:00
|
|
|
}
|
|
|
|
|
2017-03-03 08:06:11 +00:00
|
|
|
void MorseView::set_foxhunt(size_t i) {
|
2023-11-26 11:17:23 +00:00
|
|
|
message = foxhunt_codes[i - 1];
|
2023-05-18 20:16:05 +00:00
|
|
|
buffer = message.c_str();
|
|
|
|
text_message.set(message);
|
|
|
|
update_tx_duration();
|
2017-03-03 08:06:11 +00:00
|
|
|
}
|
|
|
|
|
2016-12-09 17:21:47 +00:00
|
|
|
MorseView::MorseView(
|
2023-05-18 20:16:05 +00:00
|
|
|
NavigationView& nav)
|
|
|
|
: nav_(nav) {
|
|
|
|
baseband::run_image(portapack::spi_flash::image_tag_tones);
|
|
|
|
|
|
|
|
add_children({&labels,
|
|
|
|
&checkbox_foxhunt,
|
2023-11-26 11:17:23 +00:00
|
|
|
&field_foxhunt,
|
2023-05-18 20:16:05 +00:00
|
|
|
&field_speed,
|
|
|
|
&field_tone,
|
|
|
|
&options_modulation,
|
|
|
|
&options_loop,
|
|
|
|
&text_tx_duration,
|
|
|
|
&text_message,
|
|
|
|
&button_message,
|
|
|
|
&progressbar,
|
|
|
|
&tx_view});
|
|
|
|
|
|
|
|
// Default settings
|
2023-11-26 11:17:23 +00:00
|
|
|
field_speed.set_value(speed);
|
|
|
|
field_tone.set_value(tone);
|
|
|
|
options_modulation.set_by_value(mode_cw);
|
|
|
|
options_loop.set_by_value(loop);
|
|
|
|
checkbox_foxhunt.set_value(foxhunt_mode);
|
|
|
|
field_foxhunt.set_value(foxhunt_code);
|
2023-05-18 20:16:05 +00:00
|
|
|
|
|
|
|
checkbox_foxhunt.on_select = [this](Checkbox&, bool value) {
|
|
|
|
foxhunt_mode = value;
|
|
|
|
|
|
|
|
if (foxhunt_mode)
|
2023-11-26 11:17:23 +00:00
|
|
|
set_foxhunt(foxhunt_code);
|
2023-05-18 20:16:05 +00:00
|
|
|
};
|
|
|
|
|
2023-11-26 11:17:23 +00:00
|
|
|
field_foxhunt.on_change = [this](int32_t value) {
|
|
|
|
foxhunt_code = value;
|
|
|
|
|
2023-05-18 20:16:05 +00:00
|
|
|
if (foxhunt_mode)
|
2023-11-26 11:17:23 +00:00
|
|
|
set_foxhunt(foxhunt_code);
|
2023-05-18 20:16:05 +00:00
|
|
|
};
|
|
|
|
|
2023-11-26 11:17:23 +00:00
|
|
|
options_modulation.on_change = [this](size_t i, int32_t value) {
|
|
|
|
(void)i; // avoid unused warning
|
|
|
|
mode_cw = (bool)value;
|
2023-05-18 20:16:05 +00:00
|
|
|
};
|
|
|
|
|
2023-11-26 11:17:23 +00:00
|
|
|
options_loop.on_change = [this](size_t i, uint32_t value) {
|
2023-05-18 20:16:05 +00:00
|
|
|
(void)i; // avoid unused warning
|
2023-11-26 11:17:23 +00:00
|
|
|
loop = value;
|
2023-05-18 20:16:05 +00:00
|
|
|
};
|
|
|
|
|
2023-11-26 11:17:23 +00:00
|
|
|
field_speed.on_change = [this](int32_t value) {
|
|
|
|
speed = value;
|
2023-05-18 20:16:05 +00:00
|
|
|
update_tx_duration();
|
|
|
|
};
|
|
|
|
|
2023-11-26 11:17:23 +00:00
|
|
|
field_tone.on_change = [this](int32_t value) {
|
|
|
|
tone = value;
|
|
|
|
};
|
|
|
|
|
2023-05-18 20:16:05 +00:00
|
|
|
button_message.on_select = [this, &nav](Button&) {
|
|
|
|
this->on_set_text(nav);
|
|
|
|
};
|
|
|
|
|
|
|
|
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]() {
|
|
|
|
if (start_tx()) {
|
|
|
|
run = true;
|
|
|
|
tx_view.set_transmitting(true);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
tx_view.on_stop = [this]() {
|
|
|
|
run = false;
|
|
|
|
if (ookthread) chThdTerminate(ookthread);
|
|
|
|
|
|
|
|
if (loopthread) {
|
|
|
|
chThdTerminate(loopthread);
|
|
|
|
chThdWait(loopthread);
|
|
|
|
loopthread = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
transmitter_model.disable();
|
|
|
|
baseband::kill_tone();
|
|
|
|
tx_view.set_transmitting(false);
|
|
|
|
};
|
2016-12-09 17:21:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace ui */
|