/* * 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 "AkmSensor.h" #include "akm8975.h" /*****************************************************************************/ AkmSensor::AkmSensor() : SensorBase(AKM_DEVICE_NAME, "compass"), mEnabled(0), mPendingMask(0), mInputReader(32) { 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_ACCURACY_HIGH; */ 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_ACCURACY_HIGH; /* mPendingEvents[Orientation ].version = sizeof(sensors_event_t); mPendingEvents[Orientation ].sensor = ID_O; mPendingEvents[Orientation ].type = SENSOR_TYPE_ORIENTATION; mPendingEvents[Orientation ].orientation.status = SENSOR_STATUS_ACCURACY_HIGH; */ for (int i=0 ; i 0) && (!ioctl(dev_fd, ECS_IOCTL_APP_GET_MVFLAG, &flags))) { if (flags) { mEnabled |= 1< 0) ioctl(dev_fd, ECS_IOCTL_APP_SET_TFLAG, &flags); */ } AkmSensor::~AkmSensor() { } int AkmSensor::enable(int32_t handle, int en) { int what = -1; switch (handle) { //case ID_A: what = Accelerometer; break; case ID_M: what = MagneticField; break; //case ID_O: what = Orientation; break; } if (uint32_t(what) >= numSensors) return -EINVAL; int newState = en ? 1 : 0; int err = 0; if ((uint32_t(newState)<= numSensors) return -EINVAL; if (ns < 0) return -EINVAL; mDelays[what] = ns; return update_delay(); #else return -1; #endif } int AkmSensor::update_delay() { int result = 0; if (mEnabled) { uint64_t wanted = -1LLU; for (int i=0 ; itype; if (type == EV_ABS) { // #define EV_ABS 0x03 processEvent(event->code, event->value); mInputReader.next(); } else if (type == EV_SYN) { // #define EV_SYN 0x00 int64_t time = getTimestamp(); //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_ACCEL_X: mPendingMask |= 1<