OSDN Git Service

libsensors: retry more and deal with sensor hub quirk
[android-x86/hardware-intel-libsensors.git] / common / libsensors / HidSensor_ALS.cpp
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
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 #include <fcntl.h>
17 #include <errno.h>
18 #include <math.h>
19 #include <poll.h>
20 #include <unistd.h>
21 #include <dirent.h>
22 #include <sys/select.h>
23 #include <cutils/log.h>
24
25 #include "common.h"
26 #include "SensorConfig.h"
27 #include "HidSensor_ALS.h"
28
29
30 struct als_sample{
31     unsigned short illum;
32 } __packed;
33
34 const struct sensor_t ALSSensor::sSensorInfo_als = {
35     "HID_SENSOR ALS", "Intel", 1, SENSORS_LIGHT_HANDLE, SENSOR_TYPE_LIGHT,
36         50000.0f, 1.0f, 0.75f, 0, {}
37     ,
38 };
39 const int retry_cnt = 10;
40
41 ALSSensor::ALSSensor(): SensorIIODev("als", "in_intensity_scale", "in_intensity_offset", "in_intensity_", retry_cnt){
42     ALOGV(">>ALSSensor 3D: constructor!");
43     mPendingEvent.version = sizeof(sensors_event_t);
44     mPendingEvent.sensor = ID_L;
45     mPendingEvent.type = SENSOR_TYPE_LIGHT;
46     memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data));
47     ALOGV("<<ALSSensor 3D: constructor!");
48 }
49
50 int ALSSensor::processEvent(unsigned char *raw_data, size_t raw_data_len){
51     struct als_sample *sample;
52
53     ALOGV(">>%s", __func__);
54     if (IsDeviceInitialized() == false){
55         ALOGE("Device was not initialized \n");
56         return  - 1;
57     } if (raw_data_len < sizeof(struct als_sample)){
58         ALOGE("Insufficient length \n");
59         return  - 1;
60     }
61     sample = (struct als_sample*)raw_data;
62     mPendingEvent.light = (float)sample->illum;
63
64     ALOGV("ALS %fm/s2\n", mPendingEvent.light);
65     ALOGV("<<%s", __func__);
66     return 0;
67 }