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.
23 #include <sensor_internal.h>
27 static GMainLoop *mainloop;
29 void callback(unsigned int event_type, sensor_event_data_t *event, void *user_data)
31 sensor_data_t *data = (sensor_data_t *)event->event_data;
32 printf("Accelerometer [%lld] [%6.6f] [%6.6f] [%6.6f]\n\n", data->timestamp, data->values[0], data->values[1], data->values[2]);
37 printf("Usage : ./accelerometer <event> <interval>(optional)\n\n");
40 printf("RAW_DATA_REPORT_ON_TIME\n");
42 printf("interval:\n");
43 printf("The time interval should be entered based on the sampling frequency supported by accelerometer driver on the device in ms.If no value for sensor is entered default value by the driver will be used.\n");
46 int main(int argc,char **argv)
48 int result, handle, start_handle, stop_handle;
51 mainloop = g_main_loop_new(NULL, FALSE);
52 sensor_type_t type = ACCELEROMETER_SENSOR;
53 event_condition_t *event_condition = (event_condition_t*) malloc(sizeof(event_condition_t));
54 event_condition->cond_op = CONDITION_EQUAL;
55 event_condition->cond_value1 = 100;
57 if (argc != 2 && argc != 3) {
59 free(event_condition);
63 if (strcmp(argv[1], "RAW_DATA_REPORT_ON_TIME") == 0) {
64 event = ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME;
69 free(event_condition);
73 event_condition->cond_value1 = atof(argv[2]);
75 handle = sf_connect(type);
76 result = sf_register_event(handle, event, event_condition, callback, NULL);
79 printf("Can't register accelerometer\n");
81 start_handle = sf_start(handle,0);
83 if (start_handle < 0) {
84 printf("Error\n\n\n\n");
85 sf_unregister_event(handle, event);
86 sf_disconnect(handle);
90 g_main_loop_run(mainloop);
91 g_main_loop_unref(mainloop);
93 sf_unregister_event(handle, event);
95 stop_handle = sf_stop(handle);
97 if (stop_handle < 0) {
102 sf_disconnect(handle);
104 free(event_condition);