Updating test file for gyroscope sensor 11/28711/3
authorVibhor Gaur <vibhor.gaur@samsung.com>
Tue, 14 Oct 2014 12:08:35 +0000 (17:38 +0530)
committerVibhor Gaur <vibhor.gaur@samsung.com>
Wed, 15 Oct 2014 13:28:26 +0000 (18:58 +0530)
-Updating error check conditions for start and stop handle.
-Removing redundant bool error_state variable.
-Removing redundant else condition after parameter count check.
-Removing redundant if condition assosciated with error_state.
-Updating print logs in callback by printing timestamp before other values.
-Fixing ./gyroscope to ./gyro n printformat as file name is gyro.c

Change-Id: Ia64d8dbee24f6fc85e54ec333fb6ff9067564156

test/src/gyro.c

index eaf136d..1b509b8 100644 (file)
@@ -29,12 +29,12 @@ static GMainLoop *mainloop;
 void callback(unsigned int event_type, sensor_event_data_t *event, void *user_data)
 {
        sensor_data_t *data = (sensor_data_t *)event->event_data;
-       printf("Gyroscope [%6.6f] [%6.6f] [%6.6f] [%lld]\n\n", data->values[0], data->values[1], data->values[2], data->timestamp);
+       printf("Gyroscope [%lld] [%6.6f] [%6.6f] [%6.6f] \n\n", data->timestamp, data->values[0], data->values[1], data->values[2]);
 }
 
 void printformat()
 {
-       printf("Usage : ./gyroscope <event> <interval>(optional)\n\n");
+       printf("Usage : ./gyro <event> <interval>(optional)\n\n");
        printf("event:\n");
        printf("RAW_DATA_REPORT_ON_TIME\n");
        printf("interval:\n");
@@ -43,9 +43,8 @@ void printformat()
 
 int main(int argc,char **argv)
 {
-       int result, handle;
+       int result, handle, start_handle, stop_handle;
        unsigned int event;
-       bool error_state = FALSE;
 
        mainloop = g_main_loop_new(NULL, FALSE);
        sensor_type_t type = GYROSCOPE_SENSOR;
@@ -55,7 +54,8 @@ int main(int argc,char **argv)
 
        if (argc != 2 && argc != 3) {
                printformat();
-               error_state = TRUE;
+               free(event_condition);
+               return 0;
        }
        else {
                 if (strcmp(argv[1], "RAW_DATA_REPORT_ON_TIME") == 0)
@@ -63,41 +63,42 @@ int main(int argc,char **argv)
 
                 else {
                        printformat();
-                       error_state = TRUE;
+                       free(event_condition);
+                       return 0;
                }
 
                if(argc == 3)
                        event_condition->cond_value1 = atof(argv[2]);
        }
 
-       if (!error_state) {
-               handle = sf_connect(type);
-               result = sf_register_event(handle, event, event_condition, callback, NULL);
+       handle = sf_connect(type);
+       result = sf_register_event(handle, event, event_condition, callback, NULL);
 
-               if (result < 0)
-                       printf("Can't register gyroscope\n");
+       if (result < 0)
+               printf("Can't register gyroscope\n");
 
-               if (!(sf_start(handle,0) < 0)) {
-                       printf("Success start \n");
-               }
-               else {
-                       printf("Error\n\n\n\n");
-                       sf_unregister_event(handle, event);
-                       sf_disconnect(handle);
-                       return -1;
-               }
-
-               g_main_loop_run(mainloop);
-               g_main_loop_unref(mainloop);
+       start_handle = sf_start(handle, 0);
 
+       if (start_handle < 0) {
+               printf("Error\n\n\n\n");
                sf_unregister_event(handle, event);
+               sf_disconnect(handle);
+               return -1;
+       }
 
-               if (!(sf_stop(handle) < 0))
-                       printf("Success stop \n");
+       g_main_loop_run(mainloop);
+       g_main_loop_unref(mainloop);
 
-               sf_disconnect(handle);
+       sf_unregister_event(handle, event);
+       stop_handle = sf_stop(handle);
+
+       if (stop_handle < 0) {
+               printf("Error\n\n");
+               return -1;
        }
 
+       sf_disconnect(handle);
+
        free(event_condition);
 
        return 0;