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, 16666, {}
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));
54 ALOGV("<<AccelSensor 3D: constructor!");
57 int AccelSensor::processEvent(unsigned char *raw_data, size_t raw_data_len){
58 struct accel_3d_sample *sample;
60 ALOGV(">>%s", __func__);
62 if (IsDeviceInitialized() == false){
63 ALOGE("Device was not initialized \n");
65 } if (raw_data_len < sizeof(struct accel_3d_sample)){
66 ALOGE("Insufficient length \n");
70 ALOGV("Accel:%2x:%2x:%2x:%2x:%2x:%2x", *raw_data, *(raw_data + 1), *
71 (raw_data + 2), *(raw_data + 3), *(raw_data + 4), *(raw_data + 5));
72 sample = (struct accel_3d_sample*)raw_data;
73 mPendingEvent.data[0] = mPendingEvent.acceleration.x =
74 CONVERT_A_G_VTF16E14_X(GetChannelBytesUsedSize(CHANNEL_X), GetExponentValue(), sample->accel_x);
75 mPendingEvent.data[1] = mPendingEvent.acceleration.y =
76 CONVERT_A_G_VTF16E14_Y(GetChannelBytesUsedSize(CHANNEL_Y), GetExponentValue(), sample->accel_y);
77 mPendingEvent.data[2] = mPendingEvent.acceleration.z =
78 CONVERT_A_G_VTF16E14_Z(GetChannelBytesUsedSize(CHANNEL_Z), GetExponentValue(), sample->accel_z);
80 ALOGV("ACCEL 3D Sample %fm/s2 %fm/s2 %fm/s2\n", mPendingEvent.acceleration.x,
81 mPendingEvent.acceleration.y, mPendingEvent.acceleration.z);
82 ALOGV("<<%s", __func__);