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_Accel3D.h"
33 struct accel_3d_sample{
39 const struct sensor_t AccelSensor::sSensorInfo_accel3D = {
40 "HID_SENSOR Accelerometer 3D", "Intel", 1, SENSORS_ACCELERATION_HANDLE,
41 SENSOR_TYPE_ACCELEROMETER, RANGE_A, RESOLUTION_A, 0.23f, 10000, 0, 0,
42 SENSOR_STRING_TYPE_ACCELEROMETER, "", 0 , SENSOR_FLAG_CONTINUOUS_MODE, {}
45 const long HID_USAGE_SENSOR_UNITS_G = 0x1A;
46 const long HID_USAGE_SENSOR_UNITS_METERS_PER_SEC_SQRD = (0x11, 0xE0);
47 const int retry_cnt = 10;
49 AccelSensor::AccelSensor(): SensorIIODev("accel_3d", "in_accel_scale", "in_accel_offset", "in_accel_", retry_cnt){
50 ALOGV(">>AccelSensor 3D: constructor!");
51 mPendingEvent.version = sizeof(sensors_event_t);
52 mPendingEvent.sensor = ID_A;
53 mPendingEvent.type = SENSOR_TYPE_ACCELEROMETER;
54 memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data));
56 // CDD requires 120Hz, but HSB caps out at ~62Hz. Use that as default.
57 sample_delay_min_ms = 16;
59 ALOGV("<<AccelSensor 3D: constructor!");
62 int AccelSensor::processEvent(unsigned char *raw_data, size_t raw_data_len){
63 struct accel_3d_sample *sample;
65 ALOGV(">>%s", __func__);
67 if (IsDeviceInitialized() == false){
68 ALOGE("Device was not initialized \n");
70 } if (raw_data_len < sizeof(struct accel_3d_sample)){
71 ALOGE("Insufficient length \n");
75 ALOGV("Accel:%2x:%2x:%2x:%2x:%2x:%2x", *raw_data, *(raw_data + 1), *
76 (raw_data + 2), *(raw_data + 3), *(raw_data + 4), *(raw_data + 5));
77 sample = (struct accel_3d_sample*)raw_data;
78 mPendingEvent.data[0] = mPendingEvent.acceleration.x =
79 CONVERT_A_G_VTF16E14_X(GetChannelBytesUsedSize(CHANNEL_X), GetExponentValue(), sample->accel_x);
80 mPendingEvent.data[1] = mPendingEvent.acceleration.y =
81 CONVERT_A_G_VTF16E14_Y(GetChannelBytesUsedSize(CHANNEL_Y), GetExponentValue(), sample->accel_y);
82 mPendingEvent.data[2] = mPendingEvent.acceleration.z =
83 CONVERT_A_G_VTF16E14_Z(GetChannelBytesUsedSize(CHANNEL_Z), GetExponentValue(), sample->accel_z);
85 ALOGV("ACCEL 3D Sample %fm/s2 %fm/s2 %fm/s2\n", mPendingEvent.acceleration.x,
86 mPendingEvent.acceleration.y, mPendingEvent.acceleration.z);
87 ALOGV("<<%s", __func__);