diff --git a/src/dev/trill/CentroidDetection.cpp b/src/dev/trill/CentroidDetection.cpp index 05880739b..a9dcbd9a2 100644 --- a/src/dev/trill/CentroidDetection.cpp +++ b/src/dev/trill/CentroidDetection.cpp @@ -16,9 +16,7 @@ class CentroidDetection::CalculateCentroids #include "calculateCentroids.h" void processCentroids(WORD *wVCentroid, WORD *wVCentroidSize, BYTE MAX_NUM_CENTROIDS, BYTE FIRST_SENSOR_V, BYTE LAST_SENSOR_V, BYTE numSensors) { long temp; - signed char firstActiveSensor; - signed char lastActiveSensor; - BOOL bActivityDetected; + BYTE lastActiveSensor; BYTE counter; WORD posEndOfLoop = (LAST_SENSOR_V - FIRST_SENSOR_V) << SLIDER_BITS; #include "processCentroids.h" @@ -85,7 +83,6 @@ void CentroidDetection::process(const DATA_T* rawData) cc->CSD_waSnsDiff = data.data(); cc->processCentroids(centroidBuffer.data(), sizeBuffer.data(), maxNumCentroids, 0, order.size(), num_sensors); - unsigned int locations = 0; // Look for 1st instance of 0xFFFF (no touch) in the buffer unsigned int i; for(i = 0; i < centroidBuffer.size(); ++i) diff --git a/src/dev/trill/Trill.cpp b/src/dev/trill/Trill.cpp index d20ced521..acfc36405 100644 --- a/src/dev/trill/Trill.cpp +++ b/src/dev/trill/Trill.cpp @@ -3,6 +3,18 @@ #include #include +#ifndef __try +#if __cpp_exceptions +# define __try try +# define __catch(X) catch(X) +# define __throw_exception_again throw +#else +# define __try if (true) +# define __catch(X) if (false) +# define __throw_exception_again +#endif +#endif // !__try + constexpr uint8_t Trill::speedValues[4]; #define MAX_TOUCH_1D_OR_2D (((device_type_ == SQUARE || device_type_ == HEX) ? kMaxTouchNum2D : kMaxTouchNum1D)) diff --git a/src/dev/trill/Trill.h b/src/dev/trill/Trill.h index 4c8ff42f4..027145df2 100644 --- a/src/dev/trill/Trill.h +++ b/src/dev/trill/Trill.h @@ -73,7 +73,6 @@ class Trill : public I2c std::vector dataBuffer; uint16_t commandSleepTime = 1000; size_t currentReadOffset = -1; - bool shouldReadFrameId = false; unsigned int numBits; unsigned int transmissionWidth = 16; unsigned int transmissionRightShift = 0; diff --git a/src/dev/trill/calculateCentroids.h b/src/dev/trill/calculateCentroids.h index 8994ac057..54e919308 100644 --- a/src/dev/trill/calculateCentroids.h +++ b/src/dev/trill/calculateCentroids.h @@ -1,12 +1,11 @@ // returns a WORD packing two signed chars. The high bytes is the last active sensor in the last centroid, // while the low byte is the first active sensor of the last centroid WORD calculateCentroids(WORD *centroidBuffer, WORD *sizeBuffer, BYTE maxNumCentroids, BYTE minSensor, BYTE maxSensor, BYTE numSensors) { - signed char lastActiveSensor = -1; + BYTE lastActiveSensor = 255; BYTE centroidIndex = 0, sensorIndex, actualHardwareIndex; BYTE wrappedAround = 0; BYTE inCentroid = 0; WORD peakValue = 0, troughDepth = 0; - BYTE counter; long temp; WORD lastSensorVal, currentSensorVal, currentWeightedSum, currentUnweightedSum; diff --git a/src/dev/trill/processCentroids.h b/src/dev/trill/processCentroids.h index 43fde3f9a..85a15ca1e 100644 --- a/src/dev/trill/processCentroids.h +++ b/src/dev/trill/processCentroids.h @@ -1,14 +1,13 @@ temp = calculateCentroids(wVCentroid, wVCentroidSize, MAX_NUM_CENTROIDS, FIRST_SENSOR_V, LAST_SENSOR_V, numSensors); // Vertical centroids - firstActiveSensor = temp & 0xFF; lastActiveSensor = temp >> 8; - bActivityDetected = lastActiveSensor >= 0; temp = lastActiveSensor - (LAST_SENSOR_V - FIRST_SENSOR_V );// retrieve the (wrapped) index //check for activity in the wraparound area // IF the last centroid ended after wrapping around ... // AND the first centroid was located before the end of the last ... - if(lastActiveSensor >= LAST_SENSOR_V - FIRST_SENSOR_V - && (((BYTE)temp) << SLIDER_BITS) >= wVCentroid[0] ) + if(lastActiveSensor != 255 // 255 means no active sensor + && lastActiveSensor >= LAST_SENSOR_V - FIRST_SENSOR_V + && ((unsigned)temp) << SLIDER_BITS >= wVCentroid[0] ) { // THEN the last touch is used to replace the first one for(counter = MAX_NUM_CENTROIDS - 1; counter >= 1; counter--) {