• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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/sensor_type.h"
18 
19 #include "chre/platform/assert.h"
20 
21 namespace chre {
22 
getSensorModeName(SensorMode sensorMode)23 const char *getSensorModeName(SensorMode sensorMode) {
24   switch (sensorMode) {
25     case SensorMode::Off:
26       return "Off";
27     case SensorMode::ActiveOneShot:
28       return "ActiveOneShot";
29     case SensorMode::PassiveOneShot:
30       return "PassiveOneShot";
31     case SensorMode::ActiveContinuous:
32       return "ActiveContinuous";
33     case SensorMode::PassiveContinuous:
34       return "PassiveContinuous";
35     default:
36       CHRE_ASSERT(false);
37       return "";
38   }
39 }
40 
getSensorModeFromEnum(enum chreSensorConfigureMode enumSensorMode)41 SensorMode getSensorModeFromEnum(enum chreSensorConfigureMode enumSensorMode) {
42   switch (enumSensorMode) {
43     case CHRE_SENSOR_CONFIGURE_MODE_DONE:
44       return SensorMode::Off;
45     case CHRE_SENSOR_CONFIGURE_MODE_CONTINUOUS:
46       return SensorMode::ActiveContinuous;
47     case CHRE_SENSOR_CONFIGURE_MODE_ONE_SHOT:
48       return SensorMode::ActiveOneShot;
49     case CHRE_SENSOR_CONFIGURE_MODE_PASSIVE_CONTINUOUS:
50       return SensorMode::PassiveContinuous;
51     case CHRE_SENSOR_CONFIGURE_MODE_PASSIVE_ONE_SHOT:
52       return SensorMode::PassiveOneShot;
53     default:
54       // Default to off since it is the least harmful and has no power impact.
55       return SensorMode::Off;
56   }
57 }
58 
getConfigureModeFromSensorMode(enum SensorMode enumSensorMode)59 chreSensorConfigureMode getConfigureModeFromSensorMode(
60     enum SensorMode enumSensorMode) {
61   switch (enumSensorMode) {
62     case SensorMode::Off:
63       return CHRE_SENSOR_CONFIGURE_MODE_DONE;
64     case SensorMode::ActiveContinuous:
65       return CHRE_SENSOR_CONFIGURE_MODE_CONTINUOUS;
66     case SensorMode::ActiveOneShot:
67       return CHRE_SENSOR_CONFIGURE_MODE_ONE_SHOT;
68     case SensorMode::PassiveContinuous:
69       return CHRE_SENSOR_CONFIGURE_MODE_PASSIVE_CONTINUOUS;
70     case SensorMode::PassiveOneShot:
71       return CHRE_SENSOR_CONFIGURE_MODE_PASSIVE_ONE_SHOT;
72     default:
73       // Default to off since it is the least harmful and has no power impact.
74       return CHRE_SENSOR_CONFIGURE_MODE_DONE;
75   }
76 }
77 
78 }  // namespace chre
79