diff options
author | INSUN PYO <insun.pyo@samsung.com> | 2021-09-07 12:23:35 +0900 |
---|---|---|
committer | INSUN PYO <insun.pyo@samsung.com> | 2021-09-07 12:27:42 +0900 |
commit | 2576ebfd6ce8bd477fff6fac459bd9bf72e3ef6e (patch) | |
tree | 2c76dc36297ef6225f5c6d42dd5f20f3ea9c6190 | |
parent | 8f45227cc1a8a4cf2c4fbc86f0ad7770e205b365 (diff) | |
download | session-utils-2576ebfd6ce8bd477fff6fac459bd9bf72e3ef6e.tar.gz session-utils-2576ebfd6ce8bd477fff6fac459bd9bf72e3ef6e.tar.bz2 session-utils-2576ebfd6ce8bd477fff6fac459bd9bf72e3ef6e.zip |
Add sensor example
Change-Id: Ia855e1d826bae63c3fe0c80bf7c394bf926575a7
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | packaging/session-utils.spec | 17 | ||||
-rw-r--r-- | src/sensor/CMakeLists.txt | 20 | ||||
-rw-r--r-- | src/sensor/sensor.c | 79 |
4 files changed, 117 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index b33a40e..e9772dd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,3 +12,4 @@ ADD_SUBDIRECTORY(src/simple-application) ADD_SUBDIRECTORY(src/kernel-module-load) ADD_SUBDIRECTORY(src/udev-monitor) ADD_SUBDIRECTORY(src/udev-enumerate) +ADD_SUBDIRECTORY(src/sensor) diff --git a/packaging/session-utils.spec b/packaging/session-utils.spec index b3febc1..4d6f536 100644 --- a/packaging/session-utils.spec +++ b/packaging/session-utils.spec @@ -24,6 +24,9 @@ BuildRequires: pkgconfig(capi-appfw-app-control) BuildRequires: pkgconfig(libkmod) BuildRequires: arm-rpi4-linux-kernel-devel +# sensor +BuildRequires: pkgconfig(capi-system-sensor) + %description This package provides some utils for session control in multi-user environment. @@ -133,6 +136,14 @@ This package provides udev enumerate ############################################################################### +%package -n sensor +Summary: sensor + +%description -n sensor +This package provides sensor + + +############################################################################### %prep %setup -q @@ -265,3 +276,9 @@ cd .. %license LICENSE.Apache-2.0 %manifest %{name}.manifest %{_bindir}/udev-enumerate + +############################################################################### +%files -n sensor +%license LICENSE.Apache-2.0 +%manifest %{name}.manifest +%{_bindir}/sensor diff --git a/src/sensor/CMakeLists.txt b/src/sensor/CMakeLists.txt new file mode 100644 index 0000000..b01dcf6 --- /dev/null +++ b/src/sensor/CMakeLists.txt @@ -0,0 +1,20 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(sensor C) + +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs REQUIRED + capi-system-sensor +) + +FOREACH(flag ${pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIE") + +ADD_EXECUTABLE(sensor sensor.c) +TARGET_LINK_LIBRARIES(sensor ${pkgs_LDFLAGS} -pie) + +INSTALL(TARGETS sensor DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE + GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) diff --git a/src/sensor/sensor.c b/src/sensor/sensor.c new file mode 100644 index 0000000..12a5cd0 --- /dev/null +++ b/src/sensor/sensor.c @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2020 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 <stdio.h> +#include <sensor.h> +#include <glib.h> + +GMainLoop *loop; + +void sensor_callback(sensor_h sensor, sensor_event_s events[], int events_count, void *user_data) +{ + sensor_type_e type; + sensor_get_type(sensor, &type); + + if (type == SENSOR_ACCELEROMETER){ + for(int i = 0; i < events_count; ++i){ + printf("x : %f y : %f z : %f\n", events[i].values[0], events[i].values[1], events[i].values[2]); + } + } +} + +#if 0 +static gboolean timeout(void *data) +{ + printf ("quit main loop\n"); + g_main_loop_quit(loop); + + return G_SOURCE_REMOVE; +} +#endif + +int main() +{ + bool sup; + int count, ret; + sensor_h *sh; + sensor_listener_h lh; + + sensor_is_supported(SENSOR_ACCELEROMETER, &sup); + if(!sup){ + printf("the sensor is not supported in this device.\n"); + return -1; + } + + sensor_get_sensor_list(SENSOR_ACCELEROMETER, &sh, &count); + + sensor_create_listener(sh[0], &lh); + sensor_listener_set_events_cb(lh, sensor_callback, NULL); + sensor_listener_set_option(lh, SENSOR_OPTION_ALWAYS_ON); + sensor_listener_set_interval(lh, 1); + + ret = sensor_listener_start(lh); + if (ret < 0){ + printf("error in listnener_start : %d\n", ret); + return ret; + } + + loop = g_main_loop_new(NULL, FALSE); + + //g_timeout_add_seconds(1, timeout, NULL); + + g_main_loop_run(loop); + + return 0; +} |