mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-08-14 21:17:43 +00: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:
@@ -46,7 +46,7 @@ using namespace std;
|
||||
namespace portapack {
|
||||
namespace persistent_memory {
|
||||
|
||||
constexpr rf::Frequency tuned_frequency_reset_value{100000000};
|
||||
constexpr rf::Frequency target_frequency_reset_value{100000000};
|
||||
|
||||
using ppb_range_t = range_t<ppb_t>;
|
||||
constexpr ppb_range_t ppb_range{-99000, 99000};
|
||||
@@ -257,7 +257,7 @@ struct ui_config_t {
|
||||
/* struct must pack the same way on M4 and M0 cores. */
|
||||
struct data_t {
|
||||
data_structure_version_enum structure_version;
|
||||
int64_t tuned_frequency;
|
||||
int64_t target_frequency;
|
||||
int32_t correction_ppb;
|
||||
uint32_t touch_calibration_magic;
|
||||
touch::Calibration touch_calibration;
|
||||
@@ -313,7 +313,7 @@ struct data_t {
|
||||
|
||||
constexpr data_t()
|
||||
: structure_version(data_structure_version_enum::VERSION_CURRENT),
|
||||
tuned_frequency(tuned_frequency_reset_value),
|
||||
target_frequency(target_frequency_reset_value),
|
||||
correction_ppb(ppb_reset_value),
|
||||
touch_calibration_magic(TOUCH_CALIBRATION_MAGIC),
|
||||
touch_calibration(touch::Calibration()),
|
||||
@@ -471,13 +471,13 @@ void persist() {
|
||||
|
||||
} /* namespace cache */
|
||||
|
||||
rf::Frequency tuned_frequency() {
|
||||
rf::tuning_range.reset_if_outside(data->tuned_frequency, tuned_frequency_reset_value);
|
||||
return data->tuned_frequency;
|
||||
rf::Frequency target_frequency() {
|
||||
rf::tuning_range.reset_if_outside(data->target_frequency, target_frequency_reset_value);
|
||||
return data->target_frequency;
|
||||
}
|
||||
|
||||
void set_tuned_frequency(const rf::Frequency new_value) {
|
||||
data->tuned_frequency = rf::tuning_range.clip(new_value);
|
||||
void set_target_frequency(const rf::Frequency new_value) {
|
||||
data->target_frequency = rf::tuning_range.clip(new_value);
|
||||
}
|
||||
|
||||
volume_t headphone_volume() {
|
||||
|
@@ -130,8 +130,8 @@ void persist();
|
||||
|
||||
using ppb_t = int32_t;
|
||||
|
||||
rf::Frequency tuned_frequency();
|
||||
void set_tuned_frequency(const rf::Frequency new_value);
|
||||
rf::Frequency target_frequency();
|
||||
void set_target_frequency(const rf::Frequency new_value);
|
||||
|
||||
volume_t headphone_volume();
|
||||
void set_headphone_volume(volume_t new_value);
|
||||
|
84
firmware/common/result.hpp
Normal file
84
firmware/common/result.hpp
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Kyle Reed
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2016 Furrtek
|
||||
*
|
||||
* 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 <utility>
|
||||
|
||||
template <typename TValue, typename TError>
|
||||
struct Result {
|
||||
enum class Type {
|
||||
Success,
|
||||
Error,
|
||||
} type;
|
||||
|
||||
union {
|
||||
TValue value_;
|
||||
TError error_;
|
||||
};
|
||||
|
||||
bool is_ok() const {
|
||||
return type == Type::Success;
|
||||
}
|
||||
|
||||
operator bool() const {
|
||||
return is_ok();
|
||||
}
|
||||
|
||||
bool is_error() const {
|
||||
return type == Type::Error;
|
||||
}
|
||||
|
||||
const TValue& value() const& {
|
||||
return value_;
|
||||
}
|
||||
|
||||
const TValue& operator*() const& {
|
||||
return value_;
|
||||
}
|
||||
|
||||
TValue&& operator*() && {
|
||||
return std::move(value_);
|
||||
}
|
||||
|
||||
const TError& error() const& {
|
||||
return error_;
|
||||
}
|
||||
|
||||
Result() = delete;
|
||||
|
||||
constexpr Result(TValue&& value)
|
||||
: type{Type::Success},
|
||||
value_{std::forward<TValue>(value)} {
|
||||
}
|
||||
|
||||
constexpr Result(TError error)
|
||||
: type{Type::Error},
|
||||
error_{error} {
|
||||
}
|
||||
|
||||
~Result() {
|
||||
if (is_ok())
|
||||
value_.~TValue();
|
||||
else
|
||||
error_.~TError();
|
||||
}
|
||||
};
|
@@ -1362,14 +1362,21 @@ void ImageOptionsField::set_by_value(value_t v) {
|
||||
for (const auto& option : options) {
|
||||
if (option.second == v) {
|
||||
set_selected_index(new_index);
|
||||
break;
|
||||
return;
|
||||
}
|
||||
|
||||
new_index++;
|
||||
}
|
||||
|
||||
// No exact match was found, default to 0.
|
||||
set_selected_index(0);
|
||||
}
|
||||
|
||||
void ImageOptionsField::set_options(options_t new_options) {
|
||||
options = new_options;
|
||||
|
||||
// Set an invalid index to force on_change.
|
||||
selected_index_ = (size_t)-1;
|
||||
set_by_value(0);
|
||||
set_dirty();
|
||||
}
|
||||
@@ -1440,19 +1447,25 @@ void OptionsField::set_selected_index(const size_t new_index, bool trigger_chang
|
||||
}
|
||||
|
||||
void OptionsField::set_by_value(value_t v) {
|
||||
size_t new_index{0};
|
||||
size_t new_index = 0;
|
||||
for (const auto& option : options) {
|
||||
if (option.second == v) {
|
||||
set_selected_index(new_index);
|
||||
break;
|
||||
return;
|
||||
}
|
||||
new_index++;
|
||||
}
|
||||
|
||||
// No exact match was found, default to 0.
|
||||
set_selected_index(0);
|
||||
}
|
||||
|
||||
void OptionsField::set_options(options_t new_options) {
|
||||
options = new_options;
|
||||
set_by_value(0);
|
||||
|
||||
// Set an invalid index to force on_change.
|
||||
selected_index_ = (size_t)-1;
|
||||
set_selected_index(0);
|
||||
set_dirty();
|
||||
}
|
||||
|
||||
|
@@ -94,6 +94,14 @@ int fast_int_magnitude(int y, int x);
|
||||
int int_atan2(int y, int x);
|
||||
int32_t int16_sin_s4(int32_t x);
|
||||
|
||||
template <typename TEnum>
|
||||
bool flags_enabled(TEnum value, TEnum flags) {
|
||||
auto i_value = static_cast<std::underlying_type_t<TEnum>>(value);
|
||||
auto i_flags = static_cast<std::underlying_type_t<TEnum>>(flags);
|
||||
|
||||
return (i_value & i_flags) == i_flags;
|
||||
}
|
||||
|
||||
/* Returns value constrained to min and max. */
|
||||
template <class T>
|
||||
constexpr const T& clip(const T& value, const T& minimum, const T& maximum) {
|
||||
|
Reference in New Issue
Block a user