Skip to content

Commit

Permalink
Bmp File Viewer + extras (#2119)
Browse files Browse the repository at this point in the history
* BMP initial

* Add vscode debug configuration as a template (#2109)

* usb serial debug interface & usb serial async msg (#2111)

* add serial_debug

* not use OSS

* add path print

* add string print and vec

* clean up

* clean up

* format

* add an async blocking bool

* add an async blocking bool - comment

* protect the unexpected tx

* naming

* remove demo code

* fix bottom-up format, and add auto extend, ..

* bmp write

* Minor additions

* Minor

* overwrite on create

* Tmp

* Basic view - WIP

* debug

* add literal str print in asyncmsg (#2113)

* add literal str print in asyncmsg

* remove debug things

* accept suggestion per gull

* fix documentary

* Fix bug (#2114)

* Disable Back button during Touch Calibration (#2115)

* ADS1100 (#2116)

* WIP

* WIP

* WIP

* Corrected name

* WIP

* WIP

* WIP

* WIP

* Added new calc

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* Added debug serial lines

* WIP

* Fixed issue

* Fixed calculation issue

* Added voltage to performance DFU menu

* Added padding function and added voltage to perf menu

* Clean up

* Refactor

* Fixed linting

* Hides voltage if PP does not conatin IC

* WIP showing battery %

* made the percentage a int

* Added % to header

* Removed test UI

* Removed comment

* Added fix for precision too large

* Added fix for precision too large

* Linting

* widget

* auto zoom

* remove debug

* move in screen

* fix math

* remove test code

* fix

* fix compiler warning

* BMP File viewer

* Full screen

* bg instead of noice

* add comment

* Handle some not supported formats.

---------

Co-authored-by: E.T <[email protected]>
Co-authored-by: sommermorgentraum <[email protected]>
Co-authored-by: Mark Thompson <[email protected]>
Co-authored-by: jLynx <[email protected]>
  • Loading branch information
5 people authored Apr 24, 2024
1 parent 67975d7 commit 06651dc
Show file tree
Hide file tree
Showing 15 changed files with 801 additions and 3 deletions.
3 changes: 3 additions & 0 deletions firmware/application/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ set(CPPSRC
${COMMON}/wm8731.cpp
${COMMON}/ads1110.cpp
${COMMON}/performance_counter.cpp
${COMMON}/bmpfile.cpp
app_settings.cpp
audio.cpp
baseband_api.cpp
Expand Down Expand Up @@ -261,6 +262,7 @@ set(CPPSRC
ui/ui_textentry.cpp
ui/ui_tone_key.cpp
ui/ui_transmitter.cpp
ui/ui_bmpview.cpp
apps/acars_app.cpp
apps/ais_app.cpp
apps/analog_audio_app.cpp
Expand All @@ -283,6 +285,7 @@ set(CPPSRC
apps/ui_aprs_rx.cpp
apps/ui_aprs_tx.cpp
apps/ui_bht_tx.cpp
apps/ui_bmp_file_viewer.cpp
apps/ui_btle_rx.cpp
# apps/ui_coasterp.cpp
apps/ui_debug.cpp
Expand Down
63 changes: 63 additions & 0 deletions firmware/application/apps/ui_bmp_file_viewer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright (C) 2024 HTotoo
*
* This file is part of PortaPack.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/

#include "ui_bmp_file_viewer.hpp"

extern ui::SystemView* system_view_ptr;

using namespace portapack;
namespace fs = std::filesystem;

namespace ui {

BMPFileViewer::BMPFileViewer(
NavigationView& nav,
const std::filesystem::path& path)
: nav_{nav},
path_{path} {
add_children(
{&bmp});
bmp.set_enter_pass(true); // pass the enter key to me, so i can exit. this will disable zoom + pos reset
set_focusable(true);
system_view_ptr->set_app_fullscreen(true);
}

BMPFileViewer::~BMPFileViewer() {
system_view_ptr->set_app_fullscreen(false);
}

void BMPFileViewer::focus() {
bmp.focus();
}

bool BMPFileViewer::on_key(KeyEvent k) {
if (k == KeyEvent::Select) {
nav_.pop();
return true;
}
return false;
}

void BMPFileViewer::paint(Painter&) {
bmp.load_bmp(path_);
}

} // namespace ui
51 changes: 51 additions & 0 deletions firmware/application/apps/ui_bmp_file_viewer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (C) 2024 HTotoo
*
* This file is part of PortaPack.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/

#ifndef __UI_BMP_FILE_VIEWER_H__
#define __UI_BMP_FILE_VIEWER_H__

#include "ui.hpp"
#include "ui_navigation.hpp"
#include "ui_painter.hpp"
#include "ui_styles.hpp"
#include "ui_widget.hpp"
#include "file.hpp"
#include "ui_bmpview.hpp"

namespace ui {

class BMPFileViewer : public View {
public:
BMPFileViewer(NavigationView& nav, const std::filesystem::path& path);
~BMPFileViewer();
bool on_key(KeyEvent key) override;
void paint(Painter& painter) override;
void focus() override;

private:
NavigationView& nav_;
std::filesystem::path path_{};
BMPViewer bmp{{0, 0, 240, 320}};
};

} // namespace ui

#endif // __UI_BMP_FILE_VIEWER_H__
9 changes: 8 additions & 1 deletion firmware/application/apps/ui_fileman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@
#include "ui_playlist.hpp"
#include "ui_remote.hpp"
#include "ui_ss_viewer.hpp"
#include "ui_bmp_file_viewer.hpp"
#include "ui_text_editor.hpp"
#include "ui_iq_trim.hpp"
#include "string_format.hpp"
#include "portapack.hpp"
#include "event_m0.hpp"
#include "file_path.hpp"

using namespace portapack;
namespace fs = std::filesystem;
Expand Down Expand Up @@ -694,7 +696,12 @@ bool FileManagerView::handle_file_open() {
nav_.push<ScreenshotViewer>(path);
return true;
} else if (path_iequal(bmp_ext, ext)) {
nav_.push<SplashViewer>(path);
if (path_iequal(current_path, u"/" + splash_dir)) {
nav_.push<SplashViewer>(path); // splash, so load that viewer
} else {
nav_.push<BMPFileViewer>(path); // any other bmp
}

reload_current(false);
return true;
} else if (path_iequal(rem_ext, ext)) {
Expand Down
8 changes: 8 additions & 0 deletions firmware/application/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ File::~File() {
f_close(&f);
}

void File::close() {
f_close(&f);
}

File::Result<File::Size> File::read(void* data, Size bytes_to_read) {
UINT bytes_read = 0;
const auto result = f_read(&f, data, bytes_to_read, &bytes_read);
Expand Down Expand Up @@ -98,6 +102,10 @@ File::Offset File::tell() const {
return f_tell(&f);
}

File::Result<bool> File::eof() {
return f_eof(&f);
}

File::Result<File::Offset> File::seek(Offset new_position) {
/* NOTE: Returns *old* position, not new position */
const auto old_position = tell();
Expand Down
2 changes: 2 additions & 0 deletions firmware/application/file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ class File {

// TODO: Return Result<>.
Optional<Error> open(const std::filesystem::path& filename, bool read_only = true, bool create = false);
void close();
Optional<Error> append(const std::filesystem::path& filename);
Optional<Error> create(const std::filesystem::path& filename);

Expand All @@ -342,6 +343,7 @@ class File {
Result<Offset> seek(uint64_t Offset);
Result<Offset> truncate();
Size size() const;
Result<bool> eof();

template <size_t N>
Result<Size> write(const std::array<uint8_t, N>& data) {
Expand Down
2 changes: 1 addition & 1 deletion firmware/application/string_format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ std::string to_string_decimal_padding(float decimal, int8_t precision, const int
result = to_string_dec_int(integer_part) + "." + to_string_dec_uint(fractional_part, precision, '0');

// Add padding with spaces to meet the length requirement
if (result.length() < l) {
if (result.length() < (uint32_t)l) {
int padding_length = l - result.length();
std::string padding(padding_length, ' ');
result = padding + result;
Expand Down
Loading

0 comments on commit 06651dc

Please sign in to comment.