Home | History | Annotate | Download | only in libsensors
      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 <cutils/log.h>
     25 #include <pthread.h>
     26 
     27 #include "LightSensor.h"
     28 
     29 LightSensor::LightSensor()
     30     : SamsungSensorBase(NULL, "lightsensor-level", ABS_MISC)
     31 {
     32     mPendingEvent.sensor = ID_L;
     33     mPendingEvent.type = SENSOR_TYPE_LIGHT;
     34 }
     35 
     36 bool LightSensor::handleEvent(input_event const *event) {
     37     if (event->value == -1) {
     38         return false;
     39     }
     40     // Convert adc value to lux assuming:
     41     // I = 10 * log(Ev) uA
     42     // R = 24kOhm
     43     // Max adc value 1023 = 1.25V
     44     // 1/4 of light reaches sensor
     45     mPendingEvent.light = powf(10, event->value * (125.0f / 1023.0f / 24.0f)) * 4;
     46     return true;
     47 }
     48