|
20 | 20 | public class Passthrough implements SensorEventListener {
|
21 | 21 |
|
22 | 22 | static {
|
23 |
| - System.loadLibrary("native-lib"); |
| 23 | + System.loadLibrary("native-lib-alvr"); |
24 | 24 | }
|
25 | 25 |
|
26 | 26 | private static final String TAG = Passthrough.class.getSimpleName() + "-Java";
|
@@ -154,50 +154,45 @@ public void onSensorChanged(SensorEvent event) {
|
154 | 154 | // these may occur on any axis
|
155 | 155 | for (List<Float> elem : accelAbs) {
|
156 | 156 | // we look at two halves of the passthrough_delay
|
157 |
| - // we check: |
158 |
| - // - if in the first and second half is a real peak |
159 |
| - // - whether the peaks are in the bounds |
160 |
| - // - if the summed mean is in the bounds |
161 |
| - // - if the first summed mean is below lower_bound |
162 |
| - // (to assure a resting stage before the triggering) |
163 |
| - // - if the second maximum is decending under the lower bound until curr value |
164 |
| - // If all is fulfilled we consider this a potential passthrough_change event. |
165 |
| - // The sum must then decend under lower bound until passthrough_delay |
166 |
| - int middle = halfSize - 1; |
167 |
| - List<Float> t1 = elem.subList(0, halfSize); |
168 |
| - List<Float> t2 = elem.subList(middle, elem.size()); |
| 157 | + List<Float> t1 = elem.subList(0, halfSize + 1); |
| 158 | + List<Float> t2 = elem.subList(halfSize, elem.size()); |
169 | 159 |
|
| 160 | + // and get the maxima |
170 | 161 | float max1 = Collections.max(t1);
|
171 | 162 | float max2 = Collections.max(t2);
|
172 |
| - |
173 |
| - if (max1 - t1.get(0) < detectionLowerBound |
174 |
| - || max1 - t1.get(t1.size() - 1) < detectionLowerBound |
175 |
| - || max2 - t2.get(0) < detectionLowerBound |
176 |
| - || max2 - t2.get(t2.size() - 1) < detectionLowerBound |
177 |
| - || max1 < detectionLowerBound |
178 |
| - || max1 > detectionUpperBound |
179 |
| - || max2 < detectionLowerBound |
180 |
| - || max2 > detectionUpperBound |
181 |
| - || sumMean < detectionLowerBound |
182 |
| - || sumMean > detectionUpperBound) { |
183 |
| - continue; |
184 |
| - } |
185 |
| - |
186 |
| - int end2 = 0; |
187 |
| - for (int i = 0; i < t2.size(); ++i) { |
188 |
| - if (t2.get(i) == max2) { |
| 163 | + // and check whether the 2nd half goes belowe lower bound |
| 164 | + int end2 = t2.indexOf(max2); |
| 165 | + for (int i = end2; i < t2.size(); ++i) { |
| 166 | + if (t2.get(i) < detectionLowerBound) { |
189 | 167 | end2 = i;
|
190 |
| - } |
191 |
| - if (end2 > 0) { |
192 |
| - if (t2.get(i) < detectionLowerBound) { |
193 |
| - end2 = i; |
194 |
| - break; |
195 |
| - } |
| 168 | + break; |
196 | 169 | }
|
197 | 170 | }
|
198 | 171 |
|
199 |
| - if (cumSums.get(0) < Math.max(detectionLowerBound - 0.3f, 0.5f) |
200 |
| - && t2.get(end2) < max2) { |
| 172 | + // We check |
| 173 | + if (t1.get(halfSize - 1) > t2.get(0) // if halfSize is a local minimum |
| 174 | + && t2.get(1) > t2.get(0) |
| 175 | + && max1 - t1.get(0) >= detectionLowerBound // max - start > lower bound |
| 176 | + && max1 - t1.get(t1.size() - 1) |
| 177 | + >= detectionLowerBound // max - end > lower bound |
| 178 | + && max2 - t2.get(0) >= detectionLowerBound |
| 179 | + && max2 - t2.get(t2.size() - 1) >= detectionLowerBound |
| 180 | + && max1 >= detectionLowerBound // max are in bounds |
| 181 | + && max1 <= detectionUpperBound |
| 182 | + && max2 >= detectionLowerBound |
| 183 | + && max2 <= detectionUpperBound |
| 184 | + && sumMean >= detectionLowerBound // sumMean is in bounds |
| 185 | + && sumMean <= detectionUpperBound |
| 186 | + && t2.get(end2) < max2 // the 2nd half goes below lower bound |
| 187 | + && cumSums.get(0) |
| 188 | + < Math.max( |
| 189 | + detectionLowerBound - 0.3f, |
| 190 | + 0.5f) // the first sumMean (of window) is below lower |
| 191 | + // bounds |
| 192 | + ) { |
| 193 | + // If all is fulfilled we consider this a potential passthrough_change |
| 194 | + // event. |
| 195 | + // The sum must then decend under lower bound until passthrough_delay |
201 | 196 | timestampAfterCandidate = event.timestamp;
|
202 | 197 | break;
|
203 | 198 | }
|
|
0 commit comments