OSVR-Core  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
AnalogCallback.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 myAnalogCallback(void *userdata, const OSVR_TimeValue *timestamp,
39  const OSVR_AnalogReport *report) {
40  printf("Got report: channel is %f\n", report->state);
41 }
42 
43 int main() {
44  OSVR_ClientContext ctx =
45  osvrClientInit("com.osvr.exampleclients.AnalogCallback", 0);
46 
47  OSVR_ClientInterface analogTrigger = NULL;
48  /* This is just one of the paths: specifically, the Hydra's left
49  * controller's analog trigger. More are in the docs and/or listed on
50  * startup
51  */
52  osvrClientGetInterface(ctx, "/controller/left/trigger", &analogTrigger);
53 
54  osvrRegisterAnalogCallback(analogTrigger, &myAnalogCallback, NULL);
55 
56  /* Pretend that this is your application's mainloop. */
57  int i;
58  for (i = 0; i < 1000000; ++i) {
59  osvrClientUpdate(ctx);
60  }
61 
62  osvrClientLog(ctx, OSVR_LOGLEVEL_NOTICE, "Library shut down, exiting.");
63  osvrClientShutdown(ctx);
64  return 0;
65 }
OSVR_ReturnCode osvrRegisterAnalogCallback(OSVR_ClientInterface iface, OSVR_AnalogCallback cb, void *userdata)
Register a callback for Analog reports on an interface.
OSVR_ReturnCode osvrClientGetInterface(OSVR_ClientContext ctx, const char path[], OSVR_ClientInterface *iface)
Get the interface associated with the given path.
OSVR_ClientContext osvrClientInit(const char applicationIdentifier[], uint32_t flags=0)
Initialize the library.
OSVR_ReturnCode osvrClientShutdown(OSVR_ClientContext ctx)
Shutdown the library.
OSVR_AnalogState state
The analog state.
struct OSVR_ClientContextObject * OSVR_ClientContext
Opaque handle that should be retained by your application. You need only and exactly one...
OSVR_ReturnCode osvrClientUpdate(OSVR_ClientContext ctx)
Updates the state of the context - call regularly in your mainloop.
void osvrClientLog(OSVR_ClientContext ctx, OSVR_LogLevel severity, const char *message)
Log a message from the client.
Header.
struct OSVR_ClientInterfaceObject * OSVR_ClientInterface
Opaque handle to an interface used for registering callbacks and getting status.
Report type for a callback on an analog interface.
Standardized, portable parallel to struct timeval for representing both absolute times and time inter...
Definition: TimeValueC.h:81
Header.