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

Commit 879f0910 authored by Ytai Ben-Tsvi's avatar Ytai Ben-Tsvi
Browse files

Print timestamp lag in SensorPoseProvider-example

This is useful for assessing timestamp accuracy and latency.

Test: Invocation of the example.
Bug: 188502620
Change-Id: I685bc568ee4174157411cfe26628d0ef7b4f065a
parent 8b6fe3a4
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ cc_binary {
        "libheadtracking",
        "libheadtracking-binding",
        "libsensor",
        "libutils",
    ],
}

+8 −1
Original line number Diff line number Diff line
@@ -19,9 +19,11 @@

#include <android/sensor.h>
#include <hardware/sensors.h>
#include <utils/SystemClock.h>

#include <media/SensorPoseProvider.h>

using android::elapsedRealtimeNano;
using android::media::Pose3f;
using android::media::SensorPoseProvider;
using android::media::Twist3f;
@@ -32,7 +34,12 @@ class Listener : public SensorPoseProvider::Listener {
  public:
    void onPose(int64_t timestamp, int32_t handle, const Pose3f& pose,
                const std::optional<Twist3f>& twist) override {
        std::cout << "onPose t=" << timestamp << " sensor=" << handle << " pose=" << pose
        int64_t now = elapsedRealtimeNano();

        std::cout << "onPose t=" << timestamp
                  << " lag=" << ((now - timestamp) / 1e6) << "[ms]"
                  << " sensor=" << handle
                  << " pose=" << pose
                  << " twist=";
        if (twist.has_value()) {
            std::cout << twist.value();