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

Commit 94c4f5c1 authored by Mathias Agopian's avatar Mathias Agopian
Browse files

improve sensorservice dumpsys and increase the max sensor rate to 1 ms (1000Hz)

the increased maximum rate is needed for proper gyro integration, current gyro
parts can sample at up to 800Hz

Change-Id: Ide75f6d5bc7a0fdafeb2dafd72db39e7afb9e794
parent 5fd30540
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -175,10 +175,11 @@ status_t SensorService::dump(int fd, const Vector<String16>& args)
        for (size_t i=0 ; i<mSensorList.size() ; i++) {
            const Sensor& s(mSensorList[i]);
            const sensors_event_t& e(mLastEventSeen.valueFor(s.getHandle()));
            snprintf(buffer, SIZE, "%s (vendor=%s, handle=%d, last=<%5.1f,%5.1f,%5.1f>)\n",
            snprintf(buffer, SIZE, "%s (vendor=%s, handle=%d, maxRate=%.2fHz, last=<%5.1f,%5.1f,%5.1f>)\n",
                    s.getName().string(),
                    s.getVendor().string(),
                    s.getHandle(),
                    s.getMinDelay() ? (1000000.0f / s.getMinDelay()) : 0.0f,
                    e.data[0], e.data[1], e.data[2]);
            result.append(buffer);
        }
+2 −2
Original line number Diff line number Diff line
@@ -49,8 +49,8 @@ class SensorService :
{
   friend class BinderService<SensorService>;

   static const nsecs_t MINIMUM_EVENTS_PERIOD = 10000000; // 10ms
   static const nsecs_t DEFAULT_EVENTS_PERIOD = 200000000; // 200 ms
   static const nsecs_t MINIMUM_EVENTS_PERIOD =   1000000; // 1000 Hz
   static const nsecs_t DEFAULT_EVENTS_PERIOD = 200000000; //    5 Hz

            SensorService();
    virtual ~SensorService();
+12 −2
Original line number Diff line number Diff line
@@ -27,15 +27,25 @@ int receiver(int fd, int events, void* data)
    sp<SensorEventQueue> q((SensorEventQueue*)data);
    ssize_t n;
    ASensorEvent buffer[8];

    static nsecs_t oldTimeStamp = 0;

    while ((n = q->read(buffer, 8)) > 0) {
        for (int i=0 ; i<n ; i++) {
            if (buffer[i].type == Sensor::TYPE_ACCELEROMETER) {
            if (buffer[i].type == Sensor::TYPE_GYROSCOPE) {
                printf("time=%lld, value=<%5.1f,%5.1f,%5.1f>\n",
                        buffer[i].timestamp,
                        buffer[i].acceleration.x,
                        buffer[i].acceleration.y,
                        buffer[i].acceleration.z);
            }

            if (oldTimeStamp) {
                float t = float(buffer[i].timestamp - oldTimeStamp) / s2ns(1);
                printf("%f ms (%f Hz)\n", t*1000, 1.0/t);
            }
            oldTimeStamp = buffer[i].timestamp;

        }
    }
    if (n<0 && n != -EAGAIN) {
@@ -56,7 +66,7 @@ int main(int argc, char** argv)
    sp<SensorEventQueue> q = mgr.createEventQueue();
    printf("queue=%p\n", q.get());

    Sensor const* accelerometer = mgr.getDefaultSensor(Sensor::TYPE_ACCELEROMETER);
    Sensor const* accelerometer = mgr.getDefaultSensor(Sensor::TYPE_GYROSCOPE);
    printf("accelerometer=%p (%s)\n",
            accelerometer, accelerometer->getName().string());
    q->enableSensor(accelerometer);