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, {}
44 const long HID_USAGE_SENSOR_UNITS_G = 0x1A;
45 const long HID_USAGE_SENSOR_UNITS_METERS_PER_SEC_SQRD = (0x11, 0xE0);
46 const int retry_cnt = 10;
48 AccelSensor::AccelSensor(): SensorIIODev("accel_3d", "in_accel_scale", "in_accel_offset", "in_accel_", retry_cnt){
49 ALOGV(">>AccelSensor 3D: constructor!");
50 mPendingEvent.version = sizeof(sensors_event_t);
51 mPendingEvent.sensor = ID_A;
52 mPendingEvent.type = SENSOR_TYPE_ACCELEROMETER;
53 memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data));
55 // CDD requires 120Hz, but HSB caps out at ~62Hz. Use that as default.
56 sample_delay_min_ms = 16;
58 ALOGV("<<AccelSensor 3D: constructor!");
61 int AccelSensor::processEvent(unsigned char *raw_data, size_t raw_data_len){
62 struct accel_3d_sample *sample;
64 ALOGV(">>%s", __func__);
66 if (IsDeviceInitialized() == false){
67 ALOGE("Device was not initialized \n");
69 } if (raw_data_len < sizeof(struct accel_3d_sample)){
70 ALOGE("Insufficient length \n");
74 ALOGV("Accel:%2x:%2x:%2x:%2x:%2x:%2x", *raw_data, *(raw_data + 1), *
75 (raw_data + 2), *(raw_data + 3), *(raw_data + 4), *(raw_data + 5));
76 sample = (struct accel_3d_sample*)raw_data;
77 mPendingEvent.data[0] = mPendingEvent.acceleration.x =
78 CONVERT_A_G_VTF16E14_X(GetChannelBytesUsedSize(CHANNEL_X), GetScaleValue(), sample->accel_x);
79 mPendingEvent.data[1] = mPendingEvent.acceleration.y =
80 CONVERT_A_G_VTF16E14_Y(GetChannelBytesUsedSize(CHANNEL_Y), GetScaleValue(), sample->accel_y);
81 mPendingEvent.data[2] = mPendingEvent.acceleration.z =
82 CONVERT_A_G_VTF16E14_Z(GetChannelBytesUsedSize(CHANNEL_Z), GetScaleValue(), sample->accel_z);
84 ALOGV("ACCEL 3D Sample %fm/s2 %fm/s2 %fm/s2\n", mPendingEvent.acceleration.x,
85 mPendingEvent.acceleration.y, mPendingEvent.acceleration.z);
86 ALOGV("<<%s", __func__);