OSVR-Core  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
com_osvr_example_MultipleAsync.cpp
Go to the documentation of this file.
1 
11 // Copyright 2015 Sensics, Inc.
12 //
13 // Licensed under the Apache License, Version 2.0 (the "License");
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 //
17 // http://www.apache.org/licenses/LICENSE-2.0
18 //
19 // Unless required by applicable law or agreed to in writing, software
20 // distributed under the License is distributed on an "AS IS" BASIS,
21 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 // See the License for the specific language governing permissions and
23 // limitations under the License.
24 
25 // Internal Includes
30 
31 // Library/third-party includes
32 // - none
33 
34 // Standard includes
35 #include <iostream>
36 #include <chrono>
37 #include <thread>
38 
39 // Anonymous namespace to avoid symbol collision
40 namespace {
41 
42 class MultipleAsyncDevice {
43  public:
44  MultipleAsyncDevice(OSVR_PluginRegContext ctx)
45  : m_myVal(0), m_buttonPressed(false) {
48 
50  osvrDeviceAnalogConfigure(opts, &m_analog, 1);
51 
53  osvrDeviceButtonConfigure(opts, &m_button, 1);
54 
56  osvrDeviceTrackerConfigure(opts, &m_tracker);
57 
59  m_dev.initSync(ctx, "MyAsyncDevice", opts);
60 
62  m_dev.registerUpdateCallback(this);
63  }
64 
65  OSVR_ReturnCode update() {
68  std::this_thread::sleep_for(std::chrono::seconds(1));
69 
71  m_myVal = (m_myVal + 0.1);
72  if (m_myVal > 10.0) {
73  m_myVal = 0;
74  }
75 
77  osvrDeviceAnalogSetValue(m_dev, m_analog, m_myVal, 0);
78 
80  m_buttonPressed = !m_buttonPressed;
82  m_dev, m_button,
83  m_buttonPressed ? OSVR_BUTTON_PRESSED : OSVR_BUTTON_NOT_PRESSED, 0);
84 
86  OSVR_PoseState pose;
87  osvrPose3SetIdentity(&pose);
88  osvrDeviceTrackerSendPose(m_dev, m_tracker, &pose, 0);
89  return OSVR_RETURN_SUCCESS;
90  }
91 
92  private:
97  double m_myVal;
98  bool m_buttonPressed;
99 };
100 } // namespace
101 
102 OSVR_PLUGIN(com_osvr_example_MultipleAsync) {
103 
106  new MultipleAsyncDevice(ctx));
107 
108  return OSVR_RETURN_SUCCESS;
109 }
Wrapper class for OSVR_DeviceToken.
OSVR_PLUGIN(com_osvr_example_MultipleAsync)
struct OSVR_TrackerDeviceInterfaceObject * OSVR_TrackerDeviceInterface
Opaque type used in conjunction with a device token to send data on a tracker interface.
struct OSVR_ButtonDeviceInterfaceObject * OSVR_ButtonDeviceInterface
Opaque type used in conjunction with a device token to send data on a button interface.
OSVR_ReturnCode osvrDeviceAnalogSetValue(OSVR_DeviceToken dev, OSVR_AnalogDeviceInterface iface, OSVR_AnalogState val, OSVR_ChannelCount chan)
Report the value of a single channel.
OSVR_ReturnCode osvrDeviceButtonSetValue(OSVR_DeviceToken dev, OSVR_ButtonDeviceInterface iface, OSVR_ButtonState val, OSVR_ChannelCount chan)
Report the value of a single channel.
OSVR_ReturnCode osvrDeviceTrackerSendPose(OSVR_DeviceToken dev, OSVR_TrackerDeviceInterface iface, OSVR_PoseState const *val, OSVR_ChannelCount sensor)
Report the full rigid body pose of a sensor, automatically generating a timestamp.
T * registerObjectForDeletion(OSVR_PluginRegContext ctx, T *obj)
Registers an object to be destroyed with delete when the plugin is unloaded.
struct OSVR_DeviceInitObject * OSVR_DeviceInitOptions
Opaque type of a device initialization object.
#define OSVR_RETURN_SUCCESS
The "success" value for an OSVR_ReturnCode.
Definition: ReturnCodesC.h:45
OSVR_DeviceInitOptions osvrDeviceCreateInitOptions(OSVR_PluginRegContext ctx)
Create a OSVR_DeviceInitOptions object.
#define OSVR_BUTTON_NOT_PRESSED
OSVR_ButtonState value indicating "button up".
Header including the full PluginKit C++ interface.
OSVR_ReturnCode osvrDeviceButtonConfigure(OSVR_DeviceInitOptions opts, OSVR_ButtonDeviceInterface *iface, OSVR_ChannelCount numChan)
Specify that your device will implement the Button interface.
#define OSVR_BUTTON_PRESSED
OSVR_ButtonState value indicating "button down".
A structure defining a 3D (6DOF) rigid body pose: translation and rotation.
Definition: Pose3C.h:54
struct OSVR_AnalogDeviceInterfaceObject * OSVR_AnalogDeviceInterface
Opaque type used in conjunction with a device token to send data on an analog interface.
OSVR_ReturnCode osvrDeviceTrackerConfigure(OSVR_DeviceInitOptions opts, OSVR_TrackerDeviceInterface *iface)
Specify that your device will implement the Tracker interface.
OSVR_EXTERN_C_BEGIN typedef void * OSVR_PluginRegContext
A context pointer passed in to your plugin's entry point and other locations of control flow transfer...
void osvrPose3SetIdentity(OSVR_Pose3 *pose)
Set a pose to identity.
Definition: Pose3C.h:62
OSVR_ReturnCode osvrDeviceAnalogConfigure(OSVR_DeviceInitOptions opts, OSVR_AnalogDeviceInterface *iface, OSVR_ChannelCount numChan)
Specify that your device will implement the Analog interface.