Updating test file for linear acceleration sensor 40/28740/4
authorVibhor Gaur <vibhor.gaur@samsung.com>
Wed, 15 Oct 2014 08:50:22 +0000 (14:20 +0530)
committerVibhor Gaur <vibhor.gaur@samsung.com>
Wed, 15 Oct 2014 13:47:00 +0000 (06:47 -0700)
-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.

Change-Id: I04151938310d11f2ce5b5a506ffb71180d2967b8

test/src/linear_acceleration.c

index 4ced5d8..ed36928 100755 (executable)
@@ -30,7 +30,7 @@ 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("Linear Acceleration [%6.6f] [%6.6f] [%6.6f] [%lld]\n\n", data->values[0], data->values[1], data->values[2], data->timestamp);
+       printf("Linear Acceleration [%lld] [%6.6f] [%6.6f] [%6.6f]\n\n", data->timestamp, data->values[0], data->values[1], data->values[2]);
 }
 
 void printformat()
@@ -47,8 +47,7 @@ void printformat()
 
 int main(int argc,char **argv)
 {
-       int result, handle;
-       bool error_state = FALSE;
+       int result, handle, start_handle, stop_handle;
        unsigned int event;
 
        mainloop = g_main_loop_new(NULL, FALSE);
@@ -59,48 +58,49 @@ 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)
                        event = LINEAR_ACCEL_EVENT_RAW_DATA_REPORT_ON_TIME;
                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 linear acceleration virtual sensor\n");
+       if (result < 0)
+               printf("Can't register linear acceleration virtual sensor\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);
+
+       if (stop_handle < 0) {
+               printf("Error\n\n");
+               return -1;
        }
 
+       sf_disconnect(handle);
+
        free(event_condition);
 
        return 0;