From e9cd9ca3b637b867c3ae9d4377243311651add9c Mon Sep 17 00:00:00 2001 From: Mamadou Babaei Date: Fri, 18 Nov 2022 10:16:52 +0100 Subject: [PATCH] add missing sg device wrappers in layer 4 of the api and also more documentation --- .../Private/SGCore/SGDevice.cpp | 4 +- .../SenseGloveCore/Public/SGCore/SGDevice.h | 74 ++++++++++++++++++- .../Private/SGCoreImpl/SGDeviceImpl.cpp | 4 +- .../SGCoreImpl/SGExportedFunctions.cpp | 4 +- .../Public/SGCoreImpl/SGDeviceImpl.h | 2 +- .../Public/SGCoreImpl/SGExportedFunctions.h | 2 +- .../SGCoreKismet/SGDeviceKismetLibrary.cpp | 10 +++ .../SGCoreKismet/SGDeviceKismetLibrary.h | 72 +++++++++++++++++- 8 files changed, 159 insertions(+), 13 deletions(-) diff --git a/Source/SenseGloveCore/Private/SGCore/SGDevice.cpp b/Source/SenseGloveCore/Private/SGCore/SGDevice.cpp index 0ae40b0b..a509c2ea 100644 --- a/Source/SenseGloveCore/Private/SGCore/SGDevice.cpp +++ b/Source/SenseGloveCore/Private/SGCore/SGDevice.cpp @@ -426,12 +426,12 @@ int32 USGDevice::GetDeviceIndex() const return SGCoreImpl_FSGDeviceImpl_GetDeviceIndex(&InstanceContainer); } -void USGDevice::SetDeviceIndex(const int32 Index) +void USGDevice::SetDeviceIndex(const int32 NewIndex) { SyncImplObject(); FSGIC_TSharedPtr_FSGDeviceImpl InstanceContainer{ToSGDeviceImpl()}; - SGCoreImpl_FSGDeviceImpl_SetDeviceIndex(&InstanceContainer, Index); + SGCoreImpl_FSGDeviceImpl_SetDeviceIndex(&InstanceContainer, NewIndex); SyncUProperties(); } diff --git a/Source/SenseGloveCore/Public/SGCore/SGDevice.h b/Source/SenseGloveCore/Public/SGCore/SGDevice.h index d830a188..1c60c4ea 100644 --- a/Source/SenseGloveCore/Public/SGCore/SGDevice.h +++ b/Source/SenseGloveCore/Public/SGCore/SGDevice.h @@ -29,7 +29,9 @@ * * @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. */ @@ -49,14 +51,23 @@ 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: @@ -71,6 +82,9 @@ private: FImplDeleter PimplDeleter; protected: + /** + * The basic constructor. + */ USGDevice(); public: @@ -200,39 +214,93 @@ protected: virtual void SyncUProperties(); 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; - void SetDeviceIndex(const int32 Index); + /** + * 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; -}; \ No newline at end of file +}; diff --git a/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGDeviceImpl.cpp b/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGDeviceImpl.cpp index 73773290..eba45f16 100644 --- a/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGDeviceImpl.cpp +++ b/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGDeviceImpl.cpp @@ -242,9 +242,9 @@ int32 FSGDeviceImpl::GetDeviceIndex() const return ToSGDevicePtrChecked()->GetDeviceIndex(); } -void FSGDeviceImpl::SetDeviceIndex(const int32 Index) +void FSGDeviceImpl::SetDeviceIndex(const int32 NewIndex) { - ToSGDevicePtrChecked()->SetDeviceIndex(Index); + ToSGDevicePtrChecked()->SetDeviceIndex(NewIndex); } bool FSGDeviceImpl::IsWireless() const diff --git a/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGExportedFunctions.cpp b/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGExportedFunctions.cpp index f93c47a9..dc78b3a4 100644 --- a/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGExportedFunctions.cpp +++ b/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGExportedFunctions.cpp @@ -1089,9 +1089,9 @@ int32 SGCoreImpl_FSGDeviceImpl_GetDeviceIndex( void SGCoreImpl_FSGDeviceImpl_SetDeviceIndex( void* Instance, - const int32 Index) + const int32 NewIndex) { - return StaticCast(Instance)->Ptr->SetDeviceIndex(Index); + return StaticCast(Instance)->Ptr->SetDeviceIndex(NewIndex); } bool SGCoreImpl_FSGDeviceImpl_IsWireless( diff --git a/Source/SenseGloveCoreImpl/Public/SGCoreImpl/SGDeviceImpl.h b/Source/SenseGloveCoreImpl/Public/SGCoreImpl/SGDeviceImpl.h index 70a242f2..800dc46a 100644 --- a/Source/SenseGloveCoreImpl/Public/SGCoreImpl/SGDeviceImpl.h +++ b/Source/SenseGloveCoreImpl/Public/SGCoreImpl/SGDeviceImpl.h @@ -170,7 +170,7 @@ public: int32 PacketsPerSecondSent() const; int32 GetDeviceIndex() const; - void SetDeviceIndex(int32 Index); + void SetDeviceIndex(int32 NewIndex); virtual bool IsWireless() const; diff --git a/Source/SenseGloveCoreImpl/Public/SGCoreImpl/SGExportedFunctions.h b/Source/SenseGloveCoreImpl/Public/SGCoreImpl/SGExportedFunctions.h index d1a7f6f6..093d7ecb 100644 --- a/Source/SenseGloveCoreImpl/Public/SGCoreImpl/SGExportedFunctions.h +++ b/Source/SenseGloveCoreImpl/Public/SGCoreImpl/SGExportedFunctions.h @@ -556,7 +556,7 @@ SENSEGLOVECOREIMPL_PUBLIC_API int32 SGCoreImpl_FSGDeviceImpl_GetDeviceIndex( SENSEGLOVECOREIMPL_PUBLIC_API void SGCoreImpl_FSGDeviceImpl_SetDeviceIndex( void* Instance, - int32 Index); + int32 NewIndex); SENSEGLOVECOREIMPL_PUBLIC_API bool SGCoreImpl_FSGDeviceImpl_IsWireless( void* Instance); diff --git a/Source/SenseGloveCoreKismet/Private/SGCoreKismet/SGDeviceKismetLibrary.cpp b/Source/SenseGloveCoreKismet/Private/SGCoreKismet/SGDeviceKismetLibrary.cpp index fa5df41d..80947578 100644 --- a/Source/SenseGloveCoreKismet/Private/SGCoreKismet/SGDeviceKismetLibrary.cpp +++ b/Source/SenseGloveCoreKismet/Private/SGCoreKismet/SGDeviceKismetLibrary.cpp @@ -102,6 +102,16 @@ int32 USGDeviceKismetLibrary::PacketsPerSecondSent(const USGDevice* SGDevice) return SGDevice->PacketsPerSecondSent(); } +int32 USGDeviceKismetLibrary::GetDeviceIndex(const USGDevice* SGDevice) +{ + return SGDevice->GetDeviceIndex(); +} + +void USGDeviceKismetLibrary::SetDeviceIndex(USGDevice* SGDevice, const int32 NewIndex) +{ + SGDevice->SetDeviceIndex(NewIndex); +} + bool USGDeviceKismetLibrary::IsWireless(const USGDevice* SGDevice) { return SGDevice->IsWireless(); diff --git a/Source/SenseGloveCoreKismet/Public/SGCoreKismet/SGDeviceKismetLibrary.h b/Source/SenseGloveCoreKismet/Public/SGCoreKismet/SGDeviceKismetLibrary.h index f3491d42..e4d27a0b 100644 --- a/Source/SenseGloveCoreKismet/Public/SGCoreKismet/SGDeviceKismetLibrary.h +++ b/Source/SenseGloveCoreKismet/Public/SGCoreKismet/SGDeviceKismetLibrary.h @@ -29,7 +29,9 @@ * * @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. */ @@ -48,57 +50,123 @@ class SENSEGLOVECOREKISMET_API USGDeviceKismetLibrary : public USGBlueprintFunct GENERATED_BODY() public: + /** + * Parse a main and sub firmware version from its raw (v4.12) notation + */ UFUNCTION(BlueprintCallable, Category="SenseGlove | Core | SGDevice") static void ParseFirmware(const FString& RawFirmware, int32& OutMainVersion, int32& OutSubVersion); + /** + * + */ UFUNCTION(BlueprintCallable, DisplayName="To String", Category="SenseGlove | Core | SGDevice") static FString ToString_DT(ESGDeviceType DeviceType); + /** + * Check which DeviceType this class belongs to. + */ UFUNCTION(BlueprintPure, Category="SenseGlove | Core | SGDevice") static ESGDeviceType GetDeviceType(const USGDevice* SGDevice); + /** + * Retrieve this device's unique identifier. + */ UFUNCTION(BlueprintPure, Category="SenseGlove | Core | SGDevice") static FString GetDeviceId(const USGDevice* SGDevice); + /** + * Retrieve this device's hardware version. + */ UFUNCTION(BlueprintPure, Category="SenseGlove | Core | SGDevice") static FString GetHardwareVersion(const USGDevice* SGDevice); + /** + * Retrieve this device's main firmware version. v4.12 returns 4. + */ UFUNCTION(BlueprintPure, Category="SenseGlove | Core | SGDevice") static int32 GetFirmwareVersion(const USGDevice* SGDevice); + /** + * Retrieve this device's sub firmware version. v4.12 returns 12. + */ UFUNCTION(BlueprintPure, Category="SenseGlove | Core | SGDevice") static int32 GetSubFirmwareVersion(const USGDevice* SGDevice); + /** + * + */ UFUNCTION(BlueprintPure, Category="SenseGlove | Core | SGDevice") static FString GetFirmwareString(const USGDevice* SGDevice); + /** + * Retrieve this Device's Serial/Bluetooth address. + */ UFUNCTION(BlueprintPure, Category="SenseGlove | Core | SGDevice") static FString GetAddress(const USGDevice* SGDevice); + /** + * Check if this device is currently connected to the system. + */ UFUNCTION(BlueprintPure, Category="SenseGlove | Core | SGDevice") static bool IsConnected(const USGDevice* SGDevice); + /** + * Retrieve the connection type of this Sense Glove. + */ UFUNCTION(BlueprintPure, Category="SenseGlove | Core | SGDevice") static ESGConnectionType GetConnectionType(const USGDevice* SGDevice); + /** + * Retrieve the device's Packets per Second Variable. + */ UFUNCTION(BlueprintPure, Category="SenseGlove | Core | SGDevice") static int32 PacketsPerSecondReceived(const USGDevice* SGDevice); + /** + * Retrieve the device's Packets per Second Variable. + */ UFUNCTION(BlueprintPure, Category="SenseGlove | Core | SGDevice") static int32 PacketsPerSecondSent(const USGDevice* SGDevice); + /** + * Retrieve the index of this device within SenseCom. + */ + UFUNCTION(BlueprintPure, Category="SenseGlove | Core | SGDevice") + static int32 GetDeviceIndex(const USGDevice* SGDevice); + + /** + * Change this device's index within the SenseCom. Warning: Can cause errors. + */ + UFUNCTION(BlueprintCallable, Category="SenseGlove | Core | SGDevice") + static void SetDeviceIndex(UPARAM(ref) USGDevice* SGDevice, int32 NewIndex); + + /** + * Returns true if this device is connected over a connection other than usb cable. + */ UFUNCTION(BlueprintPure, Category="SenseGlove | Core | SGDevice") static bool IsWireless(const USGDevice* SGDevice); + /** + * Returns true if this device operates on a battery. + */ UFUNCTION(BlueprintPure, Category="SenseGlove | Core | SGDevice") static bool HasBattery(const USGDevice* SGDevice); + /** + * Returns true if this device is currently charging. + */ UFUNCTION(BlueprintCallable, Category="SenseGlove | Core | SGDevice") static bool IsCharging(UPARAM(ref) USGDevice* SGDevice); + /** + * Returns the device's battery level, as a value between 0 (empty) and 1 (full). + */ UFUNCTION(BlueprintCallable, Category="SenseGlove | Core | SGDevice") static bool GetBatteryLevel(UPARAM(ref) USGDevice* SGDevice, float& OutLevel); + /** + * Get a string representation of this SGDevice, used for debugging. + */ UFUNCTION(BlueprintPure, Category="SenseGlove | Core | SGDevice") static FString ToString(const USGDevice* SGDevice); -}; \ No newline at end of file +};