replace more method calls on android with the equivalents from sgconnect for android
This commit is contained in:
@@ -40,11 +40,11 @@
|
||||
#include "Android/AndroidJava.h"
|
||||
#endif /* PLATFORM_ANDROID */
|
||||
|
||||
static constexpr char SGCONNECT_JAVA_CLASS_NAME[] = "com.senseglove.sgconnect.SGConnect";
|
||||
static constexpr char SGCONNECT_JAVA_CLASS_NAME[] = "com.senseglove.sgconnect.SGConnect";
|
||||
|
||||
int32 FSGConnectJNI::Init()
|
||||
{
|
||||
int32 Result = 0;
|
||||
int32 Result = -999;
|
||||
|
||||
#if PLATFORM_ANDROID
|
||||
JNIEnv* Env = FAndroidApplication::GetJavaEnv();
|
||||
@@ -67,7 +67,7 @@ int32 FSGConnectJNI::Init()
|
||||
|
||||
int32 FSGConnectJNI::Dispose()
|
||||
{
|
||||
int32 Result = 0;
|
||||
int32 Result = -999;
|
||||
|
||||
#if PLATFORM_ANDROID
|
||||
JNIEnv* Env = FAndroidApplication::GetJavaEnv();
|
||||
@@ -111,5 +111,104 @@ FString FSGConnectJNI::GetLibraryVersion()
|
||||
}
|
||||
#endif /* PLATFORM_ANDROID */
|
||||
|
||||
return Result;
|
||||
return Result;
|
||||
}
|
||||
|
||||
int32 FSGConnectJNI::ActiveDevices()
|
||||
{
|
||||
int32 Result = -999;
|
||||
|
||||
#if PLATFORM_ANDROID
|
||||
JNIEnv* Env = FAndroidApplication::GetJavaEnv();
|
||||
if (Env)
|
||||
{
|
||||
jclass Class = FAndroidApplication::FindJavaClass(SGCONNECT_JAVA_CLASS_NAME);
|
||||
if (!Env->IsSameObject(Class, nullptr))
|
||||
{
|
||||
jmethodID Method = Env->GetStaticMethodID(Class, "ActiveDevices", "()I");
|
||||
if (Method)
|
||||
{
|
||||
Result = Env->CallStaticIntMethod(Class, Method);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* PLATFORM_ANDROID */
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
FString FSGConnectJNI::GetDeviceString(const int32 DeviceAddress)
|
||||
{
|
||||
FString Result;
|
||||
|
||||
#if PLATFORM_ANDROID
|
||||
JNIEnv* Env = FAndroidApplication::GetJavaEnv();
|
||||
if (Env)
|
||||
{
|
||||
jclass Class = FAndroidApplication::FindJavaClass(SGCONNECT_JAVA_CLASS_NAME);
|
||||
if (!Env->IsSameObject(Class, nullptr))
|
||||
{
|
||||
jmethodID Method = Env->GetStaticMethodID(Class, "GetDeviceString", "(I)Ljava/lang/String;");
|
||||
if (Method)
|
||||
{
|
||||
jstring ResultJString = (jstring)Env->CallStaticObjectMethod(Class, Method, DeviceAddress);
|
||||
const char* ResultChars = Env->GetStringUTFChars(ResultJString, nullptr);
|
||||
Result = FString(UTF8_TO_TCHAR(ResultChars));
|
||||
Env->ReleaseStringUTFChars(ResultJString, ResultChars);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* PLATFORM_ANDROID */
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
FString FSGConnectJNI::GetSensorString(const int32 DeviceAddress)
|
||||
{
|
||||
FString Result;
|
||||
|
||||
#if PLATFORM_ANDROID
|
||||
JNIEnv* Env = FAndroidApplication::GetJavaEnv();
|
||||
if (Env)
|
||||
{
|
||||
jclass Class = FAndroidApplication::FindJavaClass(SGCONNECT_JAVA_CLASS_NAME);
|
||||
if (!Env->IsSameObject(Class, nullptr))
|
||||
{
|
||||
jmethodID Method = Env->GetStaticMethodID(Class, "GetSensorString", "(I)Ljava/lang/String;");
|
||||
if (Method)
|
||||
{
|
||||
jstring ResultJString = (jstring)Env->CallStaticObjectMethod(Class, Method, DeviceAddress);
|
||||
const char* ResultChars = Env->GetStringUTFChars(ResultJString, nullptr);
|
||||
Result = FString(UTF8_TO_TCHAR(ResultChars));
|
||||
Env->ReleaseStringUTFChars(ResultJString, ResultChars);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* PLATFORM_ANDROID */
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
int32 FSGConnectJNI::WriteHaptics(const int32 DeviceAddress, const FString& Haptics)
|
||||
{
|
||||
int32 Result = -999;
|
||||
|
||||
#if PLATFORM_ANDROID
|
||||
JNIEnv* Env = FAndroidApplication::GetJavaEnv();
|
||||
if (Env)
|
||||
{
|
||||
jclass Class = FAndroidApplication::FindJavaClass(SGCONNECT_JAVA_CLASS_NAME);
|
||||
if (!Env->IsSameObject(Class, nullptr))
|
||||
{
|
||||
jmethodID Method = Env->GetStaticMethodID(Class, "ActiveDevices", "(ILjava/lang/String;)I");
|
||||
if (Method)
|
||||
{
|
||||
jstring HapticsString = Env->NewStringUTF(TCHAR_TO_UTF8(*Haptics));
|
||||
Result = Env->CallStaticIntMethod(Class, Method, HapticsString);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* PLATFORM_ANDROID */
|
||||
|
||||
return Result;
|
||||
}
|
||||
@@ -50,4 +50,12 @@ public:
|
||||
static int32 Dispose();
|
||||
|
||||
static FString GetLibraryVersion();
|
||||
|
||||
static int32 ActiveDevices();
|
||||
|
||||
static FString GetDeviceString(int32 DeviceAddress);
|
||||
|
||||
static FString GetSensorString(int32 DeviceAddress);
|
||||
|
||||
static int32 WriteHaptics(int32 DeviceAddress, const FString& Haptics);
|
||||
};
|
||||
@@ -51,9 +51,17 @@
|
||||
#include "SGInterop/SGIC_TArray_TSharedRef_FSGDeviceImpl.h"
|
||||
#include "SGInterop/SGIC_TSharedPtr_FSGDeviceImpl.h"
|
||||
|
||||
#if PLATFORM_ANDROID
|
||||
#include "SGAndroid/SGConnectJNI.h"
|
||||
#endif /* PLATFORM_ANDROID */
|
||||
|
||||
int32 FSGDeviceList::ActiveDevices()
|
||||
{
|
||||
#if ! PLATFORM_ANDROID
|
||||
return SGCoreImpl_FSGDeviceListImpl_ActiveDevices();
|
||||
#else
|
||||
return FSGConnectJNI::ActiveDevices();
|
||||
#endif /* ! PLATFORM_ANDROID */
|
||||
}
|
||||
|
||||
bool FSGDeviceList::SenseCommRunning()
|
||||
@@ -157,27 +165,50 @@ TArray<USGDevice*> FSGDeviceList::GetDevices(UObject* Outer, const ESGDeviceType
|
||||
|
||||
bool FSGDeviceList::GetSensorDataString(const int32 IpcIndex, const FString& IpcAddress, FString& OutString)
|
||||
{
|
||||
#if ! PLATFORM_ANDROID
|
||||
FSGIC_FString IpcAddressContainer{IpcAddress};
|
||||
FSGIC_FString OutStringContainer;
|
||||
const bool bReturn = SGCoreImpl_FSGDeviceListImpl_GetSensorDataString(
|
||||
IpcIndex, &IpcAddressContainer, &OutStringContainer);
|
||||
OutString = OutStringContainer.String;
|
||||
return bReturn;
|
||||
#else
|
||||
FString Result = FSGConnectJNI::GetSensorString(IpcIndex);
|
||||
if (Result.IsEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
OutString = MoveTemp(Result);
|
||||
return true;
|
||||
#endif /* ! PLATFORM_ANDROID */
|
||||
}
|
||||
|
||||
bool FSGDeviceList::SendHaptics(const int32 IpcIndex, const FString& IpcAddress, const FString& Commands)
|
||||
{
|
||||
#if ! PLATFORM_ANDROID
|
||||
FSGIC_FString IpcAddressContainer{IpcAddress};
|
||||
FSGIC_FString CommandsContainer{Commands};
|
||||
return SGCoreImpl_FSGDeviceListImpl_SendHaptics(IpcIndex, &IpcAddressContainer, &CommandsContainer);
|
||||
#else
|
||||
int32 Result = FSGConnectJNI::WriteHaptics(IpcIndex, Commands);
|
||||
if (Result <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
#endif /* ! PLATFORM_ANDROID */
|
||||
}
|
||||
|
||||
FString FSGDeviceList::GetDeviceStringAt(const int32 IpcIndex, const FString& IpcAddress, const int32 Index)
|
||||
{
|
||||
#if ! PLATFORM_ANDROID
|
||||
FSGIC_FString IpcAddressContainer{IpcAddress};
|
||||
FSGIC_FString OutStringContainer;
|
||||
SGCoreImpl_FSGDeviceListImpl_GetDeviceStringAt(&OutStringContainer, IpcIndex, &IpcAddressContainer, Index);
|
||||
return OutStringContainer.String;
|
||||
#else
|
||||
return FSGConnectJNI::GetDeviceString(IpcIndex);
|
||||
#endif /* ! PLATFORM_ANDROID */
|
||||
}
|
||||
|
||||
FString FSGDeviceList::GetAddress(const int32 IpcIndex, const FString& IpcAddress)
|
||||
|
||||
@@ -55,6 +55,7 @@ public class SenseGloveCore : ModuleRules
|
||||
new string[]
|
||||
{
|
||||
"CoreUObject",
|
||||
"SenseGloveAndroid",
|
||||
"SenseGloveCoreImpl",
|
||||
"SenseGloveInterop",
|
||||
"SenseGloveLog",
|
||||
|
||||
Reference in New Issue
Block a user