blob: 3bf726f4077e18c9a558853eb983af9517c655bc [file] [log] [blame]
Baixing Tan1f9b03c2015-04-20 08:49:23 +08001/*
2* Copyright (C) 2015 Intel Corp
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
18#ifndef ANDROID_LIGHT_SENSOR_H
19#define ANDROID_LIGHT_SENSOR_H
20
21#include <stdint.h>
22#include <errno.h>
23#include <sys/cdefs.h>
24#include <sys/types.h>
25
26#include "sensors.h"
27#include "SensorBase.h"
28#include "InputEventReader.h"
29
30/*****************************************************************************/
31/* the GP2A is a binary proximity sensor that triggers around 5 cm on
32 * this hardware */
33#define PROXIMITY_THRESHOLD_GP2A 5.0f
34
35struct input_event;
36
37class LightSensor : public SensorBase {
38 int mEnabled;
39 int mEventsSinceEnable;
40 InputEventCircularReader mInputReader;
41 sensors_event_t mPendingEvent;
42 bool mHasPendingEvent;
43 char input_sysfs_path[PATH_MAX];
44 int input_sysfs_path_len;
45
46 int setInitialState();
47 float mPreviousLight;
48 float indexToValue(size_t index) const;
49
50public:
51 LightSensor();
52 virtual ~LightSensor();
53 virtual int readEvents(sensors_event_t* data, int count);
54 virtual bool hasPendingEvents() const;
55 virtual int setDelay(int32_t handle, int64_t ns);
56 virtual int enable(int32_t handle, int enabled);
Baixing Tanbe1c9f42015-05-06 09:51:37 +080057 virtual int isActivated(int handle);
Baixing Tan1f9b03c2015-04-20 08:49:23 +080058#ifdef HAL_VERSION_GT_1_0
59 virtual int batch(int handle, int flags, int64_t period_ns, int64_t timeout);
60#endif
61
62};
63
64/*****************************************************************************/
65
66#endif // ANDROID_LIGHT_SENSOR_H