Skip to content

Commit

Permalink
Fix crash caused by in correct config file
Browse files Browse the repository at this point in the history
  • Loading branch information
floppyhammer committed Jan 14, 2025
1 parent 3afcd30 commit 85bc09a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/gui_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ class GuiInterface {
int channelWidthMode,
const std::string &keyPath,
const std::string &codec) {
// For clearing obsolete entries.
toolkit::mINI::Instance().clear();

// Save config.
toolkit::mINI::Instance()[CONFIG_DEVICE] = vidPid;
toolkit::mINI::Instance()[CONFIG_CHANNEL] = channel;
Expand Down
25 changes: 22 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,6 @@ class MyControlPanel : public Flint::Panel {
hbox_container->add_child(label);

channel_button_ = std::make_shared<Flint::MenuButton>();
channel_button_->set_text(std::to_string(channel));
channel_button_->container_sizing.expand_h = true;
channel_button_->container_sizing.flag_h = Flint::ContainerSizingFlag::Fill;
hbox_container->add_child(channel_button_);
Expand All @@ -432,9 +431,15 @@ class MyControlPanel : public Flint::Panel {
auto callback = [this](uint32_t) { channel = std::stoi(channel_button_->get_selected_item_text()); };
channel_button_->connect_signal("item_selected", callback);

uint32_t selected = 0;
for (auto c : CHANNELS) {
channel_menu.lock()->create_item(std::to_string(c));
if (std::to_string(channel) == std::to_string(c)) {
selected = channel_menu.lock()->get_item_count() - 1;
}
}

channel_button_->select_item(selected);
}
}

Expand All @@ -449,18 +454,28 @@ class MyControlPanel : public Flint::Panel {
channel_width_button_ = std::make_shared<Flint::MenuButton>();
channel_width_button_->container_sizing.expand_h = true;
channel_width_button_->container_sizing.flag_h = Flint::ContainerSizingFlag::Fill;
channel_width_button_->set_text(CHANNEL_WIDTHS[channelWidthMode]);
hbox_container->add_child(channel_width_button_);

{
auto channel_width_menu = channel_width_button_->get_popup_menu();

auto callback = [this](uint32_t) { channelWidthMode = channel_button_->get_selected_item_index(); };
auto callback = [this](uint32_t) {
auto selected = channel_width_button_->get_selected_item_index();
if (selected.has_value()) {
channelWidthMode = selected.value();
}
};
channel_width_button_->connect_signal("item_selected", callback);

uint32_t selected = 0;
for (auto width : CHANNEL_WIDTHS) {
channel_width_menu.lock()->create_item(width);
int current_index = channel_width_menu.lock()->get_item_count() - 1;
if (channelWidthMode == current_index) {
selected = current_index;
}
}
channel_width_button_->select_item(selected);
}
}

Expand Down Expand Up @@ -529,8 +544,12 @@ class MyControlPanel : public Flint::Panel {

int main() {
Flint::App app({1280, 720});
Flint::Logger::set_module_level("Flint", Flint::Logger::Level::Debug);
app.set_window_title("Aviateur - OpenIPC FPV Ground Station");

// Redirect standard ouput to a file
freopen("last_run_log.txt", "w", stdout);

auto hbox_container = std::make_shared<Flint::HBoxContainer>();
hbox_container->set_separation(2);
hbox_container->set_anchor_flag(Flint::AnchorFlag::FullRect);
Expand Down

0 comments on commit 85bc09a

Please sign in to comment.