mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-08-14 01:15:38 -04:00
Capped max entries per Freqman file to 30 due to RAM issue
Capped max files in Soundboard to 54 and removed CTCSS options due to same issue Splitted files for jammer ranges Bugfix: Mismatch between filename and category name in Freqman Bugfix: Freqman file parsing strstr()'s might have gone out of buffer Updated binary
This commit is contained in:
parent
2d01822cdb
commit
70c7646743
11 changed files with 134 additions and 57 deletions
|
@ -43,25 +43,27 @@ bool load_freqman_file(std::string& file_stem, freqman_db &db) {
|
|||
char * line_end;
|
||||
std::string description;
|
||||
rf::Frequency frequency_a, frequency_b;
|
||||
char file_data[256];
|
||||
char file_data[257];
|
||||
freqman_entry_type type;
|
||||
|
||||
db.entries.clear();
|
||||
db.clear();
|
||||
|
||||
auto result = freqman_file.open("FREQMAN/" + file_stem + ".TXT");
|
||||
if (result.is_valid())
|
||||
return false;
|
||||
|
||||
while (1) {
|
||||
// Read a 256 bytes block from file
|
||||
freqman_file.seek(file_position);
|
||||
|
||||
memset(file_data, 0, 256);
|
||||
memset(file_data, 0, 257);
|
||||
auto read_size = freqman_file.read(file_data, 256);
|
||||
if (read_size.is_error())
|
||||
return false; // Read error
|
||||
|
||||
file_position += sizeof(file_data);
|
||||
file_position += 256;
|
||||
|
||||
// Reset line_start to beginning of buffer
|
||||
line_start = file_data;
|
||||
|
||||
if (!strstr(file_data, "f=") && !strstr(file_data, "a="))
|
||||
|
@ -102,18 +104,20 @@ bool load_freqman_file(std::string& file_stem, freqman_db &db) {
|
|||
} else
|
||||
description = "-";
|
||||
|
||||
db.entries.push_back({ frequency_a, frequency_b, description, type });
|
||||
db.push_back({ frequency_a, frequency_b, description, type });
|
||||
n++;
|
||||
|
||||
if (n >= FREQMAN_MAX_PER_FILE) return true;
|
||||
|
||||
line_start = line_end + 1;
|
||||
if (line_start - file_data >= 256) break;
|
||||
}
|
||||
|
||||
if (read_size.value() != sizeof(file_data))
|
||||
return true; // End of file
|
||||
if (read_size.value() != 256)
|
||||
break; // End of file
|
||||
|
||||
file_position -= (file_data + sizeof(file_data) - line_start);
|
||||
// Restart at beginning of last incomplete line
|
||||
file_position -= (file_data + 256 - line_start);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -127,8 +131,8 @@ bool save_freqman_file(std::string& file_stem, freqman_db &db) {
|
|||
if (!create_freqman_file(file_stem, freqman_file))
|
||||
return false;
|
||||
|
||||
for (size_t n = 0; n < db.entries.size(); n++) {
|
||||
auto& entry = db.entries[n];
|
||||
for (size_t n = 0; n < db.size(); n++) {
|
||||
auto& entry = db[n];
|
||||
|
||||
frequency_a = entry.frequency_a;
|
||||
|
||||
|
|
|
@ -30,8 +30,8 @@
|
|||
#define __FREQMAN_H__
|
||||
|
||||
#define FREQMAN_DESC_MAX_LEN 30
|
||||
#define FREQMAN_MAX_PER_FILE 50
|
||||
#define FREQMAN_MAX_PER_FILE_STR "50"
|
||||
#define FREQMAN_MAX_PER_FILE 30
|
||||
#define FREQMAN_MAX_PER_FILE_STR "30"
|
||||
|
||||
using namespace ui;
|
||||
using namespace std;
|
||||
|
@ -55,9 +55,7 @@ struct freqman_entry {
|
|||
freqman_entry_type type { };
|
||||
};
|
||||
|
||||
struct freqman_db {
|
||||
std::vector<freqman_entry> entries;
|
||||
};
|
||||
using freqman_db = std::vector<freqman_entry>;
|
||||
|
||||
std::vector<std::string> get_freqman_files();
|
||||
bool load_freqman_file(std::string& file_stem, freqman_db &db);
|
||||
|
|
|
@ -82,7 +82,7 @@ void FreqManBaseView::populate_categories() {
|
|||
options_category.set_options(categories);
|
||||
options_category.set_selected_index(0);
|
||||
|
||||
options_category.on_change = [this](size_t, int32_t category_id) {
|
||||
options_category.on_change = [this](size_t category_id, int32_t) {
|
||||
if (on_change_category)
|
||||
on_change_category(category_id);
|
||||
};
|
||||
|
@ -94,14 +94,14 @@ void FreqManBaseView::change_category(int32_t category_id) {
|
|||
|
||||
current_category_id = category_id;
|
||||
|
||||
if (!load_freqman_file(file_list[current_category_id], database))
|
||||
if (!load_freqman_file(file_list[categories[current_category_id].second], database))
|
||||
error_ = ERROR_ACCESS;
|
||||
else
|
||||
refresh_list();
|
||||
}
|
||||
|
||||
void FreqManBaseView::refresh_list() {
|
||||
if (!database.entries.size()) {
|
||||
if (!database.size()) {
|
||||
if (on_refresh_widgets)
|
||||
on_refresh_widgets(true);
|
||||
} else {
|
||||
|
@ -110,9 +110,9 @@ void FreqManBaseView::refresh_list() {
|
|||
|
||||
menu_view.clear();
|
||||
|
||||
for (size_t n = 0; n < database.entries.size(); n++) {
|
||||
for (size_t n = 0; n < database.size(); n++) {
|
||||
menu_view.add_item({
|
||||
freqman_item_string(database.entries[n], 26),
|
||||
freqman_item_string(database[n], 26),
|
||||
ui::Color::white(),
|
||||
nullptr,
|
||||
[this](){
|
||||
|
@ -127,33 +127,33 @@ void FreqManBaseView::refresh_list() {
|
|||
}
|
||||
|
||||
void FrequencySaveView::save_current_file() {
|
||||
if (database.entries.size() > FREQMAN_MAX_PER_FILE) {
|
||||
if (database.size() > FREQMAN_MAX_PER_FILE) {
|
||||
nav_.display_modal(
|
||||
"Error", "Too many entries, maximum is\n" FREQMAN_MAX_PER_FILE_STR ". Trim list ?",
|
||||
YESNO,
|
||||
[this](bool choice) {
|
||||
if (choice) {
|
||||
database.entries.resize(FREQMAN_MAX_PER_FILE);
|
||||
save_freqman_file(file_list[current_category_id], database);
|
||||
database.resize(FREQMAN_MAX_PER_FILE);
|
||||
save_freqman_file(file_list[categories[current_category_id].second], database);
|
||||
}
|
||||
nav_.pop();
|
||||
}
|
||||
);
|
||||
} else {
|
||||
save_freqman_file(file_list[current_category_id], database);
|
||||
save_freqman_file(file_list[categories[current_category_id].second], database);
|
||||
nav_.pop();
|
||||
}
|
||||
}
|
||||
|
||||
void FrequencySaveView::on_save_name() {
|
||||
text_prompt(nav_, &desc_buffer, 28, [this](std::string * buffer) {
|
||||
database.entries.push_back({ value_, 0, *buffer, SINGLE });
|
||||
database.push_back({ value_, 0, *buffer, SINGLE });
|
||||
save_current_file();
|
||||
});
|
||||
}
|
||||
|
||||
void FrequencySaveView::on_save_timestamp() {
|
||||
database.entries.push_back({ value_, 0, live_timestamp.string(), SINGLE });
|
||||
database.push_back({ value_, 0, live_timestamp.string(), SINGLE });
|
||||
save_current_file();
|
||||
}
|
||||
|
||||
|
@ -166,8 +166,8 @@ FrequencySaveView::FrequencySaveView(
|
|||
desc_buffer.reserve(28);
|
||||
|
||||
// Todo: add back ?
|
||||
/*for (size_t n = 0; n < database.entries.size(); n++) {
|
||||
if (database.entries[n].value == value_) {
|
||||
/*for (size_t n = 0; n < database.size(); n++) {
|
||||
if (database[n].value == value_) {
|
||||
error_ = ERROR_DUPLICATE;
|
||||
break;
|
||||
}
|
||||
|
@ -225,7 +225,7 @@ FrequencyLoadView::FrequencyLoadView(
|
|||
on_select_frequency = [&nav, this]() {
|
||||
nav_.pop();
|
||||
|
||||
auto& entry = database.entries[menu_view.highlighted()];
|
||||
auto& entry = database[menu_view.highlighted_index()];
|
||||
|
||||
if (entry.type == RANGE) {
|
||||
// User chose a frequency range entry
|
||||
|
@ -243,16 +243,16 @@ FrequencyLoadView::FrequencyLoadView(
|
|||
}
|
||||
|
||||
void FrequencyManagerView::on_edit_freq(rf::Frequency f) {
|
||||
database.entries[menu_view.highlighted()].frequency_a = f;
|
||||
save_freqman_file(file_list[current_category_id], database);
|
||||
database[menu_view.highlighted_index()].frequency_a = f;
|
||||
save_freqman_file(file_list[categories[current_category_id].second], database);
|
||||
refresh_list();
|
||||
}
|
||||
|
||||
void FrequencyManagerView::on_edit_desc(NavigationView& nav) {
|
||||
text_prompt(nav, &desc_buffer, 28, [this](std::string * buffer) {
|
||||
database.entries[menu_view.highlighted()].description = *buffer;
|
||||
database[menu_view.highlighted_index()].description = *buffer;
|
||||
refresh_list();
|
||||
save_freqman_file(file_list[current_category_id], database);
|
||||
save_freqman_file(file_list[categories[current_category_id].second], database);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -266,8 +266,8 @@ void FrequencyManagerView::on_new_category(NavigationView& nav) {
|
|||
}
|
||||
|
||||
void FrequencyManagerView::on_delete() {
|
||||
database.entries.erase(database.entries.begin() + menu_view.highlighted());
|
||||
save_freqman_file(file_list[current_category_id], database);
|
||||
database.erase(database.begin() + menu_view.highlighted_index());
|
||||
save_freqman_file(file_list[categories[current_category_id].second], database);
|
||||
refresh_list();
|
||||
}
|
||||
|
||||
|
@ -282,7 +282,7 @@ void FrequencyManagerView::refresh_widgets(const bool v) {
|
|||
}
|
||||
|
||||
FrequencyManagerView::~FrequencyManagerView() {
|
||||
//save_freqman_file(file_list[current_category_id], database);
|
||||
//save_freqman_file(file_list[categories[current_category_id].second], database);
|
||||
}
|
||||
|
||||
FrequencyManagerView::FrequencyManagerView(
|
||||
|
@ -321,14 +321,14 @@ FrequencyManagerView::FrequencyManagerView(
|
|||
};
|
||||
|
||||
button_edit_freq.on_select = [this, &nav](Button&) {
|
||||
auto new_view = nav.push<FrequencyKeypadView>(database.entries[menu_view.highlighted()].frequency_a);
|
||||
auto new_view = nav.push<FrequencyKeypadView>(database[menu_view.highlighted_index()].frequency_a);
|
||||
new_view->on_changed = [this](rf::Frequency f) {
|
||||
on_edit_freq(f);
|
||||
};
|
||||
};
|
||||
|
||||
button_edit_desc.on_select = [this, &nav](Button&) {
|
||||
desc_buffer = database.entries[menu_view.highlighted()].description;
|
||||
desc_buffer = database[menu_view.highlighted_index()].description;
|
||||
on_edit_desc(nav);
|
||||
};
|
||||
|
||||
|
|
|
@ -119,7 +119,7 @@ void SoundBoardView::play_sound(uint16_t id) {
|
|||
transmitter_model.set_baseband_bandwidth(1750000);
|
||||
transmitter_model.enable();
|
||||
|
||||
tone_key_index = options_tone_key.selected_index();
|
||||
tone_key_index = 0; //options_tone_key.selected_index();
|
||||
|
||||
divider = (1536000 / sounds[id].sample_rate) - 1;
|
||||
|
||||
|
@ -164,19 +164,22 @@ void SoundBoardView::refresh_buttons(uint16_t id) {
|
|||
show_infos(id);
|
||||
}
|
||||
|
||||
void SoundBoardView::change_page(Button& button, const KeyEvent key) {
|
||||
bool SoundBoardView::change_page(Button& button, const KeyEvent key) {
|
||||
// Stupid way to find out if the button is on the sides
|
||||
if (button.screen_pos().x() < 32) {
|
||||
if ((key == KeyEvent::Left) && (page > 0)) {
|
||||
page--;
|
||||
refresh_buttons(button.id);
|
||||
return true;
|
||||
}
|
||||
} else if (button.screen_pos().x() > 120) {
|
||||
if ((key == KeyEvent::Right) && (page < max_page - 1)) {
|
||||
page++;
|
||||
refresh_buttons(button.id);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
SoundBoardView::SoundBoardView(
|
||||
|
@ -210,7 +213,7 @@ SoundBoardView::SoundBoardView(
|
|||
else
|
||||
sounds[c].title = "-";
|
||||
c++;
|
||||
if (c == 108) break; // Limit to 108 files (6 pages)
|
||||
if (c == 54) break; // Limit to 54 files (3 pages)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -221,10 +224,10 @@ SoundBoardView::SoundBoardView(
|
|||
max_page = (max_sound + 18 - 1) / 18; // 3 * 6 = 18 buttons per page
|
||||
|
||||
add_children({
|
||||
&labels,
|
||||
&field_frequency,
|
||||
&number_bw,
|
||||
&text_kHz,
|
||||
&options_tone_key,
|
||||
//&options_tone_key,
|
||||
&text_title,
|
||||
&text_page,
|
||||
&text_duration,
|
||||
|
@ -234,8 +237,8 @@ SoundBoardView::SoundBoardView(
|
|||
&button_exit
|
||||
});
|
||||
|
||||
tone_keys_populate(options_tone_key);
|
||||
options_tone_key.set_selected_index(0);
|
||||
//tone_keys_populate(options_tone_key);
|
||||
//options_tone_key.set_selected_index(0);
|
||||
|
||||
const auto button_fn = [this](Button& button) {
|
||||
tx_mode = NORMAL;
|
||||
|
@ -247,8 +250,7 @@ SoundBoardView::SoundBoardView(
|
|||
};
|
||||
|
||||
const auto button_dir = [this](Button& button, const KeyEvent key) {
|
||||
this->change_page(button, key);
|
||||
return false;
|
||||
return change_page(button, key);
|
||||
};
|
||||
|
||||
// Generate buttons
|
||||
|
|
|
@ -75,7 +75,7 @@ private:
|
|||
|
||||
std::unique_ptr<WAVFileReader> reader { };
|
||||
|
||||
sound sounds[108]; // 6 pages * 18 buttons
|
||||
sound sounds[54]; // 3 pages * 18 buttons
|
||||
uint32_t max_sound { };
|
||||
uint8_t max_page { };
|
||||
|
||||
|
@ -109,29 +109,28 @@ private:
|
|||
|
||||
void do_random();
|
||||
void show_infos(uint16_t id);
|
||||
void change_page(Button& button, const KeyEvent key);
|
||||
bool change_page(Button& button, const KeyEvent key);
|
||||
void refresh_buttons(uint16_t id);
|
||||
void play_sound(uint16_t id);
|
||||
void prepare_audio();
|
||||
void on_ctcss_changed(uint32_t v);
|
||||
|
||||
Labels labels {
|
||||
{ { 10 * 8, 4 }, "BW: kHz", Color::light_grey() }
|
||||
};
|
||||
|
||||
FrequencyField field_frequency {
|
||||
{ 0, 4 },
|
||||
};
|
||||
|
||||
NumberField number_bw {
|
||||
{ 10 * 8, 4 },
|
||||
{ 13 * 8, 4 },
|
||||
3,
|
||||
{1, 150},
|
||||
{ 1, 150 },
|
||||
1,
|
||||
' '
|
||||
};
|
||||
|
||||
Text text_kHz {
|
||||
{ 13 * 8, 4, 8 * 8, 16 },
|
||||
"k CTCSS:"
|
||||
};
|
||||
|
||||
OptionsField options_tone_key {
|
||||
{ 21 * 8, 4 },
|
||||
8,
|
||||
|
@ -153,7 +152,7 @@ private:
|
|||
};
|
||||
|
||||
ProgressBar pbar {
|
||||
{ 9 * 8, 30 * 8, 19 * 8, 16 }
|
||||
{ 9 * 8, 30 * 8, 20 * 8, 16 }
|
||||
};
|
||||
|
||||
Checkbox check_loop {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue