Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'proximity-sensor-devphone' into 'master'
[iioadaptor] Handle edge case for inverted IIO proximity sensor. Fixes MER#2076

See merge request mer-core/sensorfw!48
  • Loading branch information
mlehtima committed Jan 29, 2020
2 parents ce7fa7a + 7074a07 commit 0c93151
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions adaptors/iioadaptor/iioadaptor.cpp
Expand Up @@ -56,6 +56,7 @@
// Proximity sensor
#define PROXIMITY_DEFAULT_THRESHOLD 250
#define PROXIMITY_NEAR_VALUE 0
#define PROXIMITY_FAR_VALUE 100

/* Conversion of acceleration data to SI units (m/s^2) */
#define CONVERT_A_X(x) ((float(x) / 1000) * (GRAVITY * -1.0))
Expand Down Expand Up @@ -433,10 +434,15 @@ void IioAdaptor::processSample(int fileId, int fd)
sensordLogW() << "read():" << strerror(errno);
return;
}

errno = 0; // reset errno before call
result = strtol(buf, NULL, 10);

if (result == 0)
// If any conversion error occurs, abort
if (errno != 0) {
sensordLogW() << "strtol(): Unable to convert string to long";
return;
}

switch(channel) {
case 0: {
Expand All @@ -459,11 +465,12 @@ void IioAdaptor::processSample(int fileId, int fd)
bool near = false;
int proximityValue = (result + iioDevice.offset) * iioDevice.scale;
proximityData = proximityBuffer_->nextSlot();
// IIO proximity sensors are inverted in comparison to Hybris proximity sensors
if (proximityValue >= proximityThreshold) {
near = true;
}
proximityData->withinProximity_ = near;
proximityData->value_ = near ? PROXIMITY_NEAR_VALUE : proximityValue;
proximityData->value_ = near ? PROXIMITY_NEAR_VALUE : PROXIMITY_FAR_VALUE;
}
break;
default:
Expand Down

0 comments on commit 0c93151

Please sign in to comment.