new sensor_event_t structure for the new HAL that can handle bigger payloads
Change-Id: I8f21e457c308eea9cb1f73b49b1fed36627ec55e
This commit is contained in:
parent
b1e212e7b6
commit
cdefccdba5
3 changed files with 65 additions and 13 deletions
|
@ -1,7 +1,6 @@
|
|||
# Copyright 2006 The Android Open Source Project
|
||||
|
||||
# Setting LOCAL_PATH will mess up all-subdir-makefiles, so do it beforehand.
|
||||
SAVE_MAKEFILES := $(call all-subdir-makefiles)
|
||||
|
||||
LOCAL_PATH:= $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
|
@ -19,8 +18,6 @@ ifneq ($(TARGET_SIMULATOR),true)
|
|||
LOCAL_SHARED_LIBRARIES += libdl
|
||||
endif
|
||||
|
||||
include $(SAVE_MAKEFILES)
|
||||
|
||||
LOCAL_SRC_FILES += hardware.c
|
||||
|
||||
# need "-lrt" on Linux simulator to pick up clock_gettime
|
||||
|
@ -36,5 +33,6 @@ include $(BUILD_SHARED_LIBRARY)
|
|||
|
||||
include $(addsuffix /Android.mk, $(addprefix $(LOCAL_PATH)/, \
|
||||
modules/gralloc \
|
||||
tests \
|
||||
))
|
||||
|
|
@ -249,6 +249,53 @@ typedef struct {
|
|||
} sensors_data_t;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Union of the various types of sensor data
|
||||
* that can be returned.
|
||||
*/
|
||||
typedef struct sensors_event_t {
|
||||
/* must be sizeof(struct sensors_event_t) */
|
||||
int32_t version;
|
||||
|
||||
/* sensor identifier */
|
||||
int32_t sensor;
|
||||
|
||||
/* sensor type */
|
||||
int32_t type;
|
||||
|
||||
/* reserved */
|
||||
int32_t reserved0;
|
||||
|
||||
/* time is in nanosecond */
|
||||
int64_t timestamp;
|
||||
|
||||
union {
|
||||
float data[16];
|
||||
|
||||
/* acceleration values are in meter per second per second (m/s^2) */
|
||||
sensors_vec_t acceleration;
|
||||
|
||||
/* magnetic vector values are in micro-Tesla (uT) */
|
||||
sensors_vec_t magnetic;
|
||||
|
||||
/* orientation values are in degrees */
|
||||
sensors_vec_t orientation;
|
||||
|
||||
/* temperature is in degrees centigrade (Celsius) */
|
||||
float temperature;
|
||||
|
||||
/* distance in centimeters */
|
||||
float distance;
|
||||
|
||||
/* light in SI lux units */
|
||||
float light;
|
||||
};
|
||||
uint32_t reserved1[4];
|
||||
} sensors_event_t;
|
||||
|
||||
|
||||
|
||||
struct sensor_t;
|
||||
|
||||
/**
|
||||
|
@ -327,7 +374,7 @@ struct sensors_poll_device_t {
|
|||
*
|
||||
*/
|
||||
int (*poll)(struct sensors_poll_device_t *dev,
|
||||
sensors_data_t* data, int count);
|
||||
sensors_event_t* data, int count);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ int main(int argc, char** argv)
|
|||
list[i].power);
|
||||
}
|
||||
|
||||
sensors_data_t buffer[16];
|
||||
sensors_event_t buffer[16];
|
||||
|
||||
err = sensors_open(&module->common, &device);
|
||||
if (err != 0) {
|
||||
|
@ -100,12 +100,19 @@ int main(int argc, char** argv)
|
|||
|
||||
printf("read %d events:\n", n);
|
||||
for (int i=0 ; i<n ; i++) {
|
||||
const sensors_data_t& data = buffer[i];
|
||||
const sensors_event_t& data = buffer[i];
|
||||
|
||||
if (data.version != sizeof(sensors_event_t)) {
|
||||
printf("incorrect event version (version=%d, expected=%d",
|
||||
data.version, sizeof(sensors_event_t));
|
||||
break;
|
||||
}
|
||||
|
||||
switch(data.sensor) {
|
||||
case SENSOR_TYPE_ACCELEROMETER:
|
||||
printf("sensor=%s, time=%lld, value=<%5.1f,%5.1f,%5.1f>\n",
|
||||
getSensorName(data.sensor),
|
||||
data.time,
|
||||
data.timestamp,
|
||||
data.acceleration.x,
|
||||
data.acceleration.y,
|
||||
data.acceleration.z);
|
||||
|
@ -113,7 +120,7 @@ int main(int argc, char** argv)
|
|||
case SENSOR_TYPE_MAGNETIC_FIELD:
|
||||
printf("sensor=%s, time=%lld, value=<%5.1f,%5.1f,%5.1f>\n",
|
||||
getSensorName(data.sensor),
|
||||
data.time,
|
||||
data.timestamp,
|
||||
data.magnetic.x,
|
||||
data.magnetic.y,
|
||||
data.magnetic.z);
|
||||
|
@ -121,7 +128,7 @@ int main(int argc, char** argv)
|
|||
case SENSOR_TYPE_ORIENTATION:
|
||||
printf("sensor=%s, time=%lld, value=<%5.1f,%5.1f,%5.1f>\n",
|
||||
getSensorName(data.sensor),
|
||||
data.time,
|
||||
data.timestamp,
|
||||
data.orientation.azimuth,
|
||||
data.orientation.pitch,
|
||||
data.orientation.roll);
|
||||
|
@ -129,25 +136,25 @@ int main(int argc, char** argv)
|
|||
case SENSOR_TYPE_PROXIMITY:
|
||||
printf("sensor=%s, time=%lld, value=%f\n",
|
||||
getSensorName(data.sensor),
|
||||
data.time,
|
||||
data.timestamp,
|
||||
data.distance);
|
||||
break;
|
||||
case SENSOR_TYPE_TEMPERATURE:
|
||||
printf("sensor=%s, time=%lld, value=%f\n",
|
||||
getSensorName(data.sensor),
|
||||
data.time,
|
||||
data.timestamp,
|
||||
data.temperature);
|
||||
break;
|
||||
case SENSOR_TYPE_LIGHT:
|
||||
printf("sensor=%s, time=%lld, value=%f\n",
|
||||
getSensorName(data.sensor),
|
||||
data.time,
|
||||
data.timestamp,
|
||||
data.light);
|
||||
break;
|
||||
default:
|
||||
printf("sensor=%s, time=%lld, value=<%f,%f,%f>\n",
|
||||
getSensorName(data.sensor),
|
||||
data.time,
|
||||
data.timestamp,
|
||||
data.acceleration.x,
|
||||
data.acceleration.y,
|
||||
data.acceleration.z);
|
||||
|
|
Loading…
Reference in a new issue