From b60c437dadf0d7fdbb1b5b0581b14139ed2ce4eb Mon Sep 17 00:00:00 2001 From: R-Abbasi Date: Mon, 2 Sep 2024 03:44:21 -0400 Subject: [PATCH] save calibrated values --- src/saves_popup.cpp | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/saves_popup.cpp b/src/saves_popup.cpp index f667a481..e218bea9 100644 --- a/src/saves_popup.cpp +++ b/src/saves_popup.cpp @@ -17,16 +17,21 @@ static void save(const Omniscope::Id &device, device.sampleRate); std::string fileContent; fileContent.resize_and_overwrite( - // four bytes for each y_value, three for the number - // and one new line as a separator between the numbers - values.size() * 4, [&values, &y_indx](char *begin, std::size_t) { - auto end = begin; - for (; y_indx < values.size(); y_indx++) { - end = std::to_chars(end, end + 3, values[y_indx].second).ptr; - *end++ = '\n'; - } - return end - begin; - }); + // ten bytes for each y_value, nine for the number + // and one new line as a separator between the numbers + values.size() * 10, // take const ref to values + [&values = std::as_const(values), &y_indx](char *begin, std::size_t) { + auto end = begin; + constexpr unsigned factor{100'000}; + for (; y_indx < values.size(); y_indx++) { + double value = values[y_indx].second * factor; + value = std::floor(value); + value /= factor; + end = std::to_chars(end, end + 9, value).ptr; + *end++ = '\n'; + } + return end - begin; + }); // create a .csv file to write to it std::ofstream file(outFile, std::ios::app); if (!file.is_open()) {