mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-12-02 19:01:48 +00:00
Morse CW TX and message set button
This commit is contained in:
@@ -199,6 +199,7 @@ set(CPPSRC
|
||||
${COMMON}/ais_packet.cpp
|
||||
${COMMON}/pocsag_packet.cpp
|
||||
${COMMON}/pocsag.cpp
|
||||
${COMMON}/morse.cpp
|
||||
ais_app.cpp
|
||||
tpms_app.cpp
|
||||
pocsag_app.cpp
|
||||
|
||||
@@ -32,17 +32,25 @@ Continuous (Fox-oring)
|
||||
|
||||
#include "portapack.hpp"
|
||||
#include "baseband_api.hpp"
|
||||
#include "hackrf_gpio.hpp"
|
||||
#include "portapack_shared_memory.hpp"
|
||||
#include "ui_textentry.hpp"
|
||||
|
||||
#include <cstring>
|
||||
#include <stdio.h>
|
||||
|
||||
using namespace portapack;
|
||||
using namespace morse;
|
||||
using namespace hackrf::one;
|
||||
|
||||
// TODO: Live keying mode: Dit on left key, dah on right ?
|
||||
|
||||
namespace ui {
|
||||
|
||||
void MorseView::on_set_text(NavigationView& nav) {
|
||||
textentry(nav, buffer, 28);
|
||||
}
|
||||
|
||||
void MorseView::focus() {
|
||||
tx_view.focus();
|
||||
}
|
||||
@@ -52,21 +60,58 @@ MorseView::~MorseView() {
|
||||
baseband::shutdown();
|
||||
}
|
||||
|
||||
void MorseView::paint(Painter& painter) {
|
||||
(void)painter;
|
||||
void MorseView::paint(Painter&) {
|
||||
message = buffer;
|
||||
text_message.set(message);
|
||||
}
|
||||
|
||||
static WORKING_AREA(ookthread_wa, 256);
|
||||
static msg_t ookthread_fn(void * arg) {
|
||||
uint32_t v = 0, delay = 0;
|
||||
size_t i = 0;
|
||||
uint8_t * message = shared_memory.bb_data.tones_data.message;
|
||||
MorseView * arg_c = (MorseView*)arg;
|
||||
|
||||
chRegSetThreadName("ookthread");
|
||||
for (i = 0; i < arg_c->symbol_count; i++) {
|
||||
if (chThdShouldTerminate()) break;
|
||||
|
||||
if (message[i] == 0) {
|
||||
v = 1;
|
||||
delay = MORSE_DOT;
|
||||
} else if (message[i] == 1) {
|
||||
v = 1;
|
||||
delay = MORSE_DASH;
|
||||
} else if (message[i] == 2) {
|
||||
v = 0;
|
||||
delay = MORSE_SYMBOL_SPACE;
|
||||
} else if (message[i] == 3) {
|
||||
v = 0;
|
||||
delay = MORSE_LETTER_SPACE;
|
||||
} else if (message[i] == 4) {
|
||||
v = 0;
|
||||
delay = MORSE_WORD_SPACE;
|
||||
}
|
||||
|
||||
gpio_tx.write(v);
|
||||
arg_c->on_tx_progress(i, false);
|
||||
|
||||
chThdSleepMilliseconds(delay * arg_c->time_unit_ms);
|
||||
}
|
||||
|
||||
gpio_tx.write(0);
|
||||
arg_c->on_tx_progress(0, true);
|
||||
chThdExit(0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool MorseView::start_tx() {
|
||||
size_t symbol_count;
|
||||
std::string message;
|
||||
|
||||
if (checkbox_foxhunt.value()) {
|
||||
if (checkbox_foxhunt.value())
|
||||
message = foxhunt_codes[options_foxhunt.selected_index_value()];
|
||||
} else {
|
||||
message = "ABCDEFGHIJKLMN";
|
||||
}
|
||||
|
||||
symbol_count = morse_encode(message, field_time_unit.value(), field_tone.value());
|
||||
time_unit_ms = field_time_unit.value();
|
||||
symbol_count = morse_encode(message, time_unit_ms, field_tone.value());
|
||||
|
||||
if (!symbol_count) {
|
||||
nav_.display_modal("Error", "Message too long.", INFO, nullptr);
|
||||
@@ -82,7 +127,11 @@ bool MorseView::start_tx() {
|
||||
transmitter_model.set_baseband_bandwidth(1750000);
|
||||
transmitter_model.enable();
|
||||
|
||||
baseband::set_tones_data(transmitter_model.bandwidth(), 0, symbol_count, false, false);
|
||||
if (options_modulation.selected_index() == 0) {
|
||||
ookthread = chThdCreateStatic(ookthread_wa, sizeof(ookthread_wa), NORMALPRIO + 10, ookthread_fn, this);
|
||||
} else {
|
||||
baseband::set_tones_data(transmitter_model.bandwidth(), 0, symbol_count, false, false);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -100,21 +149,29 @@ MorseView::MorseView(
|
||||
NavigationView& nav
|
||||
) : nav_ (nav)
|
||||
{
|
||||
|
||||
baseband::run_image(portapack::spi_flash::image_tag_tones);
|
||||
|
||||
add_children({
|
||||
&labels,
|
||||
&checkbox_foxhunt,
|
||||
&options_foxhunt,
|
||||
&text_time_unit,
|
||||
&field_time_unit,
|
||||
&text_tone,
|
||||
&field_tone,
|
||||
&options_modulation,
|
||||
&text_message,
|
||||
&button_message,
|
||||
&progressbar,
|
||||
&tx_view
|
||||
});
|
||||
|
||||
field_time_unit.set_value(50); // 50ms
|
||||
field_tone.set_value(700); // 700Hz
|
||||
field_time_unit.set_value(50); // 50ms
|
||||
field_tone.set_value(700); // 700Hz
|
||||
options_modulation.set_selected_index(0); // CW
|
||||
|
||||
button_message.on_select = [this, &nav](Button&) {
|
||||
this->on_set_text(nav);
|
||||
};
|
||||
|
||||
tx_view.on_edit_frequency = [this, &nav]() {
|
||||
auto new_view = nav.push<FrequencyKeypadView>(receiver_model.tuning_frequency());
|
||||
@@ -129,6 +186,7 @@ MorseView::MorseView(
|
||||
};
|
||||
|
||||
tx_view.on_stop = [this]() {
|
||||
chThdTerminate(ookthread);
|
||||
tx_view.set_transmitting(false);
|
||||
};
|
||||
|
||||
|
||||
@@ -34,6 +34,8 @@
|
||||
#include "audio.hpp"
|
||||
#include "morse.hpp"
|
||||
|
||||
#include <ch.h>
|
||||
|
||||
using namespace morse;
|
||||
|
||||
namespace ui {
|
||||
@@ -43,37 +45,32 @@ public:
|
||||
MorseView(NavigationView& nav);
|
||||
~MorseView();
|
||||
|
||||
MorseView(const MorseView&) = delete;
|
||||
MorseView(MorseView&&) = delete;
|
||||
MorseView& operator=(const MorseView&) = delete;
|
||||
MorseView& operator=(MorseView&&) = delete;
|
||||
|
||||
void focus() override;
|
||||
void paint(Painter& painter) override;
|
||||
|
||||
void on_tx_progress(const int progress, const bool done);
|
||||
uint32_t time_unit_ms { 0 };
|
||||
size_t symbol_count { 0 };
|
||||
private:
|
||||
NavigationView& nav_;
|
||||
char buffer[29] = "PORTAPACK";
|
||||
std::string message { };
|
||||
|
||||
bool start_tx();
|
||||
void on_tx_progress(const int progress, const bool done);
|
||||
void on_set_text(NavigationView& nav);
|
||||
|
||||
Text text_time_unit {
|
||||
{ 4 * 8, 6 * 8, 15 * 8, 16 },
|
||||
"Time unit: ms"
|
||||
};
|
||||
NumberField field_time_unit {
|
||||
{ 14 * 8, 6 * 8 },
|
||||
3,
|
||||
{ 1, 999 },
|
||||
1,
|
||||
' '
|
||||
};
|
||||
size_t modulation { 0 };
|
||||
Thread * ookthread { };
|
||||
|
||||
Text text_tone {
|
||||
{ 4 * 8, 8 * 8, 11 * 8, 16 },
|
||||
"Tone: Hz"
|
||||
};
|
||||
NumberField field_tone {
|
||||
{ 9 * 8, 8 * 8 },
|
||||
4,
|
||||
{ 100, 9999 },
|
||||
20,
|
||||
' '
|
||||
Labels labels {
|
||||
{ { 4 * 8, 6 * 8 }, "Time unit: ms", Color::light_grey() },
|
||||
{ { 4 * 8, 8 * 8 }, "Tone: Hz", Color::light_grey() },
|
||||
{ { 4 * 8, 10 * 8 }, "Modulation:", Color::light_grey() },
|
||||
};
|
||||
|
||||
Checkbox checkbox_foxhunt {
|
||||
@@ -99,6 +96,41 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
NumberField field_time_unit {
|
||||
{ 14 * 8, 6 * 8 },
|
||||
3,
|
||||
{ 10, 999 },
|
||||
1,
|
||||
' '
|
||||
};
|
||||
|
||||
NumberField field_tone {
|
||||
{ 9 * 8, 8 * 8 },
|
||||
4,
|
||||
{ 100, 9999 },
|
||||
20,
|
||||
' '
|
||||
};
|
||||
|
||||
OptionsField options_modulation {
|
||||
{ 15 * 8, 10 * 8 },
|
||||
2,
|
||||
{
|
||||
{ "CW", 0 },
|
||||
{ "FM", 1 }
|
||||
}
|
||||
};
|
||||
|
||||
Text text_message {
|
||||
{ 1 * 8, 14 * 8, 28 * 8, 16 },
|
||||
""
|
||||
};
|
||||
|
||||
Button button_message {
|
||||
{ 1 * 8, 16 * 8, 12 * 8, 28 },
|
||||
"Set message"
|
||||
};
|
||||
|
||||
ProgressBar progressbar {
|
||||
{ 2 * 8, 14 * 16, 208, 16 }
|
||||
};
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include "baseband_api.hpp"
|
||||
#include "string_format.hpp"
|
||||
#include "ui_textentry.hpp"
|
||||
|
||||
#include "portapack_persistent_memory.hpp"
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
#include "ui_navigation.hpp"
|
||||
#include "ui_receiver.hpp"
|
||||
#include "ui_transmitter.hpp"
|
||||
#include "ui_textentry.hpp"
|
||||
#include "bch_code.hpp"
|
||||
#include "message.hpp"
|
||||
#include "transmitter_model.hpp"
|
||||
@@ -106,8 +105,8 @@ private:
|
||||
};
|
||||
|
||||
Button button_message {
|
||||
{ 3 * 8, 14 * 8, 8 * 8, 28 },
|
||||
"Set"
|
||||
{ 3 * 8, 14 * 8, 12 * 8, 28 },
|
||||
"Set message"
|
||||
};
|
||||
|
||||
ProgressBar progressbar {
|
||||
|
||||
Reference in New Issue
Block a user