142331858975144405f95243be8427084ee7d478dJean-Baptiste Queru/* 2895401859313187f15a800e62d43e6bcbf48fadaJP Abgrall * Copyright (C) 2008 The Android Open Source Project 3895401859313187f15a800e62d43e6bcbf48fadaJP Abgrall * 4895401859313187f15a800e62d43e6bcbf48fadaJP Abgrall * Licensed under the Apache License, Version 2.0 (the "License"); 5895401859313187f15a800e62d43e6bcbf48fadaJP Abgrall * you may not use this file except in compliance with the License. 6895401859313187f15a800e62d43e6bcbf48fadaJP Abgrall * You may obtain a copy of the License at 7895401859313187f15a800e62d43e6bcbf48fadaJP Abgrall * 8895401859313187f15a800e62d43e6bcbf48fadaJP Abgrall * http://www.apache.org/licenses/LICENSE-2.0 9895401859313187f15a800e62d43e6bcbf48fadaJP Abgrall * 10895401859313187f15a800e62d43e6bcbf48fadaJP Abgrall * Unless required by applicable law or agreed to in writing, software 11895401859313187f15a800e62d43e6bcbf48fadaJP Abgrall * distributed under the License is distributed on an "AS IS" BASIS, 12895401859313187f15a800e62d43e6bcbf48fadaJP Abgrall * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13895401859313187f15a800e62d43e6bcbf48fadaJP Abgrall * See the License for the specific language governing permissions and 14895401859313187f15a800e62d43e6bcbf48fadaJP Abgrall * limitations under the License. 15895401859313187f15a800e62d43e6bcbf48fadaJP Abgrall */ 1642331858975144405f95243be8427084ee7d478dJean-Baptiste Queru 1742331858975144405f95243be8427084ee7d478dJean-Baptiste Queru#ifndef ANDROID_SENSOR_BASE_H 1842331858975144405f95243be8427084ee7d478dJean-Baptiste Queru#define ANDROID_SENSOR_BASE_H 1942331858975144405f95243be8427084ee7d478dJean-Baptiste Queru 2042331858975144405f95243be8427084ee7d478dJean-Baptiste Queru#include <stdint.h> 2142331858975144405f95243be8427084ee7d478dJean-Baptiste Queru#include <errno.h> 2242331858975144405f95243be8427084ee7d478dJean-Baptiste Queru#include <sys/cdefs.h> 2342331858975144405f95243be8427084ee7d478dJean-Baptiste Queru#include <sys/types.h> 2442331858975144405f95243be8427084ee7d478dJean-Baptiste Queru 2542331858975144405f95243be8427084ee7d478dJean-Baptiste Queru 2642331858975144405f95243be8427084ee7d478dJean-Baptiste Queru/*****************************************************************************/ 2742331858975144405f95243be8427084ee7d478dJean-Baptiste Queru 2842331858975144405f95243be8427084ee7d478dJean-Baptiste Querustruct sensors_event_t; 2942331858975144405f95243be8427084ee7d478dJean-Baptiste Queru 3042331858975144405f95243be8427084ee7d478dJean-Baptiste Queruclass SensorBase { 3142331858975144405f95243be8427084ee7d478dJean-Baptiste Queruprotected: 32895401859313187f15a800e62d43e6bcbf48fadaJP Abgrall const char* dev_name; 33895401859313187f15a800e62d43e6bcbf48fadaJP Abgrall const char* data_name; 34895401859313187f15a800e62d43e6bcbf48fadaJP Abgrall char input_name[PATH_MAX]; 35895401859313187f15a800e62d43e6bcbf48fadaJP Abgrall int dev_fd; 36895401859313187f15a800e62d43e6bcbf48fadaJP Abgrall int data_fd; 3742331858975144405f95243be8427084ee7d478dJean-Baptiste Queru 3842331858975144405f95243be8427084ee7d478dJean-Baptiste Queru int openInput(const char* inputName); 3942331858975144405f95243be8427084ee7d478dJean-Baptiste Queru static int64_t getTimestamp(); 40895401859313187f15a800e62d43e6bcbf48fadaJP Abgrall 41895401859313187f15a800e62d43e6bcbf48fadaJP Abgrall 4242331858975144405f95243be8427084ee7d478dJean-Baptiste Queru static int64_t timevalToNano(timeval const& t) { 43895401859313187f15a800e62d43e6bcbf48fadaJP Abgrall return t.tv_sec*1000000000LL + t.tv_usec*1000; 4442331858975144405f95243be8427084ee7d478dJean-Baptiste Queru } 4542331858975144405f95243be8427084ee7d478dJean-Baptiste Queru 4642331858975144405f95243be8427084ee7d478dJean-Baptiste Queru int open_device(); 4742331858975144405f95243be8427084ee7d478dJean-Baptiste Queru int close_device(); 4842331858975144405f95243be8427084ee7d478dJean-Baptiste Queru 4942331858975144405f95243be8427084ee7d478dJean-Baptiste Querupublic: 50895401859313187f15a800e62d43e6bcbf48fadaJP Abgrall SensorBase( 51895401859313187f15a800e62d43e6bcbf48fadaJP Abgrall const char* dev_name, 52895401859313187f15a800e62d43e6bcbf48fadaJP Abgrall const char* data_name); 5342331858975144405f95243be8427084ee7d478dJean-Baptiste Queru 5442331858975144405f95243be8427084ee7d478dJean-Baptiste Queru virtual ~SensorBase(); 5542331858975144405f95243be8427084ee7d478dJean-Baptiste Queru 5642331858975144405f95243be8427084ee7d478dJean-Baptiste Queru virtual int readEvents(sensors_event_t* data, int count) = 0; 5742331858975144405f95243be8427084ee7d478dJean-Baptiste Queru virtual bool hasPendingEvents() const; 5842331858975144405f95243be8427084ee7d478dJean-Baptiste Queru virtual int getFd() const; 5942331858975144405f95243be8427084ee7d478dJean-Baptiste Queru virtual int setDelay(int32_t handle, int64_t ns); 60895401859313187f15a800e62d43e6bcbf48fadaJP Abgrall virtual int enable(int32_t handle, int enabled) = 0; 6142331858975144405f95243be8427084ee7d478dJean-Baptiste Queru}; 6242331858975144405f95243be8427084ee7d478dJean-Baptiste Queru 6342331858975144405f95243be8427084ee7d478dJean-Baptiste Queru/*****************************************************************************/ 6442331858975144405f95243be8427084ee7d478dJean-Baptiste Queru 6542331858975144405f95243be8427084ee7d478dJean-Baptiste Queru#endif // ANDROID_SENSOR_BASE_H 66