X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=utils.c;h=9e4fb2735f51767f4c2a08737a4848c998fc4494;hb=259d5cfe043792f3549e8e765b97da1f486c3bc8;hp=fcde830fa1e511318cc5a4da6b250a2e6d7be042;hpb=93e42e580d09229d32e9254bcfe6424e38b8fcaa;p=android-x86%2Fhardware-intel-libsensors.git diff --git a/utils.c b/utils.c index fcde830..9e4fb27 100644 --- a/utils.c +++ b/utils.c @@ -6,6 +6,7 @@ #include #include #include +#include "common.h" #include "utils.h" @@ -219,84 +220,6 @@ int decode_type_spec( const char type_buf[MAX_TYPE_SPEC_LEN], } -int64_t sample_as_int64(unsigned char* sample, struct datum_info_t* type) -{ - uint16_t u16; - uint32_t u32; - uint64_t u64; - int i; - - switch (type->storagebits) { - case 64: - u64 = 0; - - if (type->endianness == 'b') - for (i=0; i<8; i++) - u64 = (u64 << 8) | sample[i]; - else - for (i=7; i>=0; i--) - u64 = (u64 << 8) | sample[i]; - - if (type->sign == 'u') - return (int64_t) (u64 >> type->shift); - - return ((int64_t) u64) >> type->shift; - - case 32: - if (type->endianness == 'b') - u32 = (sample[0] << 24) | (sample[1] << 16) | - (sample[2] << 8) | sample[3]; - else - u32 = (sample[3] << 24) | (sample[2] << 16) | - (sample[1] << 8) | sample[0]; - - if (type->sign == 'u') - return u32 >> type->shift; - - return ((int32_t) u32) >> type->shift; - - case 16: - if (type->endianness == 'b') - u16 = (sample[0] << 8) | sample[1]; - else - u16 = (sample[1] << 8) | sample[0]; - - if (type->sign == 'u') - return u16 >> type->shift; - - return ((int16_t) u16) >> type->shift; - } - - ALOGE("Unhandled sample storage size\n"); - return 0; -} - - -float transform_sample (int sensor_type, int channel, float val) -{ - /* Last opportunity to alter sample data before it goes to Android */ - switch (sensor_type) { - case SENSOR_TYPE_ACCELEROMETER: - /* - * Invert x axis orientation from SI units - see - * /hardware/libhardware/include/hardware/sensors.h - * for a discussion of what Android expects - */ - if (channel == 0) - return -val; - break; - - case SENSOR_TYPE_GYROSCOPE: - /* Limit drift */ - if (val > -0.05 && val < 0.05) - return 0; - break; - } - - return val; -} - - int64_t get_timestamp(void) { struct timespec ts = {0}; @@ -305,5 +228,3 @@ int64_t get_timestamp(void) return 1000000000LL * ts.tv_sec + ts.tv_nsec; } - -