OSVR-Core  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
com_osvr_example_AnalogSync.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
28 
29 // Generated JSON header file
30 #include "com_osvr_example_AnalogSync_json.h"
31 
32 // Library/third-party includes
33 // - none
34 
35 // Standard includes
36 #include <iostream>
37 
38 // Anonymous namespace to avoid symbol collision
39 namespace {
40 
41 class AnalogSyncDevice {
42  public:
43  AnalogSyncDevice(OSVR_PluginRegContext ctx) : m_myVal(0) {
46 
48  osvrDeviceAnalogConfigure(opts, &m_analog, 1);
49 
51  m_dev.initSync(ctx, "MySyncDevice", opts);
52 
54  m_dev.sendJsonDescriptor(com_osvr_example_AnalogSync_json);
55 
57  m_dev.registerUpdateCallback(this);
58  }
59 
60  OSVR_ReturnCode update() {
62  m_myVal = (m_myVal + 0.1);
63  if (m_myVal > 10.0) {
64  m_myVal = 0;
65  }
66 
68  osvrDeviceAnalogSetValue(m_dev, m_analog, m_myVal, 0);
69  return OSVR_RETURN_SUCCESS;
70  }
71 
72  private:
75  double m_myVal;
76 };
77 } // namespace
78 
79 OSVR_PLUGIN(com_osvr_example_AnalogSync) {
81  osvr::pluginkit::registerObjectForDeletion(ctx, new AnalogSyncDevice(ctx));
82  return OSVR_RETURN_SUCCESS;
83 }
Wrapper class for OSVR_DeviceToken.
OSVR_ReturnCode osvrDeviceAnalogSetValue(OSVR_DeviceToken dev, OSVR_AnalogDeviceInterface iface, OSVR_AnalogState val, OSVR_ChannelCount chan)
Report the value of a single channel.
OSVR_PLUGIN(com_osvr_example_AnalogSync)
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.
Header including the full PluginKit C++ interface.
struct OSVR_AnalogDeviceInterfaceObject * OSVR_AnalogDeviceInterface
Opaque type used in conjunction with a device token to send data on an analog 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...
OSVR_ReturnCode osvrDeviceAnalogConfigure(OSVR_DeviceInitOptions opts, OSVR_AnalogDeviceInterface *iface, OSVR_ChannelCount numChan)
Specify that your device will implement the Analog interface.