/** * @file * * @author Max Lammers * @author Mamadou Babaei * * @section LICENSE * * Copyright (c) 2020 - 2026 SenseGlove * * @section DESCRIPTION * * A threading resource that scans the computer for connections and Sense Gloves. */ #pragma once #include #include #include #include #include namespace SGConnect { enum class EExitCode : int8_t; enum class EFWErrorCodes : int8_t; class Connection; class IdResponse; struct PortInfo; class SGCONNECT_API DeviceScanner; }// namespace SGConnect /// A threading resource that scans the computer for connections and Sense Gloves. class SGCONNECT_API SGConnect::DeviceScanner// only one of these should be running at a time. { public: /// Check if the Device Scanner is still alive. static bool IsLive(); /// Set the live value of the deviceScanner from an external source. static void SetLive(bool bLive); static bool AlreadyDetected(const IdResponse& Id); /// (Re)Connect a Device to the DeviceScanner list. /// /// /// /// static bool ConnectDevice(const IdResponse& deviceId, const std::string& constants, const std::string& newAddress); static bool GetConnection(int32_t connectionIndex, std::shared_ptr& out_connection); static void ReleaseIdle(const PortInfo& ofPort); static bool Send(int32_t connectionIndex, const std::string& command, bool bHapticCommand); static bool GetLastData(int32_t connectionIndex, std::string& out_data); static bool GetLastCommand(int32_t connectionIndex, std::string& out_cmd); static bool IsConnected(int32_t connectionIndex); static bool Disconnect(int32_t connectionIndex, EExitCode exitCode); static bool GetPortInfo(int32_t connectionIndex, PortInfo& out_portInfo); static void SetSerialEnabled(bool bEnabled); static int32_t RegisterBLEConnection(const std::string& deviceJson); static int32_t UnregisterBLEConnection(const std::string& deviceJson); static int32_t GetNearbyBLEDevices(std::string& out_nearbyDevices); static bool GetPreferInternalForHaptics(); static void SetPreferInternalForHaptics(bool bInternalPreferred); private: struct Impl; std::unique_ptr Pimpl; public: /// Creates a new instance of a DeviceScanner, which immedeately begins scanning for SG Devices. /// DeviceScanner(); public: /** * The copy constructor. */ DeviceScanner(const DeviceScanner& rhs) = delete; /** * The move constructor. */ DeviceScanner(DeviceScanner&& rhs) noexcept; public: /// Cleans up any remaining unmanaged resources. virtual ~DeviceScanner(); public: /** * The copy assignment operator. */ DeviceScanner& operator=(const DeviceScanner& rhs) = delete; /** * The move assignment operator. */ DeviceScanner& operator=(DeviceScanner&& rhs) noexcept; public: EFWErrorCodes OTAFirmwareUpload(int32_t deviceIndex, const std::string& filePath, const int32_t chunkSize); int32_t GetFirmwareProgress() const; EFWErrorCodes GetLastFirmwareResult() const; void SetLastFirmwareResult(const EFWErrorCodes errCode); EFWErrorCodes Nova2OTAFirmwareUpload_BTS_to_BLE(int32_t deviceIndex, const std::string& filePath, const int32_t chunkSize); void CompleteNova2Nova2OTAFirmwareUpload(); };