/** * @file * * @author Max Lammers * @author Mamadou Babaei * * @section LICENSE * * Copyright (c) 2020 - 2022 SenseGlove * * @section DESCRIPTION * * Represents a Device built by the Sense Glove company that is compatible with * our Communications Protocol. All such devices derive from this abstract * class. */ #pragma once #include #include #include #include "DeviceTypes.hpp" #include "Platform.hpp" namespace SGCore { class SGCORE_API SGDevice; }// namespace SGCore class SGCORE_API SGCore::SGDevice { public: /// Connection type of this device, as detected by the SGConnect library. enum class EConnectionType : int8_t { /// Could not determine which connection type this SGDevice is using, most likely because it is disconnected. Unknown = -1, /// USB Serial communication. Serial, /// A bluetooth connection that creates up to two Serial Ports. BluetoothSerial, /// Bluetooth Connection Via Android/Java SDK BluetoothAndroid }; public: /// Parse a main and sub firmware version from its raw (v4.12) notation. static void ParseFirmware(const std::string& rawFirmware, int32_t& out_mainVersion, int32_t& out_subVersion); static std::string ToString(EDeviceType deviceType); private: struct Impl; std::unique_ptr Pimpl; public: /// The basic constructor. SGDevice(); /** * The copy constructor. */ SGDevice(const SGDevice& rhs); /** * The move constructor. */ SGDevice(SGDevice&& rhs) noexcept; /// The basic destructor. virtual ~SGDevice(); public: /** * The copy assignment operator. */ SGDevice& operator=(const SGDevice& rhs); /** * The move assignment operator. */ SGDevice& operator=(SGDevice&& rhs) noexcept; public: //-------------------------------------------------------------------------------------- // Device Accessors /// Check which DeviceType this class belongs to. [[nodiscard]] virtual EDeviceType GetDeviceType() const; /// Retrieve this device's unique identifier. #if SENSEGLOVE_UNREAL_ENGINE_PLUGIN [[nodiscard]] virtual std::string GetDeviceId() const; #else [[nodiscard]] virtual std::string GetDeviceId() const = 0; #endif /* SENSEGLOVE_UNREAL_ENGINE_PLUGIN */ /// Retrieve this device's hardware version. #if SENSEGLOVE_UNREAL_ENGINE_PLUGIN [[nodiscard]] virtual std::string GetHardwareVersion() const; #else [[nodiscard]] virtual std::string GetHardwareVersion() const = 0; #endif /* SENSEGLOVE_UNREAL_ENGINE_PLUGIN */ /// Retrieve this device's main firmware version. v4.12 returns 4. #if SENSEGLOVE_UNREAL_ENGINE_PLUGIN [[nodiscard]] virtual int32_t GetFirmwareVersion() const; #else [[nodiscard]] virtual int32_t GetFirmwareVersion() const = 0; #endif /* SENSEGLOVE_UNREAL_ENGINE_PLUGIN */ /// Retrieve this device's sub firmware version. v4.12 returns 12. [[nodiscard]] virtual int32_t GetSubFirmwareVersion() const; [[nodiscard]] virtual std::string GetFirmwareString() const; protected: [[nodiscard]] const std::string& GetIpcAddress() const; public: //-------------------------------------------------------------------------------------- // I/O Accessors /// Retrieve this Device's Serial/Bluetooth address. [[nodiscard]] std::string GetAddress() const; /// Check if this device is currently connected to the system. [[nodiscard]] bool IsConnected() const; /// Retrieve the connection type of this Sense Glove. [[nodiscard]] EConnectionType GetConnectionType() const; /// Retrieve the device's Packets per Second Variable. [[nodiscard]] int32_t PacketsPerSecondReceived() const; /// Retrieve the device's Packets per Second Variable. [[nodiscard]] int32_t PacketsPerSecondSent() const; /// Retrieve the index of this device within SenseCom. [[nodiscard]] int32_t GetDeviceIndex() const; /// Change this device's index within the SenseCom. Warning: Can cause errors. void SetDeviceIndex(int32_t newIndex); /// Returns true if this device is connected over a connection other than usb cable. /// [[nodiscard]] virtual bool IsWireless() const; /// Returns true if this device operates on a battery. /// [[nodiscard]] virtual bool HasBattery() const; /// Returns true if this device is currently charging. /// [[nodiscard]] virtual bool IsCharging(); /// Returns the device's battery level, as a value between 0 (empty) and 1 (full). /// /// virtual bool GetBatteryLevel(float& out_batteryLevel); //-------------------------------------------------------------------------------------- // Class Methods /// Get a string representation of this SGDevice, used for debugging. [[nodiscard]] virtual std::string ToString() const; };