From 381a05756bdbe474ab76242a4e2934d81b8975e9 Mon Sep 17 00:00:00 2001 From: Simon Shields Date: Sat, 5 Mar 2016 20:36:08 +1100 Subject: i9300: rewrite libsensors in c++ * based off t0lte sensors * AkmSensor kanged from i9100 (added sensor status support) * has a working compass! Change-Id: Iaed0463c33089ca0b636be4ba3f966f2e25f34f9 --- libsensors/AkmSensor.cpp | 281 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 281 insertions(+) create mode 100644 libsensors/AkmSensor.cpp (limited to 'libsensors/AkmSensor.cpp') diff --git a/libsensors/AkmSensor.cpp b/libsensors/AkmSensor.cpp new file mode 100644 index 0000000..e7e0a4b --- /dev/null +++ b/libsensors/AkmSensor.cpp @@ -0,0 +1,281 @@ +/* + * 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 + +#include "ak8973b.h" + +#include +#include "AkmSensor.h" + + +/*****************************************************************************/ + +int (*akm_is_sensor_enabled)(uint32_t sensor_type); +int (*akm_enable_sensor)(uint32_t sensor_type); +int (*akm_disable_sensor)(uint32_t sensor_type); +int (*akm_set_delay)(uint32_t sensor_type, uint64_t delay); + +int stub_is_sensor_enabled(uint32_t sensor_type) { + return 0; +} + +int stub_enable_disable_sensor(uint32_t sensor_type) { + return -ENODEV; +} + +int stub_set_delay(uint32_t sensor_type, uint64_t delay) { + return -ENODEV; +} + +AkmSensor::AkmSensor() +: SensorBase(NULL, NULL), + mEnabled(0), + mPendingMask(0), + mInputReader(32) +{ + /* Open the library before opening the input device. The library + * creates a uinput device. + */ + if (loadAKMLibrary() == 0) { + data_name = "compass_sensor"; + data_fd = openInput("compass_sensor"); + } + + memset(mPendingEvents, 0, sizeof(mPendingEvents)); + + mPendingEvents[Accelerometer].version = sizeof(sensors_event_t); + mPendingEvents[Accelerometer].sensor = ID_A; + mPendingEvents[Accelerometer].type = SENSOR_TYPE_ACCELEROMETER; + mPendingEvents[Accelerometer].acceleration.status = SENSOR_STATUS_UNRELIABLE; + + mPendingEvents[MagneticField].version = sizeof(sensors_event_t); + mPendingEvents[MagneticField].sensor = ID_M; + mPendingEvents[MagneticField].type = SENSOR_TYPE_MAGNETIC_FIELD; + mPendingEvents[MagneticField].magnetic.status = SENSOR_STATUS_UNRELIABLE; + + // read the actual value of all sensors if they're enabled already + struct input_absinfo absinfo; + short flags = 0; + + if (akm_is_sensor_enabled(SENSOR_TYPE_ACCELEROMETER)) { + mEnabled |= 1<= numSensors) + return -EINVAL; + + int newState = en ? 1 : 0; + int err = 0; + + if ((uint32_t(newState)<type; + if (type == EV_REL) { + processEvent(event->code, event->value); + mInputReader.next(); + } else if (type == EV_SYN) { + int64_t time = timevalToNano(event->time); + for (int j=0 ; count && mPendingMask && jcode); + mInputReader.next(); + } + } + return numEventReceived; +} + +void AkmSensor::processEvent(int code, int value) +{ + switch (code) { + case EVENT_TYPE_MAGV_X: + ALOGV("AkmSensor: MAGV_X =>%d", value); + mPendingMask |= 1<%d", value); + mPendingMask |= 1<%d", value); + mPendingMask |= 1<%d", value); + mPendingMask |= 1<