Connect to portal
This commit is contained in:
parent
652d62ed96
commit
5496613f14
2 changed files with 66 additions and 2 deletions
|
@ -1,9 +1,10 @@
|
|||
#include "SkyPortalSubsystem.h"
|
||||
#include "Engine/Engine.h"
|
||||
#include "hidapi.h"
|
||||
|
||||
|
||||
void USkyPortalSubsystem::Initialize(FSubsystemCollectionBase& Collection)
|
||||
{
|
||||
|
||||
Super::Initialize(Collection);
|
||||
// Custom initialization logic
|
||||
UE_LOG(LogTemp, Warning, TEXT("SkyPortalSubsystem Initialized"));
|
||||
|
@ -13,18 +14,55 @@ void USkyPortalSubsystem::Initialize(FSubsystemCollectionBase& Collection)
|
|||
if (res == 0)
|
||||
{
|
||||
UE_LOG(LogTemp, Log, TEXT("HIDAPI initialized successfully."));
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(LogTemp, Error, TEXT("Failed to initialize HIDAPI."));
|
||||
HidError = hid_error(NULL);
|
||||
UE_LOG(LogTemp, Error, TEXT("%s"), *HidError);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void USkyPortalSubsystem::Deinitialize()
|
||||
{
|
||||
// Custom cleanup logic
|
||||
// Disconnect portal
|
||||
if (PortalDevice) {
|
||||
hid_close(PortalDevice);
|
||||
}
|
||||
hid_exit();
|
||||
|
||||
|
||||
UE_LOG(LogTemp, Warning, TEXT("SkyPortalSubsystem Deinitialized"));
|
||||
Super::Deinitialize();
|
||||
}
|
||||
|
||||
bool USkyPortalSubsystem::ConnectPortal() {
|
||||
PortalDevice = hid_open(VendorId, ProductId, NULL); //Connect using constants
|
||||
if (PortalDevice) {
|
||||
|
||||
ReadPortal();
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
else {
|
||||
UE_LOG(LogTemp, Error, TEXT("Failed to connect to Portal."));
|
||||
// Get the error message from the HIDAPI
|
||||
HidError = hid_error(NULL);
|
||||
UE_LOG(LogTemp, Error, TEXT("%s"), *HidError);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void USkyPortalSubsystem::ReadPortal() {
|
||||
hid_read(PortalDevice, PortalRawData, 16);
|
||||
}
|
||||
|
||||
FString USkyPortalSubsystem::RawData() {
|
||||
FString Raw = "0";
|
||||
return Raw;
|
||||
}
|
|
@ -2,8 +2,12 @@
|
|||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Subsystems/EngineSubsystem.h"
|
||||
#include "hidapi.h"
|
||||
|
||||
|
||||
#include "SkyPortalSubsystem.generated.h"
|
||||
|
||||
|
||||
UCLASS()
|
||||
class SKYPORTAL_API USkyPortalSubsystem : public UEngineSubsystem
|
||||
{
|
||||
|
@ -13,4 +17,26 @@ public:
|
|||
// Override initialization and deinitialization methods
|
||||
virtual void Initialize(FSubsystemCollectionBase& Collection) override;
|
||||
virtual void Deinitialize() override;
|
||||
|
||||
// Connect to Portal, return false if portal is not found
|
||||
UFUNCTION(BlueprintCallable, CallInEditor)
|
||||
bool ConnectPortal();
|
||||
|
||||
FString HidError;
|
||||
|
||||
private:
|
||||
//Portal ref used in the subsystem
|
||||
hid_device* PortalDevice;
|
||||
|
||||
unsigned char* PortalRawData;
|
||||
|
||||
FString RawData();
|
||||
void ReadPortal();
|
||||
|
||||
protected:
|
||||
|
||||
//Constants
|
||||
const int VendorId = 5168;
|
||||
const int ProductId = 336;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue