mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2024-12-04 23:45:26 +00:00
fixed memory usage (#2380)
* fixed memory usage in ui_about_simple * fixed memory usage in freqman_db * fixed memory usage in tone_key
This commit is contained in:
parent
fc08d4ead9
commit
b108d975c0
@ -1,5 +1,7 @@
|
|||||||
#include "ui_about_simple.hpp"
|
#include "ui_about_simple.hpp"
|
||||||
|
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
#define ROLL_SPEED_FRAME_PER_LINE 60
|
#define ROLL_SPEED_FRAME_PER_LINE 60
|
||||||
// cuz frame rate of pp screen is probably 60, scroll per sec
|
// cuz frame rate of pp screen is probably 60, scroll per sec
|
||||||
|
|
||||||
@ -7,7 +9,7 @@ namespace ui {
|
|||||||
|
|
||||||
// TODO: Generate this automatically from github
|
// TODO: Generate this automatically from github
|
||||||
// Information: a line starting with a '#' will be yellow coloured
|
// Information: a line starting with a '#' will be yellow coloured
|
||||||
const std::string authors_list[] = {
|
constexpr std::string_view authors_list[] = {
|
||||||
"# * List of contributors * ",
|
"# * List of contributors * ",
|
||||||
" ",
|
" ",
|
||||||
"#Mayhem:",
|
"#Mayhem:",
|
||||||
@ -70,18 +72,18 @@ AboutView::AboutView(NavigationView& nav) {
|
|||||||
button_ok.focus();
|
button_ok.focus();
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const std::string& authors_line : authors_list) {
|
for (auto& authors_line : authors_list) {
|
||||||
// if it's starting with #, it's a title and we have to substract the '#' and paint yellow
|
// if it's starting with #, it's a title and we have to substract the '#' and paint yellow
|
||||||
if (authors_line.size() > 0) {
|
if (authors_line.size() > 0) {
|
||||||
if (authors_line[0] == '#') {
|
if (authors_line[0] == '#') {
|
||||||
menu_view.add_item(
|
menu_view.add_item(
|
||||||
{authors_line.substr(1, authors_line.size() - 1),
|
{(std::string)authors_line.substr(1, authors_line.size() - 1),
|
||||||
ui::Theme::getInstance()->fg_yellow->foreground,
|
ui::Theme::getInstance()->fg_yellow->foreground,
|
||||||
nullptr,
|
nullptr,
|
||||||
nullptr});
|
nullptr});
|
||||||
} else {
|
} else {
|
||||||
menu_view.add_item(
|
menu_view.add_item(
|
||||||
{authors_line,
|
{(std::string)authors_line,
|
||||||
Theme::getInstance()->bg_darkest->foreground,
|
Theme::getInstance()->bg_darkest->foreground,
|
||||||
nullptr,
|
nullptr,
|
||||||
nullptr});
|
nullptr});
|
||||||
|
@ -40,27 +40,39 @@ namespace fs = std::filesystem;
|
|||||||
|
|
||||||
// TODO: Clean up after moving to better lookup tables.
|
// TODO: Clean up after moving to better lookup tables.
|
||||||
using options_t = OptionsField::options_t;
|
using options_t = OptionsField::options_t;
|
||||||
extern options_t freqman_modulations;
|
|
||||||
extern options_t freqman_bandwidths[4];
|
using option_db_t = std::pair<std::string_view, int32_t>;
|
||||||
extern options_t freqman_steps;
|
using options_db_t = std::vector<option_db_t>;
|
||||||
extern options_t freqman_steps_short;
|
|
||||||
|
extern options_db_t freqman_modulations;
|
||||||
|
extern options_db_t freqman_bandwidths[4];
|
||||||
|
extern options_db_t freqman_steps;
|
||||||
|
extern options_db_t freqman_steps_short;
|
||||||
|
|
||||||
|
options_t dboptions_to_options(const options_db_t& dboptions) {
|
||||||
|
options_t options;
|
||||||
|
for (const auto& dboption : dboptions) {
|
||||||
|
options.emplace_back(dboption.first, dboption.second);
|
||||||
|
}
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
/* Set options. */
|
/* Set options. */
|
||||||
void freqman_set_modulation_option(OptionsField& option) {
|
void freqman_set_modulation_option(OptionsField& option) {
|
||||||
option.set_options(freqman_modulations);
|
option.set_options(dboptions_to_options(freqman_modulations));
|
||||||
}
|
}
|
||||||
|
|
||||||
void freqman_set_bandwidth_option(freqman_index_t modulation, OptionsField& option) {
|
void freqman_set_bandwidth_option(freqman_index_t modulation, OptionsField& option) {
|
||||||
if (is_valid(modulation))
|
if (is_valid(modulation))
|
||||||
option.set_options(freqman_bandwidths[modulation]);
|
option.set_options(dboptions_to_options(freqman_bandwidths[modulation]));
|
||||||
}
|
}
|
||||||
|
|
||||||
void freqman_set_step_option(OptionsField& option) {
|
void freqman_set_step_option(OptionsField& option) {
|
||||||
option.set_options(freqman_steps);
|
option.set_options(dboptions_to_options(freqman_steps));
|
||||||
}
|
}
|
||||||
|
|
||||||
void freqman_set_step_option_short(OptionsField& option) {
|
void freqman_set_step_option_short(OptionsField& option) {
|
||||||
option.set_options(freqman_steps_short);
|
option.set_options(dboptions_to_options(freqman_steps_short));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
@ -438,7 +450,7 @@ void FrequencyEditView::populate_bandwidth_options() {
|
|||||||
auto& bandwidths = freqman_bandwidths[entry_.modulation];
|
auto& bandwidths = freqman_bandwidths[entry_.modulation];
|
||||||
for (auto i = 0u; i < bandwidths.size(); ++i) {
|
for (auto i = 0u; i < bandwidths.size(); ++i) {
|
||||||
auto& item = bandwidths[i];
|
auto& item = bandwidths[i];
|
||||||
options.push_back({item.first, (OptionsField::value_t)i});
|
options.push_back({(std::string)item.first, (OptionsField::value_t)i});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -451,7 +463,7 @@ void FrequencyEditView::populate_step_options() {
|
|||||||
|
|
||||||
for (auto i = 0u; i < freqman_steps.size(); ++i) {
|
for (auto i = 0u; i < freqman_steps.size(); ++i) {
|
||||||
auto& item = freqman_steps[i];
|
auto& item = freqman_steps[i];
|
||||||
options.push_back({item.first, (OptionsField::value_t)i});
|
options.push_back({(std::string)item.first, (OptionsField::value_t)i});
|
||||||
}
|
}
|
||||||
|
|
||||||
field_step.set_options(std::move(options));
|
field_step.set_options(std::move(options));
|
||||||
|
@ -28,8 +28,11 @@
|
|||||||
using option_t = ui::OptionsField::option_t;
|
using option_t = ui::OptionsField::option_t;
|
||||||
using options_t = ui::OptionsField::options_t;
|
using options_t = ui::OptionsField::options_t;
|
||||||
|
|
||||||
extern options_t freqman_steps;
|
using option_db_t = std::pair<std::string_view, int32_t>;
|
||||||
extern const option_t* find_by_index(const options_t& options, freqman_index_t index);
|
using options_db_t = std::vector<option_db_t>;
|
||||||
|
|
||||||
|
extern options_db_t freqman_steps;
|
||||||
|
extern const option_db_t* find_by_index(const options_db_t& options, freqman_index_t index);
|
||||||
|
|
||||||
/* Option value lookup. */
|
/* Option value lookup. */
|
||||||
int32_t freqman_entry_get_step_value(freqman_index_t step) {
|
int32_t freqman_entry_get_step_value(freqman_index_t step) {
|
||||||
|
@ -41,7 +41,7 @@ namespace fs = std::filesystem;
|
|||||||
const std::filesystem::path freqman_extension{u".TXT"};
|
const std::filesystem::path freqman_extension{u".TXT"};
|
||||||
|
|
||||||
// NB: Don't include UI headers to keep this code unit testable.
|
// NB: Don't include UI headers to keep this code unit testable.
|
||||||
using option_t = std::pair<std::string, int32_t>;
|
using option_t = std::pair<std::string_view, int32_t>;
|
||||||
using options_t = std::vector<option_t>;
|
using options_t = std::vector<option_t>;
|
||||||
|
|
||||||
options_t freqman_modulations = {
|
options_t freqman_modulations = {
|
||||||
@ -194,27 +194,27 @@ bool operator==(const freqman_entry& lhs, const freqman_entry& rhs) {
|
|||||||
|
|
||||||
std::string freqman_entry_get_modulation_string(freqman_index_t modulation) {
|
std::string freqman_entry_get_modulation_string(freqman_index_t modulation) {
|
||||||
if (auto opt = find_by_index(freqman_modulations, modulation))
|
if (auto opt = find_by_index(freqman_modulations, modulation))
|
||||||
return opt->first;
|
return (std::string)opt->first;
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string freqman_entry_get_bandwidth_string(freqman_index_t modulation, freqman_index_t bandwidth) {
|
std::string freqman_entry_get_bandwidth_string(freqman_index_t modulation, freqman_index_t bandwidth) {
|
||||||
if (modulation < freqman_modulations.size()) {
|
if (modulation < freqman_modulations.size()) {
|
||||||
if (auto opt = find_by_index(freqman_bandwidths[modulation], bandwidth))
|
if (auto opt = find_by_index(freqman_bandwidths[modulation], bandwidth))
|
||||||
return opt->first;
|
return (std::string)opt->first;
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string freqman_entry_get_step_string(freqman_index_t step) {
|
std::string freqman_entry_get_step_string(freqman_index_t step) {
|
||||||
if (auto opt = find_by_index(freqman_steps, step))
|
if (auto opt = find_by_index(freqman_steps, step))
|
||||||
return opt->first;
|
return (std::string)opt->first;
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string freqman_entry_get_step_string_short(freqman_index_t step) {
|
std::string freqman_entry_get_step_string_short(freqman_index_t step) {
|
||||||
if (auto opt = find_by_index(freqman_steps_short, step))
|
if (auto opt = find_by_index(freqman_steps_short, step))
|
||||||
return opt->first;
|
return (std::string)opt->first;
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ float tone_key_frequency(tone_index index) {
|
|||||||
std::string tone_key_string(tone_index index) {
|
std::string tone_key_string(tone_index index) {
|
||||||
if (index < 0 || (unsigned)index >= tone_keys.size())
|
if (index < 0 || (unsigned)index >= tone_keys.size())
|
||||||
return std::string("");
|
return std::string("");
|
||||||
return tone_keys[index].first;
|
return (std::string)tone_keys[index].first;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return string showing frequency only from specific table index
|
// Return string showing frequency only from specific table index
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace tonekey {
|
namespace tonekey {
|
||||||
@ -35,7 +36,7 @@ namespace tonekey {
|
|||||||
#define F2Ix100(x) (int32_t)(x * 100.0 + 0.5) // add 0.5f to round vs truncate during FP->int conversion
|
#define F2Ix100(x) (int32_t)(x * 100.0 + 0.5) // add 0.5f to round vs truncate during FP->int conversion
|
||||||
|
|
||||||
using tone_index = int32_t;
|
using tone_index = int32_t;
|
||||||
using tone_key_t = std::vector<std::pair<std::string, uint32_t>>;
|
using tone_key_t = std::vector<std::pair<std::string_view, uint32_t>>;
|
||||||
|
|
||||||
extern const tone_key_t tone_keys;
|
extern const tone_key_t tone_keys;
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ void tone_keys_populate(OptionsField& field) {
|
|||||||
for (size_t c = 0; c < tone_keys.size(); c++) {
|
for (size_t c = 0; c < tone_keys.size(); c++) {
|
||||||
auto f = tone_keys[c].second;
|
auto f = tone_keys[c].second;
|
||||||
if ((c != 0) && (f < 1000 * 100))
|
if ((c != 0) && (f < 1000 * 100))
|
||||||
tone_name = "CTCSS " + fx100_string(f) + " #" + tone_keys[c].first;
|
tone_name = "CTCSS " + fx100_string(f) + " #" + (std::string)tone_keys[c].first;
|
||||||
else
|
else
|
||||||
tone_name = tone_keys[c].first;
|
tone_name = tone_keys[c].first;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user