@@ -19,7 +19,33 @@ class CentroidDetection::CalculateCentroids
1919 BYTE lastActiveSensor;
2020 BYTE counter;
2121 WORD posEndOfLoop = (LAST_SENSOR_V - FIRST_SENSOR_V) << SLIDER_BITS;
22- #include " processCentroids.h"
22+ temp = calculateCentroids (wVCentroid, wVCentroidSize, MAX_NUM_CENTROIDS, FIRST_SENSOR_V, LAST_SENSOR_V, numSensors); // Vertical centroids
23+ lastActiveSensor = temp >> 8 ;
24+
25+ temp = lastActiveSensor - (LAST_SENSOR_V - FIRST_SENSOR_V );// retrieve the (wrapped) index
26+ // check for activity in the wraparound area
27+ // IF the last centroid ended after wrapping around ...
28+ // AND the first centroid was located before the end of the last ...
29+ if (lastActiveSensor != 255 // 255 means no active sensor
30+ && lastActiveSensor >= LAST_SENSOR_V - FIRST_SENSOR_V
31+ && ((unsigned )temp) << SLIDER_BITS >= wVCentroid[0 ] )
32+ {
33+ // THEN the last touch is used to replace the first one
34+ for (counter = MAX_NUM_CENTROIDS - 1 ; counter >= 1 ; counter--) {
35+ if (0xFFFF == wVCentroid[counter])
36+ continue ;
37+ // replace the first centroid
38+ wVCentroidSize[0 ] = wVCentroidSize[counter];
39+ wVCentroid[0 ] = wVCentroid[counter];
40+ // wrap around the position if needed
41+ if (wVCentroid[0 ] >= posEndOfLoop)
42+ wVCentroid[0 ] -= posEndOfLoop;
43+ // discard the last centroid
44+ wVCentroid[counter] = 0xFFFF ;
45+ wVCentroidSize[counter] = 0x0 ;
46+ break ;
47+ }
48+ }
2349 }
2450};
2551
0 commit comments