SkyPortal-plugin/Source/SkyPortal/Public/SkyPortalIO.h

71 lines
1.7 KiB
C++

#pragma once
/*
* This is the bridge between hidapi and unreal and contains all the rawdata of the portal
*/
#include "CoreMinimal.h"
#include "hidapi.h"
#include "SkyPortalIO.generated.h"
DECLARE_LOG_CATEGORY_EXTERN(LogHIDApi, Log, All);
DECLARE_LOG_CATEGORY_EXTERN(LogSkyportalIO, Log, All);
constexpr auto write_buf_size = 0x21;
constexpr auto TIMEOUT = 30000; //milliseconds
/* Portal physicial device IDs */
const int VendorIds[4] = { 0x12ba, 0x54c, 0x1430, 0x1430 };
const int ProductIds[4] = { 0x150, 0x967, 0x1f17 };
/* WriteBlock
*
* Contain all the data that pass inside hidapi write + the number of bytes in case of successful write
* @param data all the block data, should be 0x21 sized
* @param BytesTransferred In case of successful write, print the number of byte transfered. Could be used for verifications
*/
USTRUCT()
struct FWriteBlock {
GENERATED_BODY()
unsigned char data[write_buf_size];
int BytesTransferred;
} ;
/* This class will contain and handle all the low-lewel functions
* Should be able to be called anywhere
*/
UCLASS()
class USkyPortalIO : public UObject
{
GENERATED_BODY()
public:
/* hidapi will write error message in here*/
UPROPERTY(BlueprintReadOnly)
FString HidError;
/*Portal ready to be listened or to receive commands*/
UPROPERTY(BlueprintReadOnly)
bool bPortalReady;
/* Connect to Portal - will write the PortalDevice var if success */
bool OpenPortalHandle();
void Write(FWriteBlock* Block);
void WriteRaw(FWriteBlock* Block);
/* Listen to portal
* @return The data sended by the portal device
*/
UFUNCTION()
uint8* Read();
void Close();
private:
/* Portal ref used in the subsystem */
hid_device* PortalDevice;
};