diff --git a/firmware/application/apps/ui_setup.cpp b/firmware/application/apps/ui_setup.cpp index 5927ead4..31a86d48 100644 --- a/firmware/application/apps/ui_setup.cpp +++ b/firmware/application/apps/ui_setup.cpp @@ -216,8 +216,6 @@ void SetPlayDeadView::focus() { } SetUIView::SetUIView(NavigationView& nav) { - uint32_t ui_config; - add_children({ &checkbox_login, &checkbox_bloff, @@ -226,24 +224,26 @@ SetUIView::SetUIView(NavigationView& nav) { &button_ok }); - ui_config = portapack::persistent_memory::ui_config(); + checkbox_showsplash.set_value(persistent_memory::config_splash()); + checkbox_login.set_value(persistent_memory::config_login()); - if (ui_config & 1) checkbox_showsplash.set_value(true); - if (ui_config & 2) checkbox_bloff.set_value(true); - if (ui_config & 16) checkbox_login.set_value(true); - options_bloff.set_selected_index((ui_config >> 5) & 7); + uint32_t backlight_timer = persistent_memory::config_backlight_timer(); + + if (backlight_timer) { + checkbox_bloff.set_value(true); + options_bloff.set_by_value(backlight_timer); + } else { + options_bloff.set_selected_index(0); + } - button_ok.on_select = [&nav, &ui_config, this](Button&) { - ui_config &= ~0b10011; + button_ok.on_select = [&nav, this](Button&) { + if (checkbox_bloff.value()) + persistent_memory::set_config_backlight_timer(options_bloff.selected_index() + 1); + else + persistent_memory::set_config_backlight_timer(0); - if (checkbox_login.value()) { - portapack::persistent_memory::set_playing_dead(0x5920C1DF); // Enable - ui_config |= (1 << 4); - } - if (checkbox_showsplash.value()) ui_config |= (1 << 0); - if (checkbox_bloff.value()) ui_config |= (1 << 1); - - portapack::persistent_memory::set_ui_config(ui_config); + persistent_memory::set_config_splash(checkbox_showsplash.value()); + persistent_memory::set_config_login(checkbox_login.value()); nav.pop(); }; } diff --git a/firmware/application/apps/ui_setup.hpp b/firmware/application/apps/ui_setup.hpp index d3cab311..d1f869c0 100644 --- a/firmware/application/apps/ui_setup.hpp +++ b/firmware/application/apps/ui_setup.hpp @@ -247,11 +247,11 @@ private: { 52, 6 * 16 + 8 }, 10, { - { "5 seconds", 0 }, - { "15 seconds", 1 }, - { "1 minute", 2 }, - { "5 minutes", 3 }, - { "10 minutes", 4 } + { "5 seconds", 5 }, + { "15 seconds", 15 }, + { "1 minute", 60 }, + { "5 minutes", 300 }, + { "10 minutes", 600 } } }; diff --git a/firmware/application/bitmap.hpp b/firmware/application/bitmap.hpp index 467ce441..506b9b70 100644 --- a/firmware/application/bitmap.hpp +++ b/firmware/application/bitmap.hpp @@ -104,7 +104,7 @@ static constexpr uint8_t bitmap_stripes_data[] = { 0x1F, 0x00, 0xFE, 0x0F, 0x00, 0xFF, 0x07, 0x80, 0xFF, - }; +}; static constexpr Bitmap bitmap_stripes { { 24, 8 }, bitmap_stripes_data }; @@ -810,44 +810,44 @@ static constexpr Bitmap bitmap_icon_keyfob { }; static constexpr uint8_t bitmap_icon_biast_off_data[] = { - 0xFF, 0xFF, - 0xFF, 0xFF, - 0x80, 0x01, - 0x80, 0x01, - 0x80, 0x01, - 0x00, 0x00, - 0x00, 0x00, - 0x20, 0x04, - 0x60, 0x06, - 0xC0, 0x03, - 0x80, 0x01, - 0xC0, 0x03, - 0x60, 0x06, - 0x20, 0x04, - 0x00, 0x00, 0x00, 0x00, + 0xFC, 0x3F, + 0x00, 0x02, + 0x00, 0x0E, + 0x00, 0x18, + 0x00, 0x10, + 0x88, 0x18, + 0xD8, 0x0E, + 0x70, 0x18, + 0x20, 0x10, + 0x70, 0x18, + 0xD8, 0x0E, + 0x88, 0x18, + 0x00, 0x10, + 0x00, 0x18, + 0x00, 0x0E, }; static constexpr Bitmap bitmap_icon_biast_off { { 16, 16 }, bitmap_icon_biast_off_data }; static constexpr uint8_t bitmap_icon_biast_on_data[] = { - 0xFF, 0xFF, - 0xFF, 0xFF, - 0x80, 0x01, - 0x80, 0x03, - 0x08, 0x06, - 0x08, 0x04, - 0x0C, 0x06, - 0x84, 0x03, - 0x0E, 0x06, - 0x3E, 0x04, - 0x38, 0x06, - 0x90, 0x03, - 0x18, 0x06, - 0x08, 0x04, - 0x08, 0x06, - 0x80, 0x03, + 0x00, 0x00, + 0xFE, 0x7F, + 0x00, 0x02, + 0x00, 0x0E, + 0x20, 0x18, + 0x20, 0x10, + 0x30, 0x18, + 0x10, 0x0E, + 0x38, 0x18, + 0xF8, 0x10, + 0xE0, 0x18, + 0x40, 0x0E, + 0x60, 0x18, + 0x20, 0x10, + 0x20, 0x18, + 0x00, 0x0E, }; static constexpr Bitmap bitmap_icon_biast_on { { 16, 16 }, bitmap_icon_biast_on_data @@ -1048,7 +1048,7 @@ static constexpr uint8_t bitmap_rssipwm_data[] = { 0x21, 0x12, 0x12, 0x21, 0x12, 0x12, 0xE1, 0xF3, 0x73, - }; +}; static constexpr Bitmap bitmap_rssipwm { { 24, 16 }, bitmap_rssipwm_data }; @@ -1100,22 +1100,22 @@ static constexpr uint8_t bitmap_tab_edge_data[] = { 0x03, 0x07, 0x07, -0x07, -0x0F, -0x0F, -0x0F, -0x1F, -0x1F, -0x1F, -0x1F, -0x3F, -0x3F, -0x3F, -0x7F, -0x7F, -0x7F, -0xFF, -0xFF, + 0x07, + 0x0F, + 0x0F, + 0x0F, + 0x1F, + 0x1F, + 0x1F, + 0x1F, + 0x3F, + 0x3F, + 0x3F, + 0x7F, + 0x7F, + 0x7F, + 0xFF, + 0xFF, }; static constexpr Bitmap bitmap_tab_edge { { 8, 24 }, bitmap_tab_edge_data diff --git a/firmware/application/event_m0.cpp b/firmware/application/event_m0.cpp index 2225610a..34bc2338 100644 --- a/firmware/application/event_m0.cpp +++ b/firmware/application/event_m0.cpp @@ -222,15 +222,13 @@ void EventDispatcher::handle_local_queue() { } void EventDispatcher::handle_rtc_tick() { - uint16_t bloff; - sd_card::poll_inserted(); portapack::temperature_logger.second_tick(); - bloff = portapack::persistent_memory::ui_config_bloff(); - if (bloff) { - if (portapack::bl_tick_counter == bloff) + uint32_t backlight_timer = portapack::persistent_memory::config_backlight_timer(); + if (backlight_timer) { + if (portapack::bl_tick_counter == backlight_timer) set_display_sleep(true); else portapack::bl_tick_counter++; diff --git a/firmware/application/ui_navigation.cpp b/firmware/application/ui_navigation.cpp index 0e9a2a87..c2ff7fdd 100644 --- a/firmware/application/ui_navigation.cpp +++ b/firmware/application/ui_navigation.cpp @@ -82,7 +82,10 @@ namespace ui { /* SystemStatusView ******************************************************/ -SystemStatusView::SystemStatusView() { +SystemStatusView::SystemStatusView( + NavigationView& nav +) : nav_ (nav) +{ static constexpr Style style_systemstatus { .font = font::fixed_8x16, .background = Color::dark_grey(), @@ -97,7 +100,7 @@ SystemStatusView::SystemStatusView() { //&button_textentry, &button_camera, &button_sleep, - &image_bias_tee, + &button_bias_tee, &sd_card_status_view, }); @@ -112,6 +115,8 @@ SystemStatusView::SystemStatusView() { else button_textentry.set_bitmap(&bitmap_icon_unistroke);*/ + refresh(); + button_back.on_select = [this](ImageButton&){ if (this->on_back) this->on_back(); @@ -121,6 +126,10 @@ SystemStatusView::SystemStatusView() { this->on_stealth(); }; + button_bias_tee.on_select = [this](ImageButton&) { + this->on_bias_tee(); + }; + /*button_textentry.on_select = [this](ImageButton&) { this->on_textentry(); };*/ @@ -137,12 +146,12 @@ SystemStatusView::SystemStatusView() { void SystemStatusView::refresh() { if (receiver_model.antenna_bias()) { - image_bias_tee.set_bitmap(&bitmap_icon_biast_on); - image_bias_tee.set_foreground(ui::Color::green()); + button_bias_tee.set_bitmap(&bitmap_icon_biast_on); + button_bias_tee.set_foreground(ui::Color::yellow()); } else { - image_bias_tee.set_bitmap(&bitmap_icon_biast_off); - image_bias_tee.set_foreground(ui::Color::light_grey()); - } + button_bias_tee.set_bitmap(&bitmap_icon_biast_off); + button_bias_tee.set_foreground(ui::Color::light_grey()); + } } void SystemStatusView::set_back_enabled(bool new_value) { @@ -159,12 +168,11 @@ void SystemStatusView::set_title(const std::string new_value) { } void SystemStatusView::on_stealth() { - bool cfg; + bool mode = not portapack::persistent_memory::stealth_mode(); - cfg = portapack::persistent_memory::stealth_mode(); - portapack::persistent_memory::set_stealth_mode(not cfg); + portapack::persistent_memory::set_stealth_mode(mode); - if (!cfg) + if (mode) button_stealth.set_foreground(ui::Color::green()); else button_stealth.set_foreground(ui::Color::light_grey()); @@ -172,6 +180,23 @@ void SystemStatusView::on_stealth() { button_stealth.set_dirty(); } +void SystemStatusView::on_bias_tee() { + bool antenna_bias = receiver_model.antenna_bias(); + + if (!antenna_bias) { + nav_.display_modal("Bias voltage", "Enable DC voltage on\nantenna connector ?", YESNO, [this](bool v) { + if (v) { + receiver_model.set_antenna_bias(true); + refresh(); + } + }); + + } else { + receiver_model.set_antenna_bias(false); + refresh(); + } +} + /*void SystemStatusView::on_textentry() { uint8_t cfg; @@ -434,7 +459,7 @@ SystemView::SystemView( (portapack::persistent_memory::ui_config() & 16)) { // Login option navigation_view.push(); } else {*/ - if (portapack::persistent_memory::ui_config() & 1) + if (portapack::persistent_memory::config_splash()) navigation_view.push(); else navigation_view.push(); diff --git a/firmware/application/ui_navigation.hpp b/firmware/application/ui_navigation.hpp index 3c843404..ee8f49e2 100644 --- a/firmware/application/ui_navigation.hpp +++ b/firmware/application/ui_navigation.hpp @@ -53,17 +53,58 @@ enum modal_t { ABORT }; +class NavigationView : public View { +public: + std::function on_view_changed { }; + + NavigationView() = default; + + NavigationView(const NavigationView&) = delete; + NavigationView(NavigationView&&) = delete; + NavigationView& operator=(const NavigationView&) = delete; + NavigationView& operator=(NavigationView&&) = delete; + + bool is_top() const; + + template + T* push(Args&&... args) { + return reinterpret_cast(push_view(std::unique_ptr(new T(*this, std::forward(args)...)))); + } + + void push(View* v); + + void pop(); + void pop_modal(); + + void display_modal(const std::string& title, const std::string& message); + void display_modal(const std::string& title, const std::string& message, const modal_t type, const std::function on_choice = nullptr); + + void focus() override; + +private: + std::vector> view_stack { }; + Widget* modal_view { nullptr }; + + Widget* view() const; + + void free_view(); + void update_view(); + View* push_view(std::unique_ptr new_view); +}; + class SystemStatusView : public View { public: std::function on_back { }; - SystemStatusView(); + SystemStatusView(NavigationView& nav); void set_back_enabled(bool new_value); void set_title(const std::string new_value); private: static constexpr auto default_title = "PortaPack|Havoc"; + + NavigationView& nav_; Rectangle backdrop { { 0 * 8, 0 * 16, 240, 16 }, @@ -110,8 +151,8 @@ private: Color::dark_grey() }; - Image image_bias_tee { - { 26 * 8, 0, 2 * 8, 1 * 16 }, + ImageButton button_bias_tee { + { 26 * 8, 0, 12, 1 * 16 }, &bitmap_icon_biast_off, Color::light_grey(), Color::dark_grey() @@ -122,6 +163,7 @@ private: }; void on_stealth(); + void on_bias_tee(); //void on_textentry(); void on_camera(); void refresh(); @@ -135,45 +177,6 @@ private: }; }; -class NavigationView : public View { -public: - std::function on_view_changed { }; - - NavigationView() = default; - - NavigationView(const NavigationView&) = delete; - NavigationView(NavigationView&&) = delete; - NavigationView& operator=(const NavigationView&) = delete; - NavigationView& operator=(NavigationView&&) = delete; - - bool is_top() const; - - template - T* push(Args&&... args) { - return reinterpret_cast(push_view(std::unique_ptr(new T(*this, std::forward(args)...)))); - } - - void push(View* v); - - void pop(); - void pop_modal(); - - void display_modal(const std::string& title, const std::string& message); - void display_modal(const std::string& title, const std::string& message, const modal_t type, const std::function on_choice = nullptr); - - void focus() override; - -private: - std::vector> view_stack { }; - Widget* modal_view { nullptr }; - - Widget* view() const; - - void free_view(); - void update_view(); - View* push_view(std::unique_ptr new_view); -}; - class BMPView : public View { public: BMPView(NavigationView& nav); @@ -227,7 +230,7 @@ public: Context& context() const override; private: - SystemStatusView status_view { }; + SystemStatusView status_view { navigation_view }; NavigationView navigation_view { }; Context& context_; }; diff --git a/firmware/application/ui_playdead.cpp b/firmware/application/ui_playdead.cpp index 36896d93..83537c9d 100644 --- a/firmware/application/ui_playdead.cpp +++ b/firmware/application/ui_playdead.cpp @@ -24,6 +24,8 @@ #include "portapack_persistent_memory.hpp" #include "string_format.hpp" +using namespace portapack; + namespace ui { void PlayDeadView::focus() { @@ -31,10 +33,10 @@ void PlayDeadView::focus() { } void PlayDeadView::paint(Painter& painter) { - if (!(portapack::persistent_memory::ui_config() & 16)) { + if (persistent_memory::config_login()) { // Blank the whole display painter.fill_rectangle( - portapack::display.screen_rect(), + display.screen_rect(), style().background ); } @@ -43,7 +45,7 @@ void PlayDeadView::paint(Painter& painter) { PlayDeadView::PlayDeadView(NavigationView& nav) { rtc::RTC datetime; - portapack::persistent_memory::set_playing_dead(0x5920C1DF); // Enable + persistent_memory::set_playing_dead(0x5920C1DF); // Enable add_children({ &text_playdead1, @@ -64,9 +66,9 @@ PlayDeadView::PlayDeadView(NavigationView& nav) { }; button_seq_entry.on_select = [this, &nav](Button&){ - if (sequence == portapack::persistent_memory::playdead_sequence()) { - portapack::persistent_memory::set_playing_dead(0x82175E23); // Disable - if (!(portapack::persistent_memory::ui_config() & 16)) { + if (sequence == persistent_memory::playdead_sequence()) { + persistent_memory::set_playing_dead(0x82175E23); // Disable + if (persistent_memory::config_login()) { text_playdead3.hidden(false); } else { nav.pop(); diff --git a/firmware/common/portapack_persistent_memory.cpp b/firmware/common/portapack_persistent_memory.cpp index 7d8e7478..dacc2263 100644 --- a/firmware/common/portapack_persistent_memory.cpp +++ b/firmware/common/portapack_persistent_memory.cpp @@ -80,6 +80,7 @@ struct data_t { uint32_t playing_dead; uint32_t playdead_sequence; + // UI uint32_t ui_config; uint32_t pocsag_last_address; @@ -203,49 +204,50 @@ void set_playdead_sequence(const uint32_t new_value) { } bool stealth_mode() { - return ((data->ui_config >> 3) & 1) ? true : false; + return (data->ui_config & 0x20000000UL) ? true : false; } -void set_stealth_mode(const bool new_value) { - data->ui_config = (data->ui_config & ~0b1000) | ((new_value & 1) << 3); +void set_stealth_mode(const bool v) { + data->ui_config = (data->ui_config & ~0x20000000UL) | (v << 29); } -uint32_t ui_config() { - uint8_t bloff_value; - - // Cap value - bloff_value = (data->ui_config >> 5) & 7; - if (bloff_value > 4) bloff_value = 1; // 15s default - - data->ui_config = (data->ui_config & 0x1F) | (bloff_value << 5); - - return data->ui_config; +bool config_splash() { + return (data->ui_config & 0x80000000UL) ? true : false; } -uint16_t ui_config_bloff() { - uint8_t bloff_value; - uint16_t bloff_seconds[5] = { 5, 15, 60, 300, 600 }; - - if (!(data->ui_config & 2)) return 0; - - // Cap value - bloff_value = (data->ui_config >> 5) & 7; - if (bloff_value > 4) bloff_value = 1; - - return bloff_seconds[bloff_value]; +bool config_login() { + return (data->ui_config & 0x40000000UL) ? true : false; } -void set_config_textentry(uint8_t new_value) { +uint32_t config_backlight_timer() { + const uint32_t timer_seconds[8] = { 0, 5, 15, 60, 300, 600, 600, 600 }; + + return timer_seconds[data->ui_config & 0x00000007UL]; +} + +void set_config_splash(bool v) { + data->ui_config = (data->ui_config & ~0x80000000UL) | (v << 31); +} + +void set_config_login(bool v) { + data->ui_config = (data->ui_config & ~0x40000000UL) | (v << 30); +} + +void set_config_backlight_timer(uint32_t i) { + data->ui_config = (data->ui_config & ~0x00000007UL) | (i & 7); +} + +/*void set_config_textentry(uint8_t new_value) { data->ui_config = (data->ui_config & ~0b100) | ((new_value & 1) << 2); } uint8_t ui_config_textentry() { return ((data->ui_config >> 2) & 1); -} +}*/ -void set_ui_config(const uint32_t new_value) { +/*void set_ui_config(const uint32_t new_value) { data->ui_config = new_value; -} +}*/ uint32_t pocsag_last_address() { return data->pocsag_last_address; diff --git a/firmware/common/portapack_persistent_memory.hpp b/firmware/common/portapack_persistent_memory.hpp index 5ff21dd6..edaf3696 100644 --- a/firmware/common/portapack_persistent_memory.hpp +++ b/firmware/common/portapack_persistent_memory.hpp @@ -69,15 +69,18 @@ uint32_t playdead_sequence(); void set_playdead_sequence(const uint32_t new_value); bool stealth_mode(); -void set_stealth_mode(const bool new_value); +void set_stealth_mode(const bool v); -uint32_t ui_config(); -void set_ui_config(const uint32_t new_value); +bool config_splash(); +bool config_login(); +uint32_t config_backlight_timer(); -uint16_t ui_config_bloff(); +void set_config_splash(bool v); +void set_config_login(bool v); +void set_config_backlight_timer(uint32_t i); -uint8_t ui_config_textentry(); -void set_config_textentry(uint8_t new_value); +//uint8_t ui_config_textentry(); +//void set_config_textentry(uint8_t new_value); uint32_t pocsag_last_address(); void set_pocsag_last_address(uint32_t address); diff --git a/firmware/graphics/icon_biast_off.png b/firmware/graphics/icon_biast_off.png index 092b6073..4fd35315 100644 Binary files a/firmware/graphics/icon_biast_off.png and b/firmware/graphics/icon_biast_off.png differ diff --git a/firmware/graphics/icon_biast_on.png b/firmware/graphics/icon_biast_on.png index 595ee4e2..054d8460 100644 Binary files a/firmware/graphics/icon_biast_on.png and b/firmware/graphics/icon_biast_on.png differ diff --git a/firmware/portapack-h1-havoc.bin b/firmware/portapack-h1-havoc.bin index b04efc3e..5d3fb694 100644 Binary files a/firmware/portapack-h1-havoc.bin and b/firmware/portapack-h1-havoc.bin differ diff --git a/firmware/tools/make_bitmap.py b/firmware/tools/make_bitmap.py index e5f4f21c..7c3c6ea6 100755 --- a/firmware/tools/make_bitmap.py +++ b/firmware/tools/make_bitmap.py @@ -62,9 +62,9 @@ def convert_png(file): if j % 8 == 7: f.write("0x%0.2X, " % data) data = 0 - + f.write("\n") - if i < rgb_im.size[0] - 1: + if i < rgb_im.size[1] - 1: f.write(' ') # Tab f.write("};\n")