Skip to content

Commit

Permalink
refactor: define notification duration
Browse files Browse the repository at this point in the history
  • Loading branch information
vtx22 committed Mar 8, 2025
1 parent fec8a9f commit 32aa0a9
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/ConfigHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void ConfigHandler::read_config()
if (!_ini_file.read(ini))
{
std::cerr << "Failed to load config.ini!" << std::endl;
ImGui::InsertNotification({ImGuiToastType::Error, 3000, "Failed to read config.ini!"});
ImGui::InsertNotification({ImGuiToastType::Error, SPARQ_NOTIFY_DURATION_ERR, "Failed to read config.ini!"});
}

std::cout << "Settings:\n";
Expand Down Expand Up @@ -51,7 +51,7 @@ void ConfigHandler::write_config()
if (!_ini_file.write(ini))
{
std::cerr << "Failed to write config.ini!" << std::endl;
ImGui::InsertNotification({ImGuiToastType::Error, 3000, "Failed to write config.ini!"});
ImGui::InsertNotification({ImGuiToastType::Error, SPARQ_NOTIFY_DURATION_ERR, "Failed to write config.ini!"});
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/ConnectionWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,17 @@ void ConnectionWindow::update_content()
{
std::cout << "Port opened successfully!\n";
_port_open = true;
ImGui::InsertNotification({ImGuiToastType::Success, 5000, "COM port opened successfully!"});
ImGui::InsertNotification({ImGuiToastType::Success, SPARQ_NOTIFY_DURATION_OK, "COM port opened successfully!"});
}
else
{
std::cerr << "Failed to open port! Error: " << rtn << "\n";
ImGui::InsertNotification({ImGuiToastType::Error, 5000, "Could not open COM port!"});
ImGui::InsertNotification({ImGuiToastType::Error, SPARQ_NOTIFY_DURATION_ERR, "Could not open COM port!"});
}
}
else
{
ImGui::InsertNotification({ImGuiToastType::Error, 5000, "No COM port selected!"});
ImGui::InsertNotification({ImGuiToastType::Error, SPARQ_NOTIFY_DURATION_ERR, "No COM port selected!"});
}
}
else if (_port_open)
Expand All @@ -170,7 +170,7 @@ void ConnectionWindow::update_content()
std::cout << "Closing COM port ..." << std::endl;

_sp->close();
ImGui::InsertNotification({ImGuiToastType::Success, 5000, "COM port closed successfully!"});
ImGui::InsertNotification({ImGuiToastType::Success, SPARQ_NOTIFY_DURATION_OK, "COM port closed successfully!"});
_port_open = false;
}
else if (!_port_open)
Expand Down
6 changes: 3 additions & 3 deletions src/DataHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ void DataHandler::export_data_csv()
if (_datasets.size() == 0)
{
std::cerr << "No data to export!\n";
ImGui::InsertNotification({ImGuiToastType::Error, 5000, "No data to export!"});
ImGui::InsertNotification({ImGuiToastType::Error, SPARQ_NOTIFY_DURATION_ERR, "No data to export!"});
return;
}

Expand All @@ -369,7 +369,7 @@ void DataHandler::export_data_csv()
if (!file.is_open())
{
std::cerr << "Failed to create csv file!\n";
ImGui::InsertNotification({ImGuiToastType::Error, 5000, "Failed to create export.csv!"});
ImGui::InsertNotification({ImGuiToastType::Error, SPARQ_NOTIFY_DURATION_ERR, "Failed to create export.csv!"});
return;
}

Expand Down Expand Up @@ -410,7 +410,7 @@ void DataHandler::export_data_csv()
file.close();

std::cout << "Export successful!\n";
ImGui::InsertNotification({ImGuiToastType::Success, 5000, "Data exported to export.csv"});
ImGui::InsertNotification({ImGuiToastType::Success, SPARQ_NOTIFY_DURATION_OK, "Data exported to export.csv"});
}

uint8_t DataHandler::xor8_cs(const uint8_t *data, uint32_t length)
Expand Down
2 changes: 1 addition & 1 deletion src/sparq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ int SPARQ::window_init()
else
{
std::cerr << "Failed to load " << SPARQ_ICON_FILE << "!\n";
ImGui::InsertNotification({ImGuiToastType::Error, 3000, "Failed to load icon.png!"});
ImGui::InsertNotification({ImGuiToastType::Error, SPARQ_NOTIFY_DURATION_ERR, "Failed to load icon.png!"});
}

window.setFramerateLimit(SPARQ_MAX_FPS);
Expand Down
2 changes: 2 additions & 0 deletions src/sparq_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@
#define SPARQ_ICON_FILE "./assets/icon.png"

#define SPARQ_RECEIVE_LOOP_DELAY 1ms
#define SPARQ_NOTIFY_DURATION_OK 3000
#define SPARQ_NOTIFY_DURATION_ERR 5000

constexpr bool SPARQ_PLATFORM_LITTLE_ENDIAN = true;

0 comments on commit 32aa0a9

Please sign in to comment.