OSDN Git Service

libsensors: Added support for Pressure sensor
[android-x86/hardware-intel-libsensors.git] / SensorBase.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
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 <assert.h>
25
26 #include <cutils/log.h>
27
28 #include <linux/input.h>
29
30 #include "SensorBase.h"
31
32 int64_t SensorBase::getTimestamp()
33 {
34     struct timespec t;
35     t.tv_sec = t.tv_nsec = 0;
36     clock_gettime(CLOCK_MONOTONIC, &t);
37     return int64_t(t.tv_sec)*1000000000LL + t.tv_nsec;
38 }
39
40 int SensorBase::open()
41 {
42     if (mDevPath == "") {
43         ALOGE("mDevPath is not set");
44         return -1;
45     }
46     mFd = ::open(mDevPath.c_str(), O_RDONLY);
47     ALOGE_IF(mFd < 0, "%s: device %s err:%d", __func__, mDevPath.c_str(), -errno);
48     ALOGV("%s: device path:%s, fd:%d", __func__, mDevPath.c_str(), mFd);
49     return mFd;
50 }
51
52 void SensorBase::close()
53 {
54     int ret = ::close(mFd);
55     mFd = -1;
56     ALOGV("%s: device path:%s, fd:%d", __func__, mDevPath.c_str(), mFd);
57 }