Files
Plugin/Source/SenseGloveCore/Public/SGCore/SGDevice.h
T

295 lines
7.9 KiB
C++

/**
* @file
*
* @author Mamadou Babaei <mamadou@senseglove.com>
*
* @section LICENSE
*
* (The MIT License)
*
* Copyright (c) 2020 - 2023 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 "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 FSGSenseGloveImpl;
/**
*
*/
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);
/**
*
*/
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 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<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 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<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:
/**
* 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;
/**
* 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.
*/
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);
/**
* Get a string representation of this SGDevice, used for debugging.
*/
virtual FString ToString() const;
};