diff --git a/src/handler.cpp b/src/handler.cpp index 4f101d46..14e6e8fe 100644 --- a/src/handler.cpp +++ b/src/handler.cpp @@ -1,15 +1,15 @@ #include "handler.hpp" +#include "../imgui-stdlib/imgui_stdlib.h" +#include "get_from_github.hpp" +#include "popups.hpp" #include -#include #include -#include "popups.hpp" -#include "get_from_github.hpp" -#include "../imgui-stdlib/imgui_stdlib.h" +#include struct AxisInfo { const std::pair> &> data; std::pair egu; - std::string timebase; // store sampleRate + std::string timebase; AxisInfo( const std::pair> &> @@ -39,14 +39,14 @@ static std::vector getDeviceInfos() { static_assert((ImAxis_Y1 + 1) == ImAxis_Y2); ImAxis_ nextYAxis = static_cast(ImAxis_Y1 + assignedEgus.size()); - assignedEgus.push_back({egu, nextYAxis}); + assignedEgus.push_back(std::make_pair(egu, nextYAxis)); } else { - fmt::println("too many Axes added, egu not added: " - "{}\nDevice id: {}", - egu, id.value()); + fmt::print("too many Axes added, egu not added: " + "{}\nDevice id: {}", + egu, id.value()); break; } - axisInfos.push_back({{deviceId, captureData[deviceId]}, + axisInfos.push_back({{deviceId, std::ref(captureData[deviceId])}, assignedEgus.back(), std::to_string(deviceId.sampleRate)}); } @@ -55,7 +55,8 @@ static std::vector getDeviceInfos() { } // also get loaded files info for (auto &[device, values] : captureData) - if (!std::ranges::contains(samplerDvcs, device)) + if (std::ranges::find(samplerDvcs, device.serial, &Omniscope::Id::serial) == + samplerDvcs.end()) axisInfos.push_back({{device, values}, {"y [Volts]", ImAxis_Y1}, std::to_string(device.sampleRate)}); @@ -74,16 +75,17 @@ void addPlots(const char *name, double x_min = std::numeric_limits::max(); double x_max = std::numeric_limits::min(); - for (auto const &axes : plotAxes) { - x_max = std::max(x_max, axes.data.second.back().first); - // TODO save max and min value over same axis - // find first and last pairs of values - 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); - axesSetup(x_max, axes.egu.first, axes.egu.second, yMin, yMax); - } + 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 + 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 = [&]() { if (!firstRun.contains(name)) { @@ -132,16 +134,16 @@ void addPlots(const char *name, } } -static void parseDeviceMetaData(Omniscope::MetaData metaData, - std::shared_ptr &device) { +void parseDeviceMetaData(Omniscope::MetaData metaData, + std::shared_ptr &device) { try { - nlohmann::json metaJson = metaData.data; - fmt::println("metaJson content is: {}", metaJson.dump()); - device->setScale(metaJson["scale"]); - device->setOffset(metaJson["offset"]); + nlohmann::json metaJson = nlohmann::json::parse(metaData.data); + fmt::println("{}", metaJson.dump()); + device->setScale(std::stod(metaJson["scale"].dump())); + device->setOffset(std::stod(metaJson["offset"].dump())); device->setEgu(metaJson["egu"]); } catch (...) { - fmt::println("Parsing Meta Data error: {}", metaData.data); + fmt::print("parsing Meta Data error: {}", metaData.data); } } @@ -158,7 +160,7 @@ void initDevices() { }; auto id = device->getId().value(); auto sampleRate = static_cast(id.sampleRate); - device->setTimeScale(1 / sampleRate); + device->setTimeScale(static_cast(1 / sampleRate)); if (!colorMap.contains(id)) { ImPlot::PushColormap(ImPlotColormap_Dark); auto c = ImPlot::GetColormapColor((colorMap.size() % 7) + 1); @@ -209,10 +211,11 @@ void devicesList(bool const &flagPaused) { if (sampler.has_value()) for (auto &device : sampler->sampleDevices) { - if (!flagPaused) + if (!flagPaused) { doDevice(device.first, appLanguage[Key::Measurement]); - else + } else { doDevice(device.first, appLanguage[Key::Stop]); + } } else for (auto &device : devices) @@ -245,6 +248,7 @@ void load_files(decltype(captureData) &loadedFiles, } // each y-value is recorded at 1/sampleRate time double step{0.00001}, base{step}; + size_t indx{2}; // y_values start from line 2 of the file while (!readfile.eof()) { // fill the vector of the values double value{}; readfile >> value; @@ -313,21 +317,21 @@ void load_files(decltype(captureData) &loadedFiles, } } -void set_config(std::string_view configpath) { +void set_config(const std::string &configpath) { if (fs::exists(configpath)) - fmt::println("Found config.json\r"); + fmt::print("found config.json\n\r"); else { - fmt::println("Did not find config.json.\nDownload from Github\r"); + fmt::print("Did not find config.json.\n Download from Github\n\r"); update_config_from_github(); } } -void set_json(const nlohmann::json &config) { - if (fs::exists(load_json(config, "languagepath"))) - fmt::println("Found language: {}\r", appLanguage[Key::German]); +void set_json(nlohmann::json &config) { + if (fs::exists(load_json(config, ("languagepath")))) + fmt::print("Found language: {}\n\r", appLanguage[Key::German]); else { - fmt::println("Did not find {}.\nDownload from Github\n", - appLanguage[Key::German]); + fmt::print("Did not find {}.\n Download from Github\n\r", + appLanguage[Key::German]); update_language_from_github(); } } diff --git a/src/handler.hpp b/src/handler.hpp index 49ce0340..f5daa0c9 100644 --- a/src/handler.hpp +++ b/src/handler.hpp @@ -17,16 +17,19 @@ inline std::set savedFileNames; // unique and ordered filenames inline std::optional sampler{}; inline std::map>> captureData; + void addPlots( const char *, std::function); +void parseDeviceMetaData(Omniscope::MetaData, + std::shared_ptr &); void initDevices(); void devicesList(bool const &flagPaused); void load_files(decltype(captureData) &, std::map &, bool &); -void set_config(std::string_view); -void set_json(const nlohmann::json &); +void set_config(const std::string &); +void set_json(nlohmann::json &); void set_inital_config(nlohmann::json &); void rstSettings(const decltype(captureData) &); -#endif \ No newline at end of file +#endif diff --git a/src/main.cpp b/src/main.cpp index 49d82f77..e3d1f8dc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -94,9 +94,9 @@ int main() { [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; + // auto auxFlagsMeasuring = + // ImPlotAxisFlags_AutoFit | ImPlotAxisFlags_NoGridLines; + // auto auxFlagsPaused = ImPlotAxisFlags_NoGridLines; ImPlot::SetupAxisTicks(ImAxis_Y1, -10, 200, 22, nullptr, true); if (!flagPaused) {