1 /* 2 * Copyright (C) 2016 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 #ifndef HARDWARE_INTERFACES_SENSORS_V1_0_DEFAULT_SENSORS_H_ 18 19 #define HARDWARE_INTERFACES_SENSORS_V1_0_DEFAULT_SENSORS_H_ 20 21 #include <android-base/macros.h> 22 #include <android/hardware/sensors/1.0/ISensors.h> 23 #include <hardware/sensors.h> 24 #include <mutex> 25 26 namespace android { 27 namespace hardware { 28 namespace sensors { 29 namespace V1_0 { 30 namespace implementation { 31 32 33 struct Sensors : public ::android::hardware::sensors::V1_0::ISensors { 34 Sensors(); 35 36 status_t initCheck() const; 37 38 Return<void> getSensorsList(getSensorsList_cb _hidl_cb) override; 39 40 Return<Result> setOperationMode(OperationMode mode) override; 41 42 Return<Result> activate( 43 int32_t sensor_handle, bool enabled) override; 44 45 Return<void> poll(int32_t maxCount, poll_cb _hidl_cb) override; 46 47 Return<Result> batch( 48 int32_t sensor_handle, 49 int64_t sampling_period_ns, 50 int64_t max_report_latency_ns) override; 51 52 Return<Result> flush(int32_t sensor_handle) override; 53 54 Return<Result> injectSensorData(const Event& event) override; 55 56 Return<void> registerDirectChannel( 57 const SharedMemInfo& mem, registerDirectChannel_cb _hidl_cb) override; 58 59 Return<Result> unregisterDirectChannel(int32_t channelHandle) override; 60 61 Return<void> configDirectReport( 62 int32_t sensorHandle, int32_t channelHandle, RateLevel rate, 63 configDirectReport_cb _hidl_cb) override; 64 65 private: 66 static constexpr int32_t kPollMaxBufferSize = 128; 67 status_t mInitCheck; 68 sensors_module_t *mSensorModule; 69 sensors_poll_device_1_t *mSensorDevice; 70 std::mutex mPollLock; 71 72 int getHalDeviceVersion() const; 73 74 static void convertFromSensorEvents( 75 size_t count, const sensors_event_t *src, hidl_vec<Event> *dst); 76 77 DISALLOW_COPY_AND_ASSIGN(Sensors); 78 }; 79 80 extern "C" ISensors *HIDL_FETCH_ISensors(const char *name); 81 82 } // namespace implementation 83 } // namespace V1_0 84 } // namespace sensors 85 } // namespace hardware 86 } // namespace android 87 88 #endif // HARDWARE_INTERFACES_SENSORS_V1_0_DEFAULT_SENSORS_H_ 89