mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-08-13 17:05:37 -04:00
App settings revamp (#1139)
* WIP AppSetting overhaul * WIP migrating apps to new settings. * remove settings, rename tuned => target * formatting * Minor fixes * Fix hang on app load * run formatter * PR comment fixes * Load modulation into receiver model in app_settings * Run formatter --------- Co-authored-by: kallanreed <kallanreed@outlook.com>
This commit is contained in:
parent
f65e743c4c
commit
8bd3d6249d
105 changed files with 914 additions and 1136 deletions
|
@ -27,53 +27,83 @@
|
|||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "file.hpp"
|
||||
#include "string_format.hpp"
|
||||
|
||||
namespace std {
|
||||
class app_settings {
|
||||
namespace app_settings {
|
||||
|
||||
enum class ResultCode : uint8_t {
|
||||
Ok, // settings found
|
||||
LoadFailed, // settings (file) not found
|
||||
SaveFailed, // unable to save settings
|
||||
SettingsDisabled, // load/save disabled in settings
|
||||
};
|
||||
|
||||
enum class Mode : uint8_t {
|
||||
RX = 0x01,
|
||||
TX = 0x02,
|
||||
RX_TX = 0x03, // Both TX/RX
|
||||
};
|
||||
|
||||
// TODO: separate types for TX/RX or union?
|
||||
struct AppSettings {
|
||||
Mode mode;
|
||||
uint32_t baseband_bandwidth;
|
||||
uint32_t sampling_rate;
|
||||
uint8_t lna;
|
||||
uint8_t vga;
|
||||
uint8_t rx_amp;
|
||||
uint8_t tx_amp;
|
||||
uint8_t tx_gain;
|
||||
uint32_t channel_bandwidth;
|
||||
uint32_t rx_frequency;
|
||||
uint32_t tx_frequency;
|
||||
uint32_t step;
|
||||
uint8_t modulation;
|
||||
uint8_t am_config_index;
|
||||
uint8_t nbfm_config_index;
|
||||
uint8_t wfm_config_index;
|
||||
uint8_t squelch;
|
||||
|
||||
uint8_t volume;
|
||||
};
|
||||
|
||||
ResultCode load_settings(const std::string& app_name, AppSettings& settings);
|
||||
ResultCode save_settings(const std::string& app_name, AppSettings& settings);
|
||||
|
||||
/* Copies common values to the receiver/transmitter models. */
|
||||
void copy_to_radio_model(const AppSettings& settings);
|
||||
|
||||
/* Copies common values from the receiver/transmitter models. */
|
||||
void copy_from_radio_model(AppSettings& settings);
|
||||
|
||||
/* RAII wrapper for automatically loading and saving settings for an app.
|
||||
* NB: This should be added to a class before any LNA/VGA controls so that
|
||||
* the receiver/transmitter models are set before the control ctors run. */
|
||||
class SettingsManager {
|
||||
public:
|
||||
#define SETTINGS_OK 0 // settings found
|
||||
#define SETTINGS_UNABLE_TO_LOAD -1 // settings (file) not found
|
||||
#define SETTINGS_UNABLE_TO_SAVE -2 // unable to save settings
|
||||
#define SETTINGS_DISABLED -3 // load/save settings disabled in settings
|
||||
SettingsManager(std::string app_name, Mode mode);
|
||||
~SettingsManager();
|
||||
|
||||
struct AppSettings {
|
||||
uint32_t baseband_bandwidth;
|
||||
uint32_t channel_bandwidth;
|
||||
uint8_t lna;
|
||||
uint8_t modulation;
|
||||
uint8_t rx_amp;
|
||||
uint32_t rx_frequency;
|
||||
uint32_t sampling_rate;
|
||||
uint8_t tx_amp;
|
||||
uint32_t tx_frequency;
|
||||
uint8_t tx_gain;
|
||||
uint8_t vga;
|
||||
uint32_t step;
|
||||
uint8_t am_config_index;
|
||||
uint8_t nbfm_config_index;
|
||||
uint8_t wfm_config_index;
|
||||
uint8_t squelch;
|
||||
};
|
||||
SettingsManager(const SettingsManager&) = delete;
|
||||
SettingsManager& operator=(const SettingsManager&) = delete;
|
||||
SettingsManager(SettingsManager&&) = delete;
|
||||
SettingsManager& operator=(SettingsManager&&) = delete;
|
||||
|
||||
int load(std::string application, AppSettings* settings);
|
||||
int save(std::string application, AppSettings* settings);
|
||||
/* True if settings were successfully loaded from file. */
|
||||
bool loaded() const { return loaded_; }
|
||||
Mode mode() const { return settings_.mode; }
|
||||
|
||||
AppSettings& raw() { return settings_; }
|
||||
|
||||
private:
|
||||
#define MAX_FILE_CONTENT_SIZE 1000
|
||||
std::string app_name_;
|
||||
AppSettings settings_;
|
||||
bool loaded_;
|
||||
};
|
||||
|
||||
char file_content[MAX_FILE_CONTENT_SIZE] = {};
|
||||
std::string file_path = "";
|
||||
std::string folder = "SETTINGS";
|
||||
int rc = SETTINGS_OK;
|
||||
File settings_file{};
|
||||
long long int setting_value{};
|
||||
|
||||
long long int read_long_long(char* file_content, const char* setting_text);
|
||||
|
||||
}; // class app_settings
|
||||
} // namespace std
|
||||
} // namespace app_settings
|
||||
|
||||
#endif /*__APP_SETTINGS_H__*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue