From 2f509abda1eba8cb2929b20b9a787e371b796d37 Mon Sep 17 00:00:00 2001 From: Vibhor Gaur Date: Tue, 23 Sep 2014 15:28:04 +0530 Subject: [PATCH] Adding test file for proximity sensor Adding test file for proximity sensor along with updated spec and cmake files. Change-Id: Iac16a6b09ae37e7d314c1092dd4411c7dfafbdab --- packaging/sensord.spec | 1 + test/CMakeLists.txt | 4 ++ test/src/proxi.c | 115 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 test/src/proxi.c diff --git a/packaging/sensord.spec b/packaging/sensord.spec index 49ee89f..f3b4b8a 100755 --- a/packaging/sensord.spec +++ b/packaging/sensord.spec @@ -142,6 +142,7 @@ systemctl daemon-reload /usr/bin/gravity /usr/bin/linear_acceleration /usr/bin/gyro +/usr/bin/proxi %license LICENSE.APLv2 %{_datadir}/license/test %endif diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 39a90ac..c016484 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -33,6 +33,7 @@ add_executable(orientation src/orientation.c) add_executable(gravity src/gravity.c) add_executable(linear_acceleration src/linear_acceleration.c) add_executable(gyro src/gyro.c) +add_executable(proxi src/proxi.c) SET_TARGET_PROPERTIES(accelerometer PROPERTIES LINKER_LANGUAGE C) SET_TARGET_PROPERTIES(geomagnetic PROPERTIES LINKER_LANGUAGE C) @@ -40,6 +41,7 @@ SET_TARGET_PROPERTIES(orientation PROPERTIES LINKER_LANGUAGE C) SET_TARGET_PROPERTIES(gravity PROPERTIES LINKER_LANGUAGE C) SET_TARGET_PROPERTIES(linear_acceleration PROPERTIES LINKER_LANGUAGE C) SET_TARGET_PROPERTIES(gyro PROPERTIES LINKER_LANGUAGE C) +SET_TARGET_PROPERTIES(proxi PROPERTIES LINKER_LANGUAGE C) target_link_libraries(accelerometer glib-2.0 dlog sensor) target_link_libraries(geomagnetic glib-2.0 dlog sensor) @@ -47,6 +49,7 @@ target_link_libraries(orientation glib-2.0 dlog sensor) target_link_libraries(gravity glib-2.0 dlog sensor) target_link_libraries(linear_acceleration glib-2.0 dlog sensor) target_link_libraries(gyro glib-2.0 dlog sensor) +target_link_libraries(proxi glib-2.0 dlog sensor) INSTALL(TARGETS accelerometer DESTINATION /usr/bin/) INSTALL(TARGETS geomagnetic DESTINATION /usr/bin/) @@ -54,5 +57,6 @@ INSTALL(TARGETS orientation DESTINATION /usr/bin/) INSTALL(TARGETS gravity DESTINATION /usr/bin/) INSTALL(TARGETS linear_acceleration DESTINATION /usr/bin/) INSTALL(TARGETS gyro DESTINATION /usr/bin/) +INSTALL(TARGETS proxi DESTINATION /usr/bin/) diff --git a/test/src/proxi.c b/test/src/proxi.c new file mode 100644 index 0000000..1bbd23d --- /dev/null +++ b/test/src/proxi.c @@ -0,0 +1,115 @@ +/* + * sensord + * + * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include +#include +#include + +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("Proximity [%lld] [%6.6f]\n\n", data->timestamp, data->values[0]); +} + +void printformat() +{ + printf("Usage : ./proxi (optional)\n\n"); + printf("event:\n"); + printf("EVENT_CHANGE_STATE\n"); + printf("EVENT_STATE_REPORT_ON_TIME\n"); + printf("EVENT_DISTANCE_DATA_REPORT_ON_TIME\n"); + printf("interval:\n"); + printf("The time interval should be entered based on the sampling frequency supported by proximity 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 result, handle, start_handle, stop_handle; + unsigned int event; + + mainloop = g_main_loop_new(NULL, FALSE); + sensor_type_t type = PROXIMITY_SENSOR; + 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; + } + + if (strcmp(argv[1], "EVENT_CHANGE_STATE") == 0) { + event = PROXIMITY_EVENT_CHANGE_STATE; + } + else if (strcmp(argv[1], "EVENT_STATE_REPORT_ON_TIME") == 0) { + event = PROXIMITY_EVENT_STATE_REPORT_ON_TIME; + } + else if (strcmp(argv[1], "EVENT_DISTANCE_DATA_REPORT_ON_TIME") == 0) { + event = PROXIMITY_EVENT_DISTANCE_DATA_REPORT_ON_TIME; + } + else { + printformat(); + free(event_condition); + return 0; + } + + if (argc == 3) + event_condition->cond_value1 = atof(argv[2]); + + handle = sf_connect(type); + result = sf_register_event(handle, event, event_condition, callback, NULL); + + if (result < 0) + printf("Can't register proximity sensor\n"); + + start_handle = sf_start(handle,0); + + if (start_handle >= 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); + + sf_unregister_event(handle, event); + + stop_handle = sf_stop(handle); + + if (stop_handle >= 0) + printf("Success stop \n"); + + sf_disconnect(handle); + + free(event_condition); + + return 0; +} + -- 2.7.4