OSDN Git Service

Merge remote-tracking branch 'x86/kitkat-x86' into lollipop-x86
[android-x86/hardware-intel-libsensors.git] / HidSensor_Pressure.cpp
1 /*
2  * Copyright (C) 2014 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_Pressure.h"
28
29 #define CHANNEL_PR 0
30
31 /* TODO: POWERCONSUMP_PRESS, PRESS_MINDELAY replace or fill that macros */
32 #define POWERCONSUMP_PRESS      0.11f
33 #define PRESS_MINDELAY         0
34 #define RANGE_PRESS                 1260
35 #define RESOLUTION_PRESS        0.0f
36
37 struct pressure_sample{
38     unsigned int pressure_s; /* TODO: check type: too short? */
39 } __packed;
40
41 const struct sensor_t PressureSensor::sSensorInfo_pressure = {
42     "HID_SENSOR Barometer Sensor", "Intel", 1, SENSORS_PRESSURE_HANDLE,
43         SENSOR_TYPE_PRESSURE, RANGE_PRESS, RESOLUTION_PRESS, POWERCONSUMP_PRESS, PRESS_MINDELAY,0,0,{}
44 };
45
46 const long HID_USAGE_SENSOR_UNITS_PASCAL = 0xF1E1;
47 const long UNIT_EXPO_DEC_BASE = 0x0F;
48 const int retry_cnt = 5;
49
50
51 PressureSensor::PressureSensor(): SensorIIODev("press", "in_pressure_scale", "in_pressure_offset", "in_pressure_", retry_cnt){
52     ALOGV(">>PressureSensor 3D: constructor!");
53     mPendingEvent.version = sizeof(sensors_event_t);
54     mPendingEvent.sensor = ID_PR;
55     mPendingEvent.type = SENSOR_TYPE_PRESSURE;
56     memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data));
57     sample_delay_min_ms = 500;
58     ALOGV("<<PressureSensor 3D: constructor!");
59 }
60
61 int PressureSensor::processEvent(unsigned char *raw_data, size_t raw_data_len){
62     struct pressure_sample *sample;
63
64     ALOGV(">>%s", __func__);
65     if (IsDeviceInitialized() == false){
66         ALOGE("Device was not initialized \n");
67         return  - 1;
68     } if (raw_data_len < sizeof(struct pressure_sample)){
69         ALOGE("Insufficient length \n");
70         return  - 1;
71     }
72     sample = (struct pressure_sample*)raw_data;
73     ALOGV("Pressure:%2x",  sample->pressure_s);
74
75     mPendingEvent.data[0] = mPendingEvent.pressure =
76                CONVERT_PR_HPA_VTF16E14(GetChannelBytesUsedSize(CHANNEL_PR), GetExponentValue(), sample->pressure_s);
77
78     ALOGV("PRESSURE Sample %f(hPa=Pa/100)\n", mPendingEvent.pressure);
79     ALOGV("<<%s", __func__);
80     return 0;
81 }