OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
AnalogInterfaceC.cpp
Go to the documentation of this file.
1 
11 // Copyright 2014 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
33 #include "HandleNullContext.h"
34 
35 // Library/third-party includes
36 // - none
37 
38 // Standard includes
39 // - none
40 
44 };
45 
46 OSVR_ReturnCode
48  OSVR_OUT_PTR OSVR_AnalogDeviceInterface *iface,
49  OSVR_IN OSVR_ChannelCount numChan) {
50  OSVR_PLUGIN_HANDLE_NULL_CONTEXT("osvrDeviceAnalogConfigure", opts);
51  OSVR_PLUGIN_HANDLE_NULL_CONTEXT("osvrDeviceAnalogConfigure", iface);
53  opts->makeInterfaceObject<OSVR_AnalogDeviceInterfaceObject>();
54  *iface = ifaceObj;
55  opts->setAnalogs(numChan, ifaceObj->analog);
56  return OSVR_RETURN_SUCCESS;
57 }
58 
59 OSVR_ReturnCode
61  OSVR_IN_PTR OSVR_AnalogDeviceInterface iface,
62  OSVR_IN OSVR_AnalogState val,
63  OSVR_IN OSVR_ChannelCount chan) {
64  OSVR_TimeValue now;
65  osvrTimeValueGetNow(&now);
66  return osvrDeviceAnalogSetValueTimestamped(dev, iface, val, chan, &now);
67 }
68 
70  OSVR_IN_PTR OSVR_DeviceToken, OSVR_IN_PTR OSVR_AnalogDeviceInterface iface,
71  OSVR_IN OSVR_AnalogState val, OSVR_IN OSVR_ChannelCount chan,
72  OSVR_IN_PTR OSVR_TimeValue const *timestamp) {
73  OSVR_PLUGIN_HANDLE_NULL_CONTEXT("osvrDeviceAnalogSetValueTimestamped",
74  iface);
75  OSVR_PLUGIN_HANDLE_NULL_CONTEXT("osvrDeviceAnalogSetValueTimestamped",
76  timestamp);
77 
78  auto guard = iface->getSendGuard();
79  if (guard->lock()) {
80  bool sendResult = iface->analog->setValue(val, chan, *timestamp);
81  return sendResult ? OSVR_RETURN_SUCCESS : OSVR_RETURN_FAILURE;
82  }
83 
84  return OSVR_RETURN_FAILURE;
85 }
86 
87 OSVR_ReturnCode
89  OSVR_IN_PTR OSVR_AnalogDeviceInterface iface,
90  OSVR_IN_PTR OSVR_AnalogState val[],
91  OSVR_IN OSVR_ChannelCount chans) {
92  OSVR_TimeValue now;
93  osvrTimeValueGetNow(&now);
94  return osvrDeviceAnalogSetValuesTimestamped(dev, iface, val, chans, &now);
95 }
96 
98  OSVR_IN_PTR OSVR_DeviceToken, OSVR_IN_PTR OSVR_AnalogDeviceInterface iface,
99  OSVR_IN_PTR OSVR_AnalogState val[], OSVR_IN OSVR_ChannelCount chans,
100  OSVR_IN_PTR OSVR_TimeValue const *timestamp) {
101  OSVR_PLUGIN_HANDLE_NULL_CONTEXT("osvrDeviceAnalogSetValuesTimestamped",
102  iface);
103  OSVR_PLUGIN_HANDLE_NULL_CONTEXT("osvrDeviceAnalogSetValuesTimestamped",
104  timestamp);
105 
106  auto guard = iface->getSendGuard();
107  if (guard->lock()) {
108  iface->analog->setValues(val, chans, *timestamp);
109  return OSVR_RETURN_SUCCESS;
110  }
111  return OSVR_RETURN_FAILURE;
112 }
OSVR_ReturnCode osvrDeviceAnalogSetValues(OSVR_DeviceToken dev, OSVR_AnalogDeviceInterface iface, OSVR_AnalogState val[], OSVR_ChannelCount chans)
Report the value of multiple channels.
uint32_t OSVR_ChannelCount
The integer type specifying a number of channels/sensors or a channel/sensor index.
Definition: ChannelCountC.h:51
A DeviceToken connects the generic device interaction code in PluginKit's C API with the workings of ...
Definition: DeviceToken.h:56
OSVR_ReturnCode osvrDeviceAnalogSetValueTimestamped(OSVR_DeviceToken, OSVR_AnalogDeviceInterface iface, OSVR_AnalogState val, OSVR_ChannelCount chan, OSVR_TimeValue const *timestamp)
Report the value of a single channel with the supplied timestamp.
void osvrTimeValueGetNow(OSVR_TimeValue *dest)
Gets the current time in the TimeValue. Parallel to gettimeofday.
Definition: TimeValueC.cpp:100
OSVR_ReturnCode osvrDeviceAnalogSetValue(OSVR_DeviceToken dev, OSVR_AnalogDeviceInterface iface, OSVR_AnalogState val, OSVR_ChannelCount chan)
Report the value of a single channel.
Structure used internally to construct the desired type of device.
#define OSVR_PLUGIN_HANDLE_NULL_CONTEXT(FUNC, CONTEXT_NAME)
Internal macro for use in C API function implementations to check the validity of a context parameter...
#define OSVR_RETURN_FAILURE
The "failure" value for an OSVR_ReturnCode.
Definition: ReturnCodesC.h:47
double OSVR_AnalogState
Type of analog channel state.
#define OSVR_RETURN_SUCCESS
The "success" value for an OSVR_ReturnCode.
Definition: ReturnCodesC.h:45
OSVR_ReturnCode osvrDeviceAnalogSetValuesTimestamped(OSVR_DeviceToken, OSVR_AnalogDeviceInterface iface, OSVR_AnalogState val[], OSVR_ChannelCount chans, OSVR_TimeValue const *timestamp)
Report the value of multiple channels with the supplied timestamp.
Standardized, portable parallel to struct timeval for representing both absolute times and time inter...
Definition: TimeValueC.h:81
Base class for the DeviceInterfaceObjects retrieved by plugins to let them send data on an interface...
OSVR_ReturnCode osvrDeviceAnalogConfigure(OSVR_DeviceInitOptions opts, OSVR_AnalogDeviceInterface *iface, OSVR_ChannelCount numChan)
Specify that your device will implement the Analog interface.