Merge branch 'tizen' into tizen_4.0
[platform/core/system/sensord.git] / src / sensorctl / sensor_manager.cpp
1 /*
2  * sensorctl
3  *
4  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #include "sensor_manager.h"
21
22 #include <stdlib.h>
23 #include <string.h>
24
25 #include "log.h"
26 #include "util.h"
27 #include "macro.h"
28
29 struct sensor_info {
30         sensor_type_t type;
31         char name[NAME_MAX_TEST];
32 };
33
34 static struct sensor_info sensor_infos[] = {
35         {ALL_SENSOR,                                    "all"},
36
37         // General Sensors
38         {ACCELEROMETER_SENSOR,                  "accelerometer"},
39         {GRAVITY_SENSOR,                                "gravity"},
40         {LINEAR_ACCEL_SENSOR,                   "linear_accel"},
41         {GEOMAGNETIC_SENSOR,                    "magnetic"},
42         {ROTATION_VECTOR_SENSOR,                "rotation_vector"},
43         {ORIENTATION_SENSOR,                    "orientation"},
44         {GYROSCOPE_SENSOR,                              "gyroscope"},
45         {LIGHT_SENSOR,                                  "light"},
46         {PROXIMITY_SENSOR,                              "proximity"},
47         {PRESSURE_SENSOR,                               "pressure"},
48         {ULTRAVIOLET_SENSOR,                    "uv"},
49         {TEMPERATURE_SENSOR,                    "temperature"},
50         {HUMIDITY_SENSOR,                               "humidity"},
51         {HRM_SENSOR,                                    "hrm"},
52         {HRM_RAW_SENSOR,                                "hrm_raw"},
53         {HRM_LED_GREEN_SENSOR,                  "hrm_led_green"},
54         {HRM_LED_IR_SENSOR,                             "hrm_led_ir"},
55         {HRM_LED_RED_SENSOR,                    "hrm_led_red"},
56         {GYROSCOPE_UNCAL_SENSOR,                "gyro_uncal"},
57         {GEOMAGNETIC_UNCAL_SENSOR,              "mag_uncal"},
58         {GYROSCOPE_RV_SENSOR,                   "gyro_rv"},
59         {GEOMAGNETIC_RV_SENSOR,                 "mag_rv"},
60
61         {HUMAN_PEDOMETER_SENSOR,                "pedo"},
62         {HUMAN_SLEEP_MONITOR_SENSOR,    "sleep_monitor"},
63
64         {AUTO_ROTATION_SENSOR,                  "rotation"},
65         //{AUTO_BRIGHTENESS_SENSOR,             "auto_brighteness"},
66         {MOTION_SENSOR,                                 "motion"},
67         {CONTEXT_SENSOR,                                "context"},
68
69         {GESTURE_MOVEMENT_SENSOR,               "movement"},
70         {GESTURE_WRIST_UP_SENSOR,               "wristup"},
71         {GESTURE_WRIST_DOWN_SENSOR,             "wristdown"},
72         {GESTURE_MOVEMENT_STATE_SENSOR, "movement_state"},
73
74         {WEAR_STATUS_SENSOR,                    "wear_status"},
75         {WEAR_ON_MONITOR_SENSOR,                "wear_on"},
76         {GPS_BATCH_SENSOR,                              "gps"},
77         {ACTIVITY_TRACKER_SENSOR,               "activity"},
78         {SLEEP_DETECTOR_SENSOR,                 "sleep_detector"},
79 };
80
81 sensor_manager::~sensor_manager()
82 {
83 }
84
85 bool sensor_manager::run(int argc, char *argv[])
86 {
87         return true;
88 }
89
90 void sensor_manager::stop(void)
91 {
92 }
93
94 sensor_type_t sensor_manager::get_sensor_type(const char *name)
95 {
96         int index;
97         int count;
98
99         if (util::is_hex(name))
100                 return (sensor_type_t) (strtol(name, NULL, 16));
101
102         if (util::is_number(name))
103                 return (sensor_type_t) (atoi(name));
104
105         count = ARRAY_SIZE(sensor_infos);
106
107         for (index = 0; index < count; ++index) {
108                 if (!strcmp(sensor_infos[index].name, name))
109                         break;
110         }
111
112         if (index == count) {
113                 _E("Invaild sensor name\n");
114                 usage_sensors();
115                 return UNKNOWN_SENSOR;
116         }
117         return sensor_infos[index].type;
118 }
119
120 void sensor_manager::usage_sensors(void)
121 {
122         _N("The sensor types are:\n");
123         int sensor_count = ARRAY_SIZE(sensor_infos);
124
125         for (int i = 0; i < sensor_count; ++i)
126                 _N("%3d: %s(%#x)\n", i, sensor_infos[i].name, sensor_infos[i].type);
127         _N("\n");
128 }