mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2026-08-21 06:59:02 +00:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a398ed1634 | |||
| 105742acbc | |||
| b43eaa8786 | |||
| b19ed5fec5 | |||
| 419bc75d2f | |||
| b3a0ad018c | |||
| a21e9ca1af | |||
| 20f45e88f3 | |||
| 967506fb97 | |||
| 24ab2f29fa |
+20
-7
@@ -23,6 +23,8 @@ cmake_policy(SET CMP0005 NEW)
|
||||
|
||||
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_LIST_DIR}/firmware/toolchain-arm-cortex-m.cmake)
|
||||
|
||||
option(USE_CCACHE "Enable ccache, please keep an eye on this because sometimes it's not quite stable and generated unusable binary" OFF)
|
||||
|
||||
project(portapack-h1)
|
||||
|
||||
set(EXPECTED_GCC_VERSION "9.2.1")
|
||||
@@ -72,13 +74,24 @@ set(HACKRF_CPLD_XSVF_PATH ${HACKRF_PATH}/firmware/cpld/sgpio_if/${HACKRF_CPLD_XS
|
||||
set(HACKRF_FIRMWARE_DFU_IMAGE ${hackrf_usb_BINARY_DIR}/${HACKRF_FIRMWARE_DFU_FILENAME})
|
||||
set(HACKRF_FIRMWARE_BIN_IMAGE ${hackrf_usb_BINARY_DIR}/${HACKRF_FIRMWARE_BIN_FILENAME})
|
||||
|
||||
# this seems causing some issues (ref. in discord discussions), so temporarily disabled, until figure out the pros and cons and bugs of this tool.
|
||||
#find_program(CCACHE "ccache")
|
||||
#if(CCACHE)
|
||||
# set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE})
|
||||
# set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE})
|
||||
# set(ENV{CCACHE_SLOPPINESS} pch_defines,time_macros)
|
||||
#endif(CCACHE)
|
||||
# this seems causing some issues (ref. in discord discussions), but it sometimes do helps, so you have your choice to use. it's default disabled, unless you use such command:
|
||||
# cmake -DUSE_CCACHE=ON ..
|
||||
# `make` or `make -j` or `make -j10` etc
|
||||
# the default behavior `cmake ..` isn't changed (aka don't use ccache)
|
||||
message(STATUS "-------v ccache info--------")
|
||||
if(USE_CCACHE)
|
||||
find_program(CCACHE_FOUND ccache)
|
||||
if(CCACHE_FOUND)
|
||||
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_FOUND})
|
||||
set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_FOUND})
|
||||
message(STATUS "Using ccache, please keep an eye on this because sometimes it's not quite stable and generated unusable binary.\n-- use `cmake -DUSE_CCACHE=OFF ..` to turn off ccache")
|
||||
else()
|
||||
message(WARNING "ccache is enabled but not found on the system.")
|
||||
endif()
|
||||
else()
|
||||
message(STATUS "Not using ccache, use `cmake -DUSE_CCACHE=ON ..` to turn on ccache")
|
||||
endif()
|
||||
message(STATUS "-------^ ccache info--------")
|
||||
|
||||
enable_testing()
|
||||
add_subdirectory(firmware)
|
||||
|
||||
@@ -35,6 +35,8 @@ using namespace portapack;
|
||||
|
||||
namespace ui {
|
||||
|
||||
#define FILE_PER_PAGE 50
|
||||
|
||||
bool SoundBoardView::is_active() const {
|
||||
return (bool)replay_thread;
|
||||
}
|
||||
@@ -178,9 +180,9 @@ void SoundBoardView::refresh_list() {
|
||||
if ((reader->channels() == 1) && ((reader->bits_per_sample() == 8) || (reader->bits_per_sample() == 16))) {
|
||||
// sounds[c].ms_duration = reader->ms_duration();
|
||||
// sounds[c].path = u"WAV/" + entry.path().native();
|
||||
if (count >= (page - 1) * 100 && count < page * 100) {
|
||||
if (count >= (page - 1) * FILE_PER_PAGE && count < page * FILE_PER_PAGE) {
|
||||
file_list.push_back(entry.path());
|
||||
if (file_list.size() == 100) {
|
||||
if (file_list.size() == FILE_PER_PAGE) {
|
||||
page++;
|
||||
break;
|
||||
}
|
||||
@@ -225,7 +227,7 @@ void SoundBoardView::refresh_list() {
|
||||
menu_view.set_highlighted(0); // Refresh
|
||||
}
|
||||
|
||||
if (file_list.size() < 100) {
|
||||
if (file_list.size() < FILE_PER_PAGE) {
|
||||
page = 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +98,6 @@ rf::Frequency GlassView::get_freq_from_bin_pos(uint8_t pos) {
|
||||
freq_at_pos = f_center_ini + ((pos - 120) * ((looking_glass_range - ((16 * looking_glass_range) / SPEC_NB_BINS)) / 2)) / (SCREEN_W / 2);
|
||||
} else
|
||||
freq_at_pos = f_min + (2 * offset * each_bin_size) + (pos * looking_glass_range) / SCREEN_W;
|
||||
|
||||
return freq_at_pos;
|
||||
}
|
||||
|
||||
@@ -257,7 +256,7 @@ void GlassView::on_range_changed() {
|
||||
bin_length = SCREEN_W;
|
||||
ignore_dc = 0;
|
||||
looking_glass_bandwidth = looking_glass_range;
|
||||
looking_glass_sampling_rate = looking_glass_bandwidth;
|
||||
looking_glass_sampling_rate = looking_glass_range;
|
||||
each_bin_size = looking_glass_bandwidth / SCREEN_W;
|
||||
looking_glass_step = looking_glass_bandwidth;
|
||||
f_center_ini = f_min + (looking_glass_bandwidth / 2); // Initial center frequency for sweep
|
||||
@@ -265,7 +264,7 @@ void GlassView::on_range_changed() {
|
||||
// view is made in multiple pass, use original bin picking
|
||||
mode = scan_type.selected_index_value();
|
||||
looking_glass_bandwidth = LOOKING_GLASS_SLICE_WIDTH_MAX;
|
||||
looking_glass_sampling_rate = LOOKING_GLASS_SLICE_WIDTH_MAX;
|
||||
looking_glass_sampling_rate = LOOKING_GLASS_MAX_SAMPLERATE;
|
||||
each_bin_size = LOOKING_GLASS_SLICE_WIDTH_MAX / SPEC_NB_BINS;
|
||||
if (mode == LOOKING_GLASS_FASTSCAN) {
|
||||
offset = 2;
|
||||
@@ -315,8 +314,8 @@ void GlassView::update_min(int32_t v) {
|
||||
int32_t min_size = steps;
|
||||
if (locked_range)
|
||||
min_size = search_span;
|
||||
if (min_size < 2)
|
||||
min_size = 2;
|
||||
if (min_size < 1)
|
||||
min_size = 1;
|
||||
if (v > 7200 - min_size) {
|
||||
v = 7200 - min_size;
|
||||
}
|
||||
@@ -332,8 +331,8 @@ void GlassView::update_max(int32_t v) {
|
||||
int32_t min_size = steps;
|
||||
if (locked_range)
|
||||
min_size = search_span;
|
||||
if (min_size < 2)
|
||||
min_size = 2;
|
||||
if (min_size < 1)
|
||||
min_size = 1;
|
||||
if (v < min_size) {
|
||||
v = min_size;
|
||||
}
|
||||
@@ -487,7 +486,12 @@ GlassView::GlassView(
|
||||
range_presets.set_selected_index(preset_index);
|
||||
|
||||
field_marker.on_encoder_change = [this](TextField&, EncoderEvent delta) {
|
||||
marker_pixel_index = clip<uint8_t>(marker_pixel_index + delta, 0, SCREEN_W);
|
||||
if ((marker_pixel_index + delta) < 0)
|
||||
marker_pixel_index = marker_pixel_index + delta + SCREEN_W;
|
||||
else if ((marker_pixel_index + delta) > SCREEN_W)
|
||||
marker_pixel_index = marker_pixel_index + delta - SCREEN_W;
|
||||
else
|
||||
marker_pixel_index = marker_pixel_index + delta;
|
||||
on_marker_change();
|
||||
};
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
namespace ui {
|
||||
|
||||
#define LOOKING_GLASS_SLICE_WIDTH_MAX 20000000
|
||||
#define LOOKING_GLASS_MAX_SAMPLERATE 20000000
|
||||
#define MHZ_DIV 1000000
|
||||
|
||||
// blanked DC (16 centered bins ignored ) and top left and right (2 bins ignored on each side )
|
||||
|
||||
@@ -96,6 +96,10 @@ set(EXTCPPSRC
|
||||
#sstvtx
|
||||
external/sstvtx/main.cpp
|
||||
external/sstvtx/ui_sstvtx.cpp
|
||||
|
||||
#random
|
||||
external/random_password/main.cpp
|
||||
external/random_password/ui_random_password.cpp
|
||||
)
|
||||
|
||||
set(EXTAPPLIST
|
||||
@@ -122,4 +126,5 @@ set(EXTAPPLIST
|
||||
adsbtx
|
||||
morse_tx
|
||||
sstvtx
|
||||
random_password
|
||||
)
|
||||
|
||||
+6
-1
@@ -46,6 +46,7 @@ MEMORY
|
||||
ram_external_app_adsbtx(rwx) : org = 0xADC50000, len = 32k
|
||||
ram_external_app_morse_tx(rwx) : org = 0xADC60000, len = 32k
|
||||
ram_external_app_sstvtx(rwx) : org = 0xADC70000, len = 32k
|
||||
ram_external_app_random_password(rwx) : org = 0xADC80000, len = 32k
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
@@ -190,6 +191,10 @@ SECTIONS
|
||||
*(*ui*external_app*sstvtx*);
|
||||
} > ram_external_app_sstvtx
|
||||
|
||||
|
||||
.external_app_random_password : ALIGN(4) SUBALIGN(4)
|
||||
{
|
||||
KEEP(*(.external_app.app_random_password.application_information));
|
||||
*(*ui*external_app*random_password*);
|
||||
} > ram_external_app_random_password
|
||||
|
||||
}
|
||||
|
||||
+41
-15
@@ -1,6 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2017 Furrtek
|
||||
* Copyright (C) 2024 HTotoo, zxkmm
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
@@ -49,10 +48,12 @@ ProtoView::ProtoView(NavigationView& nav)
|
||||
&field_vga,
|
||||
&field_volume,
|
||||
&field_frequency,
|
||||
&labels,
|
||||
&label_zoom,
|
||||
&label_shift,
|
||||
&options_zoom,
|
||||
&number_shift,
|
||||
&button_reset,
|
||||
&button_pause,
|
||||
&waveform,
|
||||
&waveform2,
|
||||
&waveform3,
|
||||
@@ -72,6 +73,10 @@ ProtoView::ProtoView(NavigationView& nav)
|
||||
button_reset.on_select = [this](Button&) {
|
||||
reset();
|
||||
};
|
||||
button_pause.on_select = [this](Button&) {
|
||||
set_pause(!paused);
|
||||
};
|
||||
set_pause(false); // need to use this to default hide shift functionality
|
||||
baseband::set_subghzd_config(0, receiver_model.sampling_rate());
|
||||
audio::set_rate(audio::Rate::Hz_24000);
|
||||
audio::output::start();
|
||||
@@ -80,6 +85,7 @@ ProtoView::ProtoView(NavigationView& nav)
|
||||
|
||||
void ProtoView::reset() {
|
||||
cnt = 0;
|
||||
set_pause(false);
|
||||
number_shift.set_value(0);
|
||||
waveform_shift = 0;
|
||||
for (uint16_t i = 0; i < MAXSIGNALBUFFER; i++) time_buffer[i] = 0;
|
||||
@@ -134,19 +140,20 @@ void ProtoView::draw() {
|
||||
drawcnt = 0;
|
||||
for (uint16_t i = 0; i < MAXDRAWCNT; i++) waveform_buffer[i] = 0; // reset
|
||||
|
||||
// add empty data for padding (so you can shift left/nagetive)
|
||||
for (int32_t i = 0;
|
||||
i < ((waveform_shift > 0) ? 0 : -waveform_shift) && drawcnt < MAXDRAWCNT; // this is for shift nagetive (left side)
|
||||
++i) {
|
||||
waveform_buffer[drawcnt++] = 0;
|
||||
// add empty data for padding (so you can shift left/negative)
|
||||
if (waveform_shift < 0) {
|
||||
for (int32_t i = 0; (i < -1 * waveform_shift) && drawcnt < MAXDRAWCNT; // this is for shift negative (move to right)
|
||||
++i) {
|
||||
waveform_buffer[drawcnt++] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
for (uint16_t i = ((waveform_shift < 0) ? -waveform_shift : 0); // this is for shift positive aka right side
|
||||
i < MAXSIGNALBUFFER && drawcnt < MAXDRAWCNT; // prevent out of ranging
|
||||
uint16_t skipped = 0;
|
||||
uint16_t to_skip = ((waveform_shift > 0) ? waveform_shift : 0); // when >0 it'll skip some to move left
|
||||
for (uint16_t i = 0;
|
||||
i < MAXSIGNALBUFFER && drawcnt < MAXDRAWCNT; // prevent out of ranging
|
||||
++i) {
|
||||
uint16_t buffer_index = (i + waveform_shift + MAXSIGNALBUFFER) % MAXSIGNALBUFFER;
|
||||
state = time_buffer[buffer_index] >= 0;
|
||||
int32_t timeabs = state ? time_buffer[buffer_index] : -1 * time_buffer[buffer_index];
|
||||
state = time_buffer[i] >= 0;
|
||||
int32_t timeabs = state ? time_buffer[i] : -1 * time_buffer[i];
|
||||
int32_t timesize = timeabs / zoom;
|
||||
if (timesize == 0) {
|
||||
remain += timeabs;
|
||||
@@ -164,7 +171,11 @@ void ProtoView::draw() {
|
||||
remain = 0;
|
||||
lmax = 0;
|
||||
for (int32_t ii = 0; ii < timesize && drawcnt < MAXDRAWCNT; ++ii) {
|
||||
waveform_buffer[drawcnt++] = state;
|
||||
if (skipped < to_skip) {
|
||||
skipped++;
|
||||
} else {
|
||||
waveform_buffer[drawcnt++] = state;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -175,6 +186,7 @@ void ProtoView::add_time(int32_t time) {
|
||||
}
|
||||
|
||||
void ProtoView::on_data(const ProtoViewDataMessage* message) {
|
||||
if (paused) return;
|
||||
// filter out invalid ones.
|
||||
uint16_t start = 0;
|
||||
uint16_t stop = 0;
|
||||
@@ -207,6 +219,20 @@ void ProtoView::on_freqchg(int64_t freq) {
|
||||
field_frequency.set_value(freq);
|
||||
}
|
||||
|
||||
void ProtoView::set_pause(bool pause) {
|
||||
paused = pause;
|
||||
if (pause) {
|
||||
label_shift.hidden(false);
|
||||
number_shift.hidden(false);
|
||||
button_pause.set_text(LanguageHelper::currentMessages[LANG_RESUME]);
|
||||
} else {
|
||||
label_shift.hidden(true);
|
||||
number_shift.hidden(true);
|
||||
button_pause.set_text(LanguageHelper::currentMessages[LANG_PAUSE]);
|
||||
}
|
||||
set_dirty();
|
||||
}
|
||||
|
||||
ProtoView::~ProtoView() {
|
||||
audio::output::stop();
|
||||
receiver_model.disable();
|
||||
|
||||
+12
-3
@@ -74,8 +74,11 @@ class ProtoView : public View {
|
||||
RxFrequencyField field_frequency{
|
||||
{0 * 8, 0 * 16},
|
||||
nav_};
|
||||
Labels labels{
|
||||
{{0 * 8, 1 * 16}, "Zoom: ", Theme::getInstance()->fg_light->foreground},
|
||||
|
||||
// need to seperate because label shift need to hide independently
|
||||
Labels label_zoom{
|
||||
{{0 * 8, 1 * 16}, "Zoom: ", Theme::getInstance()->fg_light->foreground}};
|
||||
Labels label_shift{
|
||||
{{0 * 8, 2 * 16}, "Shift: ", Theme::getInstance()->fg_light->foreground}};
|
||||
|
||||
OptionsField options_zoom{
|
||||
@@ -103,6 +106,10 @@ class ProtoView : public View {
|
||||
{screen_width - 12 * 8, 1 * 16, 96, 24},
|
||||
LanguageHelper::currentMessages[LANG_RESET]};
|
||||
|
||||
Button button_pause{
|
||||
{screen_width - 12 * 8, 1 * 16 + 24, 96, 24},
|
||||
LanguageHelper::currentMessages[LANG_PAUSE]};
|
||||
|
||||
Waveform waveform{
|
||||
{0, 8 * 8, 240, 50},
|
||||
waveform_buffer,
|
||||
@@ -136,6 +143,7 @@ class ProtoView : public View {
|
||||
Theme::getInstance()->fg_yellow->foreground};
|
||||
|
||||
bool needCntReset = false;
|
||||
bool paused = false;
|
||||
|
||||
int16_t zoom = 1; // one value in ms
|
||||
int16_t waveform_shift = 0;
|
||||
@@ -151,6 +159,7 @@ class ProtoView : public View {
|
||||
void on_data(const ProtoViewDataMessage* message);
|
||||
void draw();
|
||||
void draw2();
|
||||
void set_pause(bool pause);
|
||||
void reset();
|
||||
|
||||
MessageHandlerRegistration message_handler_packet{
|
||||
@@ -178,4 +187,4 @@ class ProtoView : public View {
|
||||
|
||||
} // namespace ui::external_app::protoview
|
||||
|
||||
#endif /*__UI_PROTOVIEW_H__*/
|
||||
#endif /*__UI_PROTOVIEW_H__*/
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Bernd Herzog
|
||||
*
|
||||
* 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.hpp"
|
||||
#include "ui_random_password.hpp"
|
||||
#include "ui_navigation.hpp"
|
||||
#include "external_app.hpp"
|
||||
|
||||
namespace ui::external_app::random_password {
|
||||
void initialize_app(ui::NavigationView& nav) {
|
||||
nav.push<RandomPasswordView>();
|
||||
}
|
||||
} // namespace ui::external_app::random_password
|
||||
|
||||
extern "C" {
|
||||
|
||||
__attribute__((section(".external_app.app_random_password.application_information"), used)) application_information_t _application_information_random_password = {
|
||||
/*.memory_location = */ (uint8_t*)0x00000000,
|
||||
/*.externalAppEntry = */ ui::external_app::random_password::initialize_app,
|
||||
/*.header_version = */ CURRENT_HEADER_VERSION,
|
||||
/*.app_version = */ VERSION_MD5,
|
||||
|
||||
/*.app_name = */ "Random passwd",
|
||||
/*.bitmap_data = */ {
|
||||
0xC0,
|
||||
0x03,
|
||||
0xE0,
|
||||
0x07,
|
||||
0x30,
|
||||
0x0C,
|
||||
0x30,
|
||||
0x0C,
|
||||
0x30,
|
||||
0x0C,
|
||||
0x30,
|
||||
0x0C,
|
||||
0xE0,
|
||||
0x07,
|
||||
0xC0,
|
||||
0x03,
|
||||
0x80,
|
||||
0x01,
|
||||
0x80,
|
||||
0x01,
|
||||
0x80,
|
||||
0x01,
|
||||
0x80,
|
||||
0x01,
|
||||
0x80,
|
||||
0x07,
|
||||
0x80,
|
||||
0x03,
|
||||
0x80,
|
||||
0x07,
|
||||
0x80,
|
||||
0x01,
|
||||
},
|
||||
/*.icon_color = */ ui::Color::yellow().v,
|
||||
/*.menu_location = */ app_location_t::UTILITIES,
|
||||
|
||||
/*.m4_app_tag = portapack::spi_flash::image_tag_afsk_rx */ {'P', 'A', 'F', 'R'},
|
||||
/*.m4_app_offset = */ 0x00000000, // will be filled at compile time
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,374 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2017 Furrtek
|
||||
* Copyright (C) 2024 zxkmm
|
||||
* 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_random_password.hpp"
|
||||
#include "ui_modemsetup.hpp"
|
||||
|
||||
#include "modems.hpp"
|
||||
#include "rtc_time.hpp"
|
||||
#include "baseband_api.hpp"
|
||||
#include "string_format.hpp"
|
||||
#include "portapack_persistent_memory.hpp"
|
||||
#include "file_path.hpp"
|
||||
|
||||
using namespace portapack;
|
||||
using namespace modems;
|
||||
using namespace ui;
|
||||
|
||||
namespace ui::external_app::random_password {
|
||||
|
||||
void RandomPasswordLogger::log_raw_data(const std::string& data) {
|
||||
log_file.write_entry(data);
|
||||
}
|
||||
|
||||
void RandomPasswordView::focus() {
|
||||
button_refresh.focus();
|
||||
}
|
||||
|
||||
RandomPasswordView::RandomPasswordView(NavigationView& nav)
|
||||
: nav_{nav} {
|
||||
baseband::run_prepared_image(portapack::memory::map::m4_code.base());
|
||||
|
||||
add_children({&rssi,
|
||||
&channel,
|
||||
&field_rf_amp,
|
||||
&field_lna,
|
||||
&field_vga,
|
||||
&field_frequency,
|
||||
&check_log,
|
||||
&button_modem_setup,
|
||||
&labels,
|
||||
&text_generated_passwd,
|
||||
&text_char_type_hints,
|
||||
&check_digits,
|
||||
&check_latin_lower,
|
||||
&check_latin_upper,
|
||||
&check_punctuation,
|
||||
&check_show_seeds,
|
||||
&check_auto_send,
|
||||
&button_refresh,
|
||||
&button_show_qr,
|
||||
&button_flood,
|
||||
&button_send,
|
||||
&field_digits,
|
||||
&check_allow_confusable_chars,
|
||||
&text_seed,
|
||||
&progressbar});
|
||||
|
||||
// no idea what's these, i copied from afsk rx app and they seems needed'
|
||||
auto def_bell202 = &modem_defs[0];
|
||||
persistent_memory::set_modem_baudrate(def_bell202->baudrate);
|
||||
serial_format_t serial_format;
|
||||
serial_format.data_bits = 7;
|
||||
serial_format.parity = EVEN;
|
||||
serial_format.stop_bits = 1;
|
||||
serial_format.bit_order = LSB_FIRST;
|
||||
persistent_memory::set_serial_format(serial_format);
|
||||
|
||||
progressbar.set_max(MAX_DIGITS * 2);
|
||||
|
||||
check_log.set_value(logging);
|
||||
check_log.on_select = [this](Checkbox&, bool v) {
|
||||
if (v) {
|
||||
nav_.display_modal(
|
||||
"Warning",
|
||||
"Sure?\n"
|
||||
"this will save all generated\n"
|
||||
"password to sdcard\n"
|
||||
"in plain text\n"
|
||||
"those which generated before\n"
|
||||
"you check me, will lost",
|
||||
YESNO,
|
||||
[this, v](bool c) {
|
||||
if (c) {
|
||||
logging = v;
|
||||
} else {
|
||||
check_log.set_value(false);
|
||||
// this is needed to check back to false cuz when trigger by human, the check to true already happened
|
||||
// this blocked interface so won't accidently saved even if user checked but selected no later here,
|
||||
// but take care of here if in the future implemented ticking/auto/batch save etc
|
||||
}
|
||||
});
|
||||
} else {
|
||||
logging = v;
|
||||
}
|
||||
};
|
||||
|
||||
button_modem_setup.on_select = [&nav](Button&) { // copied from afsk rx app
|
||||
nav.push<ModemSetupView>();
|
||||
};
|
||||
|
||||
check_digits.on_select = [this](Checkbox&, bool) {
|
||||
this->new_password();
|
||||
};
|
||||
|
||||
check_latin_lower.on_select = [this](Checkbox&, bool) {
|
||||
this->new_password();
|
||||
};
|
||||
|
||||
check_latin_upper.on_select = [this](Checkbox&, bool) {
|
||||
this->new_password();
|
||||
};
|
||||
|
||||
check_punctuation.on_select = [this](Checkbox&, bool) {
|
||||
this->new_password();
|
||||
};
|
||||
|
||||
check_allow_confusable_chars.on_select = [this](Checkbox&, bool) {
|
||||
this->new_password();
|
||||
};
|
||||
|
||||
button_refresh.on_select = [this](Button&) {
|
||||
this->set_random_freq();
|
||||
this->new_password();
|
||||
};
|
||||
|
||||
button_show_qr.on_select = [this, &nav](Button&) {
|
||||
nav.push<QRCodeView>(password.data());
|
||||
};
|
||||
|
||||
button_flood.on_select = [this](Button&) {
|
||||
if (flooding) {
|
||||
flooding = false;
|
||||
button_flood.set_text(LanguageHelper::currentMessages[LANG_FLOOD]);
|
||||
} else {
|
||||
flooding = true;
|
||||
button_flood.set_text(LanguageHelper::currentMessages[LANG_STOP]);
|
||||
}
|
||||
};
|
||||
button_send.on_select = [this, &nav](Button&) {
|
||||
async_prev_val = portapack::async_tx_enabled;
|
||||
portapack::async_tx_enabled = true;
|
||||
UsbSerialAsyncmsg::asyncmsg(password);
|
||||
portapack::async_tx_enabled = async_prev_val;
|
||||
};
|
||||
|
||||
field_digits.on_change = [this](int32_t) {
|
||||
clean_buffer();
|
||||
this->new_password();
|
||||
};
|
||||
|
||||
/// v check defauly val init
|
||||
check_digits.set_value(true);
|
||||
check_latin_lower.set_value(true);
|
||||
check_latin_upper.set_value(true);
|
||||
check_punctuation.set_value(true);
|
||||
check_show_seeds.set_value(true);
|
||||
field_digits.set_value(16);
|
||||
///^ check defauly val init
|
||||
|
||||
logger = std::make_unique<RandomPasswordLogger>();
|
||||
if (logger)
|
||||
logger->append(logs_dir / u"random.TXT");
|
||||
|
||||
// Auto-configure modem for LCR RX (will be removed later), copied from afsk rx app
|
||||
baseband::set_afsk(persistent_memory::modem_baudrate(), 8, 0, false);
|
||||
|
||||
receiver_model.enable();
|
||||
receiver_model.set_rf_amp(false);
|
||||
set_random_freq();
|
||||
new_password();
|
||||
}
|
||||
|
||||
void RandomPasswordView::on_data(uint32_t value, bool is_data) {
|
||||
if (is_data) {
|
||||
seed = static_cast<unsigned int>(value);
|
||||
text_seed.set(to_string_dec_uint(check_show_seeds.value() ? seed : 0));
|
||||
|
||||
/// v feed deque
|
||||
seeds_deque.push_back(value);
|
||||
if (seeds_deque.size() > MAX_DIGITS * 2) {
|
||||
seeds_deque.pop_front();
|
||||
}
|
||||
|
||||
///^ feed deque
|
||||
|
||||
progressbar.set_value(seeds_deque.size());
|
||||
|
||||
if (flooding && seeds_deque.size() >= MAX_DIGITS * 2) {
|
||||
new_password();
|
||||
}
|
||||
|
||||
} else {
|
||||
text_generated_passwd.set("Baudrate estimation: ~");
|
||||
text_char_type_hints.set(to_string_dec_uint(value));
|
||||
}
|
||||
}
|
||||
|
||||
void RandomPasswordView::clean_buffer() {
|
||||
seeds_deque = {};
|
||||
}
|
||||
|
||||
void RandomPasswordView::on_freqchg(int64_t freq) {
|
||||
field_frequency.set_value(freq);
|
||||
}
|
||||
|
||||
void RandomPasswordView::set_random_freq() {
|
||||
std::srand(LPC_RTC->CTIME0);
|
||||
// this is only for seed to visit random freq, the radio is still real random
|
||||
|
||||
auto random_freq = 100000000 + (std::rand() % 900000000); // 100mhz to 1ghz
|
||||
receiver_model.set_target_frequency(random_freq);
|
||||
field_frequency.set_value(random_freq);
|
||||
}
|
||||
|
||||
void RandomPasswordView::new_password() {
|
||||
if (seeds_deque.size() < MAX_DIGITS * 2) {
|
||||
seeds_buffer_not_full = true;
|
||||
text_generated_passwd.set("wait seeds buffer full");
|
||||
text_char_type_hints.set("then press generate");
|
||||
return;
|
||||
}
|
||||
password = "";
|
||||
std::string charset = "";
|
||||
std::string char_type_hints = "";
|
||||
|
||||
if (check_digits.value())
|
||||
charset += "0123456789";
|
||||
if (check_latin_lower.value())
|
||||
charset += "abcdefghijklmnopqrstuvwxyz";
|
||||
if (check_latin_upper.value())
|
||||
charset += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
if (check_punctuation.value())
|
||||
charset += ".,-!?";
|
||||
|
||||
if (!check_allow_confusable_chars.value()) {
|
||||
charset.erase(std::remove_if(charset.begin(), charset.end(),
|
||||
[](char c) { return c == '0' || c == 'O' || c == 'o' || c == '1' || c == 'l'; }),
|
||||
charset.end());
|
||||
}
|
||||
|
||||
if (charset.empty()) {
|
||||
text_generated_passwd.set("generate failed,");
|
||||
text_char_type_hints.set("select at least 1 type");
|
||||
return;
|
||||
}
|
||||
|
||||
int password_length = field_digits.value();
|
||||
|
||||
/*the seeds_buffer were feed streaming by AFSK,
|
||||
* and when generate, it use each seed for each char, and uint seeds totally can generate UINT_MAX result,
|
||||
* which already cover the 10+26+25+4 (123+abc+abc+.!)
|
||||
* so total possible password would be PW_LENGTH ^ (10+26+25+4), which already covered all the possible solution
|
||||
* (assume AFSK data is averaged in chaotic space, which maybe no one can garentee but I hope so)
|
||||
* */
|
||||
|
||||
for (int i = 0; i < password_length * 2; i += 2) {
|
||||
unsigned int seed = seeds_deque[i];
|
||||
std::srand(seed);
|
||||
uint8_t rollnum = (uint8_t)(seeds_deque[i + 1] % 128);
|
||||
uint8_t nu = 0;
|
||||
for (uint8_t o = 0; o < rollnum; ++o) nu = std::rand();
|
||||
nu++;
|
||||
char c = charset[std::rand() % charset.length()];
|
||||
password += c;
|
||||
|
||||
if (std::isdigit(c)) {
|
||||
char_type_hints += "1";
|
||||
} else if (std::islower(c)) {
|
||||
char_type_hints += "a";
|
||||
} else if (std::isupper(c)) {
|
||||
char_type_hints += "A";
|
||||
} else {
|
||||
char_type_hints += ",";
|
||||
}
|
||||
}
|
||||
|
||||
text_generated_passwd.set(password);
|
||||
text_char_type_hints.set(char_type_hints);
|
||||
|
||||
paint_password_hints(); // TODO: why flash and disappeared
|
||||
|
||||
if (logger && logging) {
|
||||
str_log += generate_log_line();
|
||||
logger->log_raw_data(str_log);
|
||||
str_log = "";
|
||||
}
|
||||
|
||||
if (check_auto_send.value() || flooding) {
|
||||
async_prev_val = portapack::async_tx_enabled;
|
||||
portapack::async_tx_enabled = true;
|
||||
// printing out seeds buufer
|
||||
// for (auto seed : seeds_deque) {
|
||||
// UsbSerialAsyncmsg::asyncmsg(std::to_string(seed));
|
||||
// }
|
||||
UsbSerialAsyncmsg::asyncmsg(password);
|
||||
portapack::async_tx_enabled = async_prev_val;
|
||||
}
|
||||
|
||||
clean_buffer();
|
||||
}
|
||||
|
||||
// tried:
|
||||
// 1. paint inline in new_password func
|
||||
// 2. paint in a seperate func and call from new_password
|
||||
// 3. override nav's paint func (i think it can tried to capture same obj) and paint, hoping set_dirty handle it correctly
|
||||
// 4. override nav's paint func (i think it can tried to capture same obj) and paint in a seperate func, hoping set_dirty handle it correctly
|
||||
// all these methods failed, and all of them only flash and disappeared. only when set_dirty in on_data (which seems incorrect), and it keep flashing never stop. but see painted content (flashing too)
|
||||
// btw this is not caused by the seed text set thing, cuz commented it out not helping.
|
||||
void RandomPasswordView::paint_password_hints() {
|
||||
Painter painter;
|
||||
const int char_width = 8;
|
||||
const int char_height = 16;
|
||||
const int start_y = 7 * char_height + 5;
|
||||
const int rect_height = 4;
|
||||
|
||||
for (size_t i = 0; i < password.length(); i++) {
|
||||
char c = password[i];
|
||||
Color color;
|
||||
if (std::isdigit(c)) {
|
||||
color = Color::red();
|
||||
} else if (std::islower(c)) {
|
||||
color = Color::green();
|
||||
} else if (std::isupper(c)) {
|
||||
color = Color::blue();
|
||||
} else {
|
||||
color = Color::white();
|
||||
}
|
||||
|
||||
painter.fill_rectangle(
|
||||
{{static_cast<int>(i) * char_width, start_y},
|
||||
{char_width, rect_height}},
|
||||
color);
|
||||
}
|
||||
}
|
||||
|
||||
std::string RandomPasswordView::generate_log_line() {
|
||||
std::string seeds_set = "";
|
||||
for (auto seed : seeds_deque) {
|
||||
seeds_set += std::to_string(seed);
|
||||
seeds_set += " ";
|
||||
}
|
||||
std::string line = "\npassword=" + password +
|
||||
"\nseeds=" + seeds_set +
|
||||
"\n";
|
||||
return line;
|
||||
}
|
||||
|
||||
RandomPasswordView::~RandomPasswordView() {
|
||||
receiver_model.disable();
|
||||
baseband::shutdown();
|
||||
}
|
||||
|
||||
} // namespace ui::external_app::random_password
|
||||
@@ -0,0 +1,219 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2017 Furrtek
|
||||
* Copyright (C) 2024 zxkmm
|
||||
* 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_RANDOM_PASSWORD_H__
|
||||
#define __UI_RANDOM_PASSWORD_H__
|
||||
|
||||
#define MAX_DIGITS 30
|
||||
|
||||
#include "ui.hpp"
|
||||
#include "ui_language.hpp"
|
||||
#include "ui_navigation.hpp"
|
||||
#include "ui_receiver.hpp"
|
||||
#include "ui_freq_field.hpp"
|
||||
#include "ui_record_view.hpp"
|
||||
#include "app_settings.hpp"
|
||||
#include "radio_state.hpp"
|
||||
#include "log_file.hpp"
|
||||
#include "utility.hpp"
|
||||
#include "ui_qrcode.hpp"
|
||||
#include "usb_serial_asyncmsg.hpp"
|
||||
#include <deque>
|
||||
|
||||
using namespace ui;
|
||||
|
||||
namespace ui::external_app::random_password {
|
||||
|
||||
class RandomPasswordLogger { // TODO: log is broken after introduced the buffer thing
|
||||
public:
|
||||
Optional<File::Error> append(const std::filesystem::path& filename) {
|
||||
return log_file.append(filename);
|
||||
}
|
||||
|
||||
void log_raw_data(const std::string& data);
|
||||
|
||||
private:
|
||||
LogFile log_file{};
|
||||
};
|
||||
|
||||
class RandomPasswordView : public View {
|
||||
public:
|
||||
RandomPasswordView(NavigationView& nav);
|
||||
~RandomPasswordView();
|
||||
|
||||
void focus() override;
|
||||
|
||||
std::string title() const override { return "R.passwd"; };
|
||||
|
||||
private:
|
||||
unsigned int seed = 0; // extern void srand (unsigned int __seed) __THROW;
|
||||
std::string password = "";
|
||||
std::deque<unsigned int> seeds_deque = {0};
|
||||
bool seeds_buffer_not_full = true;
|
||||
bool in_benchmark = false;
|
||||
bool flooding = false;
|
||||
bool logging = false;
|
||||
bool async_prev_val = false;
|
||||
std::string str_log{""};
|
||||
|
||||
void on_data(uint32_t value, bool is_data);
|
||||
void clean_buffer();
|
||||
void new_password();
|
||||
std::string generate_log_line();
|
||||
void paint_password_hints();
|
||||
|
||||
NavigationView& nav_;
|
||||
RxRadioState radio_state_{};
|
||||
app_settings::SettingsManager settings_{
|
||||
"rx_passgen", app_settings::Mode::RX};
|
||||
|
||||
Labels labels{
|
||||
{{0 * 8, 0 * 16}, "------------seeds-------------", Theme::getInstance()->fg_light->foreground},
|
||||
{{0 * 8, 3 * 16}, "-----------password-----------", Theme::getInstance()->fg_light->foreground},
|
||||
{{5 * 8, 7 * 16 - 2}, "digits:", Theme::getInstance()->fg_light->foreground},
|
||||
};
|
||||
|
||||
RFAmpField field_rf_amp{
|
||||
{13 * 8, 1 * 16}};
|
||||
LNAGainField field_lna{
|
||||
{15 * 8, 1 * 16}};
|
||||
VGAGainField field_vga{
|
||||
{18 * 8, 1 * 16}};
|
||||
|
||||
RSSI rssi{
|
||||
{21 * 8, 1 * 16 + 0, 6 * 8, 4}};
|
||||
Channel channel{
|
||||
{21 * 8, 1 * 16 + 5, 6 * 8, 4}};
|
||||
|
||||
RxFrequencyField field_frequency{
|
||||
{0 * 8, 1 * 16},
|
||||
nav_};
|
||||
|
||||
Button button_modem_setup{
|
||||
{screen_width - 12 * 8, 2 * 16 - 1, 96, 16 + 2},
|
||||
LanguageHelper::currentMessages[LANG_MODEM_SETUP]};
|
||||
|
||||
Text text_seed{
|
||||
{0, 2 * 16, 10 * 8, 16},
|
||||
"0000000000"};
|
||||
|
||||
ProgressBar progressbar{
|
||||
{10 * 8 + 2, 2 * 16, screen_width - 96 - (10 * 8 + 4) - 1, 16}};
|
||||
|
||||
Text text_generated_passwd{
|
||||
{0, 4 * 16, screen_width, 16},
|
||||
"000000000000000000000000000000"};
|
||||
|
||||
Text text_char_type_hints{
|
||||
{0, 5 * 16, screen_width, 16},
|
||||
"DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"};
|
||||
|
||||
Checkbox check_show_seeds{
|
||||
{17 * 8, 8 * 16},
|
||||
6,
|
||||
"Show seed"};
|
||||
|
||||
Checkbox check_auto_send{
|
||||
{1 * 8, 8 * 16},
|
||||
20,
|
||||
"Auto send"};
|
||||
|
||||
Checkbox check_punctuation{
|
||||
{17 * 8, 12 * 16},
|
||||
6,
|
||||
".,-!?"};
|
||||
|
||||
Checkbox check_allow_confusable_chars{
|
||||
{1 * 8, 10 * 16},
|
||||
20,
|
||||
"0 O o 1 l"};
|
||||
|
||||
Checkbox check_digits{
|
||||
{1 * 8, 12 * 16},
|
||||
3,
|
||||
"123"};
|
||||
|
||||
Checkbox check_latin_lower{
|
||||
{1 * 8, 14 * 16},
|
||||
3,
|
||||
"abc"};
|
||||
|
||||
Checkbox check_latin_upper{
|
||||
{17 * 8, 14 * 16},
|
||||
3,
|
||||
"ABC"};
|
||||
|
||||
Checkbox check_log{
|
||||
{17 * 8, 10 * 16},
|
||||
3,
|
||||
LanguageHelper::currentMessages[LANG_SAVE]};
|
||||
|
||||
Button button_flood{
|
||||
{0 * 8, 15 * 16 + 18, screen_width / 2, 22},
|
||||
LanguageHelper::currentMessages[LANG_FLOOD]};
|
||||
|
||||
Button button_send{
|
||||
{screen_width / 2 + 2, 15 * 16 + 18, screen_width / 2 - 2, 22},
|
||||
"Send pwd"};
|
||||
|
||||
Button button_refresh{
|
||||
{0 * 8, 17 * 16 + 10, screen_width / 2, 22},
|
||||
"Generate"};
|
||||
|
||||
Button button_show_qr{
|
||||
{screen_width / 2 + 2, 17 * 16 + 10, screen_width / 2 - 2, 22},
|
||||
LanguageHelper::currentMessages[LANG_SHOWQR]};
|
||||
|
||||
NumberField field_digits{
|
||||
{16 * 8, 7 * 16 - 2},
|
||||
2,
|
||||
{1, 30},
|
||||
1,
|
||||
' '};
|
||||
|
||||
void on_data_afsk(const AFSKDataMessage& message);
|
||||
|
||||
std::unique_ptr<RandomPasswordLogger> logger{};
|
||||
|
||||
MessageHandlerRegistration message_handler_packet{
|
||||
Message::ID::AFSKData,
|
||||
[this](Message* const p) {
|
||||
const auto message = static_cast<const AFSKDataMessage*>(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<const FreqChangeCommandMessage*>(p);
|
||||
this->on_freqchg(message->freq);
|
||||
}};
|
||||
|
||||
void on_freqchg(int64_t freq);
|
||||
void set_random_freq();
|
||||
};
|
||||
|
||||
} // namespace ui::external_app::random_password
|
||||
|
||||
#endif /*__UI_RANDOM_PASSWORD_H__*/
|
||||
@@ -722,8 +722,8 @@ void NavigationView::update_view() {
|
||||
auto top_view = top.view.get();
|
||||
|
||||
add_child(top_view);
|
||||
top_view->set_parent_rect({{0, 0}, size()});
|
||||
|
||||
auto newSize = (is_top()) ? Size{size().width(), size().height() - 16} : size(); // if top(), then there is the info bar at the bottom, so leave space for it
|
||||
top_view->set_parent_rect({{0, 0}, newSize});
|
||||
focus();
|
||||
set_dirty();
|
||||
|
||||
@@ -996,17 +996,48 @@ void BMPView::focus() {
|
||||
button_done.focus();
|
||||
}
|
||||
|
||||
BMPView::BMPView(NavigationView& nav) {
|
||||
BMPView::BMPView(NavigationView& nav)
|
||||
: nav_(nav) {
|
||||
add_children({&button_done});
|
||||
|
||||
button_done.on_select = [this, &nav](Button&) {
|
||||
nav.pop();
|
||||
button_done.on_select = [this](Button&) {
|
||||
handle_pop();
|
||||
};
|
||||
}
|
||||
|
||||
void BMPView::paint(Painter&) {
|
||||
if (!portapack::display.drawBMP2({0, 0}, splash_dot_bmp))
|
||||
portapack::display.drawBMP({(240 - 230) / 2, (320 - 50) / 2 - 10}, splash_bmp, true);
|
||||
portapack::display.drawBMP({(240 - 230) / 2, (320 - 50) / 2 - 10}, splash_bmp, (const uint8_t[]){0x29, 0x18, 0x16});
|
||||
}
|
||||
|
||||
bool BMPView::on_touch(const TouchEvent event) {
|
||||
/* the event thing were resolved by HTotoo, talked here https://discord.com/channels/719669764804444213/956561375155589192/1287756910950486027
|
||||
* the touch screen policy can be better, talked here https://discord.com/channels/719669764804444213/956561375155589192/1198926225897443328
|
||||
*/
|
||||
|
||||
if (!nav_.is_valid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (event.type) {
|
||||
case TouchEvent::Type::Start:
|
||||
return true;
|
||||
|
||||
case TouchEvent::Type::End:
|
||||
handle_pop();
|
||||
return true;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void BMPView::handle_pop() {
|
||||
if (nav_.is_valid()) {
|
||||
nav_.pop();
|
||||
}
|
||||
}
|
||||
|
||||
/* NotImplementedView ****************************************************/
|
||||
@@ -1072,7 +1103,7 @@ ModalMessageView::ModalMessageView(
|
||||
}
|
||||
|
||||
void ModalMessageView::paint(Painter& painter) {
|
||||
if (!compact) portapack::display.drawBMP({100, 48}, modal_warning_bmp, true);
|
||||
if (!compact) portapack::display.drawBMP({100, 48}, modal_warning_bmp, (const uint8_t[]){0, 0, 0});
|
||||
|
||||
// Break lines.
|
||||
auto lines = split_string(message_, '\n');
|
||||
|
||||
@@ -343,7 +343,11 @@ class BMPView : public View {
|
||||
void paint(Painter&) override;
|
||||
void focus() override;
|
||||
|
||||
bool on_touch(const TouchEvent event) override;
|
||||
void handle_pop();
|
||||
|
||||
private:
|
||||
NavigationView& nav_;
|
||||
Button button_done{
|
||||
{240, 0, 1, 1},
|
||||
""};
|
||||
|
||||
@@ -37,6 +37,8 @@ class USBSerial {
|
||||
void on_channel_closed();
|
||||
void setEventDispatcher(EventDispatcher* ed) { _eventDispatcher = ed; }
|
||||
|
||||
bool serial_connected() { return connected; }
|
||||
|
||||
private:
|
||||
void enable_xtal();
|
||||
void disable_pll0();
|
||||
@@ -51,4 +53,4 @@ class USBSerial {
|
||||
EventDispatcher* _eventDispatcher = NULL;
|
||||
};
|
||||
|
||||
} // namespace portapack
|
||||
} // namespace portapack
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
*/
|
||||
|
||||
#include "usb_serial_asyncmsg.hpp"
|
||||
#include "usb_serial.hpp"
|
||||
|
||||
/// value
|
||||
// to_string_bin/ to_string_decimal/ to_string_hex/ to_string_hex_array/ to_string_dec_uint/ to_string_dec_int etc seems usellss so i didn't add them here
|
||||
@@ -30,7 +31,7 @@
|
||||
|
||||
template <>
|
||||
void UsbSerialAsyncmsg::asyncmsg<int64_t>(const int64_t& data) {
|
||||
if (!portapack::async_tx_enabled) {
|
||||
if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) {
|
||||
return;
|
||||
}
|
||||
chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str());
|
||||
@@ -38,7 +39,7 @@ void UsbSerialAsyncmsg::asyncmsg<int64_t>(const int64_t& data) {
|
||||
|
||||
template <>
|
||||
void UsbSerialAsyncmsg::asyncmsg<int32_t>(const int32_t& data) {
|
||||
if (!portapack::async_tx_enabled) {
|
||||
if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) {
|
||||
return;
|
||||
}
|
||||
chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str());
|
||||
@@ -46,7 +47,7 @@ void UsbSerialAsyncmsg::asyncmsg<int32_t>(const int32_t& data) {
|
||||
|
||||
template <>
|
||||
void UsbSerialAsyncmsg::asyncmsg<int16_t>(const int16_t& data) {
|
||||
if (!portapack::async_tx_enabled) {
|
||||
if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) {
|
||||
return;
|
||||
}
|
||||
chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str());
|
||||
@@ -54,7 +55,7 @@ void UsbSerialAsyncmsg::asyncmsg<int16_t>(const int16_t& data) {
|
||||
|
||||
template <>
|
||||
void UsbSerialAsyncmsg::asyncmsg<int8_t>(const int8_t& data) {
|
||||
if (!portapack::async_tx_enabled) {
|
||||
if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) {
|
||||
return;
|
||||
}
|
||||
chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str());
|
||||
@@ -62,7 +63,7 @@ void UsbSerialAsyncmsg::asyncmsg<int8_t>(const int8_t& data) {
|
||||
|
||||
template <>
|
||||
void UsbSerialAsyncmsg::asyncmsg<uint8_t>(const uint8_t& data) {
|
||||
if (!portapack::async_tx_enabled) {
|
||||
if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) {
|
||||
return;
|
||||
}
|
||||
chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str());
|
||||
@@ -70,7 +71,7 @@ void UsbSerialAsyncmsg::asyncmsg<uint8_t>(const uint8_t& data) {
|
||||
|
||||
template <>
|
||||
void UsbSerialAsyncmsg::asyncmsg<uint16_t>(const uint16_t& data) {
|
||||
if (!portapack::async_tx_enabled) {
|
||||
if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) {
|
||||
return;
|
||||
}
|
||||
chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str());
|
||||
@@ -78,7 +79,7 @@ void UsbSerialAsyncmsg::asyncmsg<uint16_t>(const uint16_t& data) {
|
||||
|
||||
template <>
|
||||
void UsbSerialAsyncmsg::asyncmsg<uint32_t>(const uint32_t& data) {
|
||||
if (!portapack::async_tx_enabled) {
|
||||
if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) {
|
||||
return;
|
||||
}
|
||||
chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str());
|
||||
@@ -86,7 +87,7 @@ void UsbSerialAsyncmsg::asyncmsg<uint32_t>(const uint32_t& data) {
|
||||
|
||||
template <>
|
||||
void UsbSerialAsyncmsg::asyncmsg<uint64_t>(const uint64_t& data) {
|
||||
if (!portapack::async_tx_enabled) {
|
||||
if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) {
|
||||
return;
|
||||
}
|
||||
chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str());
|
||||
@@ -94,7 +95,7 @@ void UsbSerialAsyncmsg::asyncmsg<uint64_t>(const uint64_t& data) {
|
||||
|
||||
template <>
|
||||
void UsbSerialAsyncmsg::asyncmsg<float>(const float& data) {
|
||||
if (!portapack::async_tx_enabled) {
|
||||
if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) {
|
||||
return;
|
||||
}
|
||||
chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_decimal(data, 7).c_str());
|
||||
@@ -105,7 +106,7 @@ void UsbSerialAsyncmsg::asyncmsg<float>(const float& data) {
|
||||
template <>
|
||||
// usage: UsbSerialAsyncmsg::asyncmsg(path);
|
||||
void UsbSerialAsyncmsg::asyncmsg<std::filesystem::path>(const std::filesystem::path& data) {
|
||||
if (!portapack::async_tx_enabled) {
|
||||
if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) {
|
||||
return;
|
||||
}
|
||||
std::string path_str = data.string();
|
||||
@@ -114,7 +115,7 @@ void UsbSerialAsyncmsg::asyncmsg<std::filesystem::path>(const std::filesystem::p
|
||||
|
||||
template <>
|
||||
void UsbSerialAsyncmsg::asyncmsg<std::filesystem::path::string_type>(const std::filesystem::path::string_type& data) {
|
||||
if (!portapack::async_tx_enabled) {
|
||||
if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) {
|
||||
return;
|
||||
}
|
||||
std::string str_data(data.begin(), data.end());
|
||||
@@ -127,7 +128,7 @@ void UsbSerialAsyncmsg::asyncmsg<std::filesystem::path::string_type>(const std::
|
||||
template <>
|
||||
// usage: UsbSerialAsyncmsg::asyncmsg(str);
|
||||
void UsbSerialAsyncmsg::asyncmsg<std::string>(const std::string& data) {
|
||||
if (!portapack::async_tx_enabled) {
|
||||
if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) {
|
||||
return;
|
||||
}
|
||||
chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", data.c_str());
|
||||
@@ -136,7 +137,7 @@ void UsbSerialAsyncmsg::asyncmsg<std::string>(const std::string& data) {
|
||||
// string literal AKA char[]
|
||||
// usage: UsbSerialAsyncmsg::asyncmsg("abc");
|
||||
void UsbSerialAsyncmsg::asyncmsg(const char* data) {
|
||||
if (!portapack::async_tx_enabled) {
|
||||
if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) {
|
||||
return;
|
||||
}
|
||||
chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", data);
|
||||
@@ -146,8 +147,8 @@ void UsbSerialAsyncmsg::asyncmsg(const char* data) {
|
||||
template <>
|
||||
// usage: UsbSerialAsyncmsg::asyncmsg(true);
|
||||
void UsbSerialAsyncmsg::asyncmsg<bool>(const bool& data) {
|
||||
if (!portapack::async_tx_enabled) {
|
||||
if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) {
|
||||
return;
|
||||
}
|
||||
chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", data ? "true" : "false");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ class UsbSerialAsyncmsg {
|
||||
// ussgae: UsbSerialAsyncmsg::asyncmsg(vec);
|
||||
template <typename VECTORCOVER>
|
||||
void UsbSerialAsyncmsg::asyncmsg(const std::vector<VECTORCOVER>& data) {
|
||||
if (!portapack::async_tx_enabled) {
|
||||
if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) {
|
||||
return;
|
||||
}
|
||||
for (const auto& item : data) {
|
||||
|
||||
@@ -344,7 +344,20 @@ void ILI9341::render_box(const ui::Point p, const ui::Size s, const ui::Color* l
|
||||
}
|
||||
|
||||
// RLE_4 BMP loader (delta not implemented)
|
||||
void ILI9341::drawBMP(const ui::Point p, const uint8_t* bitmap, const bool transparency) {
|
||||
/* draw transparent, pass transparent color as arg, usage inline anonymous obj
|
||||
* portapack::display.drawBMP({100, 100}, foo_bmp, (const uint8_t[]){41, 24, 22}); // dec, out of {255, 255, 255}
|
||||
* portapack::display.drawBMP({100, 100}, foo_bmp, (const uint8_t[]){0x29, 0x18, 0x16}); //hex out of {0xFF, 0xFF, 0xFF}
|
||||
*
|
||||
* draw transparent, pass transparent color as arg, usage pass uint8_t[] obj
|
||||
* const uint8_t c[] = {41, 24, 22}; or const uint8_t c[3] = {0x29, 0x18, 0x16};
|
||||
* portapack::display.drawBMP({100, 100}, foo_bmp, c);
|
||||
*
|
||||
* don't draw transparent, pass nullptr as arg, usage
|
||||
* portapack::display.drawBMP({100, 100}, foo_bmp, nullptr);
|
||||
*
|
||||
* if your image use RLE compress as transparency methods, pass any valid color as arg, it doesn't matter (like the modal bmp. TODO: write RLE transparency generator)
|
||||
* */
|
||||
void ILI9341::drawBMP(const ui::Point p, const uint8_t* bitmap, const uint8_t* transparency_color) {
|
||||
const bmp_header_t* bmp_header = (const bmp_header_t*)bitmap;
|
||||
uint32_t data_idx;
|
||||
uint8_t by, c, count, transp_idx = 0;
|
||||
@@ -362,12 +375,13 @@ void ILI9341::drawBMP(const ui::Point p, const uint8_t* bitmap, const bool trans
|
||||
// Convert palette and find pure magenta index (alpha color key) rgb dec(41,24,22)
|
||||
for (c = 0; c < 16; c++) {
|
||||
palette[c] = ui::Color(bmp_palette->color[c].R, bmp_palette->color[c].G, bmp_palette->color[c].B);
|
||||
if ((bmp_palette->color[c].R == 0x29) &&
|
||||
(bmp_palette->color[c].G == 0x18) &&
|
||||
(bmp_palette->color[c].B == 0x16)) transp_idx = c;
|
||||
if (transparency_color &&
|
||||
(bmp_palette->color[c].R == transparency_color[0]) &&
|
||||
(bmp_palette->color[c].G == transparency_color[1]) &&
|
||||
(bmp_palette->color[c].B == transparency_color[2])) transp_idx = c;
|
||||
}
|
||||
|
||||
if (!transparency) {
|
||||
if (!transparency_color) {
|
||||
py = bmp_header->height + 16;
|
||||
do {
|
||||
by = bitmap[data_idx++];
|
||||
|
||||
@@ -62,7 +62,7 @@ class ILI9341 {
|
||||
const ui::Color background);
|
||||
|
||||
void draw_pixel(const ui::Point p, const ui::Color color);
|
||||
void drawBMP(const ui::Point p, const uint8_t* bitmap, const bool transparency);
|
||||
void drawBMP(const ui::Point p, const uint8_t* bitmap, const uint8_t* transparency_color);
|
||||
bool drawBMP2(const ui::Point p, const std::filesystem::path& file);
|
||||
void render_line(const ui::Point p, const uint8_t count, const ui::Color* line_buffer);
|
||||
void render_box(const ui::Point p, const ui::Size s, const ui::Color* line_buffer);
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
#include "ui_language.hpp"
|
||||
|
||||
const char* LanguageHelper::englishMessages[] = {"OK", "Cancel", "Error", "Modem setup", "Debug", "Log", "Done", "Start", "Stop", "Scan", "Clear", "Ready", "Data:", "Loop", "Reset"};
|
||||
// use the exact position in this array! the enum's value is the identifier. Best to add to the end
|
||||
const char* LanguageHelper::englishMessages[] = {"OK", "Cancel", "Error", "Modem setup", "Debug", "Log", "Done", "Start", "Stop", "Scan", "Clear", "Ready", "Data:", "Loop", "Reset", "Pause", "Resume", "Flood", "Show QR", "Save"};
|
||||
|
||||
// multi language support will changes (not in use for now)
|
||||
const char** LanguageHelper::currentMessages = englishMessages;
|
||||
|
||||
void LanguageHelper::setLanguage(LanguageList lang) {
|
||||
|
||||
@@ -1,10 +1,43 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
The purpose of this: when creating an ext app it's address will be changed. But the compiler doesn't know this, so when it optimizes literals it can remove something from one ext app, that is included in the other, to save space.
|
||||
But when we want to run this app, it won't find the literal at the fake address, so the best case we'll get just garbage or nothing instead of the string.
|
||||
So we must use this Language helper that stores the literals in the fw instead of any ext app, so it'll be always available.
|
||||
In the first run we must move those string literal here what are not so unique, like "OK".
|
||||
*/
|
||||
|
||||
#ifndef __UI_LANGUAGE_H__
|
||||
#define __UI_LANGUAGE_H__
|
||||
|
||||
// For future multi language support
|
||||
enum LanguageList {
|
||||
ENGLISH,
|
||||
};
|
||||
|
||||
// Add an element to this enum when you fill a new value.
|
||||
// Then add the string literal to the LanguageHelper::englishMessages at the exact position where the enum points to (usualy to the end)
|
||||
|
||||
enum LangConsts {
|
||||
LANG_OK,
|
||||
LANG_CANCEL,
|
||||
@@ -20,12 +53,17 @@ enum LangConsts {
|
||||
LANG_READY,
|
||||
LANG_DATADP,
|
||||
LANG_LOOP,
|
||||
LANG_RESET
|
||||
LANG_RESET,
|
||||
LANG_PAUSE,
|
||||
LANG_RESUME,
|
||||
LANG_FLOOD,
|
||||
LANG_SHOWQR,
|
||||
LANG_SAVE
|
||||
};
|
||||
|
||||
class LanguageHelper {
|
||||
public:
|
||||
static void setLanguage(LanguageList lang);
|
||||
static void setLanguage(LanguageList lang); // changes the pointer to the currently used language literal container. not used yet.
|
||||
static const char* getMessage(LangConsts msg);
|
||||
static const char** currentMessages; // expose, so can link directly too
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 5.1 KiB |
Reference in New Issue
Block a user