4 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 #include <sensorctl_log.h>
24 #include "sensor_manager.h"
26 #define NAME_MAX_TEST 32
30 char name[NAME_MAX_TEST];
31 /* if manual is true, the way of injecting fake event will be created */
35 static struct sensor_info sensor_infos[] = {
36 {ALL_SENSOR, "all", false},
39 {ACCELEROMETER_SENSOR, "accelerometer", false},
40 {GRAVITY_SENSOR, "gravity", false},
41 {LINEAR_ACCEL_SENSOR, "linear_accel", false},
42 {GEOMAGNETIC_SENSOR, "magnetic", false},
43 {ROTATION_VECTOR_SENSOR, "rotation_vector", false},
44 {ORIENTATION_SENSOR, "orientation", false},
45 {GYROSCOPE_SENSOR, "gyroscope", false},
46 {LIGHT_SENSOR, "light", false},
47 {PROXIMITY_SENSOR, "proximity", true},
48 {PRESSURE_SENSOR, "pressure", false},
49 {ULTRAVIOLET_SENSOR, "ultraviolet", false},
50 {TEMPERATURE_SENSOR, "temperature", false},
51 {HUMIDITY_SENSOR, "humidity", false},
52 {HRM_RAW_SENSOR, "hrm_raw", false},
53 {HRM_SENSOR, "hrm", false},
54 {HRM_LED_GREEN_SENSOR, "hrm_led_green", false},
55 {HRM_LED_IR_SENSOR, "hrm_led_ir", false},
56 {HRM_LED_RED_SENSOR, "hrm_led_red", false},
57 {GYROSCOPE_UNCAL_SENSOR, "gyro_uncal", false},
58 {GEOMAGNETIC_UNCAL_SENSOR, "mag_uncal", false},
59 {GYROSCOPE_RV_SENSOR, "gyro_rv", false},
60 {GEOMAGNETIC_RV_SENSOR, "mag_rv", false},
62 {HUMAN_PEDOMETER_SENSOR, "pedo", true},
63 {HUMAN_SLEEP_MONITOR_SENSOR,"sleep_monitor", true},
66 {AUTO_ROTATION_SENSOR, "auto_rotation", true},
67 {AUTO_BRIGHTNESS_SENSOR, "auto_brightness", true},
68 {MOTION_SENSOR, "motion", true},
69 {PIR_SENSOR, "pir", true},
70 {PIR_LONG_SENSOR, "pir_long", true},
71 {DUST_SENSOR, "dust", false},
72 {THERMOMETER_SENSOR, "thermometer", false},
73 {FLAT_SENSOR, "flat", true},
74 {TILT_SENSOR, "tilt", false},
75 {RV_RAW_SENSOR, "rv_raw", false},
76 {EXERCISE_SENSOR, "exercise", false},
77 {GSR_SENSOR, "gsr", false},
78 {SIMSENSE_SENSOR, "simsense", false},
79 {PPG_SENSOR, "ppg", false},
81 {GESTURE_MOVEMENT_SENSOR, "movement", true},
82 {GESTURE_WRIST_UP_SENSOR, "wristup", true},
83 {GESTURE_WRIST_DOWN_SENSOR, "wristdown", true},
84 {GESTURE_MOVEMENT_STATE_SENSOR, "movement_state",true},
86 {WEAR_STATUS_SENSOR, "wear_status", true},
87 {WEAR_ON_MONITOR_SENSOR, "wear_on", true},
88 {GPS_BATCH_SENSOR, "gps_batch", true},
89 {ACTIVITY_TRACKER_SENSOR, "activity_tracker", true},
90 {SLEEP_DETECTOR_SENSOR, "sleep_detector", true},
91 {NO_MOVE_DETECTOR_SENSOR, "no_move", true},
92 {HRM_CTRL_SENSOR, "hrm_ctrl", true},
93 {EXERCISE_COACH_SENSOR, "ex_coach", true},
94 {EXERCISE_HR_SENSOR, "ex_hr", true},
95 {RESTING_HR_SENSOR, "resting_hr", true},
96 {STEP_LEVEL_MONITOR_SENSOR, "step_level", true},
97 {ACTIVITY_LEVEL_MONITOR_SENSOR, "activity", true},
98 {CYCLE_MONITOR_SENSOR, "cycle", true},
99 {STRESS_MONITOR_SENSOR, "stress", true},
100 {AUTOSESSION_EXERCISE_SENSOR,"autosesstion", true},
101 {STAIR_TRACKER_SENSOR, "stair_tracker", true}
106 bool sensor_manager::process(int argc, char *argv[])
111 void sensor_manager::usage_sensors(void)
113 PRINT("The sensor types are:\n");
114 int sensor_count = ARRAY_SIZE(sensor_infos);
116 for (int i = 0; i < sensor_count; ++i)
117 PRINT(" %d: %s(%d)\n", i, sensor_infos[i].name, sensor_infos[i].type);
121 sensor_type_t sensor_manager::get_sensor_type(char *name)
124 int sensor_count = ARRAY_SIZE(sensor_infos);
127 return (sensor_type_t) (atoi(name));
129 for (index = 0; index < sensor_count; ++index) {
130 if (!strcmp(sensor_infos[index].name, name))
134 if (index == sensor_count) {
135 _E("ERROR: sensor name is wrong\n");
137 return UNKNOWN_SENSOR;
139 return sensor_infos[index].type;
142 const char *sensor_manager::get_sensor_name(sensor_type_t type)
145 int sensor_count = ARRAY_SIZE(sensor_infos);
147 for (index = 0; index < sensor_count; ++index) {
148 if (sensor_infos[index].type == type)
152 if (index == sensor_count) {
153 _E("ERROR: sensor name is wrong\n");
155 return "UNKNOWN SENSOR";
157 return sensor_infos[index].name;
160 bool sensor_manager::is_number(char *value)
162 if (value == NULL || *value == 0)
166 if (*value < '0' || *value > '9')