From: srinivas pandruvada Date: Wed, 30 May 2012 23:29:11 +0000 (-0700) Subject: Sensor HAL: Added Compass X-Git-Tag: android-x86-6.0-r1~35 X-Git-Url: http://git.osdn.net/view?p=android-x86%2Fhardware-intel-libsensors.git;a=commitdiff_plain;h=4c818ee6cd3304c6f975f0f8be9b417d932a15d4 Sensor HAL: Added Compass Added Compass (Magnetometer) HAL as defined by HID sensor usage table. This only implements the minimal set. Change-Id: I19c222019b8770942e23f614ada8a2c35d401471 Signed-off-by: srinivas pandruvada --- diff --git a/common/libsensors/HidSensor_Compass3D.cpp b/common/libsensors/HidSensor_Compass3D.cpp new file mode 100644 index 0000000..f9f03d0 --- /dev/null +++ b/common/libsensors/HidSensor_Compass3D.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "common.h" +#include "SensorConfig.h" +#include "HidSensor_Compass3D.h" + +#define CHANNEL_X 0 +#define CHANNEL_Y 1 +#define CHANNEL_Z 2 + +struct compass_3d_sample{ + unsigned int compass_x; + unsigned int compass_y; + unsigned int compass_z; +} __packed; + +const struct sensor_t CompassSensor::sSensorInfo_compass3D = { + "HID_SENSOR Compass 3D", "Intel", 1, SENSORS_MAGNETIC_FIELD_HANDLE, + SENSOR_TYPE_MAGNETIC_FIELD, RANGE_M, RESOLUTION_M, 0.1f, 23000, {} +}; +const int retry_cnt = 5; + +CompassSensor::CompassSensor(): SensorIIODev("magn_3d", "in_magn_scale", "in_magn_offset", "in_magn_", retry_cnt){ + ALOGV(">>ComassSensor 3D: constructor!"); + mPendingEvent.version = sizeof(sensors_event_t); + mPendingEvent.sensor = ID_M; + mPendingEvent.type = SENSOR_TYPE_MAGNETIC_FIELD; + memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data)); + ALOGV("<>%s", __func__); + if (IsDeviceInitialized() == false){ + ALOGE("Device was not initialized \n"); + return - 1; + } if (raw_data_len < sizeof(struct compass_3d_sample)){ + ALOGE("Insufficient length \n"); + return - 1; + } + sample = (struct compass_3d_sample*)raw_data; + + mPendingEvent.data[0] = mPendingEvent.magnetic.x = CONVERT_M_MG_VTF16E14_X + (GetChannelBytesUsedSize(CHANNEL_X), GetExponentValue(), sample->compass_x); + mPendingEvent.data[1] = mPendingEvent.magnetic.y = CONVERT_M_MG_VTF16E14_Y + (GetChannelBytesUsedSize(CHANNEL_Y), GetExponentValue(), sample->compass_y); + mPendingEvent.data[2] = mPendingEvent.magnetic.z = CONVERT_M_MG_VTF16E14_Z + (GetChannelBytesUsedSize(CHANNEL_Z), GetExponentValue(), sample->compass_z); + + ALOGV("COMPASS 3D Sample %fuT %fuT %fuT\n", mPendingEvent.magnetic.x, + mPendingEvent.magnetic.y, mPendingEvent.magnetic.z); + ALOGV("<<%s", __func__); + return 0; +} diff --git a/common/libsensors/HidSensor_Compass3D.h b/common/libsensors/HidSensor_Compass3D.h new file mode 100644 index 0000000..ebf117e --- /dev/null +++ b/common/libsensors/HidSensor_Compass3D.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HIDSENSOR_COMPASS3D_H +#define HIDSENSOR_COMPASS3D_H + +#include +#include +#include +#include + +#include "SensorIIODev.h" +#include "Helpers.h" + +class CompassSensor : public SensorIIODev { + +public: + CompassSensor(); + virtual int processEvent(unsigned char *raw_data, size_t raw_data_len); + static const struct sensor_t sSensorInfo_compass3D; +}; +#endif