From dbae4a3f7c76054543d1e392bd7c96bfee023e0b Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 15 Jul 2016 18:50:05 -0700 Subject: [PATCH] More on device/interfaces; --- src/device.c | 47 +++++++++++++++++++++++++++++++++++++++++++++-- src/device.h | 4 +++- src/interface.c | 22 ++++++++++++++++++++++ src/interface.h | 2 ++ 4 files changed, 72 insertions(+), 3 deletions(-) diff --git a/src/device.c b/src/device.c index 4a4625f2..42e04dfe 100644 --- a/src/device.c +++ b/src/device.c @@ -1,9 +1,10 @@ +#include #include "device.h" #include "interface.h" extern OSVR_ClientContext ctx; -int lovrDeviceGetInterface(lua_State* L) { +int lovrDeviceGetByName(lua_State* L) { const char* name = luaL_checkstring(L, 1); Interface* interface = (Interface*) malloc(sizeof(Interface)); @@ -18,7 +19,49 @@ int lovrDeviceGetInterface(lua_State* L) { return 1; } +int lovrDeviceGetHeadset(lua_State* L) { + const char* name = "/me/head"; + + Interface* headset = (Interface*) malloc(sizeof(Interface)); + osvrClientGetInterface(ctx, name, headset); + + if (headset) { + luax_pushinterface(L, headset); + } else { + lua_pushnil(L); + } + + return 1; +} + +int lovrDeviceGetControllers(lua_State* L) { + const char* leftHandPath = "/me/hands/left"; + const char* rightHandPath = "/me/hands/right"; + + Interface* leftHand = (Interface*) malloc(sizeof(Interface)); + osvrClientGetInterface(ctx, leftHandPath, leftHand); + + if (leftHand) { + luax_pushinterface(L, leftHand); + } else { + lua_pushnil(L); + } + + Interface* rightHand = (Interface*) malloc(sizeof(Interface)); + osvrClientGetInterface(ctx, rightHandPath, rightHand); + + if (rightHand) { + luax_pushinterface(L, rightHand); + } else { + lua_pushnil(L); + } + + return 2; +} + const luaL_Reg lovrDevice[] = { - { "getInterface", lovrDeviceGetInterface }, + { "getByName", lovrDeviceGetByName }, + { "getHeadset", lovrDeviceGetHeadset }, + { "getControllers", lovrDeviceGetControllers }, { NULL, NULL } }; diff --git a/src/device.h b/src/device.h index d52cf789..f898e00f 100644 --- a/src/device.h +++ b/src/device.h @@ -2,5 +2,7 @@ #include #include -int lovrDeviceGetInterface(lua_State* L); +int lovrDeviceGetByName(lua_State* L); +int lovrDeviceGetHeadset(lua_State* L); +int lovrDeviceGetControllers(lua_State* L); extern const luaL_Reg lovrDevice[]; diff --git a/src/interface.c b/src/interface.c index 769de211..317ecfd3 100644 --- a/src/interface.c +++ b/src/interface.c @@ -40,7 +40,29 @@ int lovrInterfaceGetPosition(lua_State* L) { return 3; } +int lovrInterfaceGetOrientation(lua_State* L) { + Interface* interface = luax_checkinterface(L, 1); + OSVR_TimeValue t; + OSVR_OrientationState orientation; + + osvrClientUpdate(ctx); + + OSVR_ReturnCode res = osvrGetOrientationState(*interface, &t, &orientation); + + if (res != OSVR_RETURN_SUCCESS) { + lua_pushnil(L); + return 1; + } + + lua_pushnumber(L, orientation.data[0]); + lua_pushnumber(L, orientation.data[1]); + lua_pushnumber(L, orientation.data[2]); + + return 3; +} + const luaL_Reg lovrInterface[] = { { "getPosition", lovrInterfaceGetPosition }, + { "getOrientation", lovrInterfaceGetOrientation }, { NULL, NULL } }; diff --git a/src/interface.h b/src/interface.h index 678387d5..ee0b43f2 100644 --- a/src/interface.h +++ b/src/interface.h @@ -9,4 +9,6 @@ typedef OSVR_ClientInterface Interface; void luax_pushinterface(lua_State* L, Interface* interface); Interface* luax_checkinterface(lua_State* L, int index); +int lovrInterfaceGetPosition(lua_State* L); +int lovrInterfaceGetOrientation(lua_State* L); extern const luaL_Reg lovrInterface[];