mirror of https://github.com/bjornbytes/lovr.git
lovr.headset.vibrate;
Signature changed to take strength, duration, and frequency. All are optional.
This commit is contained in:
parent
36e4529dca
commit
cb79973b98
|
@ -355,6 +355,21 @@ int l_lovrHeadsetGetAxis(lua_State* L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int l_lovrHeadsetVibrate(lua_State* L) {
|
||||
Path path = luax_optpath(L, 1, "head");
|
||||
float strength = luax_optfloat(L, 2, 1.f);
|
||||
float duration = luax_optfloat(L, 3, .5f);
|
||||
float frequency = luax_optfloat(L, 4, 0.f);
|
||||
FOREACH_TRACKING_DRIVER(driver) {
|
||||
if (driver->vibrate(path, strength, duration, frequency)) {
|
||||
lua_pushboolean(L, true);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
lua_pushboolean(L, false);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_lovrHeadsetGetControllers(lua_State* L) {
|
||||
uint8_t count;
|
||||
Controller** controllers = lovrHeadsetDriver->getControllers(&count);
|
||||
|
@ -431,6 +446,7 @@ static const luaL_Reg lovrHeadset[] = {
|
|||
{ "getVelocity", l_lovrHeadsetGetVelocity },
|
||||
{ "getAngularVelocity", l_lovrHeadsetGetAngularVelocity },
|
||||
{ "getAxis", l_lovrHeadsetGetAxis },
|
||||
{ "vibrate", l_lovrHeadsetVibrate },
|
||||
{ "getControllers", l_lovrHeadsetGetControllers },
|
||||
{ "getControllerCount", l_lovrHeadsetGetControllerCount },
|
||||
{ "renderTo", l_lovrHeadsetRenderTo },
|
||||
|
|
|
@ -7,5 +7,6 @@ int l_lovrHeadsetGetOrientation(lua_State* L);
|
|||
int l_lovrHeadsetGetVelocity(lua_State* L);
|
||||
int l_lovrHeadsetGetAngularVelocity(lua_State* L);
|
||||
int l_lovrHeadsetGetAxis(lua_State* L);
|
||||
int l_lovrHeadsetVibrate(lua_State* L);
|
||||
Path luax_optpath(lua_State* L, int index, const char* fallback);
|
||||
void luax_pushpath(lua_State* L, Path path);
|
||||
|
|
|
@ -86,10 +86,9 @@ static int l_lovrControllerIsTouched(lua_State* L) {
|
|||
|
||||
static int l_lovrControllerVibrate(lua_State* L) {
|
||||
Controller* controller = luax_checktype(L, 1, Controller);
|
||||
float duration = luax_optfloat(L, 2, .5f);
|
||||
float power = luax_optfloat(L, 3, 1.f);
|
||||
lovrHeadsetDriver->controllerVibrate(controller, duration, power);
|
||||
return 0;
|
||||
luax_pushpath(L, controller->path);
|
||||
lua_replace(L, 1);
|
||||
return l_lovrHeadsetVibrate(L);
|
||||
}
|
||||
|
||||
static int l_lovrControllerNewModel(lua_State* L) {
|
||||
|
|
|
@ -154,6 +154,10 @@ static int desktopGetAxis(Path path, float* x, float* y, float* z) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static bool desktopVibrate(Path path, float strength, float duration, float frequency) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static Controller** desktopGetControllers(uint8_t* count) {
|
||||
*count = state.controllers.length;
|
||||
return state.controllers.data;
|
||||
|
@ -175,10 +179,6 @@ static bool desktopControllerIsTouched(Controller* controller, ControllerButton
|
|||
return false;
|
||||
}
|
||||
|
||||
static void desktopControllerVibrate(Controller* controller, float duration, float power) {
|
||||
//
|
||||
}
|
||||
|
||||
static ModelData* desktopControllerNewModelData(Controller* controller) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -275,12 +275,12 @@ HeadsetInterface lovrHeadsetDesktopDriver = {
|
|||
.getVelocity = desktopGetVelocity,
|
||||
.getAngularVelocity = desktopGetAngularVelocity,
|
||||
.getAxis = desktopGetAxis,
|
||||
.vibrate = desktopVibrate,
|
||||
.getControllers = desktopGetControllers,
|
||||
.controllerIsConnected = desktopControllerIsConnected,
|
||||
.controllerGetHand = desktopControllerGetHand,
|
||||
.controllerIsDown = desktopControllerIsDown,
|
||||
.controllerIsTouched = desktopControllerIsTouched,
|
||||
.controllerVibrate = desktopControllerVibrate,
|
||||
.controllerNewModelData = desktopControllerNewModelData,
|
||||
.renderTo = desktopRenderTo,
|
||||
.update = desktopUpdate
|
||||
|
|
|
@ -113,12 +113,12 @@ typedef struct HeadsetInterface {
|
|||
bool (*getVelocity)(Path path, float* vx, float* vy, float* vz);
|
||||
bool (*getAngularVelocity)(Path path, float* vx, float* vy, float* vz);
|
||||
int (*getAxis)(Path path, float* x, float* y, float* z);
|
||||
bool (*vibrate)(Path path, float strength, float duration, float frequency);
|
||||
Controller** (*getControllers)(uint8_t* count);
|
||||
bool (*controllerIsConnected)(Controller* controller);
|
||||
ControllerHand (*controllerGetHand)(Controller* controller);
|
||||
bool (*controllerIsDown)(Controller* controller, ControllerButton button);
|
||||
bool (*controllerIsTouched)(Controller* controller, ControllerButton button);
|
||||
void (*controllerVibrate)(Controller* controller, float duration, float power);
|
||||
struct ModelData* (*controllerNewModelData)(Controller* controller);
|
||||
void (*renderTo)(void (*callback)(void*), void* userdata);
|
||||
struct Texture* (*getMirrorTexture)(void);
|
||||
|
|
|
@ -365,6 +365,18 @@ static int openvrGetAxis(Path path, float* x, float* y, float* z) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static bool openvrVibrate(Path path, float strength, float duration, float frequency) {
|
||||
if (duration <= 0) return false;
|
||||
if (!PATH_STARTS_WITH(path, PATH_HANDS)) return false;
|
||||
|
||||
TrackedDeviceIndex_t deviceIndex = getDeviceIndexForPath(path);
|
||||
if (deviceIndex == INVALID_INDEX) return false;
|
||||
|
||||
unsigned short uSeconds = (unsigned short) (duration * 1e6f);
|
||||
state.system->TriggerHapticPulse(deviceIndex, 0, uSeconds);
|
||||
return true;
|
||||
}
|
||||
|
||||
static Controller** openvrGetControllers(uint8_t* count) {
|
||||
*count = state.controllers.length;
|
||||
return state.controllers.data;
|
||||
|
@ -396,13 +408,6 @@ static bool openvrControllerIsTouched(Controller* controller, ControllerButton b
|
|||
return getButtonState(input.ulButtonTouched, button, hand);
|
||||
}
|
||||
|
||||
static void openvrControllerVibrate(Controller* controller, float duration, float power) {
|
||||
if (duration <= 0) return;
|
||||
uint32_t axis = 0;
|
||||
unsigned short uSeconds = (unsigned short) (duration * 1e6f);
|
||||
state.system->TriggerHapticPulse(controller->id, axis, uSeconds);
|
||||
}
|
||||
|
||||
static ModelData* openvrControllerNewModelData(Controller* controller) {
|
||||
if (!controller) return NULL;
|
||||
|
||||
|
@ -639,12 +644,12 @@ HeadsetInterface lovrHeadsetOpenVRDriver = {
|
|||
.getVelocity = openvrGetVelocity,
|
||||
.getAngularVelocity = openvrGetAngularVelocity,
|
||||
.getAxis = openvrGetAxis,
|
||||
.vibrate = openvrVibrate,
|
||||
.getControllers = openvrGetControllers,
|
||||
.controllerIsConnected = openvrControllerIsConnected,
|
||||
.controllerGetHand = openvrControllerGetHand,
|
||||
.controllerIsDown = openvrControllerIsDown,
|
||||
.controllerIsTouched = openvrControllerIsTouched,
|
||||
.controllerVibrate = openvrControllerVibrate,
|
||||
.controllerNewModelData = openvrControllerNewModelData,
|
||||
.renderTo = openvrRenderTo,
|
||||
.getMirrorTexture = openvrGetMirrorTexture,
|
||||
|
|
Loading…
Reference in New Issue