Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bmp File Viewer + extras #2119

Merged
merged 30 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
aabae17
BMP initial
htotoo Apr 18, 2024
c790a0c
Add vscode debug configuration as a template (#2109)
u-foka Apr 17, 2024
d4192b0
usb serial debug interface & usb serial async msg (#2111)
zxkmm Apr 18, 2024
235a585
Merge branch 'portapack-mayhem:next' into bmp
htotoo Apr 18, 2024
d691a18
fix bottom-up format, and add auto extend, ..
htotoo Apr 18, 2024
cdee257
bmp write
htotoo Apr 18, 2024
7d38239
Minor additions
htotoo Apr 18, 2024
9b5410c
Minor
htotoo Apr 18, 2024
52d401e
overwrite on create
htotoo Apr 18, 2024
57f4ef8
Tmp
htotoo Apr 18, 2024
c9b69e0
Basic view - WIP
htotoo Apr 19, 2024
fd14a28
debug
htotoo Apr 21, 2024
5324243
add literal str print in asyncmsg (#2113)
zxkmm Apr 20, 2024
4652b37
Fix bug (#2114)
htotoo Apr 20, 2024
ab6e740
Disable Back button during Touch Calibration (#2115)
NotherNgineer Apr 21, 2024
1fb7782
ADS1100 (#2116)
jLynx Apr 21, 2024
fb3a049
Merge branch 'portapack-mayhem:next' into bmp
htotoo Apr 21, 2024
d0781af
widget
htotoo Apr 21, 2024
969717d
auto zoom
htotoo Apr 21, 2024
1a2ca80
remove debug
htotoo Apr 21, 2024
c163f66
move in screen
htotoo Apr 21, 2024
ad05344
fix math
htotoo Apr 21, 2024
844fd11
remove test code
htotoo Apr 21, 2024
505367d
fix
htotoo Apr 21, 2024
7ce4a1f
fix compiler warning
htotoo Apr 21, 2024
951e757
BMP File viewer
htotoo Apr 22, 2024
50104ab
Full screen
htotoo Apr 22, 2024
01c99d4
bg instead of noice
htotoo Apr 22, 2024
813c8f5
add comment
htotoo Apr 22, 2024
e91d713
Handle some not supported formats.
htotoo Apr 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading