diff --git a/firmware/application/apps/analog_audio_app.cpp b/firmware/application/apps/analog_audio_app.cpp index 1e6c11e4..4726f44b 100644 --- a/firmware/application/apps/analog_audio_app.cpp +++ b/firmware/application/apps/analog_audio_app.cpp @@ -435,4 +435,7 @@ void AnalogAudioView::handle_coded_squelch(uint32_t value) { text_ctcss.set(tone_key_string_by_value(value, text_ctcss.parent_rect().width() / 8)); } +void AnalogAudioView::on_freqchg(int64_t freq) { + field_frequency.set_value(freq); +} } /* namespace ui */ diff --git a/firmware/application/apps/analog_audio_app.hpp b/firmware/application/apps/analog_audio_app.hpp index 6676335e..33153376 100644 --- a/firmware/application/apps/analog_audio_app.hpp +++ b/firmware/application/apps/analog_audio_app.hpp @@ -247,12 +247,21 @@ class AnalogAudioView : public View { void handle_coded_squelch(uint32_t value); + void on_freqchg(int64_t freq); + MessageHandlerRegistration message_handler_coded_squelch{ Message::ID::CodedSquelch, [this](const Message* p) { const auto message = *reinterpret_cast(p); this->handle_coded_squelch(message.value); }}; + + MessageHandlerRegistration message_handler_freqchg{ + Message::ID::FreqChangeCommand, + [this](Message* const p) { + const auto message = static_cast(p); + this->on_freqchg(message->freq); + }}; }; } /* namespace ui */ diff --git a/firmware/application/apps/capture_app.cpp b/firmware/application/apps/capture_app.cpp index a774a2c1..d5082bab 100644 --- a/firmware/application/apps/capture_app.cpp +++ b/firmware/application/apps/capture_app.cpp @@ -128,4 +128,8 @@ void CaptureAppView::focus() { record_view.focus(); } +void CaptureAppView::on_freqchg(int64_t freq) { + field_frequency.set_value(freq); +} + } /* namespace ui */ diff --git a/firmware/application/apps/capture_app.hpp b/firmware/application/apps/capture_app.hpp index f04bd1c5..d86f9c14 100644 --- a/firmware/application/apps/capture_app.hpp +++ b/firmware/application/apps/capture_app.hpp @@ -108,6 +108,15 @@ class CaptureAppView : public View { 3}; spectrum::WaterfallView waterfall{}; + + MessageHandlerRegistration message_handler_freqchg{ + Message::ID::FreqChangeCommand, + [this](Message* const p) { + const auto message = static_cast(p); + this->on_freqchg(message->freq); + }}; + + void on_freqchg(int64_t freq); }; } /* namespace ui */ diff --git a/firmware/application/apps/ert_app.cpp b/firmware/application/apps/ert_app.cpp index 3cb7f71e..0b0f1283 100644 --- a/firmware/application/apps/ert_app.cpp +++ b/firmware/application/apps/ert_app.cpp @@ -178,4 +178,8 @@ void ERTAppView::on_show_list() { recent_entries_view.focus(); } +void ERTAppView::on_freqchg(int64_t freq) { + field_frequency.set_value(freq); +} + } /* namespace ui */ diff --git a/firmware/application/apps/ert_app.hpp b/firmware/application/apps/ert_app.hpp index 283ca320..9172ca8e 100644 --- a/firmware/application/apps/ert_app.hpp +++ b/firmware/application/apps/ert_app.hpp @@ -176,6 +176,14 @@ class ERTAppView : public View { this->on_packet(packet); }}; + MessageHandlerRegistration message_handler_freqchg{ + Message::ID::FreqChangeCommand, + [this](Message* const p) { + const auto message = static_cast(p); + this->on_freqchg(message->freq); + }}; + + void on_freqchg(int64_t freq); void on_packet(const ert::Packet& packet); void on_show_list(); }; diff --git a/firmware/application/apps/pocsag_app.cpp b/firmware/application/apps/pocsag_app.cpp index d2d27933..c89e3796 100644 --- a/firmware/application/apps/pocsag_app.cpp +++ b/firmware/application/apps/pocsag_app.cpp @@ -321,6 +321,10 @@ void POCSAGAppView::on_stats(const POCSAGStatsMessage* stats) { widget_frames.set_sync(stats->has_sync); } +void POCSAGAppView::on_freqchg(int64_t freq) { + field_frequency.set_value(freq); +} + void BaudIndicator::paint(Painter& painter) { auto p = screen_pos(); char top = '-'; diff --git a/firmware/application/apps/pocsag_app.hpp b/firmware/application/apps/pocsag_app.hpp index 4530a9cb..fb7a5cd3 100644 --- a/firmware/application/apps/pocsag_app.hpp +++ b/firmware/application/apps/pocsag_app.hpp @@ -292,6 +292,15 @@ class POCSAGAppView : public View { Console console{ {0, 2 * 16 + 6, screen_width, screen_height - 54}}; + void on_freqchg(int64_t freq); + + MessageHandlerRegistration message_handler_freqchg{ + Message::ID::FreqChangeCommand, + [this](Message* const p) { + const auto message = static_cast(p); + this->on_freqchg(message->freq); + }}; + MessageHandlerRegistration message_handler_packet{ Message::ID::POCSAGPacket, [this](Message* const p) { diff --git a/firmware/application/apps/ui_aprs_rx.cpp b/firmware/application/apps/ui_aprs_rx.cpp index bdbe58ea..9296a67d 100644 --- a/firmware/application/apps/ui_aprs_rx.cpp +++ b/firmware/application/apps/ui_aprs_rx.cpp @@ -122,6 +122,10 @@ APRSRxView::APRSRxView(NavigationView& nav, Rect parent_rect) receiver_model.enable(); } +void APRSRxView::on_freqchg(int64_t freq) { + field_frequency.set_value(freq); +} + void APRSRxView::on_packet(const APRSPacketMessage* message) { std::string str_console = "\x1B"; diff --git a/firmware/application/apps/ui_aprs_rx.hpp b/firmware/application/apps/ui_aprs_rx.hpp index 1bf8792e..d2ebf6f5 100644 --- a/firmware/application/apps/ui_aprs_rx.hpp +++ b/firmware/application/apps/ui_aprs_rx.hpp @@ -185,6 +185,7 @@ class APRSRxView : public View { std::string title() const override { return "APRS RX"; }; void on_packet(const APRSPacketMessage* message); + void on_freqchg(int64_t freq); private: void on_data(uint32_t value, bool is_data); @@ -271,6 +272,13 @@ class APRSRXView : public View { this->view_stream.on_packet(message); this->view_table.on_pkt(message); }}; + + MessageHandlerRegistration message_handler_freqchg{ + Message::ID::FreqChangeCommand, + [this](Message* const p) { + const auto message = static_cast(p); + this->view_stream.on_freqchg(message->freq); + }}; }; } /* namespace ui */ diff --git a/firmware/application/apps/ui_level.cpp b/firmware/application/apps/ui_level.cpp index c8176921..a81a97b8 100644 --- a/firmware/application/apps/ui_level.cpp +++ b/firmware/application/apps/ui_level.cpp @@ -323,4 +323,9 @@ void LevelView::handle_coded_squelch(const uint32_t value) { text_ctcss.set(" "); } +void LevelView::on_freqchg(int64_t freq) { + receiver_model.set_target_frequency(freq); + button_frequency.set_text("<" + to_string_short_freq(freq) + " MHz>"); +} + } /* namespace ui */ diff --git a/firmware/application/apps/ui_level.hpp b/firmware/application/apps/ui_level.hpp index c40b89ff..b2d03b3e 100644 --- a/firmware/application/apps/ui_level.hpp +++ b/firmware/application/apps/ui_level.hpp @@ -188,6 +188,15 @@ class LevelView : public View { void handle_coded_squelch(const uint32_t value); + void on_freqchg(int64_t freq); + + MessageHandlerRegistration message_handler_freqchg{ + Message::ID::FreqChangeCommand, + [this](Message* const p) { + const auto message = static_cast(p); + this->on_freqchg(message->freq); + }}; + MessageHandlerRegistration message_handler_coded_squelch{ Message::ID::CodedSquelch, [this](const Message* const p) { diff --git a/firmware/application/apps/ui_sonde.cpp b/firmware/application/apps/ui_sonde.cpp index 0a8c576e..57e12df4 100644 --- a/firmware/application/apps/ui_sonde.cpp +++ b/firmware/application/apps/ui_sonde.cpp @@ -187,4 +187,8 @@ void SondeView::on_packet(const sonde::Packet& packet) { } } +void SondeView::on_freqchg(int64_t freq) { + field_frequency.set_value(freq); +} + } /* namespace ui */ diff --git a/firmware/application/apps/ui_sonde.hpp b/firmware/application/apps/ui_sonde.hpp index 242250ef..886ee44e 100644 --- a/firmware/application/apps/ui_sonde.hpp +++ b/firmware/application/apps/ui_sonde.hpp @@ -195,6 +195,14 @@ class SondeView : public View { const auto message = static_cast(p); this->on_orientation(message); }}; + MessageHandlerRegistration message_handler_freqchg{ + Message::ID::FreqChangeCommand, + [this](Message* const p) { + const auto message = static_cast(p); + this->on_freqchg(message->freq); + }}; + + void on_freqchg(int64_t freq); void on_gps(const GPSPosDataMessage* msg); void on_orientation(const OrientationDataMessage* msg); diff --git a/firmware/application/apps/ui_subghzd.cpp b/firmware/application/apps/ui_subghzd.cpp index 7bf2e051..102d29e9 100644 --- a/firmware/application/apps/ui_subghzd.cpp +++ b/firmware/application/apps/ui_subghzd.cpp @@ -224,6 +224,10 @@ std::string SubGhzDView::pad_string_with_spaces(int snakes) { return paddedStr; } +void SubGhzDView::on_freqchg(int64_t freq) { + field_frequency.set_value(freq); +} + template <> void RecentEntriesTable::draw( const Entry& entry, diff --git a/firmware/application/apps/ui_subghzd.hpp b/firmware/application/apps/ui_subghzd.hpp index c55a4a75..20271a35 100644 --- a/firmware/application/apps/ui_subghzd.hpp +++ b/firmware/application/apps/ui_subghzd.hpp @@ -127,6 +127,14 @@ class SubGhzDView : public View { }}; SubGhzDRecentEntriesView recent_entries_view{columns, recent}; + void on_freqchg(int64_t freq); + MessageHandlerRegistration message_handler_freqchg{ + Message::ID::FreqChangeCommand, + [this](Message* const p) { + const auto message = static_cast(p); + this->on_freqchg(message->freq); + }}; + MessageHandlerRegistration message_handler_packet{ Message::ID::SubGhzDData, [this](Message* const p) { diff --git a/firmware/application/apps/ui_weatherstation.cpp b/firmware/application/apps/ui_weatherstation.cpp index dbf9bea9..bf1faba6 100644 --- a/firmware/application/apps/ui_weatherstation.cpp +++ b/firmware/application/apps/ui_weatherstation.cpp @@ -220,6 +220,10 @@ std::string WeatherView::pad_string_with_spaces(int snakes) { return paddedStr; } +void WeatherView::on_freqchg(int64_t freq) { + field_frequency.set_value(freq); +} + template <> void RecentEntriesTable::draw( const Entry& entry, diff --git a/firmware/application/apps/ui_weatherstation.hpp b/firmware/application/apps/ui_weatherstation.hpp index 84b98d79..58292e20 100644 --- a/firmware/application/apps/ui_weatherstation.hpp +++ b/firmware/application/apps/ui_weatherstation.hpp @@ -151,6 +151,14 @@ class WeatherView : public View { }}; WeatherRecentEntriesView recent_entries_view{columns, recent}; + void on_freqchg(int64_t freq); + MessageHandlerRegistration message_handler_freqchg{ + Message::ID::FreqChangeCommand, + [this](Message* const p) { + const auto message = static_cast(p); + this->on_freqchg(message->freq); + }}; + MessageHandlerRegistration message_handler_packet{ Message::ID::WeatherData, [this](Message* const p) { diff --git a/firmware/application/external/afsk_rx/ui_afsk_rx.cpp b/firmware/application/external/afsk_rx/ui_afsk_rx.cpp index 626ff76e..6200fd60 100644 --- a/firmware/application/external/afsk_rx/ui_afsk_rx.cpp +++ b/firmware/application/external/afsk_rx/ui_afsk_rx.cpp @@ -143,6 +143,10 @@ void AFSKRxView::on_data(uint32_t value, bool is_data) { } } +void AFSKRxView::on_freqchg(int64_t freq) { + field_frequency.set_value(freq); +} + AFSKRxView::~AFSKRxView() { audio::output::stop(); receiver_model.disable(); diff --git a/firmware/application/external/afsk_rx/ui_afsk_rx.hpp b/firmware/application/external/afsk_rx/ui_afsk_rx.hpp index 2e0794cf..2ebcd08e 100644 --- a/firmware/application/external/afsk_rx/ui_afsk_rx.hpp +++ b/firmware/application/external/afsk_rx/ui_afsk_rx.hpp @@ -117,6 +117,15 @@ class AFSKRxView : public View { const auto message = static_cast(p); this->on_data(message->value, message->is_data); }}; + + MessageHandlerRegistration message_handler_freqchg{ + Message::ID::FreqChangeCommand, + [this](Message* const p) { + const auto message = static_cast(p); + this->on_freqchg(message->freq); + }}; + + void on_freqchg(int64_t freq); }; } // namespace ui::external_app::afsk_rx diff --git a/firmware/application/external/analogtv/analog_tv_app.cpp b/firmware/application/external/analogtv/analog_tv_app.cpp index 8251d94c..b9ec79ca 100644 --- a/firmware/application/external/analogtv/analog_tv_app.cpp +++ b/firmware/application/external/analogtv/analog_tv_app.cpp @@ -202,4 +202,8 @@ void AnalogTvView::update_modulation(const ReceiverModel::Mode modulation) { receiver_model.enable(); } +void AnalogTvView::on_freqchg(int64_t freq) { + field_frequency.set_value(freq); +} + } // namespace ui::external_app::analogtv diff --git a/firmware/application/external/analogtv/analog_tv_app.hpp b/firmware/application/external/analogtv/analog_tv_app.hpp index c056c7d9..21445fb0 100644 --- a/firmware/application/external/analogtv/analog_tv_app.hpp +++ b/firmware/application/external/analogtv/analog_tv_app.hpp @@ -108,6 +108,15 @@ class AnalogTvView : public View { void set_options_widget(std::unique_ptr new_widget); void update_modulation(const ReceiverModel::Mode modulation); + + MessageHandlerRegistration message_handler_freqchg{ + Message::ID::FreqChangeCommand, + [this](Message* const p) { + const auto message = static_cast(p); + this->on_freqchg(message->freq); + }}; + + void on_freqchg(int64_t freq); }; } // namespace ui::external_app::analogtv diff --git a/firmware/application/external/foxhunt/ui_foxhunt_rx.cpp b/firmware/application/external/foxhunt/ui_foxhunt_rx.cpp index 3c8bfb11..b809333e 100644 --- a/firmware/application/external/foxhunt/ui_foxhunt_rx.cpp +++ b/firmware/application/external/foxhunt/ui_foxhunt_rx.cpp @@ -103,4 +103,8 @@ void FoxhuntRxView::on_orientation(const OrientationDataMessage* msg) { geomap.update_my_orientation(msg->angle, true); } +void FoxhuntRxView::on_freqchg(int64_t freq) { + field_frequency.set_value(freq); +} + } // namespace ui::external_app::foxhunt_rx diff --git a/firmware/application/external/foxhunt/ui_foxhunt_rx.hpp b/firmware/application/external/foxhunt/ui_foxhunt_rx.hpp index ba47086d..ed61336f 100644 --- a/firmware/application/external/foxhunt/ui_foxhunt_rx.hpp +++ b/firmware/application/external/foxhunt/ui_foxhunt_rx.hpp @@ -103,6 +103,14 @@ class FoxhuntRxView : public View { [this](const Message* const p) { this->on_statistics_update(static_cast(p)->statistics); }}; + MessageHandlerRegistration message_handler_freqchg{ + Message::ID::FreqChangeCommand, + [this](Message* const p) { + const auto message = static_cast(p); + this->on_freqchg(message->freq); + }}; + + void on_freqchg(int64_t freq); float my_lat = 200; float my_lon = 200; diff --git a/firmware/application/external/nrf_rx/ui_nrf_rx.cpp b/firmware/application/external/nrf_rx/ui_nrf_rx.cpp index ad9b122e..eda09e62 100644 --- a/firmware/application/external/nrf_rx/ui_nrf_rx.cpp +++ b/firmware/application/external/nrf_rx/ui_nrf_rx.cpp @@ -125,6 +125,10 @@ void NRFRxView::on_data(uint32_t value, bool is_data) { } } +void NRFRxView::on_freqchg(int64_t freq) { + field_frequency.set_value(freq); +} + NRFRxView::~NRFRxView() { audio::output::stop(); receiver_model.disable(); diff --git a/firmware/application/external/nrf_rx/ui_nrf_rx.hpp b/firmware/application/external/nrf_rx/ui_nrf_rx.hpp index 61af7094..15b25525 100644 --- a/firmware/application/external/nrf_rx/ui_nrf_rx.hpp +++ b/firmware/application/external/nrf_rx/ui_nrf_rx.hpp @@ -89,6 +89,15 @@ class NRFRxView : public View { const auto message = static_cast(p); this->on_data(message->value, message->is_data); }}; + + MessageHandlerRegistration message_handler_freqchg{ + Message::ID::FreqChangeCommand, + [this](Message* const p) { + const auto message = static_cast(p); + this->on_freqchg(message->freq); + }}; + + void on_freqchg(int64_t freq); }; } /* namespace ui::external_app::nrf_rx */ diff --git a/firmware/application/external/protoview/ui_protoview.cpp b/firmware/application/external/protoview/ui_protoview.cpp index 47e5f047..1c5c939f 100644 --- a/firmware/application/external/protoview/ui_protoview.cpp +++ b/firmware/application/external/protoview/ui_protoview.cpp @@ -186,6 +186,10 @@ void ProtoView::on_data(const ProtoViewDataMessage* message) { draw2(); } +void ProtoView::on_freqchg(int64_t freq) { + field_frequency.set_value(freq); +} + ProtoView::~ProtoView() { audio::output::stop(); receiver_model.disable(); diff --git a/firmware/application/external/protoview/ui_protoview.hpp b/firmware/application/external/protoview/ui_protoview.hpp index b5991110..597b50c2 100644 --- a/firmware/application/external/protoview/ui_protoview.hpp +++ b/firmware/application/external/protoview/ui_protoview.hpp @@ -157,6 +157,15 @@ class ProtoView : public View { [this](const Message* const) { this->on_timer(); }}; + + MessageHandlerRegistration message_handler_freqchg{ + Message::ID::FreqChangeCommand, + [this](Message* const p) { + const auto message = static_cast(p); + this->on_freqchg(message->freq); + }}; + + void on_freqchg(int64_t freq); }; } // namespace ui::external_app::protoview diff --git a/firmware/application/usb_serial_shell.cpp b/firmware/application/usb_serial_shell.cpp index 722eef46..91187034 100644 --- a/firmware/application/usb_serial_shell.cpp +++ b/firmware/application/usb_serial_shell.cpp @@ -1147,6 +1147,23 @@ static void cmd_asyncmsg(BaseSequentialStream* chp, int argc, char* argv[]) { chprintf(chp, usage); } } +static void cmd_setfreq(BaseSequentialStream* chp, int argc, char* argv[]) { + const char* usage = "usage: setfreq freq_in_hz\r\n"; + if (argc != 1) { + chprintf(chp, usage); + return; + } + int64_t freq = atol(argv[0]); + + if (freq <= 0) { + chprintf(chp, usage); + return; + } + // radio::set_tuning_frequency(freq); // sadly this doesn't update any widget, just change the frequency. + FreqChangeCommandMessage message{freq}; + EventDispatcher::send_message(message); + chprintf(chp, "ok\r\n"); +} static const ShellCommand commands[] = { {"reboot", cmd_reboot}, @@ -1180,6 +1197,7 @@ static const ShellCommand commands[] = { {"settingsreset", cmd_settingsreset}, {"sendpocsag", cmd_sendpocsag}, {"asyncmsg", cmd_asyncmsg}, + {"setfreq", cmd_setfreq}, {NULL, NULL}}; static const ShellConfig shell_cfg1 = { diff --git a/firmware/common/message.hpp b/firmware/common/message.hpp index 2a422be7..a0bb6d5e 100644 --- a/firmware/common/message.hpp +++ b/firmware/common/message.hpp @@ -125,6 +125,7 @@ class Message { PocsagTosend = 67, BatteryStateData = 68, ProtoViewData = 69, + FreqChangeCommand = 70, MAX }; @@ -1427,4 +1428,11 @@ class ProtoViewDataMessage : public Message { const uint16_t maxptr = 99; }; +class FreqChangeCommandMessage : public Message { + public: + constexpr FreqChangeCommandMessage(int64_t freq) + : Message{ID::FreqChangeCommand}, freq{freq} {} + int64_t freq = 0; +}; + #endif /*__MESSAGE_H__*/