4 * Copyright (c) 2014 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.
24 #include <sensor_internal.h>
28 static GMainLoop *mainloop;
30 void callback(unsigned int event_type, sensor_event_data_t *event, void *user_data)
32 sensor_data_t *data = (sensor_data_t *)event->event_data;
33 printf("Linear Acceleration [%lld] [%6.6f] [%6.6f] [%6.6f]\n\n", data->timestamp, data->values[0], data->values[1], data->values[2]);
38 printf("Usage : ./linear_acceleration <event> <interval>(optional)\n\n");
40 printf("RAW_DATA_REPORT_ON_TIME\n\n");
41 printf("interval:\n");
42 printf("The time interval should be entered based on the sampling "
43 "frequencies supported by accelerometer, gyroscope and "
44 "geomagnetic sensors driver on the device in ms. If no value "
45 "for linear acceleration sensor is entered, a default value will be used.\n");
48 int main(int argc,char **argv)
50 int result, handle, start_handle, stop_handle;
53 mainloop = g_main_loop_new(NULL, FALSE);
54 sensor_type_t type = LINEAR_ACCEL_SENSOR;
55 event_condition_t *event_condition = (event_condition_t*) malloc(sizeof(event_condition_t));
56 event_condition->cond_op = CONDITION_EQUAL;
57 event_condition->cond_value1 = 100;
59 if (argc != 2 && argc != 3) {
61 free(event_condition);
65 if (strcmp(argv[1], "RAW_DATA_REPORT_ON_TIME") == 0)
66 event = LINEAR_ACCEL_EVENT_RAW_DATA_REPORT_ON_TIME;
69 free(event_condition);
74 event_condition->cond_value1 = atof(argv[2]);
77 handle = sf_connect(type);
78 result = sf_register_event(handle, event, event_condition, callback, NULL);
81 printf("Can't register linear acceleration virtual sensor\n");
83 start_handle = sf_start(handle, 0);
85 if (start_handle < 0) {
86 printf("Error\n\n\n\n");
87 sf_unregister_event(handle, event);
88 sf_disconnect(handle);
89 free(event_condition);
93 g_main_loop_run(mainloop);
94 g_main_loop_unref(mainloop);
96 sf_unregister_event(handle, event);
98 stop_handle = sf_stop(handle);
100 if (stop_handle < 0) {
102 free(event_condition);
106 sf_disconnect(handle);
108 free(event_condition);