211 lines
6.3 KiB
C++
211 lines
6.3 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
|
|
*
|
|
*
|
|
*/
|
|
|
|
|
|
#include "SGCoreImpl/SGBetaDeviceImpl.h"
|
|
|
|
#include "Containers/StringConv.h"
|
|
#include "Misc/AssertionMacros.h"
|
|
#include "Runtime/Launch/Resources/Version.h"
|
|
|
|
#include "SGBuildHacks/SGInclude_Core_BetaDevice.h"
|
|
#include "SGBuildHacks/SGInclude_Core_SGDevice.h"
|
|
#include "SGCoreImpl/SGCoreEnumCast.h"
|
|
|
|
struct FSGBetaDeviceImpl::FImpl
|
|
{
|
|
/************************
|
|
* Owner object
|
|
************************/
|
|
|
|
FSGBetaDeviceImpl* Owner;
|
|
|
|
/************************
|
|
* Constructor / Destructor
|
|
************************/
|
|
|
|
explicit FImpl(FSGBetaDeviceImpl* InOwner);
|
|
~FImpl();
|
|
|
|
/************************
|
|
* Default copy constructor & copy assignment operator
|
|
************************/
|
|
|
|
FImpl(const FImpl& Rhs) = default;
|
|
FImpl& operator=(const FImpl& Rhs) = default;
|
|
};
|
|
|
|
TSharedRef<FSGBetaDeviceImpl> FSGBetaDeviceImpl::Parse(const FString& String)
|
|
{
|
|
FSGDevicePtrType SGDevicePtr{FBetaDeviceType::Parse(TCHAR_TO_UTF8(*String))};
|
|
ensureAlwaysMsgf(SGDevicePtr, TEXT("Invalid SGDevice!"));
|
|
TSharedRef<FSGBetaDeviceImpl> BetaDeviceImpl{MakeShared<FSGBetaDeviceImpl>(
|
|
std::dynamic_pointer_cast<FBetaDeviceType>(MoveTemp(SGDevicePtr)))};
|
|
return MoveTemp(BetaDeviceImpl);
|
|
}
|
|
|
|
FSGBetaDeviceImpl::FSGBetaDeviceImpl()
|
|
: FSGDeviceImpl(),
|
|
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
|
|
{
|
|
}
|
|
|
|
FSGBetaDeviceImpl::FSGBetaDeviceImpl(const FString& ConstantsString, const FString& DeviceId,
|
|
const FString& HardwareVersion, int32 FirmwareVersion, int32 SubFirmwareVersion)
|
|
: FSGDeviceImpl(std::make_shared<FBetaDeviceType>(
|
|
TCHAR_TO_UTF8(*ConstantsString),
|
|
TCHAR_TO_UTF8(*DeviceId),
|
|
TCHAR_TO_UTF8(*HardwareVersion),
|
|
FirmwareVersion,
|
|
SubFirmwareVersion)),
|
|
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
|
|
{
|
|
}
|
|
|
|
FSGBetaDeviceImpl::FSGBetaDeviceImpl(const FBetaDeviceType BetaDevice)
|
|
: FSGDeviceImpl(std::make_shared<FBetaDeviceType>(BetaDevice)),
|
|
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
|
|
{
|
|
}
|
|
|
|
FSGBetaDeviceImpl::FSGBetaDeviceImpl(const FBetaDevicePtrType BetaDevice)
|
|
: FSGDeviceImpl(BetaDevice),
|
|
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
|
|
{
|
|
}
|
|
|
|
FSGBetaDeviceImpl::FSGBetaDeviceImpl(const FSGBetaDeviceImpl& Rhs)
|
|
: FSGDeviceImpl(Rhs),
|
|
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{*Rhs.Pimpl}, PimplDeleter))
|
|
{
|
|
Pimpl->Owner = this;
|
|
}
|
|
|
|
FSGBetaDeviceImpl::FSGBetaDeviceImpl(FSGBetaDeviceImpl&& Rhs) SG_NOEXCEPT = default;
|
|
|
|
FSGBetaDeviceImpl::~FSGBetaDeviceImpl() = default;
|
|
|
|
FSGBetaDeviceImpl& FSGBetaDeviceImpl::operator=(const FSGBetaDeviceImpl& Rhs)
|
|
{
|
|
FSGDeviceImpl::operator=(Rhs);
|
|
*Pimpl = *Rhs.Pimpl;
|
|
Pimpl->Owner = this;
|
|
return *this;
|
|
}
|
|
|
|
FSGBetaDeviceImpl& FSGBetaDeviceImpl::operator=(FSGBetaDeviceImpl&& Rhs) SG_NOEXCEPT = default;
|
|
|
|
FSGBetaDeviceImpl::FBetaDeviceType FSGBetaDeviceImpl::ToBetaDevice() const
|
|
{
|
|
return *ToBetaDevicePtr();
|
|
}
|
|
|
|
FSGBetaDeviceImpl::FBetaDevicePtrType FSGBetaDeviceImpl::ToBetaDevicePtr() const
|
|
{
|
|
return std::dynamic_pointer_cast<FBetaDeviceType>(ToSGDevicePtr());
|
|
}
|
|
|
|
FSGBetaDeviceImpl::FBetaDevicePtrType FSGBetaDeviceImpl::ToBetaDevicePtrChecked() const
|
|
{
|
|
FBetaDevicePtrType BetaDevice = std::dynamic_pointer_cast<FBetaDeviceType>(ToSGDevicePtr());
|
|
ensureAlwaysMsgf(BetaDevice.get(), TEXT("Invalid BetaDevice"));
|
|
return BetaDevice;
|
|
}
|
|
|
|
ESGDeviceType FSGBetaDeviceImpl::GetDeviceType() const
|
|
{
|
|
return FSGCoreEnumCast::ToESGDeviceType(ToBetaDevicePtrChecked()->GetDeviceType());
|
|
}
|
|
|
|
FString FSGBetaDeviceImpl::GetDeviceId() const
|
|
{
|
|
FString Id{UTF8_TO_TCHAR(ToBetaDevicePtrChecked()->GetDeviceId().c_str())};
|
|
return MoveTemp(Id);
|
|
}
|
|
|
|
FString FSGBetaDeviceImpl::GetHardwareVersion() const
|
|
{
|
|
FString Version{UTF8_TO_TCHAR(ToBetaDevicePtrChecked()->GetHardwareVersion().c_str())};
|
|
return MoveTemp(Version);
|
|
}
|
|
|
|
int32 FSGBetaDeviceImpl::GetFirmwareVersion() const
|
|
{
|
|
return ToBetaDevicePtrChecked()->GetFirmwareVersion();
|
|
}
|
|
|
|
int32 FSGBetaDeviceImpl::GetSubFirmwareVersion() const
|
|
{
|
|
return ToBetaDevicePtrChecked()->GetSubFirmwareVersion();
|
|
}
|
|
|
|
FString FSGBetaDeviceImpl::GetConstantsString() const
|
|
{
|
|
FString String{UTF8_TO_TCHAR(ToBetaDevicePtrChecked()->GetConstantsString().c_str())};
|
|
return MoveTemp(String);
|
|
}
|
|
|
|
FString FSGBetaDeviceImpl::GetSensorData() const
|
|
{
|
|
FString Data{UTF8_TO_TCHAR(ToBetaDevicePtrChecked()->GetSensorData().c_str())};
|
|
return MoveTemp(Data);
|
|
}
|
|
|
|
FString FSGBetaDeviceImpl::GetLastCommand() const
|
|
{
|
|
FString Command{UTF8_TO_TCHAR(ToBetaDevicePtrChecked()->GetLastCommand().c_str())};
|
|
return MoveTemp(Command);
|
|
}
|
|
|
|
bool FSGBetaDeviceImpl::SendHaptics(const FString& Command, const int32 Channel) const
|
|
{
|
|
return ToBetaDevicePtrChecked()->SendHaptics(TCHAR_TO_UTF8(*Command), Channel);
|
|
}
|
|
|
|
FString FSGBetaDeviceImpl::ToString() const
|
|
{
|
|
return FSGDeviceImpl::ToString();
|
|
}
|
|
|
|
FSGBetaDeviceImpl::FImpl::FImpl(FSGBetaDeviceImpl* InOwner)
|
|
: Owner(InOwner)
|
|
{
|
|
}
|
|
|
|
FSGBetaDeviceImpl::FImpl::~FImpl() = default;
|
|
|
|
void FSGBetaDeviceImpl::FImplDeleter::operator()(const FImpl* P) const
|
|
{
|
|
delete P;
|
|
} |