mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-08-14 11:38:12 +00:00
Stash radio settings per app (#1151)
* add a little Stash utility. * add radio state RAII helper. * first part of radio_state changes * add radio_state_ to rest of apps * fix freq_step and format * fix unused ui_sigfrx: corrected sample rate, added back freq setting
This commit is contained in:
@@ -126,6 +126,22 @@ constexpr const T& clip(const T& value, const T& minimum, const T& maximum) {
|
||||
return std::max(std::min(value, maximum), minimum);
|
||||
}
|
||||
|
||||
/* Saves state on construction and reverts it when destroyed. */
|
||||
template <typename T>
|
||||
struct Stash {
|
||||
Stash(T& target)
|
||||
: target_{target}, prev_{target} {
|
||||
}
|
||||
|
||||
~Stash() {
|
||||
target_ = std::move(prev_);
|
||||
}
|
||||
|
||||
private:
|
||||
T& target_;
|
||||
T prev_;
|
||||
};
|
||||
|
||||
// TODO: need to decide if this is inclusive or exclusive.
|
||||
// The implementations are different and cause the subtle
|
||||
// bugs mentioned below.
|
||||
|
Reference in New Issue
Block a user