More on device/interfaces;

This commit is contained in:
bjorn 2016-07-15 18:50:05 -07:00
parent 6198ac8999
commit dbae4a3f7c
4 changed files with 72 additions and 3 deletions

View File

@ -1,9 +1,10 @@
#include <stdlib.h>
#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 }
};

View File

@ -2,5 +2,7 @@
#include <lauxlib.h>
#include <lualib.h>
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[];

View File

@ -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 }
};

View File

@ -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[];