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 #include "chre/core/event_loop_manager.h"
18 #include "chre/core/sensor_request.h"
19 #include "chre/util/time.h"
20 #include "chre/util/macros.h"
21 #include "chre_api/chre/sensor.h"
22
23 using chre::EventLoopManager;
24 using chre::EventLoopManagerSingleton;
25 using chre::Nanoseconds;
26 using chre::SensorMode;
27 using chre::SensorRequest;
28 using chre::SensorType;
29
30 using chre::getSensorModeFromEnum;
31 using chre::getSensorTypeFromUnsignedInt;
32
chreSensorFindDefault(uint8_t sensorType,uint32_t * handle)33 DLL_EXPORT bool chreSensorFindDefault(uint8_t sensorType, uint32_t *handle) {
34 SensorType validatedSensorType = getSensorTypeFromUnsignedInt(sensorType);
35 return (validatedSensorType != SensorType::Unknown
36 && EventLoopManagerSingleton::get()->getSensorRequestManager()
37 .getSensorHandle(validatedSensorType, handle));
38 }
39
chreGetSensorInfo(uint32_t sensorHandle,struct chreSensorInfo * info)40 DLL_EXPORT bool chreGetSensorInfo(uint32_t sensorHandle,
41 struct chreSensorInfo *info) {
42 CHRE_ASSERT(info);
43
44 chre::Nanoapp *nanoapp = EventLoopManager::validateChreApiCall(__func__);
45
46 bool success = false;
47 if (info != nullptr) {
48 success = EventLoopManagerSingleton::get()->getSensorRequestManager().
49 getSensorInfo(sensorHandle, *nanoapp, info);
50 }
51 return success;
52 }
53
chreGetSensorSamplingStatus(uint32_t sensorHandle,struct chreSensorSamplingStatus * status)54 DLL_EXPORT bool chreGetSensorSamplingStatus(
55 uint32_t sensorHandle, struct chreSensorSamplingStatus *status) {
56 CHRE_ASSERT(status);
57
58 bool success = false;
59 if (status != nullptr) {
60 success = EventLoopManagerSingleton::get()->getSensorRequestManager().
61 getSensorSamplingStatus(sensorHandle, status);
62 }
63 return success;
64 }
65
chreSensorConfigure(uint32_t sensorHandle,enum chreSensorConfigureMode mode,uint64_t interval,uint64_t latency)66 DLL_EXPORT bool chreSensorConfigure(uint32_t sensorHandle,
67 enum chreSensorConfigureMode mode,
68 uint64_t interval, uint64_t latency) {
69 chre::Nanoapp *nanoapp = EventLoopManager::validateChreApiCall(__func__);
70 SensorMode sensorMode = getSensorModeFromEnum(mode);
71 SensorRequest sensorRequest(nanoapp, sensorMode, Nanoseconds(interval),
72 Nanoseconds(latency));
73 return EventLoopManagerSingleton::get()->getSensorRequestManager()
74 .setSensorRequest(nanoapp, sensorHandle, sensorRequest);
75 }
76