diff options
author | Mathias Agopian <mathias@google.com> | 2011-09-26 19:50:23 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2011-09-26 19:50:23 -0700 |
commit | 7d68d150f784da921b258cdbb330d0fc8d1aef97 (patch) | |
tree | 4e1aac1c650e6ec33a6f99ddae36d0f44c4227cb | |
parent | 619febb15c1e789cb6f1346c6b42c12c2f8bf0bc (diff) | |
parent | cc3f6a345b0cc356b22f9ea748505ce8a705d358 (diff) | |
download | hardware_libhardware-7d68d150f784da921b258cdbb330d0fc8d1aef97.zip hardware_libhardware-7d68d150f784da921b258cdbb330d0fc8d1aef97.tar.gz hardware_libhardware-7d68d150f784da921b258cdbb330d0fc8d1aef97.tar.bz2 |
am cc3f6a34: improve sensor HAL test
* commit 'cc3f6a345b0cc356b22f9ea748505ce8a705d358':
improve sensor HAL test
-rw-r--r-- | tests/nusensors/nusensors.cpp | 98 |
1 files changed, 49 insertions, 49 deletions
diff --git a/tests/nusensors/nusensors.cpp b/tests/nusensors/nusensors.cpp index 9d1a90c..3c8eae9 100644 --- a/tests/nusensors/nusensors.cpp +++ b/tests/nusensors/nusensors.cpp @@ -23,6 +23,7 @@ #include <cutils/log.h> #include <hardware/sensors.h> +#include <utils/Timers.h> char const* getSensorName(int type) { switch(type) { @@ -32,12 +33,26 @@ char const* getSensorName(int type) { return "Mag"; case SENSOR_TYPE_ORIENTATION: return "Ori"; - case SENSOR_TYPE_PROXIMITY: - return "Prx"; - case SENSOR_TYPE_TEMPERATURE: - return "Tmp"; + case SENSOR_TYPE_GYROSCOPE: + return "Gyr"; case SENSOR_TYPE_LIGHT: return "Lux"; + case SENSOR_TYPE_PRESSURE: + return "Bar"; + case SENSOR_TYPE_TEMPERATURE: + return "Tmp"; + case SENSOR_TYPE_PROXIMITY: + return "Prx"; + case SENSOR_TYPE_GRAVITY: + return "Grv"; + case SENSOR_TYPE_LINEAR_ACCELERATION: + return "Lac"; + case SENSOR_TYPE_ROTATION_VECTOR: + return "Rot"; + case SENSOR_TYPE_RELATIVE_HUMIDITY: + return "Hum"; + case SENSOR_TYPE_AMBIENT_TEMPERATURE: + return "Tam"; } return "ukn"; } @@ -54,8 +69,15 @@ int main(int argc, char** argv) return 0; } + err = sensors_open(&module->common, &device); + if (err != 0) { + printf("sensors_open() failed (%s)\n", strerror(-err)); + return 0; + } + struct sensor_t const* list; int count = module->get_sensors_list(module, &list); + printf("%d sensors found:\n", count); for (int i=0 ; i<count ; i++) { printf("%s\n" "\tvendor: %s\n" @@ -75,13 +97,8 @@ int main(int argc, char** argv) list[i].power); } - sensors_event_t buffer[16]; - - err = sensors_open(&module->common, &device); - if (err != 0) { - printf("sensors_open() failed (%s)\n", strerror(-err)); - return 0; - } + static const size_t numEvents = 16; + sensors_event_t buffer[numEvents]; for (int i=0 ; i<count ; i++) { err = device->activate(device, list[i].handle, 0); @@ -99,11 +116,11 @@ int main(int argc, char** argv) list[i].name, strerror(-err)); return 0; } - device->setDelay(device, list[i].handle, 10000000); + device->setDelay(device, list[i].handle, ms2ns(10)); } do { - int n = device->poll(device, buffer, 16); + int n = device->poll(device, buffer, numEvents); if (n < 0) { printf("poll() failed (%s)\n", strerror(-err)); break; @@ -121,59 +138,42 @@ int main(int argc, char** argv) switch(data.type) { case SENSOR_TYPE_ACCELEROMETER: - printf("sensor=%s, time=%lld, value=<%5.1f,%5.1f,%5.1f>\n", - getSensorName(data.type), - data.timestamp, - data.acceleration.x, - data.acceleration.y, - data.acceleration.z); - break; case SENSOR_TYPE_MAGNETIC_FIELD: - printf("sensor=%s, time=%lld, value=<%5.1f,%5.1f,%5.1f>\n", - getSensorName(data.type), - data.timestamp, - data.magnetic.x, - data.magnetic.y, - data.magnetic.z); - break; case SENSOR_TYPE_ORIENTATION: + case SENSOR_TYPE_GYROSCOPE: + case SENSOR_TYPE_GRAVITY: + case SENSOR_TYPE_LINEAR_ACCELERATION: + case SENSOR_TYPE_ROTATION_VECTOR: printf("sensor=%s, time=%lld, value=<%5.1f,%5.1f,%5.1f>\n", getSensorName(data.type), data.timestamp, - data.orientation.azimuth, - data.orientation.pitch, - data.orientation.roll); - break; - case SENSOR_TYPE_PROXIMITY: - printf("sensor=%s, time=%lld, value=%f\n", - getSensorName(data.type), - data.timestamp, - data.distance); - break; - case SENSOR_TYPE_TEMPERATURE: - printf("sensor=%s, time=%lld, value=%f\n", - getSensorName(data.type), - data.timestamp, - data.temperature); + data.data[0], + data.data[1], + data.data[2]); break; + case SENSOR_TYPE_LIGHT: + case SENSOR_TYPE_PRESSURE: + case SENSOR_TYPE_TEMPERATURE: + case SENSOR_TYPE_PROXIMITY: + case SENSOR_TYPE_RELATIVE_HUMIDITY: + case SENSOR_TYPE_AMBIENT_TEMPERATURE: printf("sensor=%s, time=%lld, value=%f\n", getSensorName(data.type), data.timestamp, - data.light); + data.data[0]); break; + default: - printf("sensor=%d, time=%lld, value=<%f,%f,%f>\n", + printf("sensor=%d, time=%lld, value=<%f,%f,%f, ...>\n", data.type, data.timestamp, - data.acceleration.x, - data.acceleration.y, - data.acceleration.z); + data.data[0], + data.data[1], + data.data[2]); break; } } - - } while (1); // fix that |