68 lines
No EOL
1.3 KiB
C++
68 lines
No EOL
1.3 KiB
C++
#include "SkyPortalSubsystem.h"
|
|
#include "Engine/Engine.h"
|
|
|
|
|
|
void USkyPortalSubsystem::Initialize(FSubsystemCollectionBase& Collection)
|
|
{
|
|
|
|
Super::Initialize(Collection);
|
|
// Custom initialization logic
|
|
UE_LOG(LogTemp, Warning, TEXT("SkyPortalSubsystem Initialized"));
|
|
|
|
// Initialize HIDAPI
|
|
int res = hid_init();
|
|
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()
|
|
{
|
|
// 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;
|
|
} |