Skip to content

Commit

Permalink
Changed the two analog interfaces to one location2D interface for the…
Browse files Browse the repository at this point in the history
… android pointer/mouse.
  • Loading branch information
JeroMiya committed Sep 22, 2017
1 parent e68e732 commit b0dad13
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 30 deletions.
37 changes: 14 additions & 23 deletions org_osvr_android_moverio/org_osvr_android_moverio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
#include <osvr/PluginKit/PluginKit.h>
#include <osvr/PluginKit/TrackerInterfaceC.h>
#include <osvr/PluginKit/ButtonInterfaceC.h>
#include <osvr/PluginKit/AnalogInterfaceC.h>
#include <osvr/PluginKit/Location2DInterfaceC.h>
#include <osvr/Util/Vec2C.h>

// Generated JSON header file
#include "org_osvr_android_moverio_json.h"
Expand Down Expand Up @@ -85,8 +86,7 @@ namespace {
static std::mutex sMouseMutex;

typedef struct AndroidMouseState {
OSVR_AnalogState xState;
OSVR_AnalogState yState;
OSVR_Location2DState location2DState;
OSVR_AnalogState xMinState;
OSVR_AnalogState xMaxState;
OSVR_AnalogState yMinState;
Expand All @@ -103,8 +103,8 @@ namespace {
OSVR_TimeValue now;
osvrTimeValueGetNow(&now);
AndroidMouseState mouseState = {0};
mouseState.xState = xState;
mouseState.yState = yState;
osvrVec2SetX(&mouseState.location2DState, xState);
osvrVec2SetY(&mouseState.location2DState, yState);
mouseState.xMinState = xMinState;
mouseState.xMaxState = xMaxState;
mouseState.yMinState = yMinState;
Expand Down Expand Up @@ -162,10 +162,9 @@ namespace {
};

enum {
ANDROID_ANALOG_CHANNEL_MOUSE_X = 0,
ANDROID_ANALOG_CHANNEL_MOUSE_Y,
ANDROID_LOCATION2D_CHANNEL_MOUSE = 0,

ANDROID_NUM_ANALOG_CHANNELS,
ANDROID_NUM_LOCATION2D_CHANNELS,
};

static bool ASensorEventToOSVR_OrientationState(const ASensorEvent* e, OSVR_OrientationState& orientationOut) {
Expand Down Expand Up @@ -477,7 +476,7 @@ namespace {
osvr::pluginkit::DeviceToken m_dev;
OSVR_TrackerDeviceInterface m_tracker;
OSVR_ButtonDeviceInterface m_button;
OSVR_AnalogDeviceInterface m_analog;
OSVR_Location2D_DeviceInterface m_location2D;
std::shared_ptr<ASensorThread> m_sensorThread;

public:
Expand All @@ -496,8 +495,8 @@ namespace {
/// Configure the button interfaces
osvrDeviceButtonConfigure(opts, &m_button, MOVERIO_NUM_BUTTON_CHANNELS);

/// Configure the analog interfaces
osvrDeviceAnalogConfigure(opts, &m_analog, ANDROID_NUM_ANALOG_CHANNELS);
/// Configure the location2D interfaces
osvrDeviceLocation2DConfigure(opts, &m_location2D, ANDROID_NUM_LOCATION2D_CHANNELS);

/// Create the sync device token with the options
m_dev.initSync(ctx, "MoverioTracker", opts);
Expand Down Expand Up @@ -560,34 +559,26 @@ namespace {
return OSVR_RETURN_SUCCESS;
}

OSVR_ReturnCode reportQueuedAndroidMouseState(osvr::pluginkit::DeviceToken dev, OSVR_AnalogDeviceInterface analog) {
OSVR_ReturnCode reportQueuedAndroidMouseState(osvr::pluginkit::DeviceToken dev, OSVR_Location2D_DeviceInterface location2D) {
std::lock_guard<std::mutex> lock(sMouseMutex);
while(!sMouseStateQueueSynced.empty()) {
auto mouseReport = sMouseStateQueueSynced.front();
sMouseStateQueueSynced.pop();

if(OSVR_RETURN_SUCCESS !=
osvrDeviceAnalogSetValueTimestamped(
dev, analog, mouseReport.xState, ANDROID_ANALOG_CHANNEL_MOUSE_X, &mouseReport.timestamp)) {
osvrDeviceLocation2DReportData(
location2D, mouseReport.location2DState, ANDROID_LOCATION2D_CHANNEL_MOUSE, &mouseReport.timestamp)) {
LOGE("[org_osvr_android_moverio]: Failed to send analog state.");
return OSVR_RETURN_FAILURE;
}

if(OSVR_RETURN_SUCCESS !=
osvrDeviceAnalogSetValueTimestamped(
dev, analog, mouseReport.yState, ANDROID_ANALOG_CHANNEL_MOUSE_Y, &mouseReport.timestamp)) {
LOGE("[org_osvr_android_moverio]: Failed to send analog state.");
return OSVR_RETURN_FAILURE;
}

}
return OSVR_RETURN_SUCCESS;
}

OSVR_ReturnCode update() {
OSVR_ReturnCode buttonRet = reportQueuedAndroidButtonState(m_dev, m_button);
OSVR_ReturnCode sensorRet = m_sensorThread->reportQueuedState(m_dev, m_tracker, m_button);
OSVR_ReturnCode mouseRet = reportQueuedAndroidMouseState(m_dev, m_analog);
OSVR_ReturnCode mouseRet = reportQueuedAndroidMouseState(m_dev, m_location2D);

bool ret = buttonRet == OSVR_RETURN_SUCCESS &&
sensorRet == OSVR_RETURN_SUCCESS &&
Expand Down
11 changes: 4 additions & 7 deletions org_osvr_android_moverio/org_osvr_android_moverio.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"button": {
"count": 9
},
"analog": {
"count": 2
"location2D": {
"count": 1
}
},
"semantic": {
Expand All @@ -33,16 +33,13 @@
"volumeDown": "button/6",
"back": "button/7"
},
"mouse": {
"x": "analog/0",
"y": "analog/1"
},
"mouse": "location2D/0",
"base": "tracker/1"
},
"automaticAliases": {
"/me/head": "semantic/hmd/*",
"/me/hand": "semantic/base",
"/controller/left": "semantic/controller/*",
"/mouse": "semantic/mouse/*"
"/mouse": "semantic/mouse"
}
}

0 comments on commit b0dad13

Please sign in to comment.