Created
April 15, 2014 18:59
-
-
Save JimHaughwout/10759643 to your computer and use it in GitHub Desktop.
Best items pulled from Android's sensors.h and gps.h definitions to aid in common sensor data definitions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*** How Android does GPS ***/ | |
/* Source at https://github.com/android/platform_hardware_libhardware/blob/master/include/hardware/gps.h */ | |
typedef int64_t GpsUtcTime; /** Milliseconds since January 1, 1970 */ | |
/** Flags to indicate which values are valid in a GpsLocation. */ | |
typedef uint16_t GpsLocationFlags; | |
// IMPORTANT: Note that the following values must match | |
// constants in GpsLocationProvider.java. | |
#define GPS_LOCATION_HAS_LAT_LONG 0x0001 | |
#define GPS_LOCATION_HAS_ALTITUDE 0x0002 | |
#define GPS_LOCATION_HAS_SPEED 0x0004 | |
#define GPS_LOCATION_HAS_BEARING 0x0008 | |
#define GPS_LOCATION_HAS_ACCURACY 0x0010 | |
/** Represents a location. */ | |
typedef struct { | |
size_t size; /** set to sizeof(GpsLocation) */ | |
uint16_t flags; /** Contains GpsLocationFlags bits. */ | |
double latitude; /** Latitude in degrees. */ | |
double longitude; /** Longitude in degrees. */ | |
double altitude; /* altitude in meters above the WGS 84 ellipsoid */ | |
float speed; /** speed in meters per second. */ | |
float bearing; /** heading in degrees. */ | |
float accuracy; /** expected accuracy in meters. */ | |
GpsUtcTime timestamp; /** Timestamp for the location fix. */ | |
} GpsLocation; | |
/*** Rest of file is how Android does sensors ***/ | |
/* Source at https://github.com/android/platform_hardware_libhardware/blob/master/include/hardware/sensors.h */ | |
/* SENSOR_TYPE_META_DATA */ | |
#define SENSOR_TYPE_DEVICE_PRIVATE_BASE 0x10000 /* Base for device manufacturers private sensor types. Cannot be exposed in the SDK. */ | |
#define SENSOR_TYPE_META_DATA (0) /* special token used to populate the sensors_meta_data_event structure. */ | |
#define SENSOR_TYPE_ACCELEROMETER (1) /* Acceleration in x, y, z axis in m/s^s */ | |
#define SENSOR_TYPE_GEOMAGNETIC_FIELD (2) /* Mag field in micro Tesla (uT) in x, y, z axis */. | |
#define SENSOR_TYPE_MAGNETIC_FIELD SENSOR_TYPE_GEOMAGNETIC_FIELD | |
#define SENSOR_TYPE_ORIENTATION (3) /* Azimuth, pitch and roll in degrees */ | |
#define SENSOR_TYPE_GYROSCOPE (4) /* Rotation in rad/sec around x, y, z */ | |
#define SENSOR_TYPE_LIGHT (5) /* The light sensor value is returned in SI lux units. */ | |
#define SENSOR_TYPE_PRESSURE (6) /* The pressure sensor return the athmospheric pressure in hectopascal (hPa) */ | |
#define SENSOR_TYPE_TEMPERATURE (7) /* Deprecated in Android */ | |
#define SENSOR_TYPE_PROXIMITY (8) /* The distance value is measured in centimeters */ | |
#define SENSOR_TYPE_GRAVITY (9) /* Gravity in x, y and z in m/s^s relative to sensor */ | |
#define SENSOR_TYPE_LINEAR_ACCELERATION (10) /* m/s^2 * The coordinate system is the same used for the accelerometer */ | |
#define SENSOR_TYPE_ROTATION_VECTOR (11) /** **/ | |
#define SENSOR_TYPE_RELATIVE_HUMIDITY (12) /* relative ambient air humidity as a value in percent */ | |
#define SENSOR_TYPE_AMBIENT_TEMPERATURE (13) /* The ambient (room) temperature in degree Celsius. */ | |
#define SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED (14) /* See SENSOR_TYPE_GEOMAGNETIC_FIELD */ | |
#define SENSOR_TYPE_GAME_ROTATION_VECTOR (15) /* Similar SENSOR_TYPE_ROTATION_VECTOR but without magnetic north */ | |
#define SENSOR_TYPE_GYROSCOPE_UNCALIBRATED (16) /* Rotation in rad/sec around x, y, z */ | |
#define SENSOR_TYPE_SIGNIFICANT_MOTION (17) /* Only value is 1.0, indicates significant motion event */ | |
#define SENSOR_TYPE_STEP_DETECTOR (18) /* Triggers an event each time a step is taken, returning a value of 1.0 */ | |
#define SENSOR_TYPE_STEP_COUNTER (19) /* Number of steps taken by the user since the last reboot while activated */ | |
#define SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR (20) /* see SENSOR_TYPE_ROTATION_VECTOR for more details */ | |
struct sensor_t { | |
const char* name; /* Name of this sensor. All of same "type" must have a different "name". */ | |
const char* vendor; /* vendor of the hardware part */ | |
int version; /* Firmware version */ | |
int handle; /* Essentially the sensor ID*/ | |
int type; /* See types */ | |
float maxRange; /* M maximum range of this sensor's value in SI units */ | |
float resolution; /* smallest difference between two values reported by this sensor */ | |
float power; /* rough estimate of this sensor's power consumption in mA */ | |
int32_t minDelay; /* Default is 0 (on-change), -1 = on-shot, otherwise microseconds between reads */ | |
uint32_t fifoReservedEventCount; /* number of events reserved for this sensor in the batch mode FIFO. */ | |
uint32_t fifoMaxEventCount; /* maximum number of events of this sensor that could be batched. */ | |
void* reserved[6]; /* reserved fields, must be zero */ | |
}; | |
/*** status of orientation sensor */ | |
#define SENSOR_STATUS_UNRELIABLE 0 | |
#define SENSOR_STATUS_ACCURACY_LOW 1 | |
#define SENSOR_STATUS_ACCURACY_MEDIUM 2 | |
#define SENSOR_STATUS_ACCURACY_HIGH 3 | |
/************** sensor event data applicable to most sensors ********/ | |
typedef struct { | |
union { | |
float v[3]; | |
struct { | |
float x; | |
float y; | |
float z; | |
}; | |
struct { | |
float azimuth; | |
float pitch; | |
float roll; | |
}; | |
}; | |
int8_t status; | |
uint8_t reserved[3]; | |
} sensors_vec_t; | |
/************** uncalibrated gyroscope and magnetometer event data ********/ | |
typedef struct { | |
union { | |
float uncalib[3]; | |
struct { | |
float x_uncalib; | |
float y_uncalib; | |
float z_uncalib; | |
}; | |
}; | |
union { | |
float bias[3]; | |
struct { | |
float x_bias; | |
float y_bias; | |
float z_bias; | |
}; | |
}; | |
} uncalibrated_event_t; | |
/*** Meta-data event for a sensor - e.g., Tamper */ | |
typedef struct meta_data_event { | |
int32_t what; | |
int32_t sensor; | |
} meta_data_event_t; | |
/** Union of the various types of sensor data that can be returned. ***/ | |
typedef struct sensors_event_t { | |
int32_t version; /* Firmware version */ | |
int32_t sensor; /* sensor identifier - a.k.a. handler */ | |
int32_t type; /* sensor type */ | |
int32_t reserved0; /* reserved */ | |
int64_t timestamp; /* time is in nanosecond */ | |
union { | |
union { | |
float data[16]; | |
sensors_vec_t acceleration; /* acceleration values are in meter per second per second (m/s^2) */ | |
sensors_vec_t magnetic; /* magnetic vector values are in micro-Tesla (uT) */ | |
sensors_vec_t orientation; /* orientation values are in degrees */ | |
sensors_vec_t gyro; /* gyroscope values are in rad/s */ | |
float temperature; /* temperature is in degrees centigrade (Celsius) */ | |
float distance /* distance in centimeters */ | |
float light; /* light in SI lux units */ | |
float pressure; /* pressure in hectopascal (hPa) */ | |
float relative_humidity; /* relative humidity in percent */ | |
uncalibrated_event_t uncalibrated_gyro; /* uncalibrated gyroscope values are in rad/s */ | |
uncalibrated_event_t uncalibrated_magnetic; /* uncalibrated magnetometer values are in micro-Teslas */ | |
meta_data_event_t meta_data; /* this is a special event. see SENSOR_TYPE_META_DATA above. */ | |
}; | |
union { | |
uint64_t data[8]; | |
uint64_t step_counter; /* step-counter */ | |
} u64; | |
}; | |
uint32_t reserved1[4]; | |
} sensors_event_t; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment