OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ButtonInterfaceC.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
32 #include "HandleNullContext.h"
34 
35 // Library/third-party includes
36 // - none
37 
38 // Standard includes
39 // - none
40 
43 };
44 
45 OSVR_ReturnCode
47  OSVR_OUT_PTR OSVR_ButtonDeviceInterface *iface,
48  OSVR_IN OSVR_ChannelCount numChan) {
49  OSVR_PLUGIN_HANDLE_NULL_CONTEXT("osvrDeviceButtonConfigure", opts);
50  OSVR_PLUGIN_HANDLE_NULL_CONTEXT("osvrDeviceButtonConfigure", iface);
52  opts->makeInterfaceObject<OSVR_ButtonDeviceInterfaceObject>();
53  *iface = ifaceObj;
54  opts->setButtons(numChan, ifaceObj->button);
55  return OSVR_RETURN_SUCCESS;
56 }
57 
58 OSVR_ReturnCode osvrDeviceButtonSetValue(OSVR_IN_PTR OSVR_DeviceToken dev,
59  OSVR_IN_PTR OSVR_ButtonDeviceInterface
60  iface,
61  OSVR_IN OSVR_ButtonState val,
62  OSVR_IN OSVR_ChannelCount chan) {
63  OSVR_TimeValue now;
64  osvrTimeValueGetNow(&now);
65  return osvrDeviceButtonSetValueTimestamped(dev, iface, val, chan, &now);
66 }
67 
69  OSVR_IN_PTR OSVR_DeviceToken, OSVR_IN_PTR OSVR_ButtonDeviceInterface iface,
70  OSVR_IN OSVR_ButtonState val, OSVR_IN OSVR_ChannelCount chan,
71  OSVR_IN_PTR OSVR_TimeValue const *timestamp) {
72  OSVR_PLUGIN_HANDLE_NULL_CONTEXT("osvrDeviceButtonSetValueTimestamped",
73  iface);
74  OSVR_PLUGIN_HANDLE_NULL_CONTEXT("osvrDeviceButtonSetValueTimestamped",
75  timestamp);
76 
77  auto guard = iface->getSendGuard();
78  if (guard->lock()) {
79  bool sendResult = iface->button->setValue(val, chan, *timestamp);
80  return sendResult ? OSVR_RETURN_SUCCESS : OSVR_RETURN_FAILURE;
81  }
82 
83  return OSVR_RETURN_FAILURE;
84 }
85 
86 OSVR_ReturnCode osvrDeviceButtonSetValues(OSVR_INOUT_PTR OSVR_DeviceToken dev,
87  OSVR_IN_PTR OSVR_ButtonDeviceInterface
88  iface,
89  OSVR_IN_PTR OSVR_ButtonState val[],
90  OSVR_IN OSVR_ChannelCount chans) {
91  OSVR_TimeValue now;
92  osvrTimeValueGetNow(&now);
93  return osvrDeviceButtonSetValuesTimestamped(dev, iface, val, chans, &now);
94 }
95 
97  OSVR_IN_PTR OSVR_DeviceToken, OSVR_IN_PTR OSVR_ButtonDeviceInterface iface,
98  OSVR_IN_PTR OSVR_ButtonState val[], OSVR_IN OSVR_ChannelCount chans,
99  OSVR_IN_PTR OSVR_TimeValue const *timestamp) {
100  OSVR_PLUGIN_HANDLE_NULL_CONTEXT("osvrDeviceButtonSetValuesTimestamped",
101  iface);
102  OSVR_PLUGIN_HANDLE_NULL_CONTEXT("osvrDeviceButtonSetValuesTimestamped",
103  timestamp);
104 
105  auto guard = iface->getSendGuard();
106  if (guard->lock()) {
107  iface->button->setValues(val, chans, *timestamp);
108  return OSVR_RETURN_SUCCESS;
109  }
110  return OSVR_RETURN_FAILURE;
111 }
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
void osvrTimeValueGetNow(OSVR_TimeValue *dest)
Gets the current time in the TimeValue. Parallel to gettimeofday.
Definition: TimeValueC.cpp:100
OSVR_ReturnCode osvrDeviceButtonSetValuesTimestamped(OSVR_DeviceToken, OSVR_ButtonDeviceInterface iface, OSVR_ButtonState val[], OSVR_ChannelCount chans, OSVR_TimeValue const *timestamp)
Report the value of multiple channels with the supplied timestamp.
OSVR_ReturnCode osvrDeviceButtonSetValue(OSVR_DeviceToken dev, OSVR_ButtonDeviceInterface iface, OSVR_ButtonState 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...
OSVR_ReturnCode osvrDeviceButtonSetValues(OSVR_DeviceToken dev, OSVR_ButtonDeviceInterface iface, OSVR_ButtonState val[], OSVR_ChannelCount chans)
Report the value of multiple channels.
#define OSVR_RETURN_FAILURE
The "failure" value for an OSVR_ReturnCode.
Definition: ReturnCodesC.h:47
OSVR_ReturnCode osvrDeviceButtonSetValueTimestamped(OSVR_DeviceToken, OSVR_ButtonDeviceInterface iface, OSVR_ButtonState val, OSVR_ChannelCount chan, OSVR_TimeValue const *timestamp)
Report the value of a single channel with the supplied timestamp.
#define OSVR_RETURN_SUCCESS
The "success" value for an OSVR_ReturnCode.
Definition: ReturnCodesC.h:45
uint8_t OSVR_ButtonState
Type of button state.
OSVR_ReturnCode osvrDeviceButtonConfigure(OSVR_DeviceInitOptions opts, OSVR_ButtonDeviceInterface *iface, OSVR_ChannelCount numChan)
Specify that your device will implement the Button interface.
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...