Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5deda01b authored by Ricardo Cerqueira's avatar Ricardo Cerqueira
Browse files

sensors: Fix ALS and PS lag on back-compat layer

These 2 sensors only report values on change,
instead of continuously generating samples at 'setDelay'
intervals like most others. If only these 2 (or any one of
them is enabled), we can't wait for the usual 64 samples
to be taken before reporting them to the framework, since
that'll make them visibly laggy.

This patch causes any sample from these sensors to trigger
an immediate report to the client.

Change-Id: Id5932376858c30323bff07ac4b38856dc200d074
parent 55343310
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -226,17 +226,24 @@ ssize_t SensorDevice::poll(sensors_event_t* buffer, size_t count) {
            buffer[pollsDone].acceleration = oldBuffer.vector;
            buffer[pollsDone].temperature = oldBuffer.temperature;
            LOGV("Adding results for sensor %d", buffer[pollsDone].sensor);
            /* The ALS and PS sensors only report values on change,
             * instead of a data "stream" like the others. So don't wait
             * for the number of requested samples to fill, and deliver
             * it immediately */
            if (sensorType == SENSOR_TYPE_PROXIMITY) {
#ifdef FOXCONN_SENSORS
            /* Fix ridiculous API breakages from FIH. */
            /* These idiots are returning -1 for FAR, and 1 for NEAR */
            if (sensorType == SENSOR_TYPE_PROXIMITY) {
                if (buffer[pollsDone].distance > 0) {
                    buffer[pollsDone].distance = 0;
                } else {
                    buffer[pollsDone].distance = 1;
                }
            }
#endif
		return pollsDone+1;
            } else if (sensorType == SENSOR_TYPE_LIGHT) {
		return pollsDone+1;
            }
            pollsDone++;
        }
        return pollsDone;