407 lines
11 KiB
C++
407 lines
11 KiB
C++
/**
|
|
* @file
|
|
*
|
|
* @author Mamadou Babaei <mamadou@senseglove.com>
|
|
*
|
|
* @section LICENSE
|
|
*
|
|
* (The MIT License)
|
|
*
|
|
* Copyright (c) 2020 - 2024 SenseGlove
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
* in the Software without restriction, including without limitation the rights
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
* copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
* SOFTWARE.
|
|
*
|
|
* @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 "Containers/UnrealString.h"
|
|
#include "HAL/Platform.h"
|
|
#include "Templates/UniquePtr.h"
|
|
#include "UObject/Object.h"
|
|
#include "UObject/ObjectMacros.h"
|
|
|
|
#include "SGTypes/SGCoreTypes.h"
|
|
|
|
#include "SGDevice.generated.h"
|
|
|
|
class FSGBetaDeviceImpl;
|
|
class FSGDeviceImpl;
|
|
class FSGHapticGloveImpl;
|
|
class FSGNovaGloveImpl;
|
|
class FSGNova2GloveImpl;
|
|
class FSGSenseGloveImpl;
|
|
class USGHapticChannelInfo;
|
|
class USGBetaDevice;
|
|
class USGHapticGlove;
|
|
class USGNova2Glove;
|
|
class USGNovaGlove;
|
|
class USGSenseGlove;
|
|
|
|
/**
|
|
*
|
|
*/
|
|
UCLASS(Abstract, BlueprintType)
|
|
class SENSEGLOVECORE_API USGDevice : public UObject
|
|
{
|
|
GENERATED_BODY()
|
|
|
|
public:
|
|
/**
|
|
* Parse a main and sub firmware version from its raw (v4.12) notation
|
|
*/
|
|
static void ParseFirmware(const FString& RawFirmware, int32& OutMainVersion, int32& OutSubVersion);
|
|
|
|
/**
|
|
* If true, my firmware is newer than the reference firmware.
|
|
*
|
|
* @param MyFirmwareMain
|
|
* @param MyFirmwareSub
|
|
* @param ReferenceMain
|
|
* @param ReferenceSub
|
|
* @param bInclusive
|
|
*/
|
|
static bool FirmwareNewerThan(int32 MyFirmwareMain, int32 MyFirmwareSub,
|
|
int32 ReferenceMain, int32 ReferenceSub,
|
|
bool bInclusive);
|
|
|
|
/**
|
|
* If true, my firmware is older than the reference firmware.
|
|
*
|
|
* @param MyFirmwareMain
|
|
* @param MyFirmwareSub
|
|
* @param ReferenceMain
|
|
* @param ReferenceSub
|
|
* @param bInclusive
|
|
*/
|
|
static bool FirmwareOlderThan(int32 MyFirmwareMain, int32 MyFirmwareSub,
|
|
int32 ReferenceMain, int32 ReferenceSub,
|
|
bool bInclusive);
|
|
|
|
/**
|
|
*
|
|
*/
|
|
static FString ToString(ESGDeviceType DeviceType);
|
|
|
|
private:
|
|
struct FImpl;
|
|
|
|
struct FImplDeleter
|
|
{
|
|
void operator()(const FImpl* P) const;
|
|
};
|
|
|
|
TUniquePtr<FImpl, FImplDeleter> Pimpl;
|
|
FImplDeleter PimplDeleter;
|
|
|
|
protected:
|
|
/**
|
|
* The basic constructor.
|
|
*/
|
|
USGDevice();
|
|
|
|
public:
|
|
/**
|
|
* The cast from underlying type constructor.
|
|
*/
|
|
explicit USGDevice(const FSGDeviceImpl& SGDeviceImpl);
|
|
|
|
/**
|
|
* The cast from underlying child type constructor.
|
|
*/
|
|
explicit USGDevice(const FSGBetaDeviceImpl& BetaDeviceImpl);
|
|
|
|
/**
|
|
* The cast from underlying child type constructor.
|
|
*/
|
|
explicit USGDevice(const FSGHapticGloveImpl& HapticGloveImpl);
|
|
|
|
/**
|
|
* The cast from underlying child type constructor.
|
|
*/
|
|
explicit USGDevice(const FSGNova2GloveImpl& Nova2GloveImpl);
|
|
|
|
/**
|
|
* The cast from underlying child type constructor.
|
|
*/
|
|
explicit USGDevice(const FSGNovaGloveImpl& NovaGloveImpl);
|
|
|
|
/**
|
|
* The cast from underlying child type constructor.
|
|
*/
|
|
explicit USGDevice(const FSGSenseGloveImpl& SenseGloveImpl);
|
|
|
|
protected:
|
|
/**
|
|
* The cast from underlying pointer type constructor.
|
|
*/
|
|
explicit USGDevice(TSharedRef<FSGDeviceImpl> SGDeviceImpl);
|
|
|
|
/**
|
|
* The cast from underlying child pointer type constructor.
|
|
*/
|
|
explicit USGDevice(TSharedRef<FSGBetaDeviceImpl> BetaDeviceImpl);
|
|
|
|
/**
|
|
* The cast from underlying child pointer type constructor.
|
|
*/
|
|
explicit USGDevice(TSharedRef<FSGHapticGloveImpl> HapticGloveImpl);
|
|
|
|
/**
|
|
* The cast from underlying child pointer type constructor.
|
|
*/
|
|
explicit USGDevice(TSharedRef<FSGNova2GloveImpl> Nova2GloveImpl);
|
|
|
|
/**
|
|
* The cast from underlying child pointer type constructor.
|
|
*/
|
|
explicit USGDevice(TSharedRef<FSGNovaGloveImpl> NovaGloveImpl);
|
|
|
|
/**
|
|
* The cast from underlying child pointer type constructor.
|
|
*/
|
|
explicit USGDevice(TSharedRef<FSGSenseGloveImpl> SenseGloveImpl);
|
|
|
|
public:
|
|
/**
|
|
* The destructor.
|
|
*/
|
|
virtual ~USGDevice() override;
|
|
|
|
protected:
|
|
/**
|
|
* Allows the child classes to set the underlying object after construction.
|
|
*/
|
|
void SetSGDeviceImpl(const FSGDeviceImpl& SGDeviceImpl);
|
|
|
|
/**
|
|
* Allows the child classes to set the underlying object after construction.
|
|
*/
|
|
void SetSGDeviceImpl(const FSGBetaDeviceImpl& BetaDeviceImpl);
|
|
|
|
/**
|
|
* Allows the child classes to set the underlying object after construction.
|
|
*/
|
|
void SetSGDeviceImpl(const FSGHapticGloveImpl& HapticGloveImpl);
|
|
|
|
/**
|
|
* Allows the child classes to set the underlying object after construction.
|
|
*/
|
|
void SetSGDeviceImpl(const FSGNova2GloveImpl& Nova2GloveImpl);
|
|
|
|
/**
|
|
* Allows the child classes to set the underlying object after construction.
|
|
*/
|
|
void SetSGDeviceImpl(const FSGNovaGloveImpl& NovaGloveImpl);
|
|
|
|
/**
|
|
* Allows the child classes to set the underlying object after construction.
|
|
*/
|
|
void SetSGDeviceImpl(const FSGSenseGloveImpl& SenseGloveImpl);
|
|
|
|
/**
|
|
* Allows the child classes to set the underlying object after construction.
|
|
*/
|
|
void SetSGDeviceImpl(TSharedRef<FSGDeviceImpl> SGDeviceImpl);
|
|
|
|
/**
|
|
* Allows the child classes to set the underlying object after construction.
|
|
*/
|
|
void SetSGDeviceImpl(TSharedRef<FSGBetaDeviceImpl> BetaDeviceImpl);
|
|
|
|
/**
|
|
* Allows the child classes to set the underlying object after construction.
|
|
*/
|
|
void SetSGDeviceImpl(TSharedRef<FSGHapticGloveImpl> HapticGloveImpl);
|
|
|
|
/**
|
|
* Allows the child classes to set the underlying object after construction.
|
|
*/
|
|
void SetSGDeviceImpl(TSharedRef<FSGNova2GloveImpl> Nova2GloveImpl);
|
|
|
|
/**
|
|
* Allows the child classes to set the underlying object after construction.
|
|
*/
|
|
void SetSGDeviceImpl(TSharedRef<FSGNovaGloveImpl> NovaGloveImpl);
|
|
|
|
/**
|
|
* Allows the child classes to set the underlying object after construction.
|
|
*/
|
|
void SetSGDeviceImpl(TSharedRef<FSGSenseGloveImpl> SenseGloveImpl);
|
|
|
|
public:
|
|
/**
|
|
* The cast to underlying type method.
|
|
*/
|
|
TSharedRef<FSGDeviceImpl> ToSGDeviceImpl() const;
|
|
|
|
public:
|
|
bool IsABetaDevice() const;
|
|
bool IsAHapticGlove() const;
|
|
bool IsANova2Glove() const;
|
|
bool IsANovaGlove() const;
|
|
bool IsASenseGlove() const;
|
|
|
|
public:
|
|
USGBetaDevice* AsBetaDevice(UObject* Outer) const;
|
|
|
|
USGHapticGlove* AsHapticGlove(UObject* Outer) const;
|
|
|
|
USGNova2Glove* AsNova2Glove(UObject* Outer) const;
|
|
|
|
USGNovaGlove* AsNovaGlove(UObject* Outer) const;
|
|
|
|
USGSenseGlove* AsSenseGlove(UObject* Outer) const;
|
|
|
|
public:
|
|
/**
|
|
* Check which DeviceType this class belongs to.
|
|
*/
|
|
virtual ESGDeviceType GetDeviceType() const;
|
|
|
|
/**
|
|
* Retrieve this device's unique identifier.
|
|
*/
|
|
virtual FString GetDeviceId() const PURE_VIRTUAL(FSGDevice::GetDeviceId, return FString(););
|
|
|
|
/**
|
|
* Retrieve this device's hardware version.
|
|
*/
|
|
virtual FString GetHardwareVersion() const PURE_VIRTUAL(FSGDevice::GetHardwareVersion, return FString(););
|
|
|
|
/**
|
|
* Retrieve this device's main firmware version. v4.12 returns 4.
|
|
*/
|
|
virtual int32 GetFirmwareVersion() const PURE_VIRTUAL(FSGDevice::FirmwareVersion, return -1;);
|
|
|
|
/**
|
|
* Retrieve this device's sub firmware version. v4.12 returns 12.
|
|
*/
|
|
virtual int32 GetSubFirmwareVersion() const;
|
|
|
|
/**
|
|
*
|
|
*/
|
|
virtual FString GetFirmwareString() const;
|
|
|
|
/**
|
|
* Returns true if this glove's firmware is newer than certain version.
|
|
*
|
|
* @param FirmwareMain
|
|
* @param FirmwareSub
|
|
* @param bInclusive
|
|
*/
|
|
bool FirmwareNewerThan(int32 FirmwareMain, int32 FirmwareSub, bool bInclusive) const;
|
|
|
|
/**
|
|
* Returns true if this glove's firmware is older than certain version.
|
|
*
|
|
* @param FirmwareMain
|
|
* @param FirmwareSub
|
|
* @param bInclusive
|
|
*/
|
|
bool FirmwareOlderThan(int32 FirmwareMain, int32 FirmwareSub, bool bInclusive) const;
|
|
|
|
/**
|
|
* Retrieve this Device's Serial/Bluetooth address.
|
|
*/
|
|
FString GetAddress() const;
|
|
|
|
/**
|
|
* Check if this device is currently connected to the system.
|
|
*/
|
|
bool IsConnected() const;
|
|
|
|
/**
|
|
* Retrieve the connection type of this Sense Glove.
|
|
*/
|
|
ESGConnectionType GetConnectionType() const;
|
|
|
|
/**
|
|
* Retrieve the device's Packets per Second Variable.
|
|
*/
|
|
int32 PacketsPerSecondReceived() const;
|
|
|
|
/**
|
|
* Retrieve the device's Packets per Second Variable.
|
|
*/
|
|
int32 PacketsPerSecondSent() const;
|
|
|
|
/**
|
|
* Retrieve the index of this device within SenseCom.
|
|
*/
|
|
int32 GetDeviceIndex() const;
|
|
|
|
/**
|
|
* Change this device's index within the SenseCom. Warning: Can cause errors.
|
|
*/
|
|
virtual void SetDeviceIndex(int32 NewIndex);
|
|
|
|
/**
|
|
* Returns true if this device is connected over a connection other than usb cable.
|
|
*/
|
|
virtual bool IsWireless() const;
|
|
|
|
/**
|
|
* Returns true if this device operates on a battery.
|
|
*/
|
|
virtual bool HasBattery() const;
|
|
|
|
/**
|
|
* Returns true if this device is currently charging.
|
|
*/
|
|
virtual bool IsCharging();
|
|
|
|
/**
|
|
* Returns the device's battery level, as a value between 0 (empty) and 1 (full).
|
|
*/
|
|
virtual bool GetBatteryLevel(float& OutLevel);
|
|
|
|
public:
|
|
/**
|
|
* Assign this Device's Haptic Channels. Should not be done outside the API unless you know what you're doing.
|
|
*
|
|
* @param Channels
|
|
*/
|
|
virtual void SetHapticChannels(const USGHapticChannelInfo* Channels);
|
|
|
|
/**
|
|
* The number of haptic channels this device can support.
|
|
*/
|
|
int32 GetHapticChannelCount() const;
|
|
|
|
/**
|
|
* How many channels of a specific type this SGDevice possesses.
|
|
*
|
|
* @param ChannelType
|
|
*/
|
|
int32 GetHapticChannelCount(ESGHapticChannelType ChannelType) const;
|
|
|
|
public:
|
|
/**
|
|
* Get a string representation of this SGDevice, used for debugging.
|
|
*/
|
|
virtual FString ToString() const;
|
|
}; |