2 * Copyright (C) 2014 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <sys/select.h>
23 #include <cutils/log.h>
26 #include "SensorConfig.h"
27 #include "HidSensor_Pressure.h"
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
37 struct pressure_sample{
38 unsigned int pressure_s; /* TODO: check type: too short? */
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,{}
46 const long HID_USAGE_SENSOR_UNITS_PASCAL = 0xF1E1;
47 const long UNIT_EXPO_DEC_BASE = 0x0F;
48 const int retry_cnt = 5;
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!");
61 int PressureSensor::processEvent(unsigned char *raw_data, size_t raw_data_len){
62 struct pressure_sample *sample;
64 ALOGV(">>%s", __func__);
65 if (IsDeviceInitialized() == false){
66 ALOGE("Device was not initialized \n");
68 } if (raw_data_len < sizeof(struct pressure_sample)){
69 ALOGE("Insufficient length \n");
72 sample = (struct pressure_sample*)raw_data;
73 ALOGV("Pressure:%2x", sample->pressure_s);
75 mPendingEvent.data[0] = mPendingEvent.pressure =
76 CONVERT_PR_HPA_VTF16E14(GetChannelBytesUsedSize(CHANNEL_PR), GetExponentValue(), sample->pressure_s);
78 ALOGV("PRESSURE Sample %f(hPa=Pa/100)\n", mPendingEvent.pressure);
79 ALOGV("<<%s", __func__);