Skip to content

Commit c6a593b

Browse files
SybexXcaco3
andauthored
fix for incorrect decimal shift? (jomjol#3446)
* Update ClassFlowCNNGeneral.cpp * Update ClassFlowCNNGeneral.cpp * Update ClassFlowCNNGeneral.cpp * Update ClassFlowCNNGeneral.cpp * Update code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp * Update code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp * Update code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp * Update ClassFlowCNNGeneral.cpp --------- Co-authored-by: CaCO3 <[email protected]>
1 parent c684633 commit c6a593b

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ string ClassFlowCNNGeneral::getReadout(int _analog = 0, bool _extendedResolution
6565

6666
if (CNNType == Digit) {
6767
for (int i = 0; i < GENERAL[_analog]->ROI.size(); ++i) {
68-
if (GENERAL[_analog]->ROI[i]->result_klasse >= 10) {
69-
result = result + "N";
68+
if ((GENERAL[_analog]->ROI[i]->result_klasse >= 0) && (GENERAL[_analog]->ROI[i]->result_klasse < 10)) {
69+
result = result + std::to_string(GENERAL[_analog]->ROI[i]->result_klasse);
7070
}
7171
else {
72-
result = result + std::to_string(GENERAL[_analog]->ROI[i]->result_klasse);
72+
result = result + "N";
7373
}
7474
}
7575
return result;
@@ -78,7 +78,7 @@ string ClassFlowCNNGeneral::getReadout(int _analog = 0, bool _extendedResolution
7878
if ((CNNType == DoubleHyprid10) || (CNNType == Digit100)) {
7979
float number = GENERAL[_analog]->ROI[GENERAL[_analog]->ROI.size() - 1]->result_float;
8080
// NaN?
81-
if (number >= 0) {
81+
if ((number >= 0) && (number < 10)) {
8282
// is only set if it is the first digit (no analogue before!)
8383
if (_extendedResolution) {
8484
int result_after_decimal_point = ((int) floor(number * 10)) % 10;
@@ -95,8 +95,15 @@ string ClassFlowCNNGeneral::getReadout(int _analog = 0, bool _extendedResolution
9595
else {
9696
prev = PointerEvalHybridNew(GENERAL[_analog]->ROI[GENERAL[_analog]->ROI.size() - 1]->result_float, prev, prev);
9797
}
98-
result = std::to_string(prev);
99-
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "getReadout(dig100) prev=" + std::to_string(prev));
98+
99+
// is necessary because a number greater than 9.994999 returns a 10! (for further details see check in PointerEvalHybridNew)
100+
if ((prev >= 0) && (prev < 10)) {
101+
result = std::to_string(prev);
102+
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "getReadout(dig100) prev=" + std::to_string(prev));
103+
}
104+
else {
105+
result = "N";
106+
}
100107
}
101108
}
102109
else {
@@ -107,7 +114,7 @@ string ClassFlowCNNGeneral::getReadout(int _analog = 0, bool _extendedResolution
107114
}
108115

109116
for (int i = GENERAL[_analog]->ROI.size() - 2; i >= 0; --i) {
110-
if (GENERAL[_analog]->ROI[i]->result_float >= 0) {
117+
if ((GENERAL[_analog]->ROI[i]->result_float >= 0) && (GENERAL[_analog]->ROI[i]->result_float < 10)) {
111118
prev = PointerEvalHybridNew(GENERAL[_analog]->ROI[i]->result_float, GENERAL[_analog]->ROI[i+1]->result_float, prev);
112119
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "getReadout#PointerEvalHybridNew()= " + std::to_string(prev));
113120
result = std::to_string(prev) + result;
@@ -117,7 +124,6 @@ string ClassFlowCNNGeneral::getReadout(int _analog = 0, bool _extendedResolution
117124
prev = -1;
118125
result = "N" + result;
119126
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "getReadout(result_float<0 /'N') result_float=" + std::to_string(GENERAL[_analog]->ROI[i]->result_float));
120-
121127
}
122128
}
123129
return result;
@@ -150,6 +156,9 @@ int ClassFlowCNNGeneral::PointerEvalHybridNew(float number, float number_of_pred
150156
// on first digit is no spezial logic for transition needed
151157
// we use the recognition as given. The result is the int value of the recognition
152158
// add precisition of 2 digits and round before trunc
159+
// a number greater than 9.994999 is returned as 10, this leads to an error during the decimal shift because the NUMBERS[j]->ReturnRawValue is one digit longer.
160+
// To avoid this, an additional test must be carried out, see "if ((CNNType == DoubleHyprid10) || (CNNType == Digit100))" check in getReadout()
161+
// Another alternative would be "result = (int) ((int) trunc(round((number+10 % 10)*1000))) / 1000;", which could, however, lead to other errors?
153162
result = (int) ((int) trunc(round((number+10 % 10)*100)) ) / 100;
154163

155164
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "PointerEvalHybridNew - No predecessor - Result = " + std::to_string(result) +

0 commit comments

Comments
 (0)