diff --git a/config/config.json b/config/config.json index 3f391373..248b265e 100644 --- a/config/config.json +++ b/config/config.json @@ -77,7 +77,7 @@ "language": "https://raw.githubusercontent.com/skunkforce/omniview/master/languages/Deutsch.json" } }, - "helplink": "https://moodle.aw4null.de/", + "helplink": "https://omni-scope.auto-intern.de/support/", "language": "Deutsch", "languagepath": "languages/", "menubar": { diff --git a/src/handler.cpp b/src/handler.cpp index c733792b..14e6e8fe 100644 --- a/src/handler.cpp +++ b/src/handler.cpp @@ -1,64 +1,69 @@ #include "handler.hpp" - +#include "../imgui-stdlib/imgui_stdlib.h" +#include "get_from_github.hpp" +#include "popups.hpp" #include -#include #include +#include +struct AxisInfo { + const std::pair> &> data; + std::pair egu; + std::string timebase; -#include "popups.hpp" -#include "get_from_github.hpp" + AxisInfo( + const std::pair> &> + data_, + std::pair egu_, std::string timebase_) + : data{data_}, egu{egu_}, timebase{timebase_} {} +}; -#include "../imgui-stdlib/imgui_stdlib.h" +static std::vector plotAxes; -std::vector getDeviceInfos() { +static std::vector getDeviceInfos() { std::vector axisInfos; std::vector samplerDvcs; // store live devices std::vector> assignedEgus; if (sampler.has_value()) for (auto const &device : sampler->sampleDevices) { - // 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()) { + std::string egu = + device.first->getEgu().value_or(appLanguage[Key::ADC_counts]); + if (auto id = device.first->getId(); id.has_value()) { auto deviceId = id.value(); samplerDvcs.push_back(deviceId); - std::string timebase{std::to_string(deviceId.sampleRate)}; - if (captureData.find(deviceId) != captureData.end()) { - auto eguIterator = std::ranges::find( - assignedEgus, egu, &std::pair::first); - if (eguIterator == assignedEgus.end()) { + if (captureData.contains(deviceId)) { + if (!std::ranges::contains(assignedEgus, egu, + &std::pair::first)) if (assignedEgus.size() <= 3) { + // make sure ImAxis_ values haven't changed + static_assert((ImAxis_Y1 + 1) == ImAxis_Y2); 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{ - std::make_pair(deviceId, std::ref(captureData[deviceId])), - *eguIterator, timebase}; - axisInfos.push_back(axisInfo); + axisInfos.push_back({{deviceId, std::ref(captureData[deviceId])}, + assignedEgus.back(), + std::to_string(deviceId.sampleRate)}); } } else fmt::println("Error no device id found"); } - // also add loaded files into plotAxes + // also get loaded files info for (auto &[device, values] : captureData) if (std::ranges::find(samplerDvcs, device.serial, &Omniscope::Id::serial) == - samplerDvcs.end()) { + samplerDvcs.end()) axisInfos.push_back({{device, values}, {"y [Volts]", ImAxis_Y1}, std::to_string(device.sampleRate)}); - } return axisInfos; } -void addPlots(const char *name, bool const flagPaused, +void addPlots(const char *name, std::function axesSetup) { static std::set firstRun; @@ -70,9 +75,7 @@ void addPlots(const char *name, bool const flagPaused, 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.second.size(), - // axes.egu.first); + for (auto const &axes : plotAxes) 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 @@ -83,7 +86,6 @@ void addPlots(const char *name, bool const flagPaused, // fmt::print("yMin {}, yMax{}\n", yMin, yMax); axesSetup(x_max, axes.egu.first, axes.egu.second, yMin, yMax); } - } auto const limits = [&]() { if (!firstRun.contains(name)) { @@ -98,24 +100,18 @@ void addPlots(const char *name, bool const flagPaused, 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; + return p != plot.second.begin() ? p - 1 : p; }(); 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; + return p != plot.second.end() ? p + 1 : p; }(); 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); + return s <= 1 ? 1 : static_cast(s); }(); // determine which axes is the right one to choose @@ -127,7 +123,7 @@ void addPlots(const char *name, bool const flagPaused, 2 * sizeof(double) * stride); } }; - for (int count = 0; auto const &plot : plotAxes) { + for (auto const &plot : plotAxes) { ImPlot::SetNextLineStyle(ImVec4{colorMap[plot.data.first][0], colorMap[plot.data.first][1], colorMap[plot.data.first][2], 1.0f}); @@ -142,7 +138,7 @@ void parseDeviceMetaData(Omniscope::MetaData metaData, std::shared_ptr &device) { try { nlohmann::json metaJson = nlohmann::json::parse(metaData.data); - fmt::print("{}\n", metaJson.dump()); + fmt::println("{}", metaJson.dump()); device->setScale(std::stod(metaJson["scale"].dump())); device->setOffset(std::stod(metaJson["offset"].dump())); device->setEgu(metaJson["egu"]); diff --git a/src/handler.hpp b/src/handler.hpp index 6b695c04..f5daa0c9 100644 --- a/src/handler.hpp +++ b/src/handler.hpp @@ -4,21 +4,10 @@ #include "../ai_omniscope-v2-communication_sw/src/OmniscopeSampler.hpp" #include "languages.hpp" +#include #include #include #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{}; @@ -29,9 +18,8 @@ inline std::optional sampler{}; inline std::map>> captureData; -inline std::vector plotAxes; void addPlots( - const char *, const bool, + const char *, std::function); void parseDeviceMetaData(Omniscope::MetaData, std::shared_ptr &); diff --git a/src/languages.hpp b/src/languages.hpp index 2d1fbb8a..3506ab91 100644 --- a/src/languages.hpp +++ b/src/languages.hpp @@ -12,6 +12,8 @@ enum class Key { Devices_Menu, Select_Devices, Save_Recorded_Data, + Recording_Data, + ADC_counts, Select_Storage_Location, Browse, Menu, @@ -81,6 +83,7 @@ enum class Key { y_label, Voltage, Time, + Time_sec, FontSize, SettingsText, Saving, @@ -93,10 +96,11 @@ enum class Key { inline const std::map englishLan{ {Key::Known_Car, "Known Cars"}, {Key::New_Car, "New_Car"}, - {Key::Additional_Information, "Additional_Information"}, + {Key::Additional_Information, "Additional_Information for car analysis"}, {Key::Devices_Menu, "Devices Menu"}, {Key::Select_Devices, "Select Devices"}, {Key::Save_Recorded_Data, "Save recorded Data"}, + {Key::Recording_Data, "Recording the data"}, {Key::Select_Storage_Location, "Select the storage location"}, {Key::Browse, "Browse"}, {Key::Menu, "Menu"}, @@ -167,22 +171,24 @@ inline const std::map englishLan{ {Key::y_label, "x [data points]"}, {Key::Voltage, "Voltage"}, {Key::Time, "Time"}, + {Key::Time_sec, "time [s]"}, {Key::FontSize, "Fontsize"}, {Key::SettingsText, "Set your personal settings for the software"}, {Key::Saving, "saving ..."}, {Key::Load_file, "Load file"}, {Key::Load_file_data, "Load file data"}, {Key::Load_another_file, "Load another file"}, - {Key::Path, "Path"}}; - + {Key::Path, "Path"}, + {Key::ADC_counts, "ADC counts"}}; inline const std::map germanLan{ {Key::Known_Car, "Fahrzeugauswahl"}, {Key::New_Car, "Neues Fahrzeug"}, - {Key::Additional_Information, "Weiterführende Information"}, + {Key::Additional_Information, "Optionale Angaben für KFZ-Analysen"}, {Key::Devices_Menu, "Geräteliste"}, {Key::Select_Devices, "Geräteauswahl"}, {Key::Save_Recorded_Data, "Speichern der aufgenommenen Daten"}, + {Key::Recording_Data, "Aufzeichnen der Daten"}, {Key::Select_Storage_Location, "Wählen Sie den Speicherort"}, {Key::Browse, "Durchsuchen"}, {Key::Menu, "Menü"}, @@ -254,13 +260,15 @@ inline const std::map germanLan{ {Key::y_label, "x [Datenpunkte]"}, {Key::Voltage, "Spannung"}, {Key::Time, "Zeit"}, + {Key::Time_sec, "Zeit [s]"}, {Key::FontSize, "Schriftgröße"}, {Key::SettingsText, "Legen sie hier ihre persönlichen Einstellungen fest"}, {Key::Saving, "speichern ..."}, {Key::Load_file, "Datei laden"}, {Key::Load_file_data, "Alte Daten laden"}, {Key::Load_another_file, "Eine weitere Datei laden"}, - {Key::Path, "Pfad"}}; + {Key::Path, "Pfad"}, + {Key::ADC_counts, "ADC Zählungen"}}; inline auto appLanguage = englishLan; namespace fs = std::filesystem; diff --git a/src/look_up_saves.hpp b/src/look_up_saves.hpp index 3d01b85c..dd2ac72a 100644 --- a/src/look_up_saves.hpp +++ b/src/look_up_saves.hpp @@ -34,16 +34,17 @@ inline std::string getSubdirectoriesInFolder(nlohmann::json language, vins[i] = strdup(subdirectories[i].c_str()); if (isTxtInptFieldsEmpty) { - const std::string newcar = appLanguage[Key::New_Car]; + ImGui::InputText(appLanguage[Key::Measurement], scantype, 255); ImGui::Separator(); ImGui::NewLine(); ImGui::Text(appLanguage[Key::Additional_Information]); ImGui::NewLine(); - + + const std::string newcar = appLanguage[Key::New_Car]; + ImGui::Combo(appLanguage[Key::Known_Car], &selectedOption, vins, static_cast(subdirectories.size())); - ImGui::InputText(appLanguage[Key::Measurement], scantype, 255); if (selectedOption == 0) { ImGui::InputText("Fin/Vin", inputvin, 19, ImGuiInputTextFlags_CharsUppercase | @@ -56,6 +57,10 @@ inline std::string getSubdirectoriesInFolder(nlohmann::json language, // Using vins (char* array) with ImGui }else { + ImGui::InputText(appLanguage[Key::Measurement], scantype, 255); + ImGui::Separator(); + ImGui::Text(appLanguage[Key::Additional_Information]); + ImGui::NewLine(); ImGui::Combo(appLanguage[Key::Known_Car], &selectedOption, vins, static_cast(subdirectories.size())); @@ -65,11 +70,7 @@ inline std::string getSubdirectoriesInFolder(nlohmann::json language, } static char VIN[18]; const std::string newcar = appLanguage[Key::New_Car]; - - ImGui::Separator(); - ImGui::Text(appLanguage[Key::Additional_Information]); - ImGui::NewLine(); - ImGui::InputText(appLanguage[Key::Measurement], scantype, 255); + ImGui::InputText(appLanguage[Key::Mileage], mileage, 10); } } diff --git a/src/main.cpp b/src/main.cpp index fdd17d7c..e3d1f8dc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,21 +12,15 @@ int main() { 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 flagPaused{true}; - bool Development{false}, flagInitState{true}, - open_generate_training_data{false}, open_settings{false}; + bool flagPaused{true}, development{false}, open_generate_training_data{false}, + open_settings{false}; + std::once_flag configFlag; auto loadedFiles = captureData; std::map loadedFilenames; // main loop auto render = [&]() { - if (flagInitState) { - set_inital_config(config); - flagInitState = false; - } + std::call_once(configFlag, set_inital_config, std::ref(config)); SetupImGuiStyle(false, 0.99f); ImGui::SetNextWindowPos({0.f, 0.f}); auto windowSize{ImGui::GetIO().DisplaySize}; @@ -35,7 +29,7 @@ int main() { ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoTitleBar); - if (Development && ImGui::Button("Development")) + if (development && ImGui::Button("Development")) ImGui::OpenPopup("Development Colors"); // Popup-Window content @@ -91,31 +85,30 @@ int main() { ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, windowSize.x * .009f); ImGui::BeginChild("Record Data", {0.f, windowSize.y * 0.62f}, ImGuiChildFlags_Border); - // 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, - [&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; + appLanguage[Key::Recording_Data], + [flagPaused](double x_max, std::string yLabel, ImAxis_ axis, + double yMin, double yMax) { + ImPlot::SetupLegend(ImPlotLocation_NorthEast); + // auto auxFlagsMeasuring = + // ImPlotAxisFlags_AutoFit | ImPlotAxisFlags_NoGridLines; + // auto auxFlagsPaused = ImPlotAxisFlags_NoGridLines; ImPlot::SetupAxisTicks(ImAxis_Y1, -10, 200, 22, nullptr, true); if (!flagPaused) { ImPlot::SetupAxis(axis, yLabel.c_str(), ImPlotAxisFlags_AutoFit); - ImPlot::SetupAxis(ImAxis_X1, "time [s]", ImPlotAxisFlags_AutoFit); + ImPlot::SetupAxis(ImAxis_X1, appLanguage[Key::Time_sec], + 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(ImAxis_X1, "time [s]"); + ImPlot::SetupAxis(ImAxis_X1, appLanguage[Key::Time_sec]); ImPlot::SetupAxis(axis, yLabel.c_str()); ImPlot::SetupAxisLimits(ImAxis_X1, 0, 10); ImPlot::SetupAxisLimits(axis, yMin - 2, yMax + 2); diff --git a/src/saves_popup.cpp b/src/saves_popup.cpp index 751f1d11..e686047b 100644 --- a/src/saves_popup.cpp +++ b/src/saves_popup.cpp @@ -165,11 +165,11 @@ void saves_popup(nlohmann::json const &config, nlohmann::json const &language, // ############# End popup // make a .csv file name - auto mkFileName = [&](const std::string &name) { + auto mkFileName = [&](const std::string &name, const std::string &measurement) { now = std::chrono::system_clock::now(); now_time_t = std::chrono::system_clock::to_time_t(now); now_tm = *std::gmtime(&now_time_t); - std::string filename{fmt::format("{}-{:%Y-%m-%dT%H-%M}.csv", name, now)}; + std::string filename{fmt::format("{}-{}-{:%Y-%m-%dT%H-%M}.csv", name, measurement, now)}; return filename; }; @@ -240,7 +240,7 @@ void saves_popup(nlohmann::json const &config, nlohmann::json const &language, // measurement saving preparation if device is checked if (dvcCheckedArr[i].b) { fs::path path; - auto filename = mkFileName(fmt::format("device{}", i + 1)); + auto filename = mkFileName(fmt::format("device{}", i + 1), scantype); if (hasSelectedPathArr[i].b) { path = mkdir(true, selectedPathArr[i], "", filename); hasSelectedPathArr[i].b = false; diff --git a/src/style.cpp b/src/style.cpp index b067f468..475dcada 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -134,6 +134,9 @@ void SetDeviceMenuStyle() { ImGuiStyle &style = ImGui::GetStyle(); style.Colors[ImGuiCol_Border] = {0.14f, 0.15f, 0.17f, 1.0f}; + style.Colors[ImGuiCol_FrameBg] = {0.9f, 0.9f, 0.9f, 1.0f}; + style.Colors[ImGuiCol_FrameBgHovered] = {1.0f, 1.0f, 1.0f, 1.0f}; + style.Colors[ImGuiCol_FrameBgActive] = {0.8f, 0.8f, 0.8f, 0.8f}; } namespace ImGui { @@ -309,13 +312,20 @@ void set_side_menu(const nlohmann::json &config, bool &open_settings, static bool showDiag = false; const bool showDiagPrev = showDiag; + + ImGui::PushStyleColor(ImGuiCol_Text, {0.8f, 0.8f, 0.8f, 0.7f}); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, {0.8f, 0.8f, 0.8f, 0.0f}); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, {0.8f, 0.8f, 0.8f, 0.0f}); if (loaded_png[++PngRenderedCnt] && // render Diagnostics ImGui::ImageButtonWithText( (void *)(intptr_t)image_texture[PngRenderedCnt], appLanguage[Key::Diagnostics])) { - showDiag = !showDiag; + //showDiag = !showDiag; } - if (showDiag && !showDiagPrev) + ImGui::PopStyleColor(3); + + + /*if (showDiag && !showDiagPrev) ImGui::SetNextItemOpen(false); if (showDiag && ImGui::TreeNode(appLanguage[Key::Battery_measure])) { ImGui::PushStyleColor(ImGuiCol_Text, inctColStyle); @@ -327,7 +337,7 @@ void set_side_menu(const nlohmann::json &config, bool &open_settings, showDiag = false; } ImGui::TreePop(); - } + }*/ static bool showSettings = false; if (loaded_png[++PngRenderedCnt] && // render Settings @@ -347,7 +357,7 @@ void set_side_menu(const nlohmann::json &config, bool &open_settings, } ImGui::SetCursorPosY(windowSize.y * 0.9f); ImGui::Text(fmt::format("{}: {}", appLanguage[Key::Version], - CMakeGitVersion::VersionWithGit) + "1.0.1") .c_str()); }