diff options
author | Ballista Milsim <ballista.milsim@gmail.com> | 2020-03-21 12:39:57 +0100 |
---|---|---|
committer | Ballista Milsim <ballista.milsim@gmail.com> | 2020-03-21 12:39:57 +0100 |
commit | cf89cd0ee392a73c7b92d0220b3963f1901908ae (patch) | |
tree | cf27da201041b870f1668b24b3c88506c9e80523 | |
parent | 77885b4d65f49fd220d2426c01cd336402b86c60 (diff) |
Fixes according to code review.
-rw-r--r-- | tracker-tobii/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tracker-tobii/ftnoir_tracker_tobii.cpp | 5 | ||||
-rw-r--r-- | tracker-tobii/thread.cpp | 73 | ||||
-rw-r--r-- | tracker-tobii/thread.hpp | 18 |
4 files changed, 46 insertions, 51 deletions
diff --git a/tracker-tobii/CMakeLists.txt b/tracker-tobii/CMakeLists.txt index 4593ae4e..8551c8fa 100644 --- a/tracker-tobii/CMakeLists.txt +++ b/tracker-tobii/CMakeLists.txt @@ -1,5 +1,6 @@ # https://developer.tobii.com/download-packages/stream-engine-4-1-0-for-windows-x86 # https://developer.tobii.com/download-packages/stream-engine-4-1-0-for-windows-x64 +set(SDK_TOBII "" CACHE PATH "Tobii SDK path") if(SDK_TOBII) otr_module(tracker-tobii) target_include_directories(${self} SYSTEM PRIVATE "${SDK_TOBII}/include") diff --git a/tracker-tobii/ftnoir_tracker_tobii.cpp b/tracker-tobii/ftnoir_tracker_tobii.cpp index f0d66ae4..43cb1662 100644 --- a/tracker-tobii/ftnoir_tracker_tobii.cpp +++ b/tracker-tobii/ftnoir_tracker_tobii.cpp @@ -2,6 +2,8 @@ #include "api/plugin-api.hpp" #include "compat/math.hpp" +tobii::~tobii() = default; + module_status tobii::start_tracker(QFrame*) { t.start(); @@ -18,6 +20,9 @@ void tobii::data(double *data) p.position_xyz[1] = p.position_xyz[1] - center_pose.position_xyz[1]; p.position_xyz[2] = p.position_xyz[2] - center_pose.position_xyz[2]; } + else { + center_pose = p; + } data[0] = clamp(p.position_xyz[0] * 30.0 / 300.0, -30.0, 30.0); data[1] = clamp(p.position_xyz[1] * 30.0 / 300.0, -30.0, 30.0); data[2] = clamp(p.position_xyz[2] * 30.0 / 300.0, -30.0, 30.0); diff --git a/tracker-tobii/thread.cpp b/tracker-tobii/thread.cpp index f9fd2c01..bdd48125 100644 --- a/tracker-tobii/thread.cpp +++ b/tracker-tobii/thread.cpp @@ -1,20 +1,15 @@ #include "thread.hpp" #include "compat/sleep.hpp" -tobii_thread::tobii_thread() -{ - head_pose = new tobii_head_pose_t(); - connect(this, &tobii_thread::tobii_ready_signal, this, &tobii_thread::tobii_ready_signal_impl, Qt::QueuedConnection); - connect(this, &tobii_thread::tobii_error_signal, this, &tobii_thread::tobii_error_signal_impl, Qt::QueuedConnection); -} - tobii_thread::~tobii_thread() { - if (device) tobii_device_destroy(device); - if (api) tobii_api_destroy(api); exit_thread = true; - terminate(); wait(); + + if (device) tobii_device_destroy(device); + if (api) tobii_api_destroy(api); + + quit(); } void tobii_thread::run() @@ -22,7 +17,8 @@ void tobii_thread::run() /* See https://developer.tobii.com/consumer-eye-trackers/stream-engine/ */ if (tobii_api_create(&api, nullptr, nullptr) != TOBII_ERROR_NO_ERROR) { - emit tobii_error_signal("Failed to initialize the Tobii Stream Engine API."); + error_last = "Failed to initialize the Tobii Stream Engine API."; + exit_thread = true; } std::vector<std::string> devices; @@ -33,13 +29,15 @@ void tobii_thread::run() list->push_back(url); }, &devices) != TOBII_ERROR_NO_ERROR) { - emit tobii_error_signal("Failed to enumerate devices."); + error_last = "Failed to enumerate devices."; + exit_thread = true; } if (devices.size() == 0) { tobii_api_destroy(api); - emit tobii_error_signal("No stream engine compatible device(s) found."); + error_last = "No stream engine compatible device(s) found."; + exit_thread = true; } std::string selected_device = devices[0]; @@ -54,10 +52,25 @@ void tobii_thread::run() } while (retry < retries); if (tobii_error != TOBII_ERROR_NO_ERROR) { tobii_api_destroy(api); - emit tobii_error_signal("Failed to connect to device."); + error_last = "Failed to connect to device."; + exit_thread = true; } - emit tobii_ready_signal(); + if (tobii_head_pose_subscribe(device, [](tobii_head_pose_t const* head_pose, void* user_data) { + + if ((*head_pose).position_validity != TOBII_VALIDITY_VALID + || (*head_pose).rotation_validity_xyz[0] != TOBII_VALIDITY_VALID + || (*head_pose).rotation_validity_xyz[1] != TOBII_VALIDITY_VALID + || (*head_pose).rotation_validity_xyz[2] != TOBII_VALIDITY_VALID) return; + + tobii_head_pose_t* tobii_head_pose_storage = (tobii_head_pose_t*)user_data; + *tobii_head_pose_storage = *head_pose; + + }, head_pose) != TOBII_ERROR_NO_ERROR) + { + error_last = "Failed to subscribe to head pose stream."; + exit_thread = true; + } tobii_error = TOBII_ERROR_NO_ERROR; while (!exit_thread) @@ -66,7 +79,7 @@ void tobii_thread::run() if (tobii_error == TOBII_ERROR_TIMED_OUT) continue; else if (tobii_error != TOBII_ERROR_NO_ERROR) { - emit tobii_error_signal("tobii_wait_for_callbacks failed."); + error_last = "tobii_wait_for_callbacks failed."; } tobii_error = tobii_device_process_callbacks(device); @@ -83,36 +96,14 @@ void tobii_thread::run() } while (retry < retries); if (tobii_error != TOBII_ERROR_NO_ERROR) { - emit tobii_error_signal("Connection was lost and reconnection failed."); + error_last = "Connection was lost and reconnection failed."; + exit_thread = true; } continue; } else if (tobii_error != TOBII_ERROR_NO_ERROR) { - emit tobii_error_signal("tobii_device_process_callbacks failed."); + error_last = "tobii_device_process_callbacks failed."; } } } - -void tobii_thread::tobii_error_signal_impl(QString error_message) -{ - //TODO: log? terminate? -} - -void tobii_thread::tobii_ready_signal_impl() -{ - if (tobii_head_pose_subscribe(device, [](tobii_head_pose_t const* head_pose, void* user_data) { - - if ((*head_pose).position_validity != TOBII_VALIDITY_VALID - || (*head_pose).rotation_validity_xyz[0] != TOBII_VALIDITY_VALID - || (*head_pose).rotation_validity_xyz[1] != TOBII_VALIDITY_VALID - || (*head_pose).rotation_validity_xyz[2] != TOBII_VALIDITY_VALID) return; - - tobii_head_pose_t* tobii_head_pose_storage = (tobii_head_pose_t*)user_data; - *tobii_head_pose_storage = *head_pose; - - }, head_pose) != TOBII_ERROR_NO_ERROR) - { - emit tobii_error_signal("Failed to subscribe to head pose stream."); - } -} diff --git a/tracker-tobii/thread.hpp b/tracker-tobii/thread.hpp index a2838272..d311db87 100644 --- a/tracker-tobii/thread.hpp +++ b/tracker-tobii/thread.hpp @@ -14,12 +14,11 @@ class tobii_thread : public QThread Q_OBJECT void run() override; -signals: - void tobii_error_signal(QString error_message); - void tobii_ready_signal(); - public: - tobii_thread(); + tobii_thread() + { + head_pose = new tobii_head_pose_t(); + } ~tobii_thread() override; tobii_head_pose_t* head_pose; @@ -28,10 +27,9 @@ private: tobii_api_t* api; tobii_device_t* device; - const unsigned int retries = 300; - const unsigned int interval = 100; - std::atomic<bool> exit_thread = false; + static constexpr unsigned int retries = 300; + static constexpr unsigned int interval = 100; - void tobii_error_signal_impl(QString error_message); - void tobii_ready_signal_impl(); + QString error_last = ""; + std::atomic<bool> exit_thread = false; }; |