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_Compass3D.h"
33 struct compass_3d_sample{
34 unsigned int compass_x;
35 unsigned int compass_y;
36 unsigned int compass_z;
39 const struct sensor_t CompassSensor::sSensorInfo_compass3D = {
40 "HID_SENSOR Compass 3D", "Intel", 1, SENSORS_MAGNETIC_FIELD_HANDLE,
41 SENSOR_TYPE_MAGNETIC_FIELD, RANGE_M, RESOLUTION_M, 0.1f, 66667, {}
43 const int retry_cnt = 10;
45 CompassSensor::CompassSensor(): SensorIIODev("magn_3d", "in_magn_scale", "in_magn_offset", "in_magn_", retry_cnt){
46 ALOGV(">>ComassSensor 3D: constructor!");
47 mPendingEvent.version = sizeof(sensors_event_t);
48 mPendingEvent.sensor = ID_M;
49 mPendingEvent.type = SENSOR_TYPE_MAGNETIC_FIELD;
50 memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data));
51 ALOGV("<<ComassSensor 3D: constructor!");
54 int CompassSensor::processEvent(unsigned char *raw_data, size_t raw_data_len){
55 struct compass_3d_sample *sample;
57 ALOGV(">>%s", __func__);
58 if (IsDeviceInitialized() == false){
59 ALOGE("Device was not initialized \n");
61 } if (raw_data_len < sizeof(struct compass_3d_sample)){
62 ALOGE("Insufficient length \n");
65 sample = (struct compass_3d_sample*)raw_data;
67 mPendingEvent.data[0] = mPendingEvent.magnetic.x = CONVERT_M_MG_VTF16E14_X
68 (GetChannelBytesUsedSize(CHANNEL_X), GetExponentValue(), sample->compass_x);
69 mPendingEvent.data[1] = mPendingEvent.magnetic.y = CONVERT_M_MG_VTF16E14_Y
70 (GetChannelBytesUsedSize(CHANNEL_Y), GetExponentValue(), sample->compass_y);
71 mPendingEvent.data[2] = mPendingEvent.magnetic.z = CONVERT_M_MG_VTF16E14_Z
72 (GetChannelBytesUsedSize(CHANNEL_Z), GetExponentValue(), sample->compass_z);
74 ALOGV("COMPASS 3D Sample %fuT %fuT %fuT\n", mPendingEvent.magnetic.x,
75 mPendingEvent.magnetic.y, mPendingEvent.magnetic.z);
76 ALOGV("<<%s", __func__);