1 /* 2 * Copyright (C) 2011 Samsung 3 * 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 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 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. 15 */ 16 17 #include <fcntl.h> 18 #include <errno.h> 19 #include <math.h> 20 #include <poll.h> 21 #include <unistd.h> 22 #include <dirent.h> 23 #include <sys/select.h> 24 #include <pthread.h> 25 26 #include <cutils/log.h> 27 28 #include "ProximitySensor.h" 29 30 /*****************************************************************************/ 31 32 ProximitySensor::ProximitySensor() 33 : SamsungSensorBase(NULL, "proximity", ABS_DISTANCE) 34 { 35 mPendingEvent.sensor = ID_P; 36 mPendingEvent.type = SENSOR_TYPE_PROXIMITY; 37 } 38 39 int ProximitySensor::setDelay(int32_t handle, int64_t ns) 40 { 41 return -1; 42 } 43 44 float ProximitySensor::indexToValue(size_t index) const 45 { 46 return index * PROXIMITY_THRESHOLD_GP2A; 47 } 48 49 bool ProximitySensor::hasPendingEvents() const { 50 return mHasPendingEvent; 51 } 52 53 int ProximitySensor::handleEnable(int en) { 54 if (!en) 55 return 0; 56 57 struct input_absinfo absinfo; 58 if (!ioctl(data_fd, EVIOCGABS(ABS_DISTANCE), &absinfo)) { 59 mHasPendingEvent = true; 60 mPendingEvent.distance = indexToValue(absinfo.value); 61 return 0; 62 } else { 63 return -1; 64 } 65 } 66 67 bool ProximitySensor::handleEvent(input_event const *event) { 68 mPendingEvent.distance = indexToValue(event->value); 69 return true; 70 } 71