diff --git a/README.md b/README.md index 14bf86a0..463c96c7 100644 --- a/README.md +++ b/README.md @@ -29,8 +29,13 @@ A 3d-printable housing can be found here: https://www.thingiverse.com/thing:4571 -##### Rolling - (2020-09-12) +##### Rolling - (2020-09-13) +* Implementation of decimal shift (New Parameter "DecimalShift = 1" in [PostProcessing]) +DecimalShift = 1 --> Result: 123.456 --> 1234.56 + DecimalShift = -1 --> Result: 12.3456 + The shift is done at the very first step of merging digital and analog, so all following number already will work on the shifted number. + * based on v2.0.0 (2020-09-12) diff --git a/code/lib/jomjol_flowcontroll/ClassFlowPostProcessing.cpp b/code/lib/jomjol_flowcontroll/ClassFlowPostProcessing.cpp index c2bff2ff..87ca3fb3 100644 --- a/code/lib/jomjol_flowcontroll/ClassFlowPostProcessing.cpp +++ b/code/lib/jomjol_flowcontroll/ClassFlowPostProcessing.cpp @@ -135,6 +135,7 @@ ClassFlowPostProcessing::ClassFlowPostProcessing() PreValueOkay = false; useMaxRateValue = false; checkDigitIncreaseConsistency = false; + DecimalShift = 0; FilePreValue = FormatFileName("/sdcard/config/prevalue.ini"); } @@ -148,11 +149,13 @@ ClassFlowPostProcessing::ClassFlowPostProcessing(std::vector* lfc) ListFlowControll = NULL; PreValueOkay = false; useMaxRateValue = false; - checkDigitIncreaseConsistency = false; + checkDigitIncreaseConsistency = false; + DecimalShift = 0; FilePreValue = FormatFileName("/sdcard/config/prevalue.ini"); ListFlowControll = lfc; } + bool ClassFlowPostProcessing::ReadParameter(FILE* pfile, string& aktparamgraph) { std::vector zerlegt; @@ -170,34 +173,39 @@ bool ClassFlowPostProcessing::ReadParameter(FILE* pfile, string& aktparamgraph) while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph)) { zerlegt = this->ZerlegeZeile(aktparamgraph); - if ((zerlegt[0] == "PreValueUse") && (zerlegt.size() > 1)) + if ((toUpper(zerlegt[0]) == "DECIMALSHIFT") && (zerlegt.size() > 1)) { - if ((zerlegt[1] == "True") || (zerlegt[1] == "true")) + DecimalShift = stoi(zerlegt[1]); + } + + if ((toUpper(zerlegt[0]) == "PREVALUEUSE") && (zerlegt.size() > 1)) + { + if (toUpper(zerlegt[1]) == "TRUE") { PreValueUse = true; PreValueOkay = LoadPreValue(); } } - if ((zerlegt[0] == "CheckDigitIncreaseConsistency") && (zerlegt.size() > 1)) + if ((toUpper(zerlegt[0]) == "CHECKDIGITINCREASECONSISTENCY") && (zerlegt.size() > 1)) { if (toUpper(zerlegt[1]) == "TRUE") checkDigitIncreaseConsistency = true; } - if ((zerlegt[0] == "AllowNegativeRates") && (zerlegt.size() > 1)) + if ((toUpper(zerlegt[0]) == "ALLOWNEGATIVERATES") && (zerlegt.size() > 1)) { if (toUpper(zerlegt[1]) == "TRUE") AllowNegativeRates = true; } - if ((zerlegt[0] == "ErrorMessage") && (zerlegt.size() > 1)) + if ((toUpper(zerlegt[0]) == "ERRORMESSAGE") && (zerlegt.size() > 1)) { if (toUpper(zerlegt[1]) == "TRUE") ErrorMessage = true; } - if ((zerlegt[0] == "PreValueAgeStartup") && (zerlegt.size() > 1)) + if ((toUpper(zerlegt[0]) == "PREVALUEAGESTARTUP") && (zerlegt.size() > 1)) { PreValueAgeStartup = std::stoi(zerlegt[1]); } - if ((zerlegt[0] == "MaxRateValue") && (zerlegt.size() > 1)) + if ((toUpper(zerlegt[0]) == "MAXRATEVALUE") && (zerlegt.size() > 1)) { useMaxRateValue = true; MaxRateValue = std::stof(zerlegt[1]); @@ -206,6 +214,48 @@ bool ClassFlowPostProcessing::ReadParameter(FILE* pfile, string& aktparamgraph) return true; } +string ClassFlowPostProcessing::ShiftDecimal(string in, int _decShift){ + + if (_decShift == 0){ + return in; + } + + int _pos_dec_org, _pos_dec_neu; + + _pos_dec_org = findDelimiterPos(in, "."); + if (_pos_dec_org == std::string::npos) { + _pos_dec_org = in.length(); + } + else + { + in = in.erase(_pos_dec_org, 1); + } + + _pos_dec_neu = _pos_dec_org + _decShift; + + if (_pos_dec_neu <= 0) { // Komma ist vor der ersten Ziffer + for (int i = 0; i > _pos_dec_neu; --i){ + in = in.insert(0, "0"); + } + in = "0." + in; + return in; + } + + if (_pos_dec_neu > in.length()){ // Komma soll hinter String (123 --> 1230) + for (int i = in.length(); i < _pos_dec_neu; ++i){ + in = in.insert(in.length(), "0"); + } + return in; + } + + string zw; + zw = in.substr(0, _pos_dec_neu); + zw = zw + "."; + zw = zw + in.substr(_pos_dec_neu, in.length() - _pos_dec_neu); + + return zw; +} + bool ClassFlowPostProcessing::doFlow(string zwtime) { string result = ""; @@ -258,7 +308,9 @@ bool ClassFlowPostProcessing::doFlow(string zwtime) if (isdigit && isanalog) ReturnRawValue = ReturnRawValue + "."; if (isanalog) - ReturnRawValue = ReturnRawValue + analog; + ReturnRawValue = ReturnRawValue + analog; + + ReturnRawValue = ShiftDecimal(ReturnRawValue, DecimalShift); if (!PreValueUse || !PreValueOkay) { @@ -374,7 +426,7 @@ string ClassFlowPostProcessing::ErsetzteN(string input, int lastvalueanalog = -1 if (checkDigitIncreaseConsistency && lastvalueanalog > -1) { int zifferIST; - int substrakt = 0; +// int substrakt = 0; bool lastcorrected = false; for (int i = input.length() - 1; i >= 0; --i) { diff --git a/code/lib/jomjol_flowcontroll/ClassFlowPostProcessing.h b/code/lib/jomjol_flowcontroll/ClassFlowPostProcessing.h index b3fba529..d2e25a49 100644 --- a/code/lib/jomjol_flowcontroll/ClassFlowPostProcessing.h +++ b/code/lib/jomjol_flowcontroll/ClassFlowPostProcessing.h @@ -16,6 +16,7 @@ protected: bool ErrorMessage; bool PreValueOkay; bool checkDigitIncreaseConsistency; + int DecimalShift; string FilePreValue; float PreValue; // letzter Wert, der gut ausgelesen wurde @@ -25,6 +26,7 @@ protected: string ReturnValueNoError; // korrigierter Rückgabewert ohne Fehlermeldung bool LoadPreValue(void); + string ShiftDecimal(string in, int _decShift); string ErsetzteN(string, int lastvalueanalog); diff --git a/firmware/firmware.bin b/firmware/firmware.bin index b0dec0b4..d6d12bef 100644 Binary files a/firmware/firmware.bin and b/firmware/firmware.bin differ diff --git a/firmware/html.zip b/firmware/html.zip index 65b46930..7e430bca 100644 Binary files a/firmware/html.zip and b/firmware/html.zip differ diff --git a/sd-card/config/config.ini b/sd-card/config/config.ini index b8d88d9f..e2b94ca0 100644 --- a/sd-card/config/config.ini +++ b/sd-card/config/config.ini @@ -31,6 +31,7 @@ analog3, 294, 369, 92, 92 analog4, 168, 326, 92, 92 [PostProcessing] +DecimalShift = 0 PreValueUse = True PreValueAgeStartup = 30 AllowNegativeRates = False