Reena Lee | c3c7479 | 2009-05-18 22:34:25 -0700 | [diff] [blame] | 1 | page.title=Sensors |
| 2 | pdk.version=1.0 |
| 3 | @jd:body |
David Warren | 5c40a48 | 2009-06-05 15:11:21 -0700 | [diff] [blame] | 4 | |
| 5 | <div id="qv-wrapper"> |
| 6 | <div id="qv"> |
| 7 | <h2>In this document</h2> |
| 8 | <a name="toc"/> |
| 9 | <ul> |
| 10 | <li><a href="#androidSensorsInterface">Interface</a></li> |
| 11 | </ul> |
| 12 | </div> |
| 13 | </div> |
| 14 | |
Reena Lee | c3c7479 | 2009-05-18 22:34:25 -0700 | [diff] [blame] | 15 | <p>Android defines a user space C abstraction interface for sensor hardware. The interface header is defined in |
| 16 | <code>hardware/libhardware/include/hardware/sensors.h</code>. |
| 17 | In order to integrate sensors with Android you need to build a shared library that implements this interface. |
| 18 | |
| 19 | The types of sensors currently supported by Android include: |
| 20 | <ul> |
| 21 | <li>Accelerometer</li> |
| 22 | <li>Magnetic Field</li> |
| 23 | <li>Orientation</li> |
| 24 | <li>Gyroscope</li> |
| 25 | <li>Light</li> |
| 26 | <li>Pressure</li> |
| 27 | <li>Temperature</li> |
| 28 | <li>Proximity</li> |
| 29 | </ul> |
| 30 | </p> |
| 31 | |
David Warren | 5c40a48 | 2009-06-05 15:11:21 -0700 | [diff] [blame] | 32 | <a name="androidSensorBuildingDriver"></a><h3>Building a Sensor Library</h3> |
Reena Lee | c3c7479 | 2009-05-18 22:34:25 -0700 | [diff] [blame] | 33 | <p> To implement a Sensors driver, create a shared library that implements the interface defined in <code>sensors.h</code>. You must name your shared library |
| 34 | <code>libsensors.so</code> so that it will get loaded from <code>/system/lib</code> at runtime. |
Reena Lee | d39413e | 2009-06-11 13:26:29 -0700 | [diff] [blame] | 35 | </p> |
Reena Lee | c3c7479 | 2009-05-18 22:34:25 -0700 | [diff] [blame] | 36 | |
Reena Lee | c8f0e67 | 2009-06-13 15:08:56 -0700 | [diff] [blame] | 37 | <p> The following stub file, <code>Android.mk</code>, ensures that <code>libsensors</code> compiles and links to the appropriate libraries:</p> |
| 38 | |
Reena Lee | d39413e | 2009-06-11 13:26:29 -0700 | [diff] [blame] | 39 | <pre> |
| 40 | LOCAL_PATH := $(call my-dir) |
| 41 | include $(CLEAR_VARS) |
| 42 | |
| 43 | LOCAL_MODULE := sensors |
| 44 | |
| 45 | LOCAL_PRELINK_MODULE := false |
| 46 | |
| 47 | LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw |
| 48 | |
| 49 | LOCAL_SHARED_LIBRARIES := liblog |
| 50 | # include any shared library dependencies |
| 51 | |
| 52 | LOCAL_SRC_FILES := sensors.c |
| 53 | |
| 54 | include $(BUILD_SHARED_LIBRARY) |
| 55 | </pre> |
Reena Lee | c3c7479 | 2009-05-18 22:34:25 -0700 | [diff] [blame] | 56 | |
David Warren | 5c40a48 | 2009-06-05 15:11:21 -0700 | [diff] [blame] | 57 | <a name="androidSensorsInterface"></a><h3>Interface</h3> |
Reena Lee | c3c7479 | 2009-05-18 22:34:25 -0700 | [diff] [blame] | 58 | |
| 59 | |
David Warren | 5c40a48 | 2009-06-05 15:11:21 -0700 | [diff] [blame] | 60 | <p><span class="lh3"><a name="androidDoxygenNote"></a></span> |
Reena Lee | c3c7479 | 2009-05-18 22:34:25 -0700 | [diff] [blame] | 61 | |
| 62 | <p class="note"><strong>Note</strong>: This document relies on some Doxygen-generated content that appears in an iFrame below. To return to the Doxygen default content for this page, <a href="sensors.html">click here</a>.</p> |
| 63 | |
| 64 | |
| 65 | <iframe onLoad="resizeDoxFrameHeight();" src="sensors_8h.html" scrolling="no" scroll="no" id="doxygen" marginwidth="0" marginheight="0" |
| 66 | frameborder="0" style="width:100%;"></iframe> |