This repository has been archived by the owner on Jul 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for haptic feedback on Pico controllers (#2932)
* Add support for haptic feedback on Pico controllers * Swap which contoller vibrates. Co-authored-by: Randall E. Barker <[email protected]>
- Loading branch information
1 parent
fcec46e
commit 25bc08b
Showing
6 changed files
with
151 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "VRBrowserPico.h" | ||
#include "vrb/ConcreteClass.h" | ||
#include "vrb/Logger.h" | ||
#include "JNIUtil.h" | ||
|
||
namespace { | ||
|
||
const char* sUpdateHapticsName = "updateHaptics"; | ||
const char* sUpdateHapticsSignature = "(IFF)V"; | ||
const char* sCancelAllHapticsName = "cancelAllHaptics"; | ||
const char* sCancelAllHapticsSignature = "()V"; | ||
|
||
JNIEnv* sEnv = nullptr; | ||
jclass sBrowserClass = nullptr; | ||
jobject sActivity = nullptr; | ||
jmethodID sUpdateHaptics = nullptr; | ||
jmethodID sCancelAllHaptics = nullptr; | ||
} | ||
|
||
namespace crow { | ||
|
||
void | ||
VRBrowserPico::InitializeJava(JNIEnv* aEnv, jobject aActivity) { | ||
if (aEnv == sEnv) { | ||
return; | ||
} | ||
sEnv = aEnv; | ||
if (!sEnv) { | ||
return; | ||
} | ||
sActivity = sEnv->NewGlobalRef(aActivity); | ||
sBrowserClass = sEnv->GetObjectClass(sActivity); | ||
if (!sBrowserClass) { | ||
return; | ||
} | ||
|
||
sUpdateHaptics = FindJNIMethodID(sEnv, sBrowserClass, sUpdateHapticsName, sUpdateHapticsSignature); | ||
sCancelAllHaptics = FindJNIMethodID(sEnv, sBrowserClass, sCancelAllHapticsName, sCancelAllHapticsSignature); | ||
} | ||
|
||
void | ||
VRBrowserPico::ShutdownJava() { | ||
if (!sEnv) { | ||
return; | ||
} | ||
if (sActivity) { | ||
sEnv->DeleteGlobalRef(sActivity); | ||
sActivity = nullptr; | ||
} | ||
|
||
sBrowserClass = nullptr; | ||
sUpdateHaptics = nullptr; | ||
sCancelAllHaptics = nullptr; | ||
sEnv = nullptr; | ||
} | ||
|
||
|
||
void | ||
VRBrowserPico::UpdateHaptics(jint aControllerIndex, jfloat aIntensity, jfloat aDuration) { | ||
if (!ValidateMethodID(sEnv, sActivity, sUpdateHaptics, __FUNCTION__)) { return; } | ||
sEnv->CallVoidMethod(sActivity, sUpdateHaptics, aControllerIndex, aIntensity, aDuration); | ||
CheckJNIException(sEnv, __FUNCTION__); | ||
} | ||
void | ||
VRBrowserPico::CancelAllHaptics() { | ||
if (!ValidateMethodID(sEnv, sActivity, sCancelAllHaptics, __FUNCTION__)) { return; } | ||
sEnv->CallVoidMethod(sActivity, sCancelAllHaptics); | ||
CheckJNIException(sEnv, __FUNCTION__); | ||
} | ||
|
||
} // namespace crow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#pragma once | ||
#include "vrb/MacroUtils.h" | ||
|
||
#include <memory> | ||
#include <string> | ||
#include <jni.h> | ||
#include <functional> | ||
|
||
namespace crow { | ||
|
||
namespace VRBrowserPico { | ||
void InitializeJava(JNIEnv* aEnv, jobject aActivity); | ||
void ShutdownJava(); | ||
void UpdateHaptics(jint aControllerIndex, jfloat aIntensity, jfloat aDuration); | ||
void CancelAllHaptics(); | ||
} // namespace VRBrowser; | ||
|
||
} // namespace crow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters