diff --git a/ai_omniscope-v2-communication_sw b/ai_omniscope-v2-communication_sw index 656fa456..e084bad7 160000 --- a/ai_omniscope-v2-communication_sw +++ b/ai_omniscope-v2-communication_sw @@ -1 +1 @@ -Subproject commit 656fa456c9c5c0136df8e81c3d5ddb93508553b9 +Subproject commit e084bad75322f5b0853116806a830311e3f4b8ad diff --git a/src/create_training_data.hpp b/src/create_training_data.hpp index 31e7a12a..49fc645e 100644 --- a/src/create_training_data.hpp +++ b/src/create_training_data.hpp @@ -104,7 +104,7 @@ static void selected_vcds_data(nlohmann::json const &config, nlohmann::json &metadata, std::string &inputvin, std::string &mileage, std::string &comment, std::string &api_message, bool &upload_success) { - ImGui::Text(load_json(language, "explanation", "upload", "vcds") + ImGui::TextUnformatted(load_json(language, "explanation", "upload", "vcds") .c_str()); static ImGui::FileBrowser fileBrowser; static bool first_job = true; @@ -153,11 +153,11 @@ static void selected_vcds_data(nlohmann::json const &config, ImGui::EndChild(); } -void selected_battery_measurement( +inline void selected_battery_measurement( nlohmann::json const &config, nlohmann::json const &language, nlohmann::json &metadata, std::string &inputvin, std::string &mileage, std::string &comment, std::string &api_message, bool &upload_success) { - ImGui::Text( + ImGui::TextUnformatted( load_json(language, "explanation", "upload", "battery") .c_str()); static ImGui::FileBrowser fileBrowser; @@ -333,7 +333,7 @@ static void selected_compression_data( ImGui::EndChild(); } -void popup_create_training_data_select(nlohmann::json const &config, +inline void popup_create_training_data_select(nlohmann::json const &config, nlohmann::json const &language, bool &upload_success) { diff --git a/src/get_from_github.hpp b/src/get_from_github.hpp index 472af0ed..e6221e07 100644 --- a/src/get_from_github.hpp +++ b/src/get_from_github.hpp @@ -1,84 +1,84 @@ #pragma once #include "jasonhandler.hpp" + #include #include #include #include -bool downloadFileFromGitHub(const std::string &githubUrl, - const std::string &localPath) { - // Initialisieren Sie die libcurl-Bibliothek - CURL *curl = curl_easy_init(); +inline bool downloadFileFromGitHub(std::string const& githubUrl, std::string const& localPath) { + // Initialisieren Sie die libcurl-Bibliothek + CURL* curl = curl_easy_init(); - if (curl) { - // Setzen Sie die URL - curl_easy_setopt(curl, CURLOPT_URL, githubUrl.c_str()); + if(curl) { + // Setzen Sie die URL + curl_easy_setopt(curl, CURLOPT_URL, githubUrl.c_str()); - // Setzen Sie die Schreibfunktion, um die heruntergeladene Datei zu - // speichern - FILE *file = fopen(localPath.c_str(), "wb"); + // Setzen Sie die Schreibfunktion, um die heruntergeladene Datei zu + // speichern + FILE* file = fopen(localPath.c_str(), "wb"); - if (file) { - curl_easy_setopt(curl, CURLOPT_WRITEDATA, file); + if(file) { + curl_easy_setopt(curl, CURLOPT_WRITEDATA, file); - // Führen Sie die Anfrage aus - CURLcode res = curl_easy_perform(curl); + // Führen Sie die Anfrage aus + CURLcode res = curl_easy_perform(curl); - // Überprüfen Sie den Anfragestatus - if (res != CURLE_OK) { - fmt::print("Fehler beim Herunterladen der Datei: "); - fclose(file); - curl_easy_cleanup(curl); - return false; - } + // Überprüfen Sie den Anfragestatus + if(res != CURLE_OK) { + fmt::print("Fehler beim Herunterladen der Datei: "); + fclose(file); + curl_easy_cleanup(curl); + return false; + } - // Datei schließen - fclose(file); + // Datei schließen + fclose(file); - // Rückgabe von true bei erfolgreichem Download - curl_easy_cleanup(curl); - return true; - } else { - fmt::print("Fehler beim Öffnen der lokalen Datei zum Schreiben."); + // Rückgabe von true bei erfolgreichem Download + curl_easy_cleanup(curl); + return true; + } else { + fmt::print("Fehler beim Öffnen der lokalen Datei zum Schreiben."); - curl_easy_cleanup(curl); - return false; + curl_easy_cleanup(curl); + return false; + } } - } - // Rückgabe von false bei einem Fehler - return false; + // Rückgabe von false bei einem Fehler + return false; } -bool update_config_from_github() { +inline bool update_config_from_github() { + std::filesystem::create_directories("config"); - std::filesystem::create_directories("config"); + const std::string config_url + = "https://raw.githubusercontent.com/skunkforce/" + "omniview/master/config/config.json"; + fmt::print("download config file from: {} \n\r", config_url); + bool downloaded_config = downloadFileFromGitHub(config_url, "config/config.json"); + + if(downloaded_config) { + fmt::print("download succeeded\n\r"); + } else { + fmt::print("download failed\n\r"); + } + return downloaded_config; +} +inline bool update_language_from_github() { + std::filesystem::create_directories("languages"); - const std::string config_url = "https://raw.githubusercontent.com/skunkforce/" - "omniview/master/config/config.json"; - fmt::print("download config file from: {} \n\r", config_url); - bool downloaded_config = - downloadFileFromGitHub(config_url, "config/config.json"); + const std::string lang_url + = "https://raw.githubusercontent.com/skunkforce/" + "omniview/master/languages/Deutsch.json"; + fmt::print("download language file from: {} \n\r", lang_url); + bool downloaded_langfiles = downloadFileFromGitHub(lang_url, "languages/Deutsch.json"); - if (downloaded_config) { - fmt::print("download succeeded\n\r"); - } else { - fmt::print("download failed\n\r"); - } + if(downloaded_langfiles) { + fmt::print("download succeeded\n\r"); + } else { + fmt::print("download failed\n\r"); + } + return downloaded_langfiles; } -bool update_language_from_github() { - - std::filesystem::create_directories("languages"); - - const std::string lang_url = "https://raw.githubusercontent.com/skunkforce/" - "omniview/master/languages/Deutsch.json"; - fmt::print("download language file from: {} \n\r", lang_url); - bool downloaded_langfiles = - downloadFileFromGitHub(lang_url, "languages/Deutsch.json"); - - if (downloaded_langfiles) { - fmt::print("download succeeded\n\r"); - } else { - fmt::print("download failed\n\r"); - } -} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 83faead0..6bd3438a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -24,102 +24,95 @@ #include // clang-format on -static std::vector -getAvailableLanguages(std::string const &languageFolder) { - std::vector languages; - for (auto const &entry : - std::filesystem::directory_iterator(languageFolder)) { - if (entry.is_regular_file()) { - std::string extension = entry.path().extension().string(); - if (extension == ".json") { - std::string filename = entry.path().filename().stem().string(); - languages.push_back(filename); - } +static std::vector getAvailableLanguages(std::string const& languageFolder) { + std::vector languages; + for(auto const& entry : std::filesystem::directory_iterator(languageFolder)) { + if(entry.is_regular_file()) { + std::string extension = entry.path().extension().string(); + if(extension == ".json") { + std::string filename = entry.path().filename().stem().string(); + languages.push_back(filename); + } + } } - } - return languages; + return languages; } -static void -save(std::map>> const - &alignedData, - std::filesystem::path const &outFile) { - auto minSize = std::numeric_limits::max(); - - std::vector> const *> data; - - std::string fileContent; - - for (auto sep = std::string_view{}; - auto const &[device, values] : alignedData) { - fileContent += sep; - fileContent += "\""; - fileContent += fmt::format("{}-{}", device.type, device.serial); - fileContent += "\""; - sep = ","; - minSize = std::min(values.size(), minSize); - data.push_back(std::addressof(values)); - } - fileContent += '\n'; - - for (std::size_t i{}; i < minSize; ++i) { - fileContent += fmt::format("{}", i); - fileContent += ","; - for (auto sep = std::string_view{}; auto const &vec : data) { - auto const dataPair = (*vec)[i]; - fileContent += sep; - if (dataPair.second) { - fileContent += fmt::format("{}", dataPair.second); - } - sep = ","; +static void save( + std::map>> const& alignedData, + std::filesystem::path const& outFile) { + auto minSize = std::numeric_limits::max(); + + std::vector> const*> data; + + std::string fileContent; + + for(auto sep = std::string_view{}; auto const& [device, values] : alignedData) { + fileContent += sep; + fileContent += "\""; + fileContent += fmt::format("{}-{}", device.type, device.serial); + fileContent += "\""; + sep = ","; + minSize = std::min(values.size(), minSize); + data.push_back(std::addressof(values)); } fileContent += '\n'; - } - fileContent += '\n'; + for(std::size_t i{}; i < minSize; ++i) { + fileContent += fmt::format("{}", i); + fileContent += ","; + for(auto sep = std::string_view{}; auto const& vec : data) { + auto const dataPair = (*vec)[i]; + fileContent += sep; + if(dataPair.second) { + fileContent += fmt::format("{}", dataPair.second); + } + sep = ","; + } + fileContent += '\n'; + } + + fileContent += '\n'; - auto path = outFile; - path.remove_filename(); - if (!std::filesystem::exists(path) && !path.empty()) { - std::filesystem::create_directories(path); - } + auto path = outFile; + path.remove_filename(); + if(!std::filesystem::exists(path) && !path.empty()) { + std::filesystem::create_directories(path); + } - fmt::print("start save {}\n", outFile.string()); - std::ofstream file{outFile}; - // fmt::print("{}\n", fileContent); - file << fileContent; - file.flush(); - file.close(); + fmt::print("start save {}\n", outFile.string()); + std::ofstream file{outFile}; + // fmt::print("{}\n", fileContent); + file << fileContent; + file.flush(); + file.close(); - fmt::print("finished save\n"); + fmt::print("finished save\n"); } -static void set_button_style_to(nlohmann::json const &config, - std::string const &name) { - ImGui::PushStyleColor( +static void set_button_style_to(nlohmann::json const& config, std::string const& name) { + ImGui::PushStyleColor( ImGuiCol_Button, ImVec4(load_json(config, "button", name, "normal"))); - ImGui::PushStyleColor( + ImGui::PushStyleColor( ImGuiCol_ButtonHovered, ImVec4(load_json(config, "button", name, "hover"))); - ImGui::PushStyleColor( + ImGui::PushStyleColor( ImGuiCol_ButtonActive, ImVec4(load_json(config, "button", name, "active"))); } -static void load_settings(nlohmann::json const &config) { - ImGui::PushStyleColor(ImGuiCol_MenuBarBg, - ImVec4(load_json(config, "menubar", "main"))); - ImGui::PushStyleColor(ImGuiCol_PopupBg, - ImVec4(load_json(config, "menubar", "popup"))); - ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(load_json( - config, "text", "color", "normal"))); - ImGui::PushStyleColor(ImGuiCol_WindowBg, - ImVec4(load_json(config, "window", "color"))); - set_button_style_to(config, "standart"); - - ImGuiIO &io = ImGui::GetIO(); - io.FontGlobalScale = load_json(config, "text", "scale"); +static void load_settings(nlohmann::json const& config) { + ImGui::PushStyleColor(ImGuiCol_MenuBarBg, ImVec4(load_json(config, "menubar", "main"))); + ImGui::PushStyleColor(ImGuiCol_PopupBg, ImVec4(load_json(config, "menubar", "popup"))); + ImGui::PushStyleColor( + ImGuiCol_Text, + ImVec4(load_json(config, "text", "color", "normal"))); + ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(load_json(config, "window", "color"))); + set_button_style_to(config, "standart"); + + ImGuiIO& io = ImGui::GetIO(); + io.FontGlobalScale = load_json(config, "text", "scale"); } // ########################################################################### @@ -127,159 +120,185 @@ static void load_settings(nlohmann::json const &config) { // ########################################################################### int main() { + nlohmann::json config; + const std::string configpath = "config/config.json"; + if(std::filesystem::exists(configpath)) { + fmt::print("found config.json\n\r"); - nlohmann::json config; - const std::string configpath = "config/config.json"; - 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(); - } - config = load_json_file(configpath); - if (std::filesystem::exists( - load_json(config, ("languagepath")))) { - fmt::print("found language: {}\n\r", - load_json(config, ("language"))); - - } else { - fmt::print("Did not find {}.\n Download from Github\n\r", - load_json(config, ("language"))); - update_language_from_github(); - } - - std::vector availableLanguages = - getAvailableLanguages(load_json(config, ("languagepath"))); - - nlohmann::json language = - load_json_file(load_json(config, "languagepath") + - load_json(config, "language") + ".json"); - - static constexpr int VID = 0x2e8au; - static constexpr int PID = 0x000au; - // static constexpr std::size_t captureDataReserve = 1 << 26; - OmniscopeDeviceManager deviceManager{}; - std::vector> - devices; // = deviceManager.getDevices(VID, PID); - // auto newDevices = devices; - - // auto startTimepoint = std::chrono::system_clock::now(); - 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}; - static bool open_settings = false; - - static bool upload_success = false; - - static ImVec2 mainMenuBarSize; - std::optional sampler{}; - std::map>> captureData; - - std::map> colorMap; - - std::string path; - path.resize(256); - - auto addPlots = [&, firstRun = std::set{}]( - auto const &name, auto const &plots, - auto axesSetup) mutable { - auto const plotRegion = ImGui::GetContentRegionAvail(); - if (ImPlot::BeginPlot(name, plotRegion)) { - 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_min, x_max); + } else { + fmt::print("Did not find config.json.\n Download from Github\n\r"); + update_config_from_github(); + } + config = load_json_file(configpath); + if(std::filesystem::exists(load_json(config, ("languagepath")))) { + fmt::print("found language: {}\n\r", load_json(config, ("language"))); - 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) { - 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; - }(); - - 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; - }(); - 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); - }(); - - 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); - } - }; + } else { + fmt::print( + "Did not find {}.\n Download from Github\n\r", + load_json(config, ("language"))); + update_language_from_github(); + } - for (auto const &plot : plots) { - ImPlot::SetNextLineStyle(ImVec4{colorMap[plot.first][0], - colorMap[plot.first][1], - colorMap[plot.first][2], 1.0f}); - addPlot(plot); - } + std::vector availableLanguages + = getAvailableLanguages(load_json(config, ("languagepath"))); + + nlohmann::json language = load_json_file( + load_json(config, "languagepath") + load_json(config, "language") + + ".json"); + + static constexpr int VID = 0x2e8au; + static constexpr int PID = 0x000au; + // static constexpr std::size_t captureDataReserve = 1 << 26; + OmniscopeDeviceManager deviceManager{}; + std::vector> + devices; // = deviceManager.getDevices(VID, PID); + // auto newDevices = devices; + std::map> colorMap; + auto initDevices = [&]() { + devices = deviceManager.getDevices(VID, PID); - ImPlot::EndPlot(); - } - }; - - auto render = [&]() { - load_settings(config); - ImGui::SetNextWindowPos(ImVec2(0.0f, mainMenuBarSize.y)); - ImGui::SetNextWindowSize(ImGui::GetIO().DisplaySize); - ImGui::Begin("OmniScopev2 Data Capture Tool", nullptr, - ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | - ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove); // - - // ############################ Menu bar ############################## - // main menu - ImGui::BeginMainMenuBar(); - if (ImGui::BeginMenu( - load_json(language, "menubar", "menu", "label") - .c_str())) { - if (ImGui::BeginMenu(load_json(language, "menubar", "menu", - "language_option") - .c_str())) { - for (const auto &lang : availableLanguages) { - if (ImGui::MenuItem(lang.c_str())) { - config["language"] = lang; - write_json_file(configpath, config); - } + for(auto& device : devices) { + auto id = device->getId().value(); + 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)}); } + }; + + // auto startTimepoint = std::chrono::system_clock::now(); + 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}; + static bool open_settings = false; + static bool upload_success = false; + static ImVec2 mainMenuBarSize; + std::optional sampler{}; + std::map>> captureData; + + std::string path; + path.resize(256); + + auto addPlots + = [&, + firstRun + = std::set{}](auto const& name, auto const& plots, auto axesSetup) mutable { + auto const plotRegion = ImGui::GetContentRegionAvail(); + if(ImPlot::BeginPlot(name, plotRegion)) { + 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_min, 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) { + 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; + }(); + + 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; + }(); + + 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); + }(); + + 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) { + ImPlot::SetNextLineStyle(ImVec4{ + colorMap[plot.first][0], + colorMap[plot.first][1], + colorMap[plot.first][2], + 1.0f}); + addPlot(plot); + } + + ImPlot::EndPlot(); + } + }; + + auto render = [&]() { + load_settings(config); + ImGui::SetNextWindowPos(ImVec2(0.0f, mainMenuBarSize.y)); + ImGui::SetNextWindowSize(ImGui::GetIO().DisplaySize); + ImGui::Begin( + "OmniScopev2 Data Capture Tool", + nullptr, + ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize + | ImGuiWindowFlags_NoMove); // + + // ############################ Menu bar ############################## + // main menu + ImGui::BeginMainMenuBar(); + if(ImGui::BeginMenu(load_json(language, "menubar", "menu", "label").c_str())) { + if(ImGui::BeginMenu( + load_json(language, "menubar", "menu", "language_option").c_str())) + { + for(const auto& lang : availableLanguages) { + if(ImGui::MenuItem(lang.c_str())) { + config["language"] = lang; + write_json_file(configpath, config); + } + } + + ImGui::EndMenu(); } @@ -317,316 +336,341 @@ int main() { mainMenuBarSize = ImGui::GetItemRectSize(); ImGui::EndMainMenuBar(); - // ############################ Live Capture - // ############################## - ImGui::BeginChild("Live Capture", ImVec2(-1, 620)); - if (sampler.has_value()) { - sampler->copyOut(captureData); - } + + // ############################ Live Capture + // ############################## + ImGui::BeginChild("Live Capture", ImVec2(-1, 620)); + if(sampler.has_value()) { + sampler->copyOut(captureData); + } - addPlots("Aufnahme der Daten", captureData, - [&sampler, &xmax_paused](auto /*x_min*/, auto x_max) { - if (sampler.has_value()) { - ImPlot::SetupAxes("x [Datenpunkte]", "y [ADC Wert]", - ImPlotAxisFlags_AutoFit, - ImPlotAxisFlags_AutoFit); - ImPlot::SetupAxisLimits(ImAxis_X1, x_max - 7500, x_max + 7500, - ImGuiCond_Always); - } else { - xmax_paused = x_max; - ImPlot::SetupAxes("x [Datenpunkte]", "y [ADC Wert]", 0, 0); - } - }); - - ImGui::EndChild(); - float optimal_buttonstripe_height; - if (load_json(config, "button", "sizey") < - (ImGui::GetTextLineHeightWithSpacing() * 1.1)) { - optimal_buttonstripe_height = - (ImGui::GetTextLineHeightWithSpacing() * 1.1); - } else { - optimal_buttonstripe_height = - load_json(config, "button", "sizey") * 1.1; - } - ImGui::BeginChild("Buttonstripe", ImVec2(-1, optimal_buttonstripe_height), - false, ImGuiWindowFlags_NoScrollbar); - - // ############################ Popup Speichern - // ############################## - if (ImGui::BeginPopupModal("Speichern der aufgenommenen Daten", nullptr, - ImGuiWindowFlags_AlwaysAutoResize)) { - ImGui::SetItemDefaultFocus(); - - static char inputvin[18] = ""; - static char mileage[10] = ""; - static char scantype[255] = ""; - ImGui::SetItemDefaultFocus(); - ImGui::InputText( - load_json(language, "input", "fin", "label").c_str(), - inputvin, sizeof(inputvin)); - ImGui::InputText( - load_json(language, "input", "scantype", "label") - .c_str(), - scantype, sizeof(scantype)); - - ImGui::InputText( - load_json(language, "input", "mileage", "label").c_str(), - mileage, sizeof(mileage)); - - if (ImGui::Button( - load_json(language, "button", "save").c_str(), - ImVec2(load_json(config, "button")))) { - 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_view path_sv{path.data()}; - std::string filename{ - fmt::format("{}-{:%Y-%m-%dT%H-%M}.csv", mileage, now)}; - std::filesystem::path path_path = path_sv; - if (captureData.empty()) { - ImGui::CloseCurrentPopup(); + addPlots( + "Aufnahme der Daten", + captureData, + [&sampler, &xmax_paused](auto /*x_min*/, auto x_max) { + if(sampler.has_value()) { + ImPlot::SetupAxes( + "x [Datenpunkte]", + "y [ADC Wert]", + ImPlotAxisFlags_AutoFit, + ImPlotAxisFlags_AutoFit); + ImPlot::SetupAxisLimits(ImAxis_X1, x_max - 7500, x_max + 7500, ImGuiCond_Always); + } else { + xmax_paused = x_max; + ImPlot::SetupAxes("x [Datenpunkte]", "y [ADC Wert]", 0, 0); + } + }); + + ImGui::EndChild(); + float optimal_buttonstripe_height; + if( + load_json(config, "button", "sizey") + < (ImGui::GetTextLineHeightWithSpacing() * 1.1)) + { + optimal_buttonstripe_height = (ImGui::GetTextLineHeightWithSpacing() * 1.1); } else { - // create the given folder_structure - std::filesystem::path first_folder = - load_json(config, "scanfolder"); - std::filesystem::path complete_path = - first_folder / inputvin / scantype; - std::filesystem::create_directories(complete_path); - - save(captureData, path_path / complete_path / filename); - - // nicht mehr im save-kontext, sondern in create training - // data send_to_api(config, path_path / filename, inputvin, - // scantype); - ImGui::CloseCurrentPopup(); - } - } - ImGui::SameLine(); - if (ImGui::Button( - load_json(language, "button", "back").c_str(), - ImVec2(load_json(config, "button")))) { - ImGui::CloseCurrentPopup(); - } + optimal_buttonstripe_height = load_json(config, "button", "sizey") * 1.1; - ImGui::EndPopup(); - } - ImGui::SetNextWindowPos(ImVec2(0, 100)); - ImGui::SetNextWindowSize(ImVec2(0, 800)); - if (!sampler.has_value()) { - if (ImGui::BeginPopupModal("Erstellung Lerndatensatz", nullptr, - ImGuiWindowFlags_AlwaysAutoResize | - ImGuiWindowFlags_NoSavedSettings | - ImGuiWindowFlags_NoMove)) { - ImGui::SetItemDefaultFocus(); - - popup_create_training_data_select(config, language, upload_success); - ImGui::EndPopup(); - } - if (upload_success == true) { - ImGui::OpenPopup("##upload_success"); - } - if (ImGui::BeginPopupModal("##upload_success", nullptr, - ImGuiWindowFlags_AlwaysAutoResize | - ImGuiWindowFlags_NoSavedSettings | - ImGuiWindowFlags_NoMove)) { - ImGui::Text( - load_json(language, "training", "upload_success") - .c_str()); - if (ImGui::Button( - load_json(language, "button", "ok").c_str())) { - ImGui::CloseCurrentPopup(); - upload_success = false; } + ImGui::BeginChild( + "Buttonstripe", + ImVec2(-1, optimal_buttonstripe_height), + false, + ImGuiWindowFlags_NoScrollbar); - ImGui::SetItemDefaultFocus(); - ImGui::EndPopup(); - } - // Start nur wenn Devices vorhanden soind, sonst Suche Geräte - if (ImGui::Button("Suche Geräte", - ImVec2(load_json(config, "button")))) { - devices.clear(); - deviceManager.clearDevices(); - devices = deviceManager.getDevices(VID, PID); + // ############################ Popup Speichern + // ############################## + if(ImGui::BeginPopupModal( + "Speichern der aufgenommenen Daten", + nullptr, + ImGuiWindowFlags_AlwaysAutoResize)) + { + ImGui::SetItemDefaultFocus(); + + static char inputvin[18] = ""; + static char mileage[10] = ""; + static char scantype[255] = ""; + ImGui::SetItemDefaultFocus(); + ImGui::InputText( + load_json(language, "input", "fin", "label").c_str(), + inputvin, + sizeof(inputvin)); + ImGui::InputText( + load_json(language, "input", "scantype", "label").c_str(), + scantype, + sizeof(scantype)); + ImGui::InputText( + load_json(language, "input", "mileage", "label").c_str(), + mileage, + sizeof(mileage)); + + if(ImGui::Button( + load_json(language, "button", "save").c_str(), + ImVec2(load_json(config, "button")))) + { + 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_view path_sv{path.data()}; + std::string filename{fmt::format("{}-{:%Y-%m-%dT%H-%M}.csv", mileage, now)}; + std::filesystem::path path_path = path_sv; + if(captureData.empty()) { + ImGui::CloseCurrentPopup(); + } else { + // create the given folder_structure + std::filesystem::path first_folder + = load_json(config, "scanfolder"); + std::filesystem::path complete_path = first_folder / inputvin / scantype; + std::filesystem::create_directories(complete_path); + + save(captureData, path_path / complete_path / filename); + + // nicht mehr im save-kontext, sondern in create training + // data send_to_api(config, path_path / filename, inputvin, + // scantype); + ImGui::CloseCurrentPopup(); + } + } + ImGui::SameLine(); + if(ImGui::Button( + load_json(language, "button", "back").c_str(), + ImVec2(load_json(config, "button")))) + { + ImGui::CloseCurrentPopup(); + } - for (auto &device : devices) { - auto id = device->getId().value(); - if (!colorMap.contains(id)) { - ImPlot::PushColormap(ImPlotColormap_Dark); - auto c = ImPlot::GetColormapColor(colorMap.size()); - colorMap[id] = std::array{c.x, c.y, c.z}; - ImPlot::PopColormap(); - } - - auto &color = colorMap[id]; - fmt::print("col {}\n", color); - device->send( - Omniscope::SetRgb{static_cast(color[0] * 255), - static_cast(color[1] * 255), - static_cast(color[2] * 255)}); + ImGui::EndPopup(); } - } + ImGui::SetNextWindowPos(ImVec2(0, 100)); + ImGui::SetNextWindowSize(ImVec2(0, 800)); + if(!sampler.has_value()) { + if(ImGui::BeginPopupModal( + "Erstellung Lerndatensatz", + nullptr, + ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings + | ImGuiWindowFlags_NoMove)) + { + ImGui::SetItemDefaultFocus(); + + popup_create_training_data_select(config, language, upload_success); + ImGui::EndPopup(); + } + if(upload_success == true) { + ImGui::OpenPopup("upload_success"); + } + if(ImGui::BeginPopupModal( + "upload_success", + nullptr, + ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings + | ImGuiWindowFlags_NoMove)) + { + ImGui::TextUnformatted( + load_json(language, "training", "upload_success").c_str()); + if(ImGui::Button(load_json(language, "button", "ok").c_str())) { + ImGui::CloseCurrentPopup(); + upload_success = false; + } + + ImGui::SetItemDefaultFocus(); + ImGui::EndPopup(); + } + // Start nur wenn Devices vorhanden soind, sonst Suche Geräte + if(ImGui::Button("Suche Geräte", ImVec2(load_json(config, "button")))) { + devices.clear(); + deviceManager.clearDevices(); + initDevices(); + } - if (!devices.empty()) { - ImGui::SameLine(); - // ############################ Start Button + if(!devices.empty()) { + ImGui::SameLine(); + // ############################ Start Button + // ############################## + set_button_style_to(config, "start"); + if(ImGui::Button( + load_json(language, "button", "start").c_str(), + ImVec2(load_json(config, "button")))) + { + // sampler anlegen + // std::optinal sampler{}; + sampler.emplace(deviceManager, std::move(devices)); + } + ImGui::PopStyleColor(3); + } + // set_button_style_to(config, "standart"); + } else { + // ############################ Stop Button + // ############################## + set_button_style_to(config, "stop"); + if(ImGui::Button( + load_json(language, "button", "stop").c_str(), + ImVec2(load_json(config, "button")))) + { + sampler.reset(); + devices.clear(); + deviceManager.clearDevices(); + initDevices(); + } + ImGui::PopStyleColor(3); + // set_button_style_to(config, "standart"); + } + if(!sampler.has_value()) { + ImGui::SameLine(); + if(ImGui::Button( + load_json(language, "button", "save").c_str(), + ImVec2(load_json(config, "button")))) + { + // savecontext = true;//Opens new overlay + + ImGui::OpenPopup("Speichern der aufgenommenen Daten"); + } + ImGui::SameLine(); + ImGui::PushStyleColor( + ImGuiCol_Text, + load_json(config, "text", "color", "inactive")); + // ImGui::FileBrowser fileBrowser; + if(ImGui::Button( + load_json(language, "button", "analyse_data").c_str(), + ImVec2(load_json(config, "button")))) + { + // fileBrowser.Open(); + } + /* + //fileBrowser.Display(); + if (fileBrowser.HasSelected()) { + // Hier kannst du auf die ausgewählten Dateien zugreifen + for (const auto &selectedFile : fileBrowser.GetSelected()) { + std::string filename = selectedFile.string(); + // Verarbeite die ausgewählte Datei + // ... + } + + fileBrowser.ClearSelected(); + } + */ + ImGui::PopStyleColor(); + ImGui::PushStyleColor( + ImGuiCol_Text, + load_json(config, "text", "color", "normal")); + ImGui::SameLine(); + + // ############################ Button create trainings data + // ############################## + if(ImGui::Button( + load_json(language, "button", "create_training_data").c_str(), + ImVec2(load_json(config, "button")))) + { + ImGui::SetNextWindowPos(ImVec2(0, 0)); + ImGui::SetNextWindowSize(ImVec2(0, 0)); + ImGui::OpenPopup("Erstellung Lerndatensatz"); + } + ImGui::PopStyleColor(); + } else { + ImGui::SameLine(); + ImGui::PushStyleColor( + ImGuiCol_Text, + load_json(config, "text", "color", "inactive")); + if(ImGui::Button( + load_json(language, "button", "save").c_str(), + ImVec2(load_json(config, "button")))) + {} + ImGui::SameLine(); + if(ImGui::Button( + load_json(language, "button", "analyse_data").c_str(), + ImVec2(load_json(config, "button")))) + {} + ImGui::SameLine(); + if(ImGui::Button( + load_json(language, "button", "create_training_data").c_str(), + ImVec2(load_json(config, "button")))) + {} + ImGui::PopStyleColor(); + } + ImGui::EndChild(); + // ############################ Settings Menu // ############################## - set_button_style_to(config, "start"); - if (ImGui::Button( - load_json(language, "button", "start").c_str(), - ImVec2(load_json(config, "button")))) { - // sampler anlegen - // std::optinal sampler{}; - sampler.emplace(deviceManager, std::move(devices)); + std::string settingstitle = load_json(language, "settings", "title"); + if(open_settings == true) { + 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(); } - ImGui::PopStyleColor(3); - } - // set_button_style_to(config, "standart"); - } else { - // ############################ Stop Button - // ############################## - set_button_style_to(config, "stop"); - if (ImGui::Button( - load_json(language, "button", "stop").c_str(), - ImVec2(load_json(config, "button")))) { - sampler.reset(); - } - ImGui::PopStyleColor(3); - // set_button_style_to(config, "standart"); - } - if (!sampler.has_value()) { - ImGui::SameLine(); - if (ImGui::Button( - load_json(language, "button", "save").c_str(), - ImVec2(load_json(config, "button")))) { - // savecontext = true;//Opens new overlay - - ImGui::OpenPopup("Speichern der aufgenommenen Daten"); - } - ImGui::SameLine(); - ImGui::PushStyleColor( - ImGuiCol_Text, load_json(config, "text", "color", "inactive")); - // ImGui::FileBrowser fileBrowser; - if (ImGui::Button( - load_json(language, "button", "analyse_data") - .c_str(), - ImVec2(load_json(config, "button")))) { - // fileBrowser.Open(); - } - /* - //fileBrowser.Display(); - if (fileBrowser.HasSelected()) { - // Hier kannst du auf die ausgewählten Dateien zugreifen - for (const auto &selectedFile : fileBrowser.GetSelected()) { - std::string filename = selectedFile.string(); - // Verarbeite die ausgewählte Datei - // ... - } - - fileBrowser.ClearSelected(); - } - */ - ImGui::PopStyleColor(); - ImGui::PushStyleColor( - ImGuiCol_Text, load_json(config, "text", "color", "normal")); - ImGui::SameLine(); - - // ############################ Button create trainings data - // ############################## - if (ImGui::Button( - load_json(language, "button", "create_training_data") - .c_str(), - ImVec2(load_json(config, "button")))) { - ImGui::SetNextWindowPos(ImVec2(0, 0)); - ImGui::SetNextWindowSize(ImVec2(0, 0)); - ImGui::OpenPopup("Erstellung Lerndatensatz"); - } - ImGui::PopStyleColor(); - } else { - ImGui::SameLine(); - ImGui::PushStyleColor( - ImGuiCol_Text, load_json(config, "text", "color", "inactive")); - if (ImGui::Button( - load_json(language, "button", "save").c_str(), - ImVec2(load_json(config, "button")))) { - } - ImGui::SameLine(); - if (ImGui::Button( - load_json(language, "button", "analyse_data") - .c_str(), - ImVec2(load_json(config, "button")))) { - } - ImGui::SameLine(); - if (ImGui::Button( - load_json(language, "button", "create_training_data") - .c_str(), - ImVec2(load_json(config, "button")))) { - } - ImGui::PopStyleColor(); - } - ImGui::EndChild(); - // ############################ Settings Menu - // ############################## - std::string settingstitle = - load_json(language, "settings", "title"); - if (open_settings == true) { - 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(); - } - // ############################ Devicelist - // ############################## - ImGui::BeginChild("Devicelist", ImVec2(-1, 0)); - // ImVec2 center = ImGui::GetMainViewport()->GetCenter(); - // ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, - // ImVec2(0.5f, 0.5f)); - - ImGui::Text("gefundene Geräte:"); - if (ImGui::BeginListBox("##", ImVec2(1024, -1))) { - for (auto &device : devices) { - 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)}); + // ############################ Devicelist + // ############################## + ImGui::BeginChild("Devicelist", ImVec2(-1, 0)); + // ImVec2 center = ImGui::GetMainViewport()->GetCenter(); + // ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, + // ImVec2(0.5f, 0.5f)); + + ImGui::Text("gefundene Geräte:"); + if(ImGui::BeginListBox("##", ImVec2(1024, -1))) { + 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(fmt::format("Fehler").c_str()); + } + }; + + if(sampler.has_value()) { + for(auto& device : sampler->sampleDevices) { + doDevice(device.first, "Messung"); + } + } else { + for(auto& device : devices) { + doDevice(device, "Bereit"); + } + } + ImGui::EndListBox(); } + ImGui::EndChild(); 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::EndListBox(); + ImGui::End(); + ImGui::PopStyleColor(7); + }; + + ImGuiInstance window{1920, 1080, load_json(config, "title")}; + while(window.run(render)) { } - ImGui::EndChild(); - ImGui::SameLine(); - ImGui::End(); - ImGui::PopStyleColor(7); - }; - - ImGuiInstance window{1920, 1080, load_json(config, "title")}; - while (window.run(render)) { - } - return 0; + return 0; } diff --git a/src/settingspopup.hpp b/src/settingspopup.hpp index dd61ab4f..828e6bcb 100644 --- a/src/settingspopup.hpp +++ b/src/settingspopup.hpp @@ -38,9 +38,9 @@ static void popup_settings(nlohmann::json &config, nlohmann::json &language, // #################################################################################### static float ButtonSizeX = load_json(config, "button", "sizex"); static float ButtonSizeY = load_json(config, "button", "sizey"); - ImGui::Text( + ImGui::TextUnformatted( load_json(language, "settings", "buttonexplain").c_str()); - ImGui::Text(load_json(language, "general", "width").c_str()); + ImGui::TextUnformatted(load_json(language, "general", "width").c_str()); ImGui::SameLine(); float oldButtonSizeX = ButtonSizeX; @@ -56,7 +56,7 @@ static void popup_settings(nlohmann::json &config, nlohmann::json &language, if (ImGui::Button("X-")) { ButtonSizeX -= 10.0f; } - ImGui::Text(load_json(language, "general", "height").c_str()); + ImGui::TextUnformatted(load_json(language, "general", "height").c_str()); ImGui::SameLine(); ImGui::InputFloat("Y##ButtonSizeY",