diff --git a/firmware/application/pocsag_app.cpp b/firmware/application/pocsag_app.cpp index bf84acf5..609af233 100644 --- a/firmware/application/pocsag_app.cpp +++ b/firmware/application/pocsag_app.cpp @@ -59,11 +59,8 @@ void POCSAGAppView::update_freq(rf::Frequency f) { set_target_frequency(f); portapack::persistent_memory::set_tuned_frequency(f); // Maybe not ? - - auto mhz = to_string_dec_int(f / 1000000, 4); - auto hz100 = to_string_dec_int((f / 100) % 10000, 4, '0'); - button_setfreq.set_text(mhz + "." + hz100); + button_setfreq.set_text(to_string_short_freq(f)); } POCSAGAppView::POCSAGAppView(NavigationView& nav) { diff --git a/firmware/application/recent_entries.cpp b/firmware/application/recent_entries.cpp index bc6ef17a..4b9c7562 100644 --- a/firmware/application/recent_entries.cpp +++ b/firmware/application/recent_entries.cpp @@ -41,7 +41,7 @@ void RecentEntriesHeader::paint(Painter& painter) { const Style style { .font = parent_style.font, - .background = Color::blue(), + .background = Color::dark_blue(), .foreground = parent_style.foreground, }; diff --git a/firmware/application/string_format.cpp b/firmware/application/string_format.cpp index 86716331..f96dd361 100644 --- a/firmware/application/string_format.cpp +++ b/firmware/application/string_format.cpp @@ -112,10 +112,8 @@ std::string to_string_dec_int( return q; } -std::string to_string_short_freq(const uint64_t f, const int32_t l) { - auto final_str = to_string_dec_int(f / 1000000, 4) + "."; - final_str += to_string_dec_int((f / 100) % 10000, l, '0'); - +std::string to_string_short_freq(const uint64_t f) { + auto final_str = to_string_dec_int(f / 1000000, 4) + "." + to_string_dec_int((f / 100) % 10000, 4, '0'); return final_str; } diff --git a/firmware/application/string_format.hpp b/firmware/application/string_format.hpp index 206d1ad6..68822520 100644 --- a/firmware/application/string_format.hpp +++ b/firmware/application/string_format.hpp @@ -36,7 +36,7 @@ std::string to_string_dec_int(const int32_t n, const int32_t l = 0, const char f std::string to_string_hex(const uint64_t n, const int32_t l = 0); std::string to_string_hex_array(uint8_t * const array, const int32_t l = 0); -std::string to_string_short_freq(const uint64_t f, const int32_t l = 4); +std::string to_string_short_freq(const uint64_t f); std::string to_string_datetime(const rtc::RTC& value); std::string to_string_time(const rtc::RTC& value); diff --git a/firmware/application/ui_jammer.cpp b/firmware/application/ui_jammer.cpp index 90f60fc7..44a8b433 100644 --- a/firmware/application/ui_jammer.cpp +++ b/firmware/application/ui_jammer.cpp @@ -55,11 +55,8 @@ void JammerView::update_range(const uint32_t n) { center = (range_ptr->min + range_ptr->max) / 2; bw_khz = abs(range_ptr->max - range_ptr->min) / 1000; - - auto center_mhz = to_string_dec_int(center / 1000000, 4); - auto center_hz100 = to_string_dec_int((center / 1000) % 1000, 3, '0'); - label = "C:" + center_mhz + "." + center_hz100 + "M W:"; + label = "C:" + to_string_short_freq(center) + "M W:"; if (bw_khz < 1000) { label += to_string_dec_int(bw_khz, 3) + "kHz"; diff --git a/firmware/application/ui_lcr.cpp b/firmware/application/ui_lcr.cpp index e3a56b7c..2e74a0c4 100644 --- a/firmware/application/ui_lcr.cpp +++ b/firmware/application/ui_lcr.cpp @@ -73,7 +73,7 @@ void LCRView::paint(Painter& painter) { button_setrgsb.set_text(rgsb); // Recap: frequency @ baudrate - final_str = to_string_short_freq(persistent_memory::tuned_frequency(), 3); + final_str = to_string_short_freq(persistent_memory::tuned_frequency()); final_str += '@'; final_str += to_string_dec_int(persistent_memory::modem_baudrate(), 4); final_str += "bps "; diff --git a/firmware/application/ui_modemsetup.cpp b/firmware/application/ui_modemsetup.cpp index 76b2c2b1..b4983f61 100644 --- a/firmware/application/ui_modemsetup.cpp +++ b/firmware/application/ui_modemsetup.cpp @@ -44,7 +44,7 @@ void ModemSetupView::focus() { void ModemSetupView::update_freq(rf::Frequency f) { persistent_memory::set_tuned_frequency(f); - button_setfreq.set_text(to_string_short_freq(f, 4)); + button_setfreq.set_text(to_string_short_freq(f)); } ModemSetupView::ModemSetupView( diff --git a/firmware/application/ui_receiver.cpp b/firmware/application/ui_receiver.cpp index d41c0b4d..6552a84e 100644 --- a/firmware/application/ui_receiver.cpp +++ b/firmware/application/ui_receiver.cpp @@ -65,25 +65,14 @@ void FrequencyField::set_step(rf::Frequency new_value) { } void FrequencyField::paint(Painter& painter) { - const auto mhz = to_string_dec_int(value_ / 1000000, 4); - const auto hz100 = to_string_dec_int((value_ / 100) % 10000, 4, '0'); + const std::string str_value = to_string_short_freq(value_); const auto paint_style = has_focus() ? style().invert() : style(); painter.draw_string( screen_pos(), paint_style, - mhz - ); - painter.draw_string( - screen_pos() + Point { 4 * 8, 0 }, - paint_style, - "." - ); - painter.draw_string( - screen_pos() + Point { 5 * 8, 0 }, - paint_style, - hz100 + str_value ); } diff --git a/firmware/application/ui_scanner.cpp b/firmware/application/ui_scanner.cpp index ccb0fb5e..a61b05fb 100644 --- a/firmware/application/ui_scanner.cpp +++ b/firmware/application/ui_scanner.cpp @@ -20,6 +20,9 @@ * Boston, MA 02110-1301, USA. */ +// BUG: Mirroring in proc_wideband... +// BUG: Lock on frequency, if frequency jump, still locked on first one + #include "ui_scanner.hpp" #include "baseband_api.hpp" @@ -61,6 +64,7 @@ void ScannerView::do_detection() { uint8_t power_max = 0; int32_t bin_max = -1; uint32_t bin_max_pixel = 0; + uint32_t snap_value; uint8_t power; rtc::RTC datetime; std::string str_approx, str_timestamp; @@ -91,7 +95,12 @@ void ScannerView::do_detection() { if ((bin_max != locked_bin) || (!locked)) { if (!locked) { - resolved_frequency = slices[slice_counter].center_frequency + (SCAN_BIN_WIDTH * (bin_max - 120)); // Init + resolved_frequency = slices[slice_counter].center_frequency + (SCAN_BIN_WIDTH * (bin_max - 120)); + + if (check_snap.value()) { + snap_value = options_snap.selected_index_value(); + resolved_frequency = round(resolved_frequency / snap_value) * snap_value; + } // Check range if ((resolved_frequency >= f_min) && (resolved_frequency <= f_max)) { @@ -110,11 +119,6 @@ void ScannerView::do_detection() { text_infos.set("Locked ! "); big_display.set_style(&style_locked); - // Approximation/error display - str_approx = "." + to_string_dec_uint(((resolved_frequency - 4883) / 1000) % 10000); - str_approx += "~." + to_string_dec_uint(((resolved_frequency + 4883) / 1000) % 10000); - text_approx.set(str_approx); - locked = true; locked_bin = bin_max; @@ -269,7 +273,7 @@ void ScannerView::on_range_changed() { receiver_model.set_tuning_frequency(slices[0].center_frequency); slices_nb = 1; - text_slices.set("1"); + text_slices.set(" 1"); } slice_counter = 0; @@ -346,14 +350,18 @@ ScannerView::ScannerView( &text_infos, &vu_max, &progress_timers, - //&check_goto, - //&options_goto, + &check_snap, + &options_snap, &big_display, - &recent_entries_view, - &text_approx + &recent_entries_view }); + baseband::set_spectrum(SCAN_SLICE_WIDTH, 32); + recent_entries_view.set_parent_rect({ 0, 28 * 8, 240, 12 * 8 }); + recent_entries_view.on_select = [this, &nav](const ScannerRecentEntry& entry) { + nav.push(entry.frequency); + }; text_mean.set_style(&style_grey); text_slices.set_style(&style_grey); @@ -361,9 +369,8 @@ ScannerView::ScannerView( progress_timers.set_style(&style_grey); big_display.set_style(&style_grey); - baseband::set_spectrum(SCAN_SLICE_WIDTH, 32); - - //options_goto.set_selected_index(0); // Nothing + check_snap.set_value(true); + options_snap.set_selected_index(1); // 12.5kHz field_threshold.set_value(80); field_threshold.on_change = [this](int32_t value) { diff --git a/firmware/application/ui_scanner.hpp b/firmware/application/ui_scanner.hpp index 7f2b67b7..3e84f470 100644 --- a/firmware/application/ui_scanner.hpp +++ b/firmware/application/ui_scanner.hpp @@ -149,17 +149,9 @@ private: { { 1 * 8, 4 * 8 }, "Trig: /255 Mean: /255", Color::light_grey() }, { { 1 * 8, 6 * 8 }, "Slices: /32 Rate: Hz", Color::light_grey() }, { { 6 * 8, 10 * 8 }, "Timer Status", Color::light_grey() }, - { { 1 * 8, 25 * 8 }, "+/-4.9kHz:", Color::light_grey() }, + { { 1 * 8, 25 * 8 }, "Accuracy: +/-4.9kHz", Color::light_grey() }, { { 26 * 8, 25 * 8 }, "MHz", Color::light_grey() } }; - - NumberField field_threshold { - { 6 * 8, 2 * 16 }, - 3, - { 5, 255 }, - 5, - ' ' - }; FrequencyField field_frequency_min { { 1 * 8, 1 * 16 }, @@ -174,6 +166,13 @@ private: { 26 * 8, 1 * 16 } }; + NumberField field_threshold { + { 6 * 8, 2 * 16 }, + 3, + { 5, 255 }, + 5, + ' ' + }; Text text_mean { { 22 * 8, 2 * 16, 3 * 8, 16 }, "---" @@ -192,6 +191,7 @@ private: 16, false }; + ProgressBar progress_timers { { 6 * 8, 12 * 8, 5 * 8, 16 } }; @@ -199,19 +199,20 @@ private: { 13 * 8, 12 * 8, 15 * 8, 16 }, "Listening" }; - Checkbox check_goto { + + Checkbox check_snap { { 6 * 8, 15 * 8 }, - 8, - "On lock:", + 7, + "Adjust:", true }; - OptionsField options_goto { - { 17 * 8, 15 * 8 }, + OptionsField options_snap { + { 15 * 8, 15 * 8 }, 7, { - { "Nothing", 0 }, - { "NFM RX ", 1 }, - { "POCSAG ", 2 } + { "25kHz ", 25000 }, + { "12.5kHz", 12500 }, + { "8.33kHz", 8333 } } }; @@ -220,11 +221,6 @@ private: 0 }; - Text text_approx { - { 11 * 8, 25 * 8, 11 * 8, 16 }, - "..." - }; - MessageHandlerRegistration message_handler_spectrum_config { Message::ID::ChannelSpectrumConfig, [this](const Message* const p) { diff --git a/firmware/common/ui.hpp b/firmware/common/ui.hpp index b6777f35..0a5ebd42 100644 --- a/firmware/common/ui.hpp +++ b/firmware/common/ui.hpp @@ -95,6 +95,9 @@ struct Color { static constexpr Color blue() { return { 0, 0, 255 }; } + static constexpr Color dark_blue() { + return { 0, 0, 127 }; + } static constexpr Color cyan() { return { 0, 255, 255 }; diff --git a/firmware/portapack-h1-havoc.bin b/firmware/portapack-h1-havoc.bin index 735e8f7f..6b70476d 100644 Binary files a/firmware/portapack-h1-havoc.bin and b/firmware/portapack-h1-havoc.bin differ