SkyPortal-plugin/Source/SkyPortal/Private/SkyPortalSubsystem.cpp

68 lines
1.3 KiB
C++
Raw Normal View History

2024-09-18 13:30:30 +00:00
#include "SkyPortalSubsystem.h"
#include "Engine/Engine.h"
2024-09-19 12:03:16 +00:00
2024-09-18 13:30:30 +00:00
void USkyPortalSubsystem::Initialize(FSubsystemCollectionBase& Collection)
{
2024-09-19 12:03:16 +00:00
2024-09-18 13:30:30 +00:00
Super::Initialize(Collection);
// Custom initialization logic
UE_LOG(LogTemp, Warning, TEXT("SkyPortalSubsystem Initialized"));
2024-09-18 14:54:36 +00:00
2024-09-18 16:10:50 +00:00
// Initialize HIDAPI
int res = hid_init();
if (res == 0)
{
UE_LOG(LogTemp, Log, TEXT("HIDAPI initialized successfully."));
2024-09-19 12:03:16 +00:00
2024-09-18 16:10:50 +00:00
}
else
{
UE_LOG(LogTemp, Error, TEXT("Failed to initialize HIDAPI."));
2024-09-19 12:03:16 +00:00
HidError = hid_error(NULL);
UE_LOG(LogTemp, Error, TEXT("%s"), *HidError);
2024-09-18 16:10:50 +00:00
}
2024-09-18 14:54:36 +00:00
2024-09-18 13:30:30 +00:00
}
void USkyPortalSubsystem::Deinitialize()
{
2024-09-19 12:03:16 +00:00
// Disconnect portal
if (PortalDevice) {
hid_close(PortalDevice);
}
hid_exit();
2024-09-18 16:10:50 +00:00
2024-09-18 13:30:30 +00:00
UE_LOG(LogTemp, Warning, TEXT("SkyPortalSubsystem Deinitialized"));
Super::Deinitialize();
2024-09-19 12:03:16 +00:00
}
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;
2024-09-18 13:30:30 +00:00
}