From: Vibhor Gaur Date: Mon, 22 Dec 2014 12:20:40 +0000 (+0530) Subject: Adding polling based support for testing pressure sensor X-Git-Tag: submit/tizen/20150113.012540~54 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a1ae1f819ee4830c3e565863b1fb4d75efdf3c7d;p=platform%2Fcore%2Fsystem%2Fsensord.git Adding polling based support for testing pressure sensor Change-Id: I843b060db3f28a76cbac33c7deebb701055e8681 --- diff --git a/test/src/pressure.c b/test/src/pressure.c index e3ed4b4..a92ad59 100644 --- a/test/src/pressure.c +++ b/test/src/pressure.c @@ -16,14 +16,14 @@ * limitations under the License. * */ - #include #include #include #include #include #include -#include +#include +#include static GMainLoop *mainloop; @@ -35,71 +35,106 @@ void callback(unsigned int event_type, sensor_event_data_t *event, void *user_da void printformat() { - printf("Usage : ./pressure (optional)\n\n"); - printf("event:\n"); - printf("RAW_DATA_REPORT_ON_TIME\n"); + printf("Usage : ./pressure (optional) (optional)\n\n"); + + printf("mode:"); + printf("[-p]\n"); + printf("p is for polling based,default mode is event driven\n"); + + printf("event:"); + printf("[RAW_DATA_REPORT_ON_TIME]\n"); + printf("interval:\n"); printf("The time interval should be entered based on the sampling frequency supported by pressure driver on the device in ms.If no value for sensor is entered default value by the driver will be used.\n"); } -int main(int argc, char **argv) +int main(int argc,char **argv) { int result, handle, start_handle, stop_handle; unsigned int event; - mainloop = g_main_loop_new(NULL, FALSE); - sensor_type_t type = PRESSURE_SENSOR; + event = PRESSURE_EVENT_RAW_DATA_REPORT_ON_TIME; event_condition_t *event_condition = (event_condition_t*) malloc(sizeof(event_condition_t)); event_condition->cond_op = CONDITION_EQUAL; - event_condition->cond_value1 = 100; - if (argc != 2 && argc != 3) { - printformat(); - free(event_condition); - return 0; - } + sensor_type_t type = PRESSURE_SENSOR; - if (strcmp(argv[1], "RAW_DATA_REPORT_ON_TIME") != 0) { + if (argc != 2 && argc != 3 && argc!=4) { printformat(); free(event_condition); return 0; } - event = PRESSURE_EVENT_RAW_DATA_REPORT_ON_TIME; + else if (argc>=3 && strcmp(argv[1], "-p") == 0 && strcmp(argv[2], "RAW_DATA_REPORT_ON_TIME") == 0) { + printf("Polling based\n"); - if (argc == 3) - event_condition->cond_value1 = atof(argv[2]); + handle = sf_connect(type); + result = sf_start(handle, 1); - handle = sf_connect(type); - result = sf_register_event(handle, event, event_condition, callback, NULL); + if (result < 0) { + printf("Can't start pressure SENSOR\n"); + printf("Error\n\n\n\n"); + return -1; + } - if (result < 0) - printf("Can't register pressure\n"); + sensor_data_t data; - start_handle = sf_start(handle,0); + while(1) { + result = sf_get_data(handle, PRESSURE_BASE_DATA_SET , &data); + printf("Pressure [%lld] [%6.6f] [%6.6f] [%6.6f]\n\n", data.timestamp, data.values[0], data.values[1], data.values[2]); + usleep(100000); + } - if (start_handle < 0) { - printf("Error\n\n\n\n"); - sf_unregister_event(handle, event); - sf_disconnect(handle); - return -1; + result = sf_disconnect(handle); + + if (result < 0) { + printf("Can't disconnect pressure sensor\n"); + printf("Error\n\n\n\n"); + return -1; + } } - g_main_loop_run(mainloop); - g_main_loop_unref(mainloop); + else if (strcmp(argv[1], "RAW_DATA_REPORT_ON_TIME") == 0) { + printf("Event based\n"); - sf_unregister_event(handle, event); + event_condition->cond_value1 = 10.52; + if (argc == 3) + event_condition->cond_value1 = atof(argv[2]); - stop_handle = sf_stop(handle); + handle = sf_connect(type); + result = sf_register_event(handle, event, event_condition, callback, NULL); - if (stop_handle < 0) { - printf("Error\n\n"); - return -1; - } + if (result < 0) + printf("Can't register pressure\n"); + + 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; + } + + g_main_loop_run(mainloop); + g_main_loop_unref(mainloop); + + sf_unregister_event(handle, event); - sf_disconnect(handle); + stop_handle = sf_stop(handle); - free(event_condition); + if (stop_handle < 0) { + printf("Error\n\n"); + return -1; + } + + sf_disconnect(handle); + free(event_condition); + } + + else { + printformat(); + } return 0; }