Skip to content

Commit

Permalink
Trill: removed unused variables warnings and signed/unsigned
Browse files Browse the repository at this point in the history
comparisons, added definition for __try/__catch which were failing the
CI
  • Loading branch information
giuliomoro committed Nov 23, 2024
1 parent 9093a12 commit 6a2be9b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
5 changes: 1 addition & 4 deletions src/dev/trill/CentroidDetection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions src/dev/trill/Trill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
#include <vector>
#include <string.h>

#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))

Expand Down
1 change: 0 additions & 1 deletion src/dev/trill/Trill.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ class Trill : public I2c
std::vector<uint8_t> dataBuffer;
uint16_t commandSleepTime = 1000;
size_t currentReadOffset = -1;
bool shouldReadFrameId = false;
unsigned int numBits;
unsigned int transmissionWidth = 16;
unsigned int transmissionRightShift = 0;
Expand Down
3 changes: 1 addition & 2 deletions src/dev/trill/calculateCentroids.h
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
7 changes: 3 additions & 4 deletions src/dev/trill/processCentroids.h
Original file line number Diff line number Diff line change
@@ -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--) {
Expand Down

0 comments on commit 6a2be9b

Please sign in to comment.