-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathArrayValidate.cpp
More file actions
86 lines (76 loc) · 2.01 KB
/
ArrayValidate.cpp
File metadata and controls
86 lines (76 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "ArrayValidate.h"
ArrayValidate::ArrayValidate(int *mainArray, int maximumRows,int maximumColumns, int discardingLimit, int averageDiscardingLimit)
{
_mainRows=maximumRows;
_mainColumns=maximumColumns;
_discardingLimit=discardingLimit;
_averageDiscardingLimit=averageDiscardingLimit;
_mainArray=mainArray;
}
int ArrayValidate::validateArray(int *compareArray, int caLen)
{
int i=0,j=0,element;
int mainArraySingleRowLen=0;
int possibleIndex=0;
for(i=0;i<_mainRows;i++)
{
mainArraySingleRowLen=0;
for(j=0;j<_mainColumns;j++)
{
element=(*(_mainArray+i*_mainColumns+j));
if(element>0)
{
mainArraySingleRowLen++;
}
}
if(mainArraySingleRowLen==caLen)
{
int x=i+1;
possibleIndex=(possibleIndex*10)+x;
}
}
// Serial.println("---------------------------------possibleIndex--------------------------------");
// Serial.println(possibleIndex);
if(possibleIndex==0)
{
return 240;
}
else
{
int totalDifference=0;
int diff=0;
int ind=0;
while(possibleIndex!=0)
{
ind=possibleIndex%10;
ind--;
//Serial.println("---------------------------------CURRENTLY WORKING WITH INDEX--------------------------------");
//Serial.println(ind);
for (i=0;i<caLen;i++)
{
diff = abs(compareArray[i] - *(_mainArray+ind*_mainColumns+i));
if (diff > _discardingLimit)
{
// Individual values too far off
goto label;
}
totalDifference += diff;
}
// too inaccurate
if (totalDifference/caLen>_averageDiscardingLimit)
{
label: possibleIndex=possibleIndex/10;
totalDifference=0;
diff=0;
ind=0;
}
else
{
// Serial.println("---------------------------------RETURNED INDEX--------------------------------");
// Serial.println(ind);
return ind;
}
}
return 240;
}
}