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>
25 #include <sensor_common.h>
29 static GMainLoop *mainloop;
31 void callback(unsigned int event_type, sensor_event_data_t *event, void *user_data)
33 sensor_data_t *data = (sensor_data_t *)event->event_data;
34 printf("Gyroscope [%lld] [%6.6f] [%6.6f] [%6.6f]\n\n", data->timestamp, data->values[0], data->values[1], data->values[2]);
39 printf("Usage : ./gyro <mode>(optional) <event> <interval>(optional)\n\n");
43 printf("p is for polling based,default mode is event driven\n");
46 printf("[RAW_DATA_REPORT_ON_TIME]\n");
48 printf("interval:\n");
49 printf("The time interval should be entered based on the sampling frequency supported by gyroscope driver on the device in ms.If no value for sensor is entered default value by the driver will be used.\n");
52 int main(int argc,char **argv)
54 int result, handle, start_handle, stop_handle;
56 mainloop = g_main_loop_new(NULL, FALSE);
57 event = GYROSCOPE_EVENT_RAW_DATA_REPORT_ON_TIME;
58 event_condition_t *event_condition = (event_condition_t*) malloc(sizeof(event_condition_t));
59 event_condition->cond_op = CONDITION_EQUAL;
61 sensor_type_t type = GYROSCOPE_SENSOR;
63 if (argc != 2 && argc != 3 && argc!=4) {
65 free(event_condition);
69 else if (argc>=3 && strcmp(argv[1], "-p") == 0 && strcmp(argv[2], "RAW_DATA_REPORT_ON_TIME") == 0) {
70 printf("Polling based\n");
72 handle = sf_connect(type);
73 result = sf_start(handle, 1);
76 printf("Can't start gyroscope SENSOR\n");
77 printf("Error\n\n\n\n");
78 free(event_condition);
85 result = sf_get_data(handle, GYRO_BASE_DATA_SET , &data);
86 printf("Gyroscope [%lld] [%6.6f] [%6.6f] [%6.6f]\n\n", data.timestamp, data.values[0], data.values[1], data.values[2]);
90 result = sf_disconnect(handle);
93 printf("Can't disconnect gyroscope sensor\n");
94 printf("Error\n\n\n\n");
95 free(event_condition);
100 else if (strcmp(argv[1], "RAW_DATA_REPORT_ON_TIME") == 0) {
101 printf("Event based\n");
103 event_condition->cond_value1 = 10.52;
105 event_condition->cond_value1 = atof(argv[2]);
107 handle = sf_connect(type);
108 result = sf_register_event(handle, event, event_condition, callback, NULL);
111 printf("Can't register gyroscope\n");
113 start_handle = sf_start(handle,0);
115 if (start_handle < 0) {
116 printf("Error\n\n\n\n");
117 sf_unregister_event(handle, event);
118 sf_disconnect(handle);
119 free(event_condition);
123 g_main_loop_run(mainloop);
124 g_main_loop_unref(mainloop);
126 sf_unregister_event(handle, event);
128 stop_handle = sf_stop(handle);
130 if (stop_handle < 0) {
132 free(event_condition);
136 sf_disconnect(handle);
137 free(event_condition);