Fix morse tx cw+loop (#2827)

This commit is contained in:
Totoo
2025-10-17 17:03:34 +02:00
committed by GitHub
parent cbbd8103d3
commit 6782e12a15
+15 -14
View File
@@ -45,12 +45,9 @@ static msg_t ookthread_fn(void* arg) {
uint8_t* message_symbols = shared_memory.bb_data.tones_data.message; uint8_t* message_symbols = shared_memory.bb_data.tones_data.message;
uint8_t symbol; uint8_t symbol;
MorseView* arg_c = (MorseView*)arg; MorseView* arg_c = (MorseView*)arg;
chRegSetThreadName("ookthread"); chRegSetThreadName("ookthread");
for (uint32_t i = 0; i < arg_c->symbol_count; i++) { for (uint32_t i = 0; i < arg_c->symbol_count; i++) {
if (chThdShouldTerminate()) break; if (chThdShouldTerminate()) break;
symbol = message_symbols[i]; symbol = message_symbols[i];
v = (symbol < 2) ? 1 : 0; // TX on for dot or dash, off for pause v = (symbol < 2) ? 1 : 0; // TX on for dot or dash, off for pause
@@ -61,9 +58,7 @@ static msg_t ookthread_fn(void* arg) {
} else { } else {
gpio_og_tx.write(v); // in hackrf <=r6, "1" means tx , "0" no tx. gpio_og_tx.write(v); // in hackrf <=r6, "1" means tx , "0" no tx.
} }
arg_c->on_tx_progress(i, false); arg_c->on_tx_progress(i, false);
chThdSleepMilliseconds(delay * arg_c->time_unit_ms); chThdSleepMilliseconds(delay * arg_c->time_unit_ms);
} }
@@ -82,19 +77,14 @@ static msg_t ookthread_fn(void* arg) {
static msg_t loopthread_fn(void* arg) { static msg_t loopthread_fn(void* arg) {
MorseView* arg_c = (MorseView*)arg; MorseView* arg_c = (MorseView*)arg;
uint32_t wait = arg_c->loop; uint32_t wait = arg_c->loop;
chRegSetThreadName("loopthread"); chRegSetThreadName("loopthread");
for (uint32_t i = 0; i < wait; i++) { for (uint32_t i = 0; i < wait; i++) {
if (chThdShouldTerminate()) break; if (chThdShouldTerminate()) break;
arg_c->on_loop_progress(i, false); arg_c->on_loop_progress(i, false);
chThdSleepMilliseconds(1000); chThdSleepMilliseconds(1000);
} }
if (!chThdShouldTerminate()) arg_c->on_loop_progress(0, true);
arg_c->on_loop_progress(0, true);
chThdExit(0); chThdExit(0);
return 0; return 0;
} }
@@ -132,6 +122,15 @@ void MorseView::focus() {
} }
MorseView::~MorseView() { MorseView::~MorseView() {
if (ookthread) {
chThdTerminate(ookthread);
ookthread = nullptr;
}
if (loopthread) {
chThdTerminate(loopthread);
chThdWait(loopthread);
loopthread = nullptr;
}
transmitter_model.disable(); transmitter_model.disable();
baseband::shutdown(); baseband::shutdown();
} }
@@ -181,6 +180,9 @@ void MorseView::update_tx_duration() {
void MorseView::on_tx_progress(const uint32_t progress, const bool done) { void MorseView::on_tx_progress(const uint32_t progress, const bool done) {
if (done) { if (done) {
if (ookthread) {
ookthread = nullptr;
}
transmitter_model.disable(); transmitter_model.disable();
progressbar.set_value(0); progressbar.set_value(0);
@@ -190,10 +192,10 @@ void MorseView::on_tx_progress(const uint32_t progress, const bool done) {
progressbar.set_value(0); progressbar.set_value(0);
if (loopthread) { if (loopthread) {
chThdRelease(loopthread); chThdTerminate(loopthread);
chThdWait(loopthread);
loopthread = nullptr; loopthread = nullptr;
} }
loopthread = chThdCreateFromHeap(NULL, 1024, NORMALPRIO, loopthread_fn, this); loopthread = chThdCreateFromHeap(NULL, 1024, NORMALPRIO, loopthread_fn, this);
} else { } else {
tx_view.set_transmitting(false); tx_view.set_transmitting(false);
@@ -219,7 +221,6 @@ void MorseView::set_foxhunt(size_t i) {
MorseView::MorseView( MorseView::MorseView(
NavigationView& nav) NavigationView& nav)
: nav_(nav) { : nav_(nav) {
// baseband::run_image(portapack::spi_flash::image_tag_tones);
baseband::run_prepared_image(portapack::memory::map::m4_code.base()); baseband::run_prepared_image(portapack::memory::map::m4_code.base());
add_children({&labels, add_children({&labels,