diff options
Diffstat (limited to 'tracker-trackhat/trackhat.hpp')
-rw-r--r-- | tracker-trackhat/trackhat.hpp | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/tracker-trackhat/trackhat.hpp b/tracker-trackhat/trackhat.hpp index b80e4c2f..5599e963 100644 --- a/tracker-trackhat/trackhat.hpp +++ b/tracker-trackhat/trackhat.hpp @@ -2,12 +2,14 @@ #include "../tracker-pt/pt-api.hpp" #include "compat/macros.hpp" +#include "compat/timer.hpp" #include "options/options.hpp" #include <track_hat_driver.h> #include <array> #include <atomic> +#include <optional> #include <opencv2/core/mat.hpp> enum model_type : int @@ -28,6 +30,10 @@ TH_ErrorCode log_error(TH_ErrorCode error, const char* source, const char* file, #define th_check_(expr, expr2) ::trackhat_impl::log_error((expr), expr2) #define th_check(expr) ::trackhat_impl::log_error((expr), #expr, __FILE__, __LINE__, function_name) +enum class led_mode : unsigned char { + off, constant, dynamic, +}; + struct trackhat_settings : opts { static constexpr int min_gain = 1, max_gain = 47, @@ -44,6 +50,7 @@ struct trackhat_settings : opts value<slider_value> point_filter_coefficient{b, "point-filter-coefficient", { 1.5, 1, 4 }}; value<slider_value> point_filter_limit { b, "point-filter-limit", { 0.1, 0.01, 1 }}; value<slider_value> point_filter_deadzone { b, "point-filter-deadzone", {0, 0, 1}}; + value<led_mode> led { b, "led-mode", led_mode::dynamic }; }; class setting_receiver : public QObject @@ -59,9 +66,31 @@ private: std::atomic<bool> changed{false}; }; +enum class led_state : unsigned char { + invalid, stopped, not_tracking, tracking, +}; + +struct led_updater final { + trackHat_SetLeds_t leds_ {TH_UNCHANGED, TH_UNCHANGED, TH_UNCHANGED}; + std::optional<Timer> timer_; + led_state state_ = led_state::invalid; + + trackHat_SetLeds_t next_state(led_mode mode, led_state new_state); + void update_(trackHat_Device_t* device, trackHat_SetLeds_t leds); + void update(trackHat_Device_t* device, led_mode mode, led_state new_state); + + static constexpr int SWITCH_TIME_MS = 2000; + static constexpr + trackHat_SetLeds_t LED_idle = {TH_OFF, TH_SOLID, TH_OFF}, + LED_off = {TH_OFF, TH_OFF, TH_OFF}, + LED_tracking {TH_OFF, TH_SOLID, TH_SOLID}, + LED_not_tracking {TH_SOLID, TH_OFF, TH_OFF}; +}; + } // ns trackhat_impl -using typename trackhat_impl::trackhat_settings; +using trackhat_impl::trackhat_settings; +using trackhat_impl::led_updater; struct trackhat_metadata final : pt_runtime_traits { @@ -94,6 +123,7 @@ struct camera_handle final camera_handle() = default; ~camera_handle() = default; + constexpr operator bool() const { return state_ >= st_streaming; } [[nodiscard]] bool ensure_connected(); [[nodiscard]] bool ensure_device_exists(); void disconnect(); @@ -139,6 +169,7 @@ private: camera_handle device; pt_settings s{trackhat_metadata::module_name}; trackhat_settings t; + led_updater led; }; struct trackhat_frame final : pt_frame |