OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ButtonCallback.c
Go to the documentation of this file.
1 
11 /*
12 // Copyright 2014 Sensics, Inc.
13 //
14 // Licensed under the Apache License, Version 2.0 (the "License");
15 // you may not use this file except in compliance with the License.
16 // You may obtain a copy of the License at
17 //
18 // http://www.apache.org/licenses/LICENSE-2.0
19 //
20 // Unless required by applicable law or agreed to in writing, software
21 // distributed under the License is distributed on an "AS IS" BASIS,
22 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 // See the License for the specific language governing permissions and
24 // limitations under the License.
25 */
26 
27 /* Internal Includes */
31 
32 /* Library/third-party includes */
33 /* none */
34 
35 /* Standard includes */
36 #include <stdio.h>
37 
38 void myButtonCallback(void *userdata, const OSVR_TimeValue *timestamp,
39  const OSVR_ButtonReport *report) {
40  printf("Got report: button is %s\n",
41  (report->state ? "pressed" : "released"));
42 }
43 
44 int main() {
45  OSVR_ClientContext ctx =
46  osvrClientInit("com.osvr.exampleclients.ButtonCallback", 0);
47 
48  OSVR_ClientInterface button1 = NULL;
49  /* This is just one of the paths: specifically, the Hydra's left
50  * controller's button labelled "1". More are in the docs and/or listed on
51  * startup
52  */
53  osvrClientGetInterface(ctx, "/controller/left/1", &button1);
54 
55  osvrRegisterButtonCallback(button1, &myButtonCallback, NULL);
56 
57  /* Pretend that this is your application's mainloop. */
58  int i;
59  for (i = 0; i < 1000000; ++i) {
60  osvrClientUpdate(ctx);
61  }
62 
63  osvrClientShutdown(ctx);
64  printf("Library shut down, exiting.\n");
65  return 0;
66 }
OSVR_ReturnCode osvrClientGetInterface(OSVR_ClientContext ctx, const char path[], OSVR_ClientInterface *iface)
Get the interface associated with the given path.
Definition: InterfaceC.cpp:37
OSVR_ClientContext osvrClientInit(const char applicationIdentifier[], uint32_t flags=0)
Initialize the library.
Definition: ContextC.cpp:48
Report type for a callback on a button interface.
OSVR_ReturnCode osvrClientShutdown(OSVR_ClientContext ctx)
Shutdown the library.
Definition: ContextC.cpp:78
OSVR_ButtonState state
The button state: 1 is pressed, 0 is not pressed.
OSVR_ReturnCode osvrClientUpdate(OSVR_ClientContext ctx)
Updates the state of the context - call regularly in your mainloop.
Definition: ContextC.cpp:72
Header.
Standardized, portable parallel to struct timeval for representing both absolute times and time inter...
Definition: TimeValueC.h:81
OSVR_ReturnCode osvrRegisterButtonCallback(OSVR_ClientInterface iface, OSVR_ButtonCallback cb, void *userdata)
Register a callback for Button reports on an interface.
Header.