| Vladimir Chtchetkine | db611d5 | 2011-11-01 17:35:07 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  * Copyright (C) 2011 The Android Open Source Project | 
 | 3 |  * | 
 | 4 |  * Licensed under the Apache License, Version 2.0 (the "License"); | 
 | 5 |  * you may not use this file except in compliance with the License. | 
 | 6 |  * You may obtain a copy of the License at | 
 | 7 |  * | 
 | 8 |  *      http://www.apache.org/licenses/LICENSE-2.0 | 
 | 9 |  * | 
 | 10 |  * Unless required by applicable law or agreed to in writing, software | 
 | 11 |  * distributed under the License is distributed on an "AS IS" BASIS, | 
 | 12 |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
 | 13 |  * See the License for the specific language governing permissions and | 
 | 14 |  * limitations under the License. | 
 | 15 |  */ | 
 | 16 |  | 
 | 17 | #ifndef ANDROID_SENSORS_PORT_H_ | 
 | 18 | #define ANDROID_SENSORS_PORT_H_ | 
 | 19 |  | 
 | 20 | /* | 
 | 21 |  * Encapsulates exchange protocol between the sensor emulator, and an application | 
 | 22 |  * running on an Android device that provides sensor values, and is connected to | 
 | 23 |  * the host via USB. | 
 | 24 |  */ | 
 | 25 |  | 
 | 26 | #include "android/android-device.h" | 
 | 27 |  | 
 | 28 | /* Declares sensors port descriptor. */ | 
 | 29 | typedef struct AndroidSensorsPort AndroidSensorsPort; | 
 | 30 |  | 
 | 31 | /* Creates sensors port, and connects it to the device. | 
 | 32 |  * Param: | 
 | 33 |  *  opaque - An opaque pointer that is passed back to the callback routines. | 
 | 34 |  * Return: | 
 | 35 |  *  Initialized device descriptor on success, or NULL on failure. If failure is | 
 | 36 |  *  returned from this routine, 'errno' indicates the reason for failure. If this | 
 | 37 |  *  routine successeds, a connection is established with the sensor reading | 
 | 38 |  *  application on the device. | 
 | 39 |  */ | 
 | 40 | extern AndroidSensorsPort* sensors_port_create(void* opaque); | 
 | 41 |  | 
 | 42 | /* Disconnects from the sensors port, and destroys the descriptor. */ | 
 | 43 | extern void sensors_port_destroy(AndroidSensorsPort* asp); | 
 | 44 |  | 
 | 45 | /* Initializes sensors on the connected device. */ | 
 | 46 | extern int sensors_port_init_sensors(AndroidSensorsPort* asp); | 
 | 47 |  | 
 | 48 | /* Checks if port is connected to a sensor reading application on the device. | 
 | 49 |  * Note that connection can go out and then be restored at any time after | 
 | 50 |  * sensors_port_create API succeeded. | 
 | 51 |  */ | 
 | 52 | extern int sensors_port_is_connected(AndroidSensorsPort* asp); | 
 | 53 |  | 
 | 54 | /* Enables events from a particular sensor. | 
 | 55 |  * Param: | 
 | 56 |  *  asp - Android sensors port instance returned from sensors_port_create. | 
 | 57 |  *  name - Name of the sensor to enable events on. If this parameter is "all", | 
 | 58 |  *      then events on all sensors will be enabled. | 
 | 59 |  * Return: | 
 | 60 |  *  Zero on success, failure otherwise. | 
 | 61 |  */ | 
 | 62 | extern int sensors_port_enable_sensor(AndroidSensorsPort* asp, const char* name); | 
 | 63 |  | 
 | 64 |  | 
 | 65 | /* Disables events from a particular sensor. | 
 | 66 |  * Param: | 
 | 67 |  *  asp - Android sensors port instance returned from sensors_port_create. | 
 | 68 |  *  name - Name of the sensor to disable events on. If this parameter is "all", | 
 | 69 |  *      then events on all sensors will be disable. | 
 | 70 |  * Return: | 
 | 71 |  *  Zero on success, failure otherwise. | 
 | 72 |  */ | 
 | 73 | extern int sensors_port_disable_sensor(AndroidSensorsPort* asp, const char* name); | 
 | 74 |  | 
 | 75 | /* Queries the connected application to start delivering sensor events. | 
 | 76 |  * Param: | 
 | 77 |  *  asp - Android sensors port instance returned from sensors_port_create. | 
 | 78 |  * Return: | 
 | 79 |  *  Zero on success, failure otherwise. | 
 | 80 |  */ | 
 | 81 | extern int sensors_port_start(AndroidSensorsPort* asp); | 
 | 82 |  | 
 | 83 | /* Queries the connected application to stop delivering sensor events. | 
 | 84 |  * Param: | 
 | 85 |  *  asp - Android sensors port instance returned from sensors_port_create. | 
 | 86 |  * Return: | 
 | 87 |  *  Zero on success, failure otherwise. | 
 | 88 |  */ | 
 | 89 | extern int sensors_port_stop(AndroidSensorsPort* asp); | 
 | 90 |  | 
 | 91 | #endif  /* ANDROID_SENSORS_PORT_H_ */ |