From 829b390ad63fbd2b78b8bdfed7cdc91bb760d482 Mon Sep 17 00:00:00 2001 From: Niklas Date: Tue, 7 May 2024 17:07:11 +0200 Subject: [PATCH 1/8] Update the reading and parsing of the calibration Values --- ai_omniscope-v2-communication_sw | 2 +- src/handler.cpp | 47 ++- src/handler.hpp | 3 +- src/languages.hpp | 20 +- src/main.cpp | 522 +++++++++++++++++++------------ 5 files changed, 375 insertions(+), 219 deletions(-) diff --git a/ai_omniscope-v2-communication_sw b/ai_omniscope-v2-communication_sw index e084bad7..85429281 160000 --- a/ai_omniscope-v2-communication_sw +++ b/ai_omniscope-v2-communication_sw @@ -1 +1 @@ -Subproject commit e084bad75322f5b0853116806a830311e3f4b8ad +Subproject commit 8542928198f0759afb567a81f05b3d45e1790b16 diff --git a/src/handler.cpp b/src/handler.cpp index 29e5e818..15062ab0 100644 --- a/src/handler.cpp +++ b/src/handler.cpp @@ -27,7 +27,7 @@ void addPlots(const char *name, const bool flagPaused, } return ImPlot::GetPlotLimits(); }(); - auto addPlot = [&](auto const &plot) { + auto addPlot = [&](auto const &plot, int plotCount) { if (!plot.second.empty()) { auto const start = [&]() { auto p = std::lower_bound(plot.second.begin(), plot.second.end(), @@ -51,33 +51,56 @@ void addPlots(const char *name, const bool flagPaused, return 1; return static_cast(s); }(); - + ImAxis_ nextXAxis = static_cast(ImAxis_X1 + plotCount); + ImAxis_ nextYAxis = static_cast(ImAxis_Y1 + plotCount); + ImPlot::SetAxes(nextXAxis, nextYAxis); ImPlot::PlotLine( fmt::format("{}-{}", plot.first.type, plot.first.serial).c_str(), std::addressof(start->first), std::addressof(start->second), static_cast(std::distance(start, end)) / stride, 0, 0, 2 * sizeof(double) * stride); + } }; - for (auto const &plot : plots) { + for (int count = 0; auto const &plot : plots) { ImPlot::SetNextLineStyle(ImVec4{colorMap[plot.first][0], colorMap[plot.first][1], colorMap[plot.first][2], 1.0f}); - addPlot(plot); + addPlot(plot, count); + ++count; } ImPlot::EndPlot(); } } +void parseDeviceMetaData(Omniscope::MetaData metaData, std::shared_ptr& device){ + try{ + nlohmann::json metaJson = nlohmann::json::parse(metaData.data); + fmt::print("{}\n", metaJson.dump()); + device->setScale(std::stod(metaJson["scale"].dump())); + device->setOffset(std::stod(metaJson["offset"].dump())); + device->setEgu(metaJson["egu"]); + }catch(...){ + fmt::print("parsing Meta Data error: {}", metaData.data); + } +} + void initDevices() { constexpr int VID = 0x2e8au; constexpr int PID = 0x000au; devices = deviceManager.getDevices(VID, PID); for (auto &device : devices) { + auto metaDataCb = [&](auto const& msg) { + if (std::holds_alternative(msg)) { + parseDeviceMetaData(std::get(msg), device); + } + }; auto id = device->getId().value(); + auto sampleRate = static_cast(id.sampleRate); + device->setTimeScale(static_cast(1 / sampleRate)); if (!colorMap.contains(id)) { ImPlot::PushColormap(ImPlotColormap_Dark); auto c = ImPlot::GetColormapColor((colorMap.size() % 7) + 1); @@ -88,10 +111,13 @@ void initDevices() { device->send(Omniscope::SetRgb{static_cast(color[0] * 255), static_cast(color[1] * 255), static_cast(color[2] * 255)}); - } + //set Callback for MetaData + device->setMessageCallback(metaDataCb); + device->send(Omniscope::GetMetaData{}); + } } -void devicesList() { +void devicesList(bool const& flagPaused) { auto doDevice = [&](auto &device, auto msg) { auto &color = colorMap[device->getId().value()]; if (ImGui::ColorEdit3( @@ -124,8 +150,13 @@ void devicesList() { }; if (sampler.has_value()) - for (auto &device : sampler->sampleDevices) - doDevice(device.first, appLanguage[Key::Measurement]); + for (auto &device : sampler->sampleDevices){ + if(!flagPaused){ + doDevice(device.first, appLanguage[Key::Measurement]); + }else{ + doDevice(device.first, appLanguage[Key::Stop]); + } + } else for (auto &device : devices) doDevice(device, appLanguage[Key::Ready]); diff --git a/src/handler.hpp b/src/handler.hpp index 05218e42..ebd7db39 100644 --- a/src/handler.hpp +++ b/src/handler.hpp @@ -18,8 +18,9 @@ inline std::map>> captureData; void addPlots(const char *, const bool, std::function); +void parseDeviceMetaData(Omniscope::MetaData, std::shared_ptr&); void initDevices(); -void devicesList(); +void devicesList(bool const& flagPaused); void set_config(const std::string &); void set_json(nlohmann::json &); void rstSettings(); diff --git a/src/languages.hpp b/src/languages.hpp index 777e9b8a..c4885384 100644 --- a/src/languages.hpp +++ b/src/languages.hpp @@ -76,7 +76,11 @@ enum class Key { Battery_measure, Attitude, German, - Ready + Ready, + x_label, + y_label, + Voltage, + Time }; inline const std::map englishLan{ @@ -151,7 +155,11 @@ inline const std::map englishLan{ {Key::Battery_measure, "Battery measurement"}, {Key::Attitude, "Attitude"}, {Key::German, "German"}, - {Key::Ready, "Ready"}}; + {Key::Ready, "Ready"}, + {Key::x_label, "y [ADC counts]"}, + {Key::y_label, "x [data points]"}, + {Key::Voltage, "Voltage"}, + {Key::Time, "Time"}}; inline const std::map germanLan{ {Key::Known_Car, "Fahrzeugauswahl"}, @@ -225,7 +233,11 @@ inline const std::map germanLan{ {Key::Battery_measure, "Batteriemessung"}, {Key::Attitude, "Einstellung"}, {Key::German, "Deutsch"}, - {Key::Ready, "Bereit"}}; + {Key::Ready, "Bereit"}, + {Key::x_label, "y [ADC Zähler]"}, + {Key::y_label, "x [Datenpunkte]"}, + {Key::Voltage, "Spannung"}, + {Key::Time, "Zeit"}}; inline auto appLanguage = englishLan; -#endif \ No newline at end of file +#endif diff --git a/src/main.cpp b/src/main.cpp index a3a97b8c..8839c235 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,215 +1,327 @@ +#include +#include +#include + #include "popups.hpp" #include "settingspopup.hpp" #include "style.hpp" -#include +std::vector uniqueSorted(const std::vector& input) { + std::set uniqueSet(input.begin(), input.end()); + + std::vector result(uniqueSet.begin(), uniqueSet.end()); + + return result; +} int main() { - const std::string configpath = "config/config.json"; - set_config(configpath); - nlohmann::json config = load_json_file(configpath); - set_json(config); - nlohmann::json language = - load_json_file(load_json(config, "languagepath") + - load_json(config, "language") + ".json"); - // local variables - auto now = std::chrono::system_clock::now(); - std::time_t now_time_t = std::chrono::system_clock::to_time_t(now); - std::tm now_tm = *std::gmtime(&now_time_t); - double xmax_paused{0}; - bool open_settings = false; - bool open_generate_training_data = false; - bool upload_success = false; - static bool flagPaused = true; - bool flagDataNotSaved = true; - bool Development = false; - - // main loop - auto render = [&]() { - SetupImGuiStyle(false, 0.99f, config); - ImGui::SetNextWindowPos({0.f, 0.f}); - auto windowSize{ImGui::GetIO().DisplaySize}; - ImGui::SetNextWindowSize(windowSize); - const ImVec2 toolBtnSize{windowSize.x * .1f, - windowSize.y * .1f}; // toolbar buttons size - ImGui::Begin("OmniScopev2 Data Capture Tool", nullptr, - ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | - ImGuiWindowFlags_NoTitleBar); - - if (Development && ImGui::Button("Development")) - ImGui::OpenPopup("Development Colors"); - - // Popup-Window content - if (ImGui::BeginPopup("Development Colors")) { - PopupStyleEditor(); - ImGui::EndPopup(); - } - - ImGui::BeginChild("Left Side", {windowSize.x * .18f, 0.f}); - set_side_menu(config, flagPaused, open_settings, - open_generate_training_data); - // there're four "BeginChild"s, one as the left side - // and three on the right side - ImGui::EndChild(); // end child "Left Side" - ImGui::SameLine(); - ImGui::BeginChild("Right Side", {0.f, 0.f}); - if (sampler.has_value() && !flagPaused) - sampler->copyOut(captureData); - ImGui::BeginChild("Buttonstripe", {-1.f, windowSize.y * .1f}, false, - ImGuiWindowFlags_NoScrollbar); - // ############################ Popup Save - if (ImGui::BeginPopupModal(appLanguage[Key::Save_Recorded_Data], nullptr, - ImGuiWindowFlags_AlwaysAutoResize)) { - ImGui::SetItemDefaultFocus(); - saves_popup(config, language, captureData, now, now_time_t, now_tm, - flagDataNotSaved); - ImGui::EndPopup(); - } - // ############################ Popup Reset - if (ImGui::BeginPopupModal(appLanguage[Key::Reset_q], nullptr, - ImGuiWindowFlags_AlwaysAutoResize)) { - ImGui::SetItemDefaultFocus(); - ImGui::Text(appLanguage[Key::Measure_not_saved]); - if (ImGui::Button(appLanguage[Key::Continue_del])) { - rstSettings(); - ImGui::CloseCurrentPopup(); - } - ImGui::SameLine(); - if (ImGui::Button(appLanguage[Key::Back])) - ImGui::CloseCurrentPopup(); - ImGui::EndPopup(); - } - - if (flagPaused) { - // ######################## Buttonstripe - if (!devices.empty()) - if (!sampler.has_value()) { - set_button_style_to(config, "start"); // Start Button - if (ImGui::Button(appLanguage[Key::Start], toolBtnSize)) { - sampler.emplace(deviceManager, std::move(devices)); - flagPaused = false; - flagDataNotSaved = true; - } - ImGui::PopStyleColor(3); + const std::string configpath = "config/config.json"; + set_config(configpath); + nlohmann::json config = load_json_file(configpath); + set_json(config); + nlohmann::json language = + load_json_file(load_json(config, "languagepath") + + load_json(config, "language") + ".json"); + // local variables + auto now = std::chrono::system_clock::now(); + std::time_t now_time_t = std::chrono::system_clock::to_time_t(now); + std::tm now_tm = *std::gmtime(&now_time_t); + bool open_settings = false; + bool open_generate_training_data = false; + bool upload_success = false; + static bool flagPaused = true; + bool flagDataNotSaved = true; + bool Development = false; + + // main loop + auto render = [&]() { + SetupImGuiStyle(false, 0.99f, config); + ImGui::SetNextWindowPos({0.f, 0.f}); + auto windowSize{ImGui::GetIO().DisplaySize}; + ImGui::SetNextWindowSize(windowSize); + const ImVec2 toolBtnSize{windowSize.x * .1f, + windowSize.y * .1f}; // toolbar buttons size + ImGui::Begin("OmniScopev2 Data Capture Tool", nullptr, + ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | + ImGuiWindowFlags_NoTitleBar); + + if (Development && ImGui::Button("Development")) + ImGui::OpenPopup("Development Colors"); + + // Popup-Window content + if (ImGui::BeginPopup("Development Colors")) { + PopupStyleEditor(); + ImGui::EndPopup(); } - // set_button_style_to(config, "standart"); - } else { - // ############################ Stop Button - set_button_style_to(config, "stop"); - if (ImGui::Button(appLanguage[Key::Stop], toolBtnSize)) - flagPaused = true; - ImGui::PopStyleColor(3); - } - if (flagPaused) { - ImGui::SameLine(); - - // Start/reset the measurement when the measurement is paused, - // followed by a query as to whether the old data should be saved - if (sampler.has_value()) { + + ImGui::BeginChild("Left Side", {windowSize.x * .18f, 0.f}); + set_side_menu(config, flagPaused, open_settings, + open_generate_training_data); + // there're four "BeginChild"s, one as the left side + // and three on the right side + ImGui::EndChild(); // end child "Left Side" ImGui::SameLine(); - set_button_style_to(config, "start"); - if (ImGui::Button(appLanguage[Key::Continue], toolBtnSize)) { - flagPaused = false; - flagDataNotSaved = true; + ImGui::BeginChild("Right Side", {0.f, 0.f}); + if (sampler.has_value() && !flagPaused) sampler->copyOut(captureData); + ImGui::BeginChild("Buttonstripe", {-1.f, windowSize.y * .1f}, false, + ImGuiWindowFlags_NoScrollbar); + // ############################ Popup Save + if (ImGui::BeginPopupModal(appLanguage[Key::Save_Recorded_Data], + nullptr, + ImGuiWindowFlags_AlwaysAutoResize)) { + ImGui::SetItemDefaultFocus(); + saves_popup(config, language, captureData, now, now_time_t, now_tm, + flagDataNotSaved); + ImGui::EndPopup(); } - ImGui::PopStyleColor(3); - ImGui::SameLine(); + // ############################ Popup Reset + if (ImGui::BeginPopupModal(appLanguage[Key::Reset_q], nullptr, + ImGuiWindowFlags_AlwaysAutoResize)) { + ImGui::SetItemDefaultFocus(); + ImGui::Text(appLanguage[Key::Measure_not_saved]); + if (ImGui::Button(appLanguage[Key::Continue_del])) { + rstSettings(); + ImGui::CloseCurrentPopup(); + } + ImGui::SameLine(); + if (ImGui::Button(appLanguage[Key::Back])) + ImGui::CloseCurrentPopup(); + ImGui::EndPopup(); + } + + if (flagPaused) { + // ######################## Buttonstripe + if (!devices.empty()) + if (!sampler.has_value()) { + set_button_style_to(config, "start"); // Start Button + if (ImGui::Button(appLanguage[Key::Start], toolBtnSize)) { + sampler.emplace(deviceManager, std::move(devices)); + flagPaused = false; + flagDataNotSaved = true; + } + ImGui::PopStyleColor(3); + } + // set_button_style_to(config, "standart"); + } else { + // ############################ Stop Button + set_button_style_to(config, "stop"); + if (ImGui::Button(appLanguage[Key::Stop], toolBtnSize)) { + flagPaused = true; + for (auto& device : sampler->sampleDevices) { + device.first->send(Omniscope::Stop{}); + } + } + ImGui::PopStyleColor(3); + } + if (flagPaused) { + ImGui::SameLine(); + + // Start/reset the measurement when the measurement is paused, + // followed by a query as to whether the old data should be saved + if (sampler.has_value()) { + ImGui::SameLine(); + set_button_style_to(config, "start"); + if (ImGui::Button(appLanguage[Key::Continue], toolBtnSize)) { + flagPaused = false; + flagDataNotSaved = true; + for (auto& device : sampler->sampleDevices) { + device.first->send(Omniscope::Start{}); + } + } + ImGui::PopStyleColor(3); + ImGui::SameLine(); + + set_button_style_to(config, "stop"); + if (ImGui::Button(appLanguage[Key::Reset], toolBtnSize)) { + if (flagDataNotSaved) + ImGui::OpenPopup(appLanguage[Key::Reset_q]); + else { + rstSettings(); + flagPaused = true; + } + } + ImGui::PopStyleColor(3); + } + ImGui::SameLine(); - set_button_style_to(config, "stop"); - if (ImGui::Button(appLanguage[Key::Reset], toolBtnSize)) { - if (flagDataNotSaved) - ImGui::OpenPopup(appLanguage[Key::Reset_q]); - else { - rstSettings(); - flagPaused = true; - } + // gray out "Save" button when pop-up is open + const bool pushStyle = + ImGui::IsPopupOpen(appLanguage[Key::Save_Recorded_Data]); + + if (pushStyle) ImGui::PushStyleColor(ImGuiCol_Text, inctColStyle); + if (ImGui::Button(appLanguage[Key::Save], toolBtnSize)) { + if (sampler.has_value()) + ImGui::OpenPopup(appLanguage[Key::Save_Recorded_Data]); + else + ImGui::OpenPopup(appLanguage[Key::Save_warning], + ImGuiPopupFlags_NoOpenOverExistingPopup); + } + info_popup(appLanguage[Key::Save_warning], + appLanguage[Key::No_dvc_available]); + + if (pushStyle) ImGui::PopStyleColor(); + } else { + ImGui::SameLine(); + ImGui::PushStyleColor(ImGuiCol_Text, inctColStyle); + ImGui::Button(appLanguage[Key::Save], toolBtnSize); + ImGui::PopStyleColor(); + } + ImGui::EndChild(); // end child "Buttonstripe" + // ############################ Settings Menu + std::string settingstitle = + load_json(language, "settings", "title"); + if (open_settings) { + ImGui::OpenPopup(settingstitle.c_str()); + open_settings = false; } - ImGui::PopStyleColor(3); - } - ImGui::SameLine(); - - // gray out "Save" button when pop-up is open - const bool pushStyle = ImGui::IsPopupOpen(appLanguage[Key::Save_Recorded_Data]); - - if (pushStyle) - ImGui::PushStyleColor(ImGuiCol_Text, inctColStyle); - if (ImGui::Button(appLanguage[Key::Save], toolBtnSize)) { - if (sampler.has_value()) - ImGui::OpenPopup(appLanguage[Key::Save_Recorded_Data]); - else - ImGui::OpenPopup(appLanguage[Key::Save_warning], - ImGuiPopupFlags_NoOpenOverExistingPopup); - } - info_popup(appLanguage[Key::Save_warning], - appLanguage[Key::No_dvc_available]); - - if (pushStyle) - ImGui::PopStyleColor(); - } else { - ImGui::SameLine(); - ImGui::PushStyleColor(ImGuiCol_Text, inctColStyle); - ImGui::Button(appLanguage[Key::Save], toolBtnSize); - ImGui::PopStyleColor(); - } - ImGui::EndChild(); // end child "Buttonstripe" - // ############################ Settings Menu - std::string settingstitle = - load_json(language, "settings", "title"); - if (open_settings) { - ImGui::OpenPopup(settingstitle.c_str()); - open_settings = false; - } - if (ImGui::BeginPopupModal(settingstitle.c_str(), nullptr, - ImGuiWindowFlags_AlwaysAutoResize)) { - ImGui::SetItemDefaultFocus(); - popup_settings(config, language, configpath); - ImGui::EndPopup(); - } - // Generate training data popup - if (open_generate_training_data) - generateTrainingData(open_generate_training_data, captureData, - savedFileNames, config); - - // ############################ addPlots("Recording the data", ...) - ImGui::Dummy({0.f, windowSize.y * .01f}); - PushPlotRegionColors(); - ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, windowSize.x * .009f); - ImGui::BeginChild("Record Data", {0.f, windowSize.y * 0.62f}, - ImGuiChildFlags_Border); - - addPlots("Recording the data", flagPaused, [&xmax_paused](double x_max) { - if (!flagPaused) { - ImPlot::SetupAxes("x [Data points]", "y [ADC Value]", - ImPlotAxisFlags_AutoFit, ImPlotAxisFlags_AutoFit); - ImPlot::SetupAxisLimits(ImAxis_X1, x_max - 7500, x_max + 7500, - ImGuiCond_Always); - } else { - xmax_paused = x_max; - ImPlot::SetupAxes("x [Seconds]", "y [Volts]"); - ImPlot::SetupAxesLimits(0, 10, -10, 200); - ImPlot::SetupAxisTicks(ImAxis_Y1, -10, 200, 22, nullptr, true); - ImPlot::SetupLegend(ImPlotLocation_NorthEast); - } - }); - ImGui::EndChild(); // end child Record Data - ImGui::PopStyleVar(); - PopPlotRegionColors(); - // ############################ Devicelist - SetDeviceMenuStyle(); - - ImGui::Dummy({0.f, windowSize.y * .01f}); - ImGui::BeginChild("Devicelist"); - ImGui::Dummy({windowSize.x * .36f, 0.f}); - ImGui::SameLine(); - ImGui::Text(appLanguage[Key::Devices_found]); - devicesList(); - ImGui::EndChild(); // end child "Devicelist" - ImGui::EndChild(); // end child "Right Side" - ImGui::End(); - }; - - ImGuiInstance window{1500, 800, - fmt::format("{} {}", CMakeGitVersion::Target::Name, - CMakeGitVersion::Project::Version)}; - while (window.run(render)); - return 0; -} \ No newline at end of file + if (ImGui::BeginPopupModal(settingstitle.c_str(), nullptr, + ImGuiWindowFlags_AlwaysAutoResize)) { + ImGui::SetItemDefaultFocus(); + popup_settings(config, language, configpath); + ImGui::EndPopup(); + } + // Generate training data popup + if (open_generate_training_data) + generateTrainingData(open_generate_training_data, captureData, + savedFileNames, config); + + // ############################ addPlots("Recording the data", ...) + ImGui::Dummy({0.f, windowSize.y * .01f}); + PushPlotRegionColors(); + ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, + windowSize.x * .009f); + ImGui::BeginChild("Record Data", {0.f, windowSize.y * 0.62f}, + ImGuiChildFlags_Border); + auto const plotRegion = ImGui::GetContentRegionAvail(); + + // Axes 1 to 3 + // Check if time base for axes are same + // check if egu and timescale for plot are same + // error if third device is added + addPlots("Recording the data", flagPaused, [](double x_max) { + ImPlot::SetupLegend(ImPlotLocation_NorthEast | + ImPlotLegendFlags_Outside); + // ImPlot::SetupAxisTicks(ImAxis_Y1, -10, 200, 22, nullptr, + // true); + static std::vector egus; + static std::vector x_labels; + static std::vector y_labels; + static bool init = true; + if (sampler.has_value()) { + if (init) { + std::size_t numberOfDevices = sampler->sampleDevices.size(); + for (auto& device : sampler->sampleDevices) { + if (device.first->getEgu().has_value()) { + auto egu = device.first->getEgu().value(); + fmt::print("egu found: {}\n", egu); + egus.push_back(fmt::format( + "{} {}", appLanguage[Key::Voltage], egu)); + } + } + egus = uniqueSorted(egus); + fmt::print("egus: {}\n", egus); + init = false; + } + if(!egus.empty() && !flagPaused){ + //Setup Axes for corresponding EGUs found + if(egus.size() >= 1){ + //Setup First Axis with first text from one EGU + } + if(egus.size() >= 2){ + //Setup second Axis with third text from one EGU + } + if(egus.size() >= 3){ + //Setup third Axis with third text from one EGU + } + }else if(!egus.empty() && flagPaused){ + //Same as above but with paused axis + if(egus.size() >= 1){ + //Setup First Axis with first text from one EGU + } + if(egus.size() >= 2){ + //Setup second Axis with third text from one EGU + } + if(egus.size() >= 3){ + //Setup third Axis with third text from one EGU + } + }else if(egus.empty() && !flagPaused){ + //Setup first Axis for default Text Measuring + }else if(egus.empty() && flagPaused){ + //Setup first Axis for default Text Paused + } + } + auto auxFlagsMeasuring = + ImPlotAxisFlags_AutoFit | ImPlotAxisFlags_NoGridLines; + auto auxFlagsPaused = ImPlotAxisFlags_NoGridLines; + /* + if (!flagPaused) { + if (numberOfDevices >= 1) { + ImPlot::SetupAxis(ImAxis_X1, + x_labels[0].c_str(), ImPlotAxisFlags_AutoFit); + ImPlot::SetupAxis(ImAxis_Y1, + y_labels[0].c_str(), ImPlotAxisFlags_AutoFit); + ImPlot::SetupAxisLimits(ImAxis_X1, x_max - 1, + x_max + 2, ImGuiCond_Always); + } + if (numberOfDevices >= 2) { + ImPlot::SetupAxis(ImAxis_X2, + x_labels[1].c_str(), auxFlagsMeasuring); + ImPlot::SetupAxis(ImAxis_Y2, + y_labels[1].c_str(), auxFlagsMeasuring); + ImPlot::SetupAxisLimits(ImAxis_X2, x_max - 1, + x_max + 2, ImGuiCond_Always); + } + if (numberOfDevices >= 3) { + ImPlot::SetupAxis(ImAxis_X3, + x_labels[2].c_str(), auxFlagsMeasuring); + ImPlot::SetupAxis(ImAxis_Y3, + y_labels[2].c_str(), auxFlagsMeasuring); + ImPlot::SetupAxisLimits(ImAxis_X3, x_max - 1, + x_max + 2, ImGuiCond_Always); + } + } else { + ImPlot::SetupAxis(ImAxis_X1, x_labels[0].c_str()); + ImPlot::SetupAxis(ImAxis_Y1, y_labels[0].c_str()); + ImPlot::SetupAxesLimits(0, 10, -10, 200); + if (numberOfDevices >= 2) { + ImPlot::SetupAxis(ImAxis_X2, + x_labels[1].c_str(), auxFlagsPaused); + ImPlot::SetupAxis(ImAxis_Y2, + y_labels[1].c_str(), auxFlagsPaused); + ImPlot::SetupAxisLimits(ImAxis_X2, 0, 10); + ImPlot::SetupAxisLimits(ImAxis_Y2, -10, 200); + } + if (numberOfDevices >= 3) { + ImPlot::SetupAxis(ImAxis_X3, + x_labels[2].c_str(), auxFlagsPaused); + ImPlot::SetupAxis(ImAxis_Y3, + y_labels[2].c_str(), auxFlagsPaused); + ImPlot::SetupAxisLimits(ImAxis_X3, 0, 10); + ImPlot::SetupAxisLimits(ImAxis_Y3, -10, 200); + } + } + */ + }); + ImGui::EndChild(); // end child Record Data + ImGui::PopStyleVar(); + PopPlotRegionColors(); + // ############################ Devicelist + SetDeviceMenuStyle(); + + ImGui::Dummy({0.f, windowSize.y * .01f}); + ImGui::BeginChild("Devicelist"); + ImGui::Dummy({windowSize.x * .36f, 0.f}); + ImGui::SameLine(); + ImGui::Text(appLanguage[Key::Devices_found]); + devicesList(flagPaused); + ImGui::EndChild(); // end child "Devicelist" + ImGui::EndChild(); // end child "Right Side" + ImGui::End(); + }; + + ImGuiInstance window{1500, 800, + fmt::format("{} {}", CMakeGitVersion::Target::Name, + CMakeGitVersion::Project::Version)}; + while (window.run(render)) + ; + return 0; +} From 79ef138be8dd5cd31eb7d376d7ec54c81aca8bbb Mon Sep 17 00:00:00 2001 From: Niklas Date: Wed, 8 May 2024 16:48:54 +0200 Subject: [PATCH 2/8] Change some routines --- src/handler.cpp | 3 +- src/main.cpp | 102 ++++++++++++++++++++++++++++++++---------------- 2 files changed, 70 insertions(+), 35 deletions(-) diff --git a/src/handler.cpp b/src/handler.cpp index 15062ab0..87e52312 100644 --- a/src/handler.cpp +++ b/src/handler.cpp @@ -51,6 +51,8 @@ void addPlots(const char *name, const bool flagPaused, return 1; return static_cast(s); }(); + + //determine which axes is the right one to choose ImAxis_ nextXAxis = static_cast(ImAxis_X1 + plotCount); ImAxis_ nextYAxis = static_cast(ImAxis_Y1 + plotCount); ImPlot::SetAxes(nextXAxis, nextYAxis); @@ -62,7 +64,6 @@ void addPlots(const char *name, const bool flagPaused, } }; - for (int count = 0; auto const &plot : plots) { ImPlot::SetNextLineStyle(ImVec4{colorMap[plot.first][0], colorMap[plot.first][1], diff --git a/src/main.cpp b/src/main.cpp index 8839c235..0269a718 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -31,6 +31,7 @@ int main() { static bool flagPaused = true; bool flagDataNotSaved = true; bool Development = false; + static bool initAxesSetup = true; // main loop auto render = [&]() { @@ -80,6 +81,7 @@ int main() { ImGui::Text(appLanguage[Key::Measure_not_saved]); if (ImGui::Button(appLanguage[Key::Continue_del])) { rstSettings(); + initAxesSetup = true; ImGui::CloseCurrentPopup(); } ImGui::SameLine(); @@ -137,6 +139,7 @@ int main() { else { rstSettings(); flagPaused = true; + initAxesSetup = true; } } ImGui::PopStyleColor(3); @@ -200,14 +203,16 @@ int main() { addPlots("Recording the data", flagPaused, [](double x_max) { ImPlot::SetupLegend(ImPlotLocation_NorthEast | ImPlotLegendFlags_Outside); - // ImPlot::SetupAxisTicks(ImAxis_Y1, -10, 200, 22, nullptr, - // true); + // ImPlot::SetupAxisTicks(ImAxis_Y1, -10, 200, 22, nullptr, true); static std::vector egus; - static std::vector x_labels; + static std::size_t defaultAxesCounter; + static std::string x_label{fmt::format("{} [s]", appLanguage[Key::Time])}; static std::vector y_labels; - static bool init = true; if (sampler.has_value()) { - if (init) { + if (initAxesSetup) { + egus.clear(); + y_labels.clear(); + axesCounter = 0; std::size_t numberOfDevices = sampler->sampleDevices.size(); for (auto& device : sampler->sampleDevices) { if (device.first->getEgu().has_value()) { @@ -215,38 +220,73 @@ int main() { fmt::print("egu found: {}\n", egu); egus.push_back(fmt::format( "{} {}", appLanguage[Key::Voltage], egu)); + }else{ + ++defaultAxesCounter; } } egus = uniqueSorted(egus); - fmt::print("egus: {}\n", egus); - init = false; + fmt::print("egus: {} size: {}\n", egus, egus.size()); + if(egus.size() <= 3){ + y_labels.resize(egus.size()); + std::copy(egus.begin(), egus.end(), y_labels.begin()); + }else{ + fmt::print("Too many different devices!\n"); + } + initAxesSetup = false; } - if(!egus.empty() && !flagPaused){ - //Setup Axes for corresponding EGUs found - if(egus.size() >= 1){ - //Setup First Axis with first text from one EGU + if (egus.empty() && !flagPaused) { + ImPlot::SetupAxis(ImAxis_X1, + fmt::format("sample count").c_str(), + ImPlotAxisFlags_AutoFit); + ImPlot::SetupAxis(ImAxis_Y1, + fmt::format("ADC value").c_str(), + ImPlotAxisFlags_AutoFit); + ImPlot::SetupAxisLimits(ImAxis_X1, x_max - 1, x_max + 2, + ImGuiCond_Always); + } else if (egus.empty() && flagPaused) { + ImPlot::SetupAxis(ImAxis_X1, + fmt::format("sample count").c_str()); + ImPlot::SetupAxis(ImAxis_Y1, + fmt::format("ADC value").c_str()); + ImPlot::SetupAxisLimits(ImAxis_X1, x_max - 1, x_max + 2, + ImGuiCond_Always); + } else if (!egus.empty() && !flagPaused) { + if ((egus.size() + defaultAxesCounter) >= 1) { + // Setup First Axis with first text from one EGU + ImPlot::SetupAxis(ImAxis_X1, x_label.c_str(), + ImPlotAxisFlags_AutoFit); + ImPlot::SetupAxis(ImAxis_Y1, y_labels[0].c_str(), + ImPlotAxisFlags_AutoFit); + ImPlot::SetupAxisLimits(ImAxis_X1, x_max - 1, x_max + 2, + ImGuiCond_Always); } - if(egus.size() >= 2){ - //Setup second Axis with third text from one EGU + if (egus.size() >= 2) { + // Setup second Axis with third text from one EGU + ImPlot::SetupAxis(ImAxis_X2, x_label.c_str(), + ImPlotAxisFlags_AutoFit); + ImPlot::SetupAxis(ImAxis_Y2, y_labels[1].c_str(), + ImPlotAxisFlags_AutoFit); + ImPlot::SetupAxisLimits(ImAxis_X2, x_max - 1, x_max + 2, + ImGuiCond_Always); } - if(egus.size() >= 3){ - //Setup third Axis with third text from one EGU + if (egus.size() >= 3) { + ImPlot::SetupAxis(ImAxis_X3, x_label.c_str(), + ImPlotAxisFlags_AutoFit); + ImPlot::SetupAxis(ImAxis_Y3, y_labels[2].c_str(), + ImPlotAxisFlags_AutoFit); + ImPlot::SetupAxisLimits(ImAxis_X3, x_max - 1, x_max + 2, + ImGuiCond_Always); } - }else if(!egus.empty() && flagPaused){ - //Same as above but with paused axis - if(egus.size() >= 1){ - //Setup First Axis with first text from one EGU + } else if (!egus.empty() && flagPaused) { + if (egus.size() >= 1) { + // Setup First Axis with first text from one EGU } - if(egus.size() >= 2){ - //Setup second Axis with third text from one EGU + if (egus.size() >= 2) { + // Setup second Axis with third text from one EGU } - if(egus.size() >= 3){ - //Setup third Axis with third text from one EGU + if (egus.size() >= 3) { + // Setup second Axis with third text from one EGU } - }else if(egus.empty() && !flagPaused){ - //Setup first Axis for default Text Measuring - }else if(egus.empty() && flagPaused){ - //Setup first Axis for default Text Paused } } auto auxFlagsMeasuring = @@ -255,13 +295,7 @@ int main() { /* if (!flagPaused) { if (numberOfDevices >= 1) { - ImPlot::SetupAxis(ImAxis_X1, - x_labels[0].c_str(), ImPlotAxisFlags_AutoFit); - ImPlot::SetupAxis(ImAxis_Y1, - y_labels[0].c_str(), ImPlotAxisFlags_AutoFit); - ImPlot::SetupAxisLimits(ImAxis_X1, x_max - 1, - x_max + 2, ImGuiCond_Always); - } + } if (numberOfDevices >= 2) { ImPlot::SetupAxis(ImAxis_X2, x_labels[1].c_str(), auxFlagsMeasuring); From 9f87b589638fc64853d4acfd2029bc04a83196c7 Mon Sep 17 00:00:00 2001 From: Niklas Date: Mon, 3 Jun 2024 17:28:51 +0200 Subject: [PATCH 3/8] Update data structure --- src/handler.cpp | 396 ++++++++++++++++++++++++++++++------------------ src/main.cpp | 199 ++++++------------------ 2 files changed, 289 insertions(+), 306 deletions(-) diff --git a/src/handler.cpp b/src/handler.cpp index 87e52312..e1e6f33d 100644 --- a/src/handler.cpp +++ b/src/handler.cpp @@ -1,189 +1,283 @@ -#include -#include #include "handler.hpp" + +#include + +#include +#include + #include "get_from_github.hpp" -void addPlots(const char *name, const bool flagPaused, +/* +std::vector categorizeDevices() { + std::unordered_map< + std::string, + std::map>>> + groupedData; + + for (auto const &device : sampler->sampleDevices) { + auto id = device.first->getId(); + if (id.has_value()) { + std::string egu{"default"}; + if (device.first->getEgu().has_value()) { + egu = device.first->getEgu().value(); + } + if (captureData.find(id.value()) != captureData.end()) { + groupedData[egu][id.value()] = captureData.at(id.value()); + } + } + } + std::vector axisInfos; + for (const auto &group : groupedData) { + std::string timebase; + ImAxis_ axis; + //AxisInfo info{group.second, "test", timebase, axis}; + //axisInfos.push_back(info); + } + + for (const auto& info : axisInfos) { + std::cout << "EGU: " << info.egu << ", Timebase: " << info.timebase << +", Axis: " << info.axis << std::endl; std::cout << "Data:" << std::endl; for +(const auto& dataEntry : info.data) { std::cout << " ID: " << +dataEntry.first.serial << ", Values: "; for (const auto& valuePair : +dataEntry.second) { std::cout << "(" << valuePair.first << ", " << +valuePair.second << ") "; + } + std::cout << std::endl; + } + } + return axisInfos; +} +*/ +struct AxisInfo { + std::vector>& data; + Omniscope::Id deviceId; + std::string egu; + std::string timebase; + ImAxis_ axis; + + AxisInfo(auto& data_, std::string egu_, Omniscope::Id deviceId_) : data{data_}, egu{egu_}, deviceId{deviceId_} + {} +}; + +std::vector getDeviceInfos() { + std::vector axisInfos; + + if (sampler.has_value()) { + for (auto const &device : sampler->sampleDevices) { + std::string egu = device.first->getEgu().value_or("default"); + auto id = device.first->getId(); + if (id.has_value()) { + Omniscope::Id deviceId = id.value(); + + if (captureData.find(deviceId) != captureData.end()) { + AxisInfo axisInfo{captureData[deviceId], egu, deviceId}; + axisInfos.push_back(axisInfo); + } + } + else{ + fmt::print("Error no device id found\n"); + } + } + + } + + return axisInfos; +} + +/* + * Compute connected devices + * catogerize them after EGU an timebase + * setup axes + * plot data in rigt axis + */ + +void addPlots(const char *name, bool const flagPaused, std::function axesSetup) { - static std::set firstRun; - const auto &plots{captureData}; - auto const plotRegion = ImGui::GetContentRegionAvail(); - - if (ImPlot::BeginPlot(name, plotRegion, ImPlotFlags_NoFrame)) { - double x_min = std::numeric_limits::max(); - double x_max = std::numeric_limits::min(); - - for (auto const &plot : plots) - if (!plot.second.empty()) { - x_min = std::min(x_min, plot.second.front().first); - x_max = std::max(x_max, plot.second.back().first); - } - - axesSetup(x_max); - auto const limits = [&]() { - if (!firstRun.contains(name)) { - firstRun.insert(name); - return ImPlotRect(x_min, x_max, 0, 0); - } - return ImPlot::GetPlotLimits(); - }(); - auto addPlot = [&](auto const &plot, int plotCount) { - if (!plot.second.empty()) { - auto const start = [&]() { - auto p = std::lower_bound(plot.second.begin(), plot.second.end(), - std::pair{limits.X.Min, 0}); - if (p != plot.second.begin()) - return p - 1; - return p; - }(); + static std::set firstRun; + static bool initialAxesSetup = true; + auto const plotRegion = ImGui::GetContentRegionAvail(); + static std::vector plotAxes; - auto const end = [&]() { - auto p = std::upper_bound(start, plot.second.end(), - std::pair{limits.X.Max, 0}); - if (p != plot.second.end()) - return p + 1; - return p; - }(); + if(initialAxesSetup){ + //plotAxes = getDeviceInfos(); + if(plotAxes.size() > 0){ + fmt::print("foo Size: {}\n", plotAxes.size()); + initialAxesSetup = false; + } + } - std::size_t const stride = [&]() -> std::size_t { - auto const s = std::distance(start, end) / (plotRegion.x * 2.0); - if (1 >= s) - return 1; - return static_cast(s); + if (ImPlot::BeginPlot(name, plotRegion, ImPlotFlags_NoFrame)) { + double x_min = std::numeric_limits::max(); + double x_max = std::numeric_limits::min(); + + auto const limits = [&]() { + if (!firstRun.contains(name)) { + firstRun.insert(name); + return ImPlotRect(x_min, x_max, 0, 0); + } + return ImPlot::GetPlotLimits(); }(); + auto addPlot = [&](auto const &plot, int plotCount) { + if (!plot.second.empty()) { + auto const start = [&]() { + auto p = std::lower_bound( + plot.second.begin(), plot.second.end(), + std::pair{limits.X.Min, 0}); + if (p != plot.second.begin()) return p - 1; + return p; + }(); - //determine which axes is the right one to choose - ImAxis_ nextXAxis = static_cast(ImAxis_X1 + plotCount); - ImAxis_ nextYAxis = static_cast(ImAxis_Y1 + plotCount); - ImPlot::SetAxes(nextXAxis, nextYAxis); - ImPlot::PlotLine( - fmt::format("{}-{}", plot.first.type, plot.first.serial).c_str(), - std::addressof(start->first), std::addressof(start->second), - static_cast(std::distance(start, end)) / stride, 0, 0, - 2 * sizeof(double) * stride); - - } - }; - for (int count = 0; auto const &plot : plots) { - ImPlot::SetNextLineStyle(ImVec4{colorMap[plot.first][0], - colorMap[plot.first][1], - colorMap[plot.first][2], 1.0f}); - addPlot(plot, count); - ++count; - } + auto const end = [&]() { + auto p = std::upper_bound( + start, plot.second.end(), + std::pair{limits.X.Max, 0}); + if (p != plot.second.end()) return p + 1; + return p; + }(); - ImPlot::EndPlot(); - } + std::size_t const stride = [&]() -> std::size_t { + auto const s = + std::distance(start, end) / (plotRegion.x * 2.0); + if (1 >= s) return 1; + return static_cast(s); + }(); + + // determine which axes is the right one to choose + ImAxis_ nextXAxis = static_cast(ImAxis_X1 + plotCount); + ImAxis_ nextYAxis = static_cast(ImAxis_Y1 + plotCount); + ImPlot::SetAxes(nextXAxis, nextYAxis); + ImPlot::PlotLine( + fmt::format("{}-{}", plot.first.type, plot.first.serial) + .c_str(), + std::addressof(start->first), std::addressof(start->second), + static_cast(std::distance(start, end)) / + stride, + 0, 0, 2 * sizeof(double) * stride); + } + }; + for (int count = 0; auto const &plot : captureData) { + ImPlot::SetNextLineStyle(ImVec4{colorMap[plot.first][0], + colorMap[plot.first][1], + colorMap[plot.first][2], 1.0f}); + addPlot(plot, count); + ++count; + } + + ImPlot::EndPlot(); + } } -void parseDeviceMetaData(Omniscope::MetaData metaData, std::shared_ptr& device){ - try{ +void parseDeviceMetaData(Omniscope::MetaData metaData, + std::shared_ptr &device) { + try { nlohmann::json metaJson = nlohmann::json::parse(metaData.data); fmt::print("{}\n", metaJson.dump()); device->setScale(std::stod(metaJson["scale"].dump())); device->setOffset(std::stod(metaJson["offset"].dump())); device->setEgu(metaJson["egu"]); - }catch(...){ + } catch (...) { fmt::print("parsing Meta Data error: {}", metaData.data); } } void initDevices() { - constexpr int VID = 0x2e8au; - constexpr int PID = 0x000au; - - devices = deviceManager.getDevices(VID, PID); - for (auto &device : devices) { - auto metaDataCb = [&](auto const& msg) { - if (std::holds_alternative(msg)) { - parseDeviceMetaData(std::get(msg), device); + constexpr int VID = 0x2e8au; + constexpr int PID = 0x000au; + + devices = deviceManager.getDevices(VID, PID); + for (auto &device : devices) { + auto metaDataCb = [&](auto const &msg) { + if (std::holds_alternative(msg)) { + parseDeviceMetaData(std::get(msg), device); + } + }; + auto id = device->getId().value(); + auto sampleRate = static_cast(id.sampleRate); + device->setTimeScale(static_cast(1 / sampleRate)); + if (!colorMap.contains(id)) { + ImPlot::PushColormap(ImPlotColormap_Dark); + auto c = ImPlot::GetColormapColor((colorMap.size() % 7) + 1); + colorMap[id] = std::array{c.x, c.y, c.z}; + ImPlot::PopColormap(); } - }; - auto id = device->getId().value(); - auto sampleRate = static_cast(id.sampleRate); - device->setTimeScale(static_cast(1 / sampleRate)); - if (!colorMap.contains(id)) { - ImPlot::PushColormap(ImPlotColormap_Dark); - auto c = ImPlot::GetColormapColor((colorMap.size() % 7) + 1); - colorMap[id] = std::array{c.x, c.y, c.z}; - ImPlot::PopColormap(); - } - auto &color = colorMap[id]; - device->send(Omniscope::SetRgb{static_cast(color[0] * 255), - static_cast(color[1] * 255), - static_cast(color[2] * 255)}); - //set Callback for MetaData - device->setMessageCallback(metaDataCb); - device->send(Omniscope::GetMetaData{}); + auto &color = colorMap[id]; + device->send( + Omniscope::SetRgb{static_cast(color[0] * 255), + static_cast(color[1] * 255), + static_cast(color[2] * 255)}); + // set Callback for MetaData + device->setMessageCallback(metaDataCb); + device->send(Omniscope::GetMetaData{}); } } -void devicesList(bool const& flagPaused) { - auto doDevice = [&](auto &device, auto msg) { - auto &color = colorMap[device->getId().value()]; - if (ImGui::ColorEdit3( - fmt::format("{:<32}", - fmt::format("{}-{}", device->getId().value().type, - device->getId().value().serial)) - .c_str(), - color.data(), - ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoPicker | - ImGuiColorEditFlags_NoTooltip)) { - device->send( - Omniscope::SetRgb{static_cast(color[0] * 255), - static_cast(color[1] * 255), - static_cast(color[2] * 255)}); - } - ImGui::SameLine(); - ImGui::TextUnformatted(fmt::format("HW: v{}.{}.{} SW: v{}.{}.{} ", - device->getId().value().hwVersion.major, - device->getId().value().hwVersion.minor, - device->getId().value().hwVersion.patch, - device->getId().value().swVersion.major, - device->getId().value().swVersion.minor, - device->getId().value().swVersion.patch) - .c_str()); - ImGui::SameLine(); - if (device->isRunning()) - ImGui::TextUnformatted(fmt::format("{}", msg).c_str()); - else - ImGui::TextUnformatted("Error"); - }; +void devicesList(bool const &flagPaused) { + auto doDevice = [&](auto &device, auto msg) { + auto &color = colorMap[device->getId().value()]; + if (ImGui::ColorEdit3( + fmt::format("{:<32}", + fmt::format("{}-{}", device->getId().value().type, + device->getId().value().serial)) + .c_str(), + color.data(), + ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoPicker | + ImGuiColorEditFlags_NoTooltip)) { + device->send( + Omniscope::SetRgb{static_cast(color[0] * 255), + static_cast(color[1] * 255), + static_cast(color[2] * 255)}); + } + ImGui::SameLine(); + ImGui::TextUnformatted( + fmt::format("HW: v{}.{}.{} SW: v{}.{}.{} ", + device->getId().value().hwVersion.major, + device->getId().value().hwVersion.minor, + device->getId().value().hwVersion.patch, + device->getId().value().swVersion.major, + device->getId().value().swVersion.minor, + device->getId().value().swVersion.patch) + .c_str()); + ImGui::SameLine(); + if (device->isRunning()) + ImGui::TextUnformatted(fmt::format("{}", msg).c_str()); + else + ImGui::TextUnformatted("Error"); + }; - if (sampler.has_value()) - for (auto &device : sampler->sampleDevices){ - if(!flagPaused){ + if (sampler.has_value()) + for (auto &device : sampler->sampleDevices) { + if (!flagPaused) { doDevice(device.first, appLanguage[Key::Measurement]); - }else{ + } else { doDevice(device.first, appLanguage[Key::Stop]); } } - else - for (auto &device : devices) - doDevice(device, appLanguage[Key::Ready]); + else + for (auto &device : devices) doDevice(device, appLanguage[Key::Ready]); } void set_config(const std::string &configpath) { - if (std::filesystem::exists(configpath)) - fmt::print("found config.json\n\r"); - else { - fmt::print("Did not find config.json.\n Download from Github\n\r"); - update_config_from_github(); - } + if (std::filesystem::exists(configpath)) + fmt::print("found config.json\n\r"); + else { + fmt::print("Did not find config.json.\n Download from Github\n\r"); + update_config_from_github(); + } } void set_json(nlohmann::json &config) { - if (std::filesystem::exists(load_json(config, ("languagepath")))) - fmt::print("Found language: {}\n\r",appLanguage[Key::German]); - else { - fmt::print("Did not find {}.\n Download from Github\n\r", - appLanguage[Key::German]); - update_language_from_github(); - } + if (std::filesystem::exists( + load_json(config, ("languagepath")))) + fmt::print("Found language: {}\n\r", appLanguage[Key::German]); + else { + fmt::print("Did not find {}.\n Download from Github\n\r", + appLanguage[Key::German]); + update_language_from_github(); + } } void rstSettings() { - sampler.reset(); - devices.clear(); - savedFileNames.clear(); - deviceManager.clearDevices(); - captureData.clear(); + sampler.reset(); + devices.clear(); + savedFileNames.clear(); + deviceManager.clearDevices(); + captureData.clear(); } diff --git a/src/main.cpp b/src/main.cpp index 0269a718..f093b336 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,9 +5,12 @@ #include "popups.hpp" #include "settingspopup.hpp" #include "style.hpp" -std::vector uniqueSorted(const std::vector& input) { - std::set uniqueSet(input.begin(), input.end()); - +std::vector uniqueSortedEgus( + std::vector> const& input) { + std::set uniqueSet; + for (auto const& [str1, str2] : input) { + uniqueSet.emplace(str1); + } std::vector result(uniqueSet.begin(), uniqueSet.end()); return result; @@ -40,7 +43,7 @@ int main() { auto windowSize{ImGui::GetIO().DisplaySize}; ImGui::SetNextWindowSize(windowSize); const ImVec2 toolBtnSize{windowSize.x * .1f, - windowSize.y * .1f}; // toolbar buttons size + windowSize.y * .1f}; // toolbar buttons size ImGui::Begin("OmniScopev2 Data Capture Tool", nullptr, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoTitleBar); @@ -203,159 +206,45 @@ int main() { addPlots("Recording the data", flagPaused, [](double x_max) { ImPlot::SetupLegend(ImPlotLocation_NorthEast | ImPlotLegendFlags_Outside); - // ImPlot::SetupAxisTicks(ImAxis_Y1, -10, 200, 22, nullptr, true); - static std::vector egus; - static std::size_t defaultAxesCounter; - static std::string x_label{fmt::format("{} [s]", appLanguage[Key::Time])}; - static std::vector y_labels; - if (sampler.has_value()) { - if (initAxesSetup) { - egus.clear(); - y_labels.clear(); - axesCounter = 0; - std::size_t numberOfDevices = sampler->sampleDevices.size(); - for (auto& device : sampler->sampleDevices) { - if (device.first->getEgu().has_value()) { - auto egu = device.first->getEgu().value(); - fmt::print("egu found: {}\n", egu); - egus.push_back(fmt::format( - "{} {}", appLanguage[Key::Voltage], egu)); - }else{ - ++defaultAxesCounter; - } - } - egus = uniqueSorted(egus); - fmt::print("egus: {} size: {}\n", egus, egus.size()); - if(egus.size() <= 3){ - y_labels.resize(egus.size()); - std::copy(egus.begin(), egus.end(), y_labels.begin()); - }else{ - fmt::print("Too many different devices!\n"); - } - initAxesSetup = false; - } - if (egus.empty() && !flagPaused) { - ImPlot::SetupAxis(ImAxis_X1, - fmt::format("sample count").c_str(), - ImPlotAxisFlags_AutoFit); - ImPlot::SetupAxis(ImAxis_Y1, - fmt::format("ADC value").c_str(), - ImPlotAxisFlags_AutoFit); - ImPlot::SetupAxisLimits(ImAxis_X1, x_max - 1, x_max + 2, - ImGuiCond_Always); - } else if (egus.empty() && flagPaused) { - ImPlot::SetupAxis(ImAxis_X1, - fmt::format("sample count").c_str()); - ImPlot::SetupAxis(ImAxis_Y1, - fmt::format("ADC value").c_str()); - ImPlot::SetupAxisLimits(ImAxis_X1, x_max - 1, x_max + 2, - ImGuiCond_Always); - } else if (!egus.empty() && !flagPaused) { - if ((egus.size() + defaultAxesCounter) >= 1) { - // Setup First Axis with first text from one EGU - ImPlot::SetupAxis(ImAxis_X1, x_label.c_str(), - ImPlotAxisFlags_AutoFit); - ImPlot::SetupAxis(ImAxis_Y1, y_labels[0].c_str(), - ImPlotAxisFlags_AutoFit); - ImPlot::SetupAxisLimits(ImAxis_X1, x_max - 1, x_max + 2, - ImGuiCond_Always); - } - if (egus.size() >= 2) { - // Setup second Axis with third text from one EGU - ImPlot::SetupAxis(ImAxis_X2, x_label.c_str(), - ImPlotAxisFlags_AutoFit); - ImPlot::SetupAxis(ImAxis_Y2, y_labels[1].c_str(), - ImPlotAxisFlags_AutoFit); - ImPlot::SetupAxisLimits(ImAxis_X2, x_max - 1, x_max + 2, - ImGuiCond_Always); - } - if (egus.size() >= 3) { - ImPlot::SetupAxis(ImAxis_X3, x_label.c_str(), - ImPlotAxisFlags_AutoFit); - ImPlot::SetupAxis(ImAxis_Y3, y_labels[2].c_str(), - ImPlotAxisFlags_AutoFit); - ImPlot::SetupAxisLimits(ImAxis_X3, x_max - 1, x_max + 2, - ImGuiCond_Always); - } - } else if (!egus.empty() && flagPaused) { - if (egus.size() >= 1) { - // Setup First Axis with first text from one EGU - } - if (egus.size() >= 2) { - // Setup second Axis with third text from one EGU - } - if (egus.size() >= 3) { - // Setup second Axis with third text from one EGU - } - } - } auto auxFlagsMeasuring = ImPlotAxisFlags_AutoFit | ImPlotAxisFlags_NoGridLines; auto auxFlagsPaused = ImPlotAxisFlags_NoGridLines; + // ImPlot::SetupAxisTicks(ImAxis_Y1, -10, 200, 22, nullptr, true); /* - if (!flagPaused) { - if (numberOfDevices >= 1) { - } - if (numberOfDevices >= 2) { - ImPlot::SetupAxis(ImAxis_X2, - x_labels[1].c_str(), auxFlagsMeasuring); - ImPlot::SetupAxis(ImAxis_Y2, - y_labels[1].c_str(), auxFlagsMeasuring); - ImPlot::SetupAxisLimits(ImAxis_X2, x_max - 1, - x_max + 2, ImGuiCond_Always); - } - if (numberOfDevices >= 3) { - ImPlot::SetupAxis(ImAxis_X3, - x_labels[2].c_str(), auxFlagsMeasuring); - ImPlot::SetupAxis(ImAxis_Y3, - y_labels[2].c_str(), auxFlagsMeasuring); - ImPlot::SetupAxisLimits(ImAxis_X3, x_max - 1, - x_max + 2, ImGuiCond_Always); - } - } else { - ImPlot::SetupAxis(ImAxis_X1, x_labels[0].c_str()); - ImPlot::SetupAxis(ImAxis_Y1, y_labels[0].c_str()); - ImPlot::SetupAxesLimits(0, 10, -10, 200); - if (numberOfDevices >= 2) { - ImPlot::SetupAxis(ImAxis_X2, - x_labels[1].c_str(), auxFlagsPaused); - ImPlot::SetupAxis(ImAxis_Y2, - y_labels[1].c_str(), auxFlagsPaused); - ImPlot::SetupAxisLimits(ImAxis_X2, 0, 10); - ImPlot::SetupAxisLimits(ImAxis_Y2, -10, 200); - } - if (numberOfDevices >= 3) { - ImPlot::SetupAxis(ImAxis_X3, - x_labels[2].c_str(), auxFlagsPaused); - ImPlot::SetupAxis(ImAxis_Y3, - y_labels[2].c_str(), auxFlagsPaused); - ImPlot::SetupAxisLimits(ImAxis_X3, 0, 10); - ImPlot::SetupAxisLimits(ImAxis_Y3, -10, 200); - } - } - */ - }); - ImGui::EndChild(); // end child Record Data - ImGui::PopStyleVar(); - PopPlotRegionColors(); - // ############################ Devicelist - SetDeviceMenuStyle(); - - ImGui::Dummy({0.f, windowSize.y * .01f}); - ImGui::BeginChild("Devicelist"); - ImGui::Dummy({windowSize.x * .36f, 0.f}); - ImGui::SameLine(); - ImGui::Text(appLanguage[Key::Devices_found]); - devicesList(flagPaused); - ImGui::EndChild(); // end child "Devicelist" - ImGui::EndChild(); // end child "Right Side" - ImGui::End(); - }; - - ImGuiInstance window{1500, 800, - fmt::format("{} {}", CMakeGitVersion::Target::Name, - CMakeGitVersion::Project::Version)}; - while (window.run(render)) - ; - return 0; + if(!flagPaused){ + ImPlot::SetupAxis(axis.plotXAxis, axis.xLabel.c_str(), ImPlotAxisFlags_AutoFit); + ImPlot::SetupAxis(axis.plotYAxis, axis.yLabel.c_str(), ImPlotAxisFlags_AutoFit); + ImPlot::SetupAxisLimits(axis.plotXAxis, axis.xMin - 2, axis.xMax + 2, ImGuiCond_Always); + ImPlot::SetupAxisLimits(axis.plotYAxis, axis.yMin - 2, axis.yMax + 2, ImGuiCond_Always); + }else{ + ImPlot::SetupAxis(axis.plotXAxis, axis.xLabel.c_str()); + ImPlot::SetupAxis(axis.plotYAxis, axis.yLabel.c_str()); + ImPlot::SetupAxisLimits(axis.plotXAxis, axis.xMin - 2, axis.xMax + 2, ImGuiCond_Always); + ImPlot::SetupAxisLimits(axis.plotYAxis, axis.yMin - 2, axis.yMax + 2, ImGuiCond_Always); + } + */ + }); + ImGui::EndChild(); // end child Record Data + ImGui::PopStyleVar(); + PopPlotRegionColors(); + // ############################ Devicelist + SetDeviceMenuStyle(); + + ImGui::Dummy({0.f, windowSize.y * .01f}); + ImGui::BeginChild("Devicelist"); + ImGui::Dummy({windowSize.x * .36f, 0.f}); + ImGui::SameLine(); + ImGui::Text(appLanguage[Key::Devices_found]); + devicesList(flagPaused); + ImGui::EndChild(); // end child "Devicelist" + ImGui::EndChild(); // end child "Right Side" + ImGui::End(); +}; + +ImGuiInstance window{1500, 800, + fmt::format("{} {}", CMakeGitVersion::Target::Name, + CMakeGitVersion::Project::Version)}; +while (window.run(render)) + ; +return 0; } From 125299592336accbf03b06a35559aa50fef27507 Mon Sep 17 00:00:00 2001 From: Niklas Date: Tue, 4 Jun 2024 16:35:49 +0200 Subject: [PATCH 4/8] Update loading dynamic axes --- src/handler.cpp | 66 +++++++++++++++++++++++++++++++++++-------------- src/handler.hpp | 3 ++- src/main.cpp | 34 +++++++++---------------- 3 files changed, 62 insertions(+), 41 deletions(-) diff --git a/src/handler.cpp b/src/handler.cpp index e1e6f33d..07cb31cf 100644 --- a/src/handler.cpp +++ b/src/handler.cpp @@ -2,8 +2,8 @@ #include -#include #include +#include #include "get_from_github.hpp" @@ -49,38 +49,56 @@ valuePair.second << ") "; } */ struct AxisInfo { - std::vector>& data; + std::vector> &data; Omniscope::Id deviceId; - std::string egu; + std::pair egu; std::string timebase; - ImAxis_ axis; - AxisInfo(auto& data_, std::string egu_, Omniscope::Id deviceId_) : data{data_}, egu{egu_}, deviceId{deviceId_} - {} + AxisInfo(auto &data_, std::pair egu_, + Omniscope::Id deviceId_, std::string timebase_) + : data{data_}, egu{egu_}, deviceId{deviceId_}, timebase{timebase_} {} }; std::vector getDeviceInfos() { std::vector axisInfos; - + std::vector> assignedEgus; if (sampler.has_value()) { for (auto const &device : sampler->sampleDevices) { std::string egu = device.first->getEgu().value_or("default"); auto id = device.first->getId(); if (id.has_value()) { Omniscope::Id deviceId = id.value(); - + std::string timebase{std::to_string(deviceId.sampleRate)}; if (captureData.find(deviceId) != captureData.end()) { - AxisInfo axisInfo{captureData[deviceId], egu, deviceId}; + auto eguIterator = std::ranges::find( + assignedEgus, egu, + &std::pair::first); + + if (eguIterator == assignedEgus.end()) { + if (assignedEgus.size() <= 3) { + ImAxis_ nextYAxis = static_cast( + ImAxis_Y1 + assignedEgus.size()); + assignedEgus.push_back( + std::make_pair(egu, nextYAxis)); + eguIterator = (assignedEgus.end() - 1); + } else { + fmt::print( + "too many Axes added, egu not added: " + "{}\nDevice id: {}", + egu, id.value()); + break; + } + } + + AxisInfo axisInfo{captureData[deviceId], *eguIterator, + deviceId, timebase}; axisInfos.push_back(axisInfo); } - } - else{ + } else { fmt::print("Error no device id found\n"); } } - } - return axisInfos; } @@ -92,24 +110,33 @@ std::vector getDeviceInfos() { */ void addPlots(const char *name, bool const flagPaused, - std::function axesSetup) { + std::function + axesSetup) { static std::set firstRun; static bool initialAxesSetup = true; auto const plotRegion = ImGui::GetContentRegionAvail(); static std::vector plotAxes; - if(initialAxesSetup){ - //plotAxes = getDeviceInfos(); - if(plotAxes.size() > 0){ + if (initialAxesSetup) { + plotAxes = getDeviceInfos(); + if (plotAxes.size() > 0) { fmt::print("foo Size: {}\n", plotAxes.size()); initialAxesSetup = false; } + fmt::print("plot axes: {}\n", plotAxes.size()); } - if (ImPlot::BeginPlot(name, plotRegion, ImPlotFlags_NoFrame)) { double x_min = std::numeric_limits::max(); double x_max = std::numeric_limits::min(); + for (auto const &axes : plotAxes) { + fmt::print("data size:{}, egu: {}\n", axes.data.size(), + axes.egu.first); + auto [yMin, yMax] = + std::minmax_element(axes.data.begin(), axes.data.end()); + axesSetup(x_max, axes.egu.first, axes.egu.second, yMin->second, yMax->second); + } + auto const limits = [&]() { if (!firstRun.contains(name)) { firstRun.insert(name); @@ -117,6 +144,9 @@ void addPlots(const char *name, bool const flagPaused, } return ImPlot::GetPlotLimits(); }(); + + + auto addPlot = [&](auto const &plot, int plotCount) { if (!plot.second.empty()) { auto const start = [&]() { diff --git a/src/handler.hpp b/src/handler.hpp index ebd7db39..618407bc 100644 --- a/src/handler.hpp +++ b/src/handler.hpp @@ -7,6 +7,7 @@ #include #include #include +#include // global variables inline OmniscopeDeviceManager deviceManager{}; @@ -17,7 +18,7 @@ inline std::optional sampler{}; inline std::map>> captureData; -void addPlots(const char *, const bool, std::function); +void addPlots(const char *, const bool, std::function); void parseDeviceMetaData(Omniscope::MetaData, std::shared_ptr&); void initDevices(); void devicesList(bool const& flagPaused); diff --git a/src/main.cpp b/src/main.cpp index f093b336..4f8ad8fa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,16 +5,6 @@ #include "popups.hpp" #include "settingspopup.hpp" #include "style.hpp" -std::vector uniqueSortedEgus( - std::vector> const& input) { - std::set uniqueSet; - for (auto const& [str1, str2] : input) { - uniqueSet.emplace(str1); - } - std::vector result(uniqueSet.begin(), uniqueSet.end()); - - return result; -} int main() { const std::string configpath = "config/config.json"; @@ -203,26 +193,26 @@ int main() { // Check if time base for axes are same // check if egu and timescale for plot are same // error if third device is added - addPlots("Recording the data", flagPaused, [](double x_max) { + addPlots("Recording the data", flagPaused, [](double x_max, std::string yLabel, ImAxis_ axis, double yMin, double yMax) { ImPlot::SetupLegend(ImPlotLocation_NorthEast | ImPlotLegendFlags_Outside); auto auxFlagsMeasuring = ImPlotAxisFlags_AutoFit | ImPlotAxisFlags_NoGridLines; auto auxFlagsPaused = ImPlotAxisFlags_NoGridLines; - // ImPlot::SetupAxisTicks(ImAxis_Y1, -10, 200, 22, nullptr, true); - /* + ImPlot::SetupAxisTicks(ImAxis_Y1, -10, 200, 22, nullptr, true); + if(!flagPaused){ - ImPlot::SetupAxis(axis.plotXAxis, axis.xLabel.c_str(), ImPlotAxisFlags_AutoFit); - ImPlot::SetupAxis(axis.plotYAxis, axis.yLabel.c_str(), ImPlotAxisFlags_AutoFit); - ImPlot::SetupAxisLimits(axis.plotXAxis, axis.xMin - 2, axis.xMax + 2, ImGuiCond_Always); - ImPlot::SetupAxisLimits(axis.plotYAxis, axis.yMin - 2, axis.yMax + 2, ImGuiCond_Always); + ImPlot::SetupAxis(axis, yLabel.c_str(), ImPlotAxisFlags_AutoFit); + ImPlot::SetupAxis(ImAxis_X1, "time [s]", ImPlotAxisFlags_AutoFit); + ImPlot::SetupAxisLimits(axis, yMin - 2, yMax + 2, ImGuiCond_Always); + ImPlot::SetupAxisLimits(ImAxis_X1, x_max - 1, x_max + 9, ImGuiCond_Always); + }else{ - ImPlot::SetupAxis(axis.plotXAxis, axis.xLabel.c_str()); - ImPlot::SetupAxis(axis.plotYAxis, axis.yLabel.c_str()); - ImPlot::SetupAxisLimits(axis.plotXAxis, axis.xMin - 2, axis.xMax + 2, ImGuiCond_Always); - ImPlot::SetupAxisLimits(axis.plotYAxis, axis.yMin - 2, axis.yMax + 2, ImGuiCond_Always); + ImPlot::SetupAxis(ImAxis_X1, "time [s]"); + ImPlot::SetupAxis(axis, yLabel.c_str()); + ImPlot::SetupAxisLimits(ImAxis_X1, 0, 10); + ImPlot::SetupAxisLimits(axis, yMin - 2, yMax + 2); } - */ }); ImGui::EndChild(); // end child Record Data ImGui::PopStyleVar(); From ab10a9978197c307c6d03915f6ffca015a2b6ce2 Mon Sep 17 00:00:00 2001 From: Niklas Date: Wed, 5 Jun 2024 14:26:06 +0200 Subject: [PATCH 5/8] Update multi axis plot --- ai_omniscope-v2-communication_sw | 2 +- src/handler.cpp | 118 ++++++++----------------------- src/handler.hpp | 12 ++++ 3 files changed, 41 insertions(+), 91 deletions(-) diff --git a/ai_omniscope-v2-communication_sw b/ai_omniscope-v2-communication_sw index 85429281..8bf918dc 160000 --- a/ai_omniscope-v2-communication_sw +++ b/ai_omniscope-v2-communication_sw @@ -1 +1 @@ -Subproject commit 8542928198f0759afb567a81f05b3d45e1790b16 +Subproject commit 8bf918dcb69a6567f28d0e3c34bbd500fad71de2 diff --git a/src/handler.cpp b/src/handler.cpp index 07cb31cf..3a91c86f 100644 --- a/src/handler.cpp +++ b/src/handler.cpp @@ -7,64 +7,13 @@ #include "get_from_github.hpp" -/* -std::vector categorizeDevices() { - std::unordered_map< - std::string, - std::map>>> - groupedData; - - for (auto const &device : sampler->sampleDevices) { - auto id = device.first->getId(); - if (id.has_value()) { - std::string egu{"default"}; - if (device.first->getEgu().has_value()) { - egu = device.first->getEgu().value(); - } - if (captureData.find(id.value()) != captureData.end()) { - groupedData[egu][id.value()] = captureData.at(id.value()); - } - } - } - std::vector axisInfos; - for (const auto &group : groupedData) { - std::string timebase; - ImAxis_ axis; - //AxisInfo info{group.second, "test", timebase, axis}; - //axisInfos.push_back(info); - } - - for (const auto& info : axisInfos) { - std::cout << "EGU: " << info.egu << ", Timebase: " << info.timebase << -", Axis: " << info.axis << std::endl; std::cout << "Data:" << std::endl; for -(const auto& dataEntry : info.data) { std::cout << " ID: " << -dataEntry.first.serial << ", Values: "; for (const auto& valuePair : -dataEntry.second) { std::cout << "(" << valuePair.first << ", " << -valuePair.second << ") "; - } - std::cout << std::endl; - } - } - return axisInfos; -} -*/ -struct AxisInfo { - std::vector> &data; - Omniscope::Id deviceId; - std::pair egu; - std::string timebase; - - AxisInfo(auto &data_, std::pair egu_, - Omniscope::Id deviceId_, std::string timebase_) - : data{data_}, egu{egu_}, deviceId{deviceId_}, timebase{timebase_} {} -}; - std::vector getDeviceInfos() { std::vector axisInfos; std::vector> assignedEgus; if (sampler.has_value()) { for (auto const &device : sampler->sampleDevices) { - std::string egu = device.first->getEgu().value_or("default"); + // TODO replace ADC counts with language variable + std::string egu = device.first->getEgu().value_or("ADC counts"); auto id = device.first->getId(); if (id.has_value()) { Omniscope::Id deviceId = id.value(); @@ -73,7 +22,6 @@ std::vector getDeviceInfos() { auto eguIterator = std::ranges::find( assignedEgus, egu, &std::pair::first); - if (eguIterator == assignedEgus.end()) { if (assignedEgus.size() <= 3) { ImAxis_ nextYAxis = static_cast( @@ -89,9 +37,10 @@ std::vector getDeviceInfos() { break; } } - - AxisInfo axisInfo{captureData[deviceId], *eguIterator, - deviceId, timebase}; + AxisInfo axisInfo{ + std::make_pair(deviceId, + std::ref(captureData[deviceId])), + *eguIterator, timebase}; axisInfos.push_back(axisInfo); } } else { @@ -102,39 +51,32 @@ std::vector getDeviceInfos() { return axisInfos; } -/* - * Compute connected devices - * catogerize them after EGU an timebase - * setup axes - * plot data in rigt axis - */ - void addPlots(const char *name, bool const flagPaused, std::function axesSetup) { static std::set firstRun; - static bool initialAxesSetup = true; auto const plotRegion = ImGui::GetContentRegionAvail(); - static std::vector plotAxes; - - if (initialAxesSetup) { + //TODO search devices must work aswell + if (plotAxes.size() <= 0) { plotAxes = getDeviceInfos(); - if (plotAxes.size() > 0) { - fmt::print("foo Size: {}\n", plotAxes.size()); - initialAxesSetup = false; - } - fmt::print("plot axes: {}\n", plotAxes.size()); } if (ImPlot::BeginPlot(name, plotRegion, ImPlotFlags_NoFrame)) { double x_min = std::numeric_limits::max(); double x_max = std::numeric_limits::min(); for (auto const &axes : plotAxes) { - fmt::print("data size:{}, egu: {}\n", axes.data.size(), - axes.egu.first); - auto [yMin, yMax] = - std::minmax_element(axes.data.begin(), axes.data.end()); - axesSetup(x_max, axes.egu.first, axes.egu.second, yMin->second, yMax->second); + // fmt::print("data size:{}, egu: {}\n", axes.data.second.size(), + // axes.egu.first); + if (!axes.data.second.empty()) { + x_max = std::max(x_max, axes.data.second.back().first); + //TODO save max and min value over same axis + auto [min, max] = std::minmax_element(axes.data.second.begin(), + axes.data.second.end()); + double yMin = min->first + (min->first * 0.15); + double yMax = max->second + (max->second * 0.15); + // fmt::print("yMin {}, yMax{}\n", yMin, yMax); + axesSetup(x_max, axes.egu.first, axes.egu.second, yMin, yMax); + } } auto const limits = [&]() { @@ -145,9 +87,7 @@ void addPlots(const char *name, bool const flagPaused, return ImPlot::GetPlotLimits(); }(); - - - auto addPlot = [&](auto const &plot, int plotCount) { + auto addPlot = [&](auto const &plot, ImAxis_ yAxis) { if (!plot.second.empty()) { auto const start = [&]() { auto p = std::lower_bound( @@ -173,9 +113,7 @@ void addPlots(const char *name, bool const flagPaused, }(); // determine which axes is the right one to choose - ImAxis_ nextXAxis = static_cast(ImAxis_X1 + plotCount); - ImAxis_ nextYAxis = static_cast(ImAxis_Y1 + plotCount); - ImPlot::SetAxes(nextXAxis, nextYAxis); + ImPlot::SetAxes(ImAxis_X1, yAxis); ImPlot::PlotLine( fmt::format("{}-{}", plot.first.type, plot.first.serial) .c_str(), @@ -185,12 +123,11 @@ void addPlots(const char *name, bool const flagPaused, 0, 0, 2 * sizeof(double) * stride); } }; - for (int count = 0; auto const &plot : captureData) { - ImPlot::SetNextLineStyle(ImVec4{colorMap[plot.first][0], - colorMap[plot.first][1], - colorMap[plot.first][2], 1.0f}); - addPlot(plot, count); - ++count; + for (int count = 0; auto const &plot : plotAxes) { + ImPlot::SetNextLineStyle(ImVec4{ + colorMap[plot.data.first][0], colorMap[plot.data.first][1], + colorMap[plot.data.first][2], 1.0f}); + addPlot(plot.data, plot.egu.second); } ImPlot::EndPlot(); @@ -310,4 +247,5 @@ void rstSettings() { savedFileNames.clear(); deviceManager.clearDevices(); captureData.clear(); + plotAxes.clear(); } diff --git a/src/handler.hpp b/src/handler.hpp index 618407bc..37b60c1c 100644 --- a/src/handler.hpp +++ b/src/handler.hpp @@ -9,6 +9,17 @@ #include #include +struct AxisInfo { + std::pair>&> data; + std::pair egu; + std::string timebase; + + AxisInfo( + std::pair>&> data_, + std::pair egu_, std::string timebase_) + : data{data_}, egu{egu_}, timebase{timebase_} {} +}; + // global variables inline OmniscopeDeviceManager deviceManager{}; inline std::vector> devices; @@ -17,6 +28,7 @@ inline std::set savedFileNames; // unique and ordered filenames inline std::optional sampler{}; inline std::map>> captureData; +inline std::vector plotAxes; void addPlots(const char *, const bool, std::function); void parseDeviceMetaData(Omniscope::MetaData, std::shared_ptr&); From 3298311c2eef61250db3401d03801367dd8d5d4e Mon Sep 17 00:00:00 2001 From: Niklas Date: Wed, 5 Jun 2024 16:19:59 +0200 Subject: [PATCH 6/8] Update submodule --- ai_omniscope-v2-communication_sw | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ai_omniscope-v2-communication_sw b/ai_omniscope-v2-communication_sw index 8bf918dc..887ce6f3 160000 --- a/ai_omniscope-v2-communication_sw +++ b/ai_omniscope-v2-communication_sw @@ -1 +1 @@ -Subproject commit 8bf918dcb69a6567f28d0e3c34bbd500fad71de2 +Subproject commit 887ce6f3cce5eefc23041bb30c361da44ad67c63 From cdaa3633989776bb437126ebbe893bc461bb0c6a Mon Sep 17 00:00:00 2001 From: Niklas Date: Wed, 5 Jun 2024 16:32:42 +0200 Subject: [PATCH 7/8] Update submodule --- ai_omniscope-v2-communication_sw | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ai_omniscope-v2-communication_sw b/ai_omniscope-v2-communication_sw index 887ce6f3..93dede90 160000 --- a/ai_omniscope-v2-communication_sw +++ b/ai_omniscope-v2-communication_sw @@ -1 +1 @@ -Subproject commit 887ce6f3cce5eefc23041bb30c361da44ad67c63 +Subproject commit 93dede90c91f5ef17f4b2c2b00ed911e0b52a319 From 2f211d66f46771dcf67a3f73c5c97dd8b788db48 Mon Sep 17 00:00:00 2001 From: Niklas Date: Tue, 11 Jun 2024 14:49:35 +0200 Subject: [PATCH 8/8] Update axis loading --- src/handler.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/handler.cpp b/src/handler.cpp index 3a91c86f..baa3e74f 100644 --- a/src/handler.cpp +++ b/src/handler.cpp @@ -56,9 +56,12 @@ void addPlots(const char *name, bool const flagPaused, axesSetup) { static std::set firstRun; auto const plotRegion = ImGui::GetContentRegionAvail(); + static int activeAxes{0}; //TODO search devices must work aswell - if (plotAxes.size() <= 0) { + if (plotAxes.size() <= activeAxes) { plotAxes = getDeviceInfos(); + activeAxes = plotAxes.size(); + } if (ImPlot::BeginPlot(name, plotRegion, ImPlotFlags_NoFrame)) { double x_min = std::numeric_limits::max();