Merge remote-tracking branch 'origin/next' into ssd_to_usb

This commit is contained in:
Bernd Herzog 2023-04-01 19:24:53 +02:00
commit db5fcaba44
5 changed files with 1435 additions and 1240 deletions

View File

@ -394,6 +394,104 @@ void SetConverterSettingsView::focus() {
button_save.focus(); button_save.focus();
} }
// ---------------------------------------------------------
// Persistent Memory Settings
// ---------------------------------------------------------
SetPersistentMemoryView::SetPersistentMemoryView(NavigationView& nav) {
add_children({
&text_pmem_about,
&text_pmem_informations,
&text_pmem_status,
&check_load_mem_at_startup,
&button_save_mem_to_file,
&button_load_mem_from_file,
&button_return
});
bool load_mem_at_startup = false ;
File pmem_flag_file_handle ;
std::string pmem_flag_file = "/SETTINGS/PMEM_FILEFLAG" ;
auto result = pmem_flag_file_handle.open(pmem_flag_file);
if(!result.is_valid())
{
load_mem_at_startup = true ;
}
check_load_mem_at_startup.set_value(load_mem_at_startup);
check_load_mem_at_startup.on_select = [this](Checkbox&, bool v) {
File pmem_flag_file_handle ;
std::string pmem_flag_file = "/SETTINGS/PMEM_FILEFLAG" ;
if( v )
{
auto result = pmem_flag_file_handle.open(pmem_flag_file);
if(result.is_valid())
{
auto result = pmem_flag_file_handle.create(pmem_flag_file); //third: create if it is not there
if( !result.is_valid() )
{
text_pmem_status.set("pmem flag file created");
}
else
{
text_pmem_status.set("!err. creating pmem flagfile!");
}
}
else
{
text_pmem_status.set("pmem flag already present");
}
}
else
{
auto result = delete_file( pmem_flag_file );
if( result != 0 )
{
text_pmem_status.set("!err. deleting pmem flagfile!");
}
else
{
text_pmem_status.set("pmem flag file deleted");
}
}
};
button_save_mem_to_file.on_select = [&nav, this](Button&) {
if( !portapack::persistent_memory::save_persistent_settings_to_file("SETTINGS/pmem_settings") )
{
text_pmem_status.set("!problem saving settings!");
}
else
{
text_pmem_status.set("settings saved");
}
};
button_load_mem_from_file.on_select = [&nav, this](Button&) {
if( !portapack::persistent_memory::load_persistent_settings_from_file("SETTINGS/pmem_settings") )
{
text_pmem_status.set("!problem loading settings!");
}
else
{
text_pmem_status.set("settings loaded");
//Refresh status bar with icon up or down
StatusRefreshMessage message { };
EventDispatcher::send_message(message);
}
};
button_return.on_select = [&nav, this](Button&) {
nav.pop();
};
}
void SetPersistentMemoryView::focus() {
button_return.focus();
}
//
// Audio settings
//
SetAudioView::SetAudioView(NavigationView& nav) { SetAudioView::SetAudioView(NavigationView& nav) {
add_children({ add_children({
&labels, &labels,
@ -458,7 +556,8 @@ SettingsMenuView::SettingsMenuView(NavigationView& nav) {
{ "Calibration", ui::Color::dark_cyan(), &bitmap_icon_options_touch, [&nav](){ nav.push<TouchCalibrationView>(); } }, { "Calibration", ui::Color::dark_cyan(), &bitmap_icon_options_touch, [&nav](){ nav.push<TouchCalibrationView>(); } },
{ "App Settings", ui::Color::dark_cyan(), &bitmap_icon_setup, [&nav](){ nav.push<SetAppSettingsView>(); } }, { "App Settings", ui::Color::dark_cyan(), &bitmap_icon_setup, [&nav](){ nav.push<SetAppSettingsView>(); } },
{ "Converter", ui::Color::dark_cyan(), &bitmap_icon_options_radio, [&nav](){ nav.push<SetConverterSettingsView>(); } }, { "Converter", ui::Color::dark_cyan(), &bitmap_icon_options_radio, [&nav](){ nav.push<SetConverterSettingsView>(); } },
{ "QR Code", ui::Color::dark_cyan(), &bitmap_icon_qr_code, [&nav](){ nav.push<SetQRCodeView>(); } } { "QR Code", ui::Color::dark_cyan(), &bitmap_icon_qr_code, [&nav](){ nav.push<SetQRCodeView>(); } },
{ "P.Memory Mgmt", ui::Color::dark_cyan(), &bitmap_icon_memory, [&nav](){ nav.push<SetPersistentMemoryView>(); } },
}); });
set_max_rows(2); // allow wider buttons set_max_rows(2); // allow wider buttons
} }

View File

@ -432,6 +432,54 @@ private:
}; };
}; };
class SetPersistentMemoryView : public View {
public:
SetPersistentMemoryView(NavigationView& nav);
void focus() override;
std::string title() const override { return "P.Mem Mgmt"; };
private:
Text text_pmem_about {
{ 0, 1 * 16, 240 , 16 },
"PersistentMemory from/to SD"
};
Text text_pmem_informations {
{ 0, 2 * 16, 240 , 16 },
"use: when no/dead coin bat."
};
Text text_pmem_status {
{ 0, 3 * 16, 240 , 16 },
""
};
Checkbox check_load_mem_at_startup {
{ 18, 6 * 16},
19,
"load from sd at startup"
};
Button button_save_mem_to_file {
{ 0, 9 * 16, 240, 32 },
"save p.mem to sdcard"
};
Button button_load_mem_from_file {
{ 0, 12 * 16, 240, 32 },
"load p.mem from sdcard"
};
Button button_return {
{ 16 * 8, 16 * 16, 12 * 8, 32 },
"Return",
};
};
class SettingsMenuView : public BtnGridView { class SettingsMenuView : public BtnGridView {
public: public:
SettingsMenuView(NavigationView& nav); SettingsMenuView(NavigationView& nav);

View File

@ -723,6 +723,14 @@ SystemView::SystemView(
navigation_view.push<SystemMenuView>(); navigation_view.push<SystemMenuView>();
File pmem_flag_file_handle ;
std::string pmem_flag_file = "/SETTINGS/PMEM_FILEFLAG" ;
auto result = pmem_flag_file_handle.open(pmem_flag_file);
if(!result.is_valid())
{
portapack::persistent_memory::load_persistent_settings_from_file("SETTINGS/pmem_settings");
}
if (portapack::persistent_memory::config_splash()) if (portapack::persistent_memory::config_splash())
{ {
navigation_view.push<BMPView>(); navigation_view.push<BMPView>();

View File

@ -34,6 +34,12 @@
#include <algorithm> #include <algorithm>
#include <utility> #include <utility>
#include <string>
#include <fstream>
#include "file.hpp"
using namespace std;
namespace portapack { namespace portapack {
namespace persistent_memory { namespace persistent_memory {
@ -406,7 +412,7 @@ static_assert(sizeof(data_t) <= sizeof(backup_ram_t) - sizeof(uint32_t));
static backup_ram_t* const backup_ram = reinterpret_cast<backup_ram_t*>(memory::map::backup_ram.base()); static backup_ram_t* const backup_ram = reinterpret_cast<backup_ram_t*>(memory::map::backup_ram.base());
static backup_ram_t cached_backup_ram; static backup_ram_t cached_backup_ram;
static data_t* const data = reinterpret_cast<data_t*>(&cached_backup_ram); static data_t* data = reinterpret_cast<data_t*>(&cached_backup_ram);
namespace cache { namespace cache {
@ -423,6 +429,7 @@ void defaults() {
set_recon_update_ranges_when_recon( true ); set_recon_update_ranges_when_recon( true );
set_recon_load_hamradios( true ); set_recon_load_hamradios( true );
set_recon_match_mode( 0 ); set_recon_match_mode( 0 );
} }
void init() { void init() {
@ -774,5 +781,32 @@ void set_config_updown_converter(const bool v){
void set_config_converter_freq(const int64_t v ){ void set_config_converter_freq(const int64_t v ){
data-> converter_frequency_offset = v ; data-> converter_frequency_offset = v ;
} }
// sd persisting settings
int save_persistent_settings_to_file( std::string filename )
{
delete_file( filename );
File outfile ;
auto result = outfile.create(filename);
if( result.is_valid() )
{
return false ;
}
outfile.write( reinterpret_cast<char*>(&cached_backup_ram), sizeof(backup_ram_t) );
return true ;
}
int load_persistent_settings_from_file( std::string filename )
{
File infile ;
auto result = infile.open(filename);
if( !result.is_valid() )
{
infile.read( reinterpret_cast<char*>(&cached_backup_ram), sizeof(backup_ram_t) );
return true ;
}
return false ;
}
} /* namespace persistent_memory */ } /* namespace persistent_memory */
} /* namespace portapack */ } /* namespace portapack */

View File

@ -36,6 +36,7 @@ using namespace modems;
using namespace serializer; using namespace serializer;
namespace portapack { namespace portapack {
namespace persistent_memory { namespace persistent_memory {
enum backlight_timeout_t { enum backlight_timeout_t {
@ -216,7 +217,12 @@ void set_clkout_freq(uint32_t freq);
void set_recon_load_hamradios(const bool v ); void set_recon_load_hamradios(const bool v );
void set_recon_match_mode( const bool v ); void set_recon_match_mode( const bool v );
// sd persisting settings
int save_persistent_settings_to_file( std::string filename );
int load_persistent_settings_from_file( std::string filename );
} /* namespace persistent_memory */ } /* namespace persistent_memory */
} /* namespace portapack */ } /* namespace portapack */
#endif/*__PORTAPACK_PERSISTENT_MEMORY_H__*/ #endif/*__PORTAPACK_PERSISTENT_MEMORY_H__*/