Files
Plugin/Source/ThirdParty/include/SenseGlove/Core/SGDevice.hpp
T

234 lines
8.0 KiBLFS
C++

/**
* @file
*
* @author Max Lammers <max@senseglove.com>
* @author Mamadou Babaei <mamadou@senseglove.com>
*
* @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 <cstdint>
#include <memory>
#include <string>
#include "DeviceTypes.hpp"
#include "Platform.hpp"
namespace SGCore
{
class SGCORE_API SGDevice;
}// namespace SGCore
class SGCORE_API SGCore::SGDevice
{
public:
/// <summary> Connection type of this device, as detected by the SGConnect library. </summary>
enum class EConnectionType : int8_t
{
/// <summary> Could not determine which connection type this SGDevice is using, most likely because it is disconnected. </summary>
Unknown = -1,
/// <summary> USB Serial communication. </summary>
Serial,
/// <summary> A bluetooth connection that creates up to two Serial Ports. </summary>
BluetoothSerial,
/// <summary> Bluetooth Connection Via Android/Java SDK </summary>
BluetoothAndroid
};
public:
/// <summary> Parse a main and sub firmware version from its raw (v4.12) notation. </summary>
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<Impl> Pimpl;
public:
/// <summary> The basic constructor. </summary>
SGDevice();
/**
* The copy constructor.
*/
SGDevice(const SGDevice& rhs);
/**
* The move constructor.
*/
SGDevice(SGDevice&& rhs) noexcept;
/// <summary> The basic destructor. </summary>
virtual ~SGDevice();
public:
/**
* The copy assignment operator.
*/
SGDevice& operator=(const SGDevice& rhs);
/**
* The move assignment operator.
*/
SGDevice& operator=(SGDevice&& rhs) noexcept;
public:
//--------------------------------------------------------------------------------------
// Device Accessors
///<summary> Check which DeviceType this class belongs to. </summary>
#if !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN )
[[nodiscard]]
#endif /* !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) */
virtual EDeviceType GetDeviceType() const;
/// <summary> Retrieve this device's unique identifier. </summary>
#if SENSEGLOVE_UNREAL_ENGINE_PLUGIN
#if !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN )
[[nodiscard]]
#endif /* !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) */
virtual std::string GetDeviceId() const;
#else /* SENSEGLOVE_UNREAL_ENGINE_PLUGIN */
#if !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN )
[[nodiscard]]
#endif /* !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) */
virtual std::string GetDeviceId() const = 0;
#endif /* SENSEGLOVE_UNREAL_ENGINE_PLUGIN */
/// <summary> Retrieve this device's hardware version. </summary>
#if SENSEGLOVE_UNREAL_ENGINE_PLUGIN
#if !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN )
[[nodiscard]]
#endif /* !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) */
virtual std::string GetHardwareVersion() const;
#else /* SENSEGLOVE_UNREAL_ENGINE_PLUGIN */
#if !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN )
[[nodiscard]]
#endif /* !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) */
virtual std::string GetHardwareVersion() const = 0;
#endif /* SENSEGLOVE_UNREAL_ENGINE_PLUGIN */
/// <summary> Retrieve this device's main firmware version. v4.12 returns 4. </summary>
#if SENSEGLOVE_UNREAL_ENGINE_PLUGIN
#if !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN )
[[nodiscard]]
#endif /* !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) */
virtual int32_t GetFirmwareVersion() const;
#else /* SENSEGLOVE_UNREAL_ENGINE_PLUGIN */
#if !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN )
[[nodiscard]]
#endif /* !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) */
virtual int32_t GetFirmwareVersion() const = 0;
#endif /* SENSEGLOVE_UNREAL_ENGINE_PLUGIN */
/// <summary> Retrieve this device's sub firmware version. v4.12 returns 12. </summary>
#if !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN )
[[nodiscard]]
#endif /* !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) */
virtual int32_t GetSubFirmwareVersion() const;
#if !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN )
[[nodiscard]]
#endif /* !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) */
virtual std::string GetFirmwareString() const;
protected:
#if !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN )
[[nodiscard]]
#endif /* !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) */
const std::string& GetIpcAddress() const;
public:
//--------------------------------------------------------------------------------------
// I/O Accessors
///<summary> Retrieve this Device's Serial/Bluetooth address. </summary>
#if !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN )
[[nodiscard]]
#endif /* !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) */
std::string GetAddress() const;
/// <summary> Check if this device is currently connected to the system. </summary>
#if !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN )
[[nodiscard]]
#endif /* !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) */
bool IsConnected() const;
/// <summary> Retrieve the connection type of this Sense Glove. </summary>
#if !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN )
[[nodiscard]]
#endif /* !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) */
EConnectionType GetConnectionType() const;
/// <summary> Retrieve the device's Packets per Second Variable. </summary>
#if !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN )
[[nodiscard]]
#endif /* !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) */
int32_t PacketsPerSecondReceived() const;
/// <summary> Retrieve the device's Packets per Second Variable. </summary>
#if !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN )
[[nodiscard]]
#endif /* !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) */
int32_t PacketsPerSecondSent() const;
/// <summary> Retrieve the index of this device within SenseCom. </summary>
#if !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN )
[[nodiscard]]
#endif /* !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) */
int32_t GetDeviceIndex() const;
/// <summary> Change this device's index within the SenseCom. Warning: Can cause errors. </summary>
void SetDeviceIndex(int32_t newIndex);
/// <summary> Returns true if this device is connected over a connection other than usb cable. </summary>
/// <returns></returns>
#if !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN )
[[nodiscard]]
#endif /* !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) */
virtual bool IsWireless() const;
/// <summary> Returns true if this device operates on a battery. </summary>
/// <returns></returns>
#if !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN )
[[nodiscard]]
#endif /* !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) */
virtual bool HasBattery() const;
/// <summary> Returns true if this device is currently charging. </summary>
/// <returns></returns>
#if !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN )
[[nodiscard]]
#endif /* !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) */
virtual bool IsCharging();
/// <summary> Returns the device's battery level, as a value between 0 (empty) and 1 (full). </summary>
/// <param name="battLvl"></param>
/// <returns></returns>
virtual bool GetBatteryLevel(float& out_batteryLevel);
//--------------------------------------------------------------------------------------
// Class Methods
///<summary> Get a string representation of this SGDevice, used for debugging. </summary>
#if !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN )
[[nodiscard]]
#endif /* !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) */
virtual std::string ToString() const;
};