2 * Copyright (C) 2008 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #include <sys/select.h>
23 #include <cutils/log.h>
26 #include "SensorConfig.h"
27 #include "HidSensor_Gyro3D.h"
33 struct gyro_3d_sample{
39 const struct sensor_t GyroSensor::sSensorInfo_gyro3D = {
40 "HID_SENSOR Gyro 3D", "Intel", 1, SENSORS_GYROSCOPE_HANDLE,
41 SENSOR_TYPE_GYROSCOPE, RANGE_GYRO, RESOLUTION_GYRO, 6.10f, 1250, {}
43 const int HID_USAGE_SENSOR_UNITS_DEGREES_PER_SECOND = 0x15;
44 const int HID_USAGE_SENSOR_UNITS_RADIANS_PER_SECOND = 0xF012;
45 const int retry_cnt = 10;
47 GyroSensor::GyroSensor(): SensorIIODev("gyro_3d", "in_anglvel_scale", "in_anglvel_offset", "in_anglvel_", retry_cnt){
48 ALOGV("GyroSensor: constructor\n");
49 mPendingEvent.version = sizeof(sensors_event_t);
50 mPendingEvent.sensor = ID_GY;
51 mPendingEvent.type = SENSOR_TYPE_GYROSCOPE;
52 memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data));
56 int GyroSensor::processEvent(unsigned char *raw_data, size_t raw_data_len){
57 struct gyro_3d_sample *sample;
59 ALOGV(">>%s", __func__);
60 if (IsDeviceInitialized() == false){
61 ALOGE("Device was not initialized \n");
63 } if (raw_data_len < sizeof(struct gyro_3d_sample)){
64 ALOGE("Insufficient length \n");
67 sample = (struct gyro_3d_sample*)raw_data;
68 if (GetUnitValue() == HID_USAGE_SENSOR_UNITS_DEGREES_PER_SECOND){
69 mPendingEvent.data[0] = mPendingEvent.gyro.x = CONVERT_G_D_VTF16E14_X
70 (GetChannelBytesUsedSize(CHANNEL_X), GetExponentValue(), sample->gyro_x)
72 mPendingEvent.data[1] = mPendingEvent.gyro.y = CONVERT_G_D_VTF16E14_Y
73 (GetChannelBytesUsedSize(CHANNEL_Y), GetExponentValue(), sample->gyro_y)
75 mPendingEvent.data[2] = mPendingEvent.gyro.z = CONVERT_G_D_VTF16E14_Z
76 (GetChannelBytesUsedSize(CHANNEL_Z), GetExponentValue(), sample->gyro_z)
79 else if (GetUnitValue() == HID_USAGE_SENSOR_UNITS_RADIANS_PER_SECOND){
80 mPendingEvent.data[0] = mPendingEvent.gyro.x = CONVERT_FROM_VTF16
81 (GetChannelBytesUsedSize(CHANNEL_X), GetExponentValue(), sample->gyro_x)
83 mPendingEvent.data[1] = mPendingEvent.gyro.y = CONVERT_FROM_VTF16
84 (GetChannelBytesUsedSize(CHANNEL_Y), GetExponentValue(), sample->gyro_y)
86 mPendingEvent.data[2] = mPendingEvent.gyro.z = CONVERT_FROM_VTF16
87 (GetChannelBytesUsedSize(CHANNEL_Z), GetExponentValue(), sample->gyro_z)
91 ALOGE("Gyro Unit is not supported");
94 ALOGV("GYRO 3D Sample %fm/s2 %fm/s2 %fm/s2\n", mPendingEvent.gyro.x,
95 mPendingEvent.gyro.y, mPendingEvent.gyro.z);
96 ALOGV("<<%s", __func__);