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

Commit cd43fbb4 authored by Mathias Agopian's avatar Mathias Agopian Committed by Android (Google) Code Review
Browse files

Merge "improve sensorservice dumpsys and increase the max sensor rate to 1 ms...

Merge "improve sensorservice dumpsys and increase the max sensor rate to 1 ms (1000Hz)" into gingerbread
parents 06fd1dc5 94c4f5c1
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);