Skip to content

Commit

Permalink
feat: debug printing to console for init and some state changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vtx22 committed Mar 8, 2025
1 parent 6ab9402 commit fec8a9f
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 8 deletions.
26 changes: 25 additions & 1 deletion src/ConfigHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,40 @@ ConfigHandler::ConfigHandler()

void ConfigHandler::read_config()
{
std::cout << std::endl;

std::cout << "Loading " << SPARQ_CONFIG_FILE << " ..." << std::endl;

mINI::INIFile _ini_file(SPARQ_CONFIG_FILE);
if (!_ini_file.read(ini))
{
std::cerr << "Failed to read config.ini!" << std::endl;
std::cerr << "Failed to load config.ini!" << std::endl;
ImGui::InsertNotification({ImGuiToastType::Error, 3000, "Failed to read config.ini!"});
}

std::cout << "Settings:\n";
std::cout << "Graphics Settings:\n";
std::cout << " Antialiasing: " << std::stoi(ini["graphics"]["antialiasing"]) << "\n";
std::cout << " VSync: " << ((ini["graphics"]["vsync"] == "1") ? "Enabled" : "Disabled") << "\n";
std::cout << " FPS Limit: " << SPARQ_MAX_FPS << "\n";

std::cout << "Downsampling Settings:\n";
std::cout << " Enabled: " << ((ini["downsampling"]["enabled"] == "1") ? "True" : "False") << "\n";
std::cout << " Mode: " << std::stoi(ini["downsampling"]["mode"]) << "\n";
std::cout << " Max Samples: " << std::stoi(ini["downsampling"]["max_samples"]) << "\n";
std::cout << " Max Samples Type: " << std::stoi(ini["downsampling"]["max_samples_type"]) << "\n";

std::cout << "Color Settings:\n";
auto cm = (ImPlotColormap)std::stoi(ini["color"]["colormap"]);
std::cout << " Colormap: " << cm << "\n";

std::cout << std::endl;
}

void ConfigHandler::write_config()
{
std::cout << "Writing " << SPARQ_CONFIG_FILE << " ..." << std::endl;

mINI::INIFile _ini_file(SPARQ_CONFIG_FILE);
if (!_ini_file.write(ini))
{
Expand Down
12 changes: 11 additions & 1 deletion src/ConnectionWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,21 @@ void ConnectionWindow::update_content()
if (!(_com_ports.size() == 1 && _com_ports[0] == "COM-"))
{
_signature = hex_chars_to_byte(_signature_chars[0], _signature_chars[1]);
if (_sp->open(_com_ports[_current_id].c_str(), _baud_rate) == SERIAL_ERR::OK)

const char *selected_port = _com_ports[_current_id].c_str();
std::cout << "Opening Port: " << selected_port << " (" << _baud_rate << ") ..." << std::endl;

int rtn = _sp->open(selected_port, _baud_rate);

if (rtn == SERIAL_ERR::OK)
{
std::cout << "Port opened successfully!\n";
_port_open = true;
ImGui::InsertNotification({ImGuiToastType::Success, 5000, "COM port opened successfully!"});
}
else
{
std::cerr << "Failed to open port! Error: " << rtn << "\n";
ImGui::InsertNotification({ImGuiToastType::Error, 5000, "Could not open COM port!"});
}
}
Expand All @@ -159,6 +167,8 @@ void ConnectionWindow::update_content()

if (ImGui::Button("Close"))
{
std::cout << "Closing COM port ..." << std::endl;

_sp->close();
ImGui::InsertNotification({ImGuiToastType::Success, 5000, "COM port closed successfully!"});
_port_open = false;
Expand Down
2 changes: 1 addition & 1 deletion src/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ max_samples = 100000
max_samples_type = 0

[color]
colormap = 5
colormap = 3
17 changes: 12 additions & 5 deletions src/sparq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ SPARQ::SPARQ()

int SPARQ::init()
{
std::cout << "\n=== SPARQ " << SPARQ_VERSION << " ===\n\n";
std::cout << "Initializing ...\n\n";

object_init();

if (window_init() < 0)
Expand All @@ -20,6 +23,8 @@ int SPARQ::init()

void SPARQ::object_init()
{
std::cout << "Initializing objects ...\n";

static Serial serial_port;
static ConsoleWindow console_window;
static DataHandler data_handler(&serial_port, &console_window);
Expand Down Expand Up @@ -49,30 +54,29 @@ int SPARQ::window_init()
{
auto &config = ConfigHandler::get_instance();

std::cout << "Initializing window ...\n";

sf::ContextSettings settings;
settings.antialiasingLevel = std::stoi(config.ini["graphics"]["antialiasing"]);

static sf::RenderWindow window(sf::VideoMode(1280, 720), std::string("SPARQ - ") + SPARQ_VERSION, sf::Style::Default, settings);

std::cout << "Loading " << SPARQ_ICON_FILE << " ...\n";
sf::Image icon;
if (icon.loadFromFile(SPARQ_ICON_FILE))
{
window.setIcon(icon.getSize().x, icon.getSize().y, icon.getPixelsPtr());
}
else
{
std::cerr << "Failed to load " << SPARQ_ICON_FILE << "!\n";
ImGui::InsertNotification({ImGuiToastType::Error, 3000, "Failed to load icon.png!"});
}

window.setFramerateLimit(SPARQ_MAX_FPS);
bool vsync_enabled = config.ini["graphics"]["vsync"] == "1";
window.setVerticalSyncEnabled(vsync_enabled);

std::cout << "Applied Graphics Settings:\n";
std::cout << " Antialiasing Level: " << settings.antialiasingLevel << "\n";
std::cout << " VSync: " << (vsync_enabled ? "Enabled" : "Disabled") << "\n";
std::cout << " FPS Limit: " << SPARQ_MAX_FPS << "\n";

BOOL USE_DARK_MODE = true;
DwmSetWindowAttribute(window.getSystemHandle(), 20, &USE_DARK_MODE, sizeof(USE_DARK_MODE));
ShowWindow(window.getSystemHandle(), SW_MAXIMIZE);
Expand All @@ -83,6 +87,7 @@ int SPARQ::window_init()
return -1;
}

std::cout << "Loading " << SPARQ_FONT << " ...\n";
float baseFontSize = 18.f;
ImGuiIO &io = ImGui::GetIO();
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable | ImGuiConfigFlags_ViewportsEnable;
Expand Down Expand Up @@ -111,6 +116,8 @@ int SPARQ::window_init()

config.apply_in_context_settings();

std::cout << "\nInitialization complete!\n\n";

return 0;
}

Expand Down

0 comments on commit fec8a9f

Please sign in to comment.