From: Jin Yoon Date: Wed, 19 Apr 2017 08:34:19 +0000 (+0900) Subject: Initial version X-Git-Tag: accepted/tizen/4.0/unified/20170816.012243~1 X-Git-Url: http://review.tizen.org/git/?p=apps%2Fnative%2Fthing-toggler.git;a=commitdiff_plain;h=3e0192f0752cd4a3d3ad326c445fa1b5288c9629 Initial version --- diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..0c3a186 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,44 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(thing-toggler C) + +SET(INSTALL_EXEC_PREFIX "${INSTALL_PREFIX}/bin") +SET(INSTALL_RESDIR "${INSTALL_PREFIX}/res") +SET(CMAKE_VERBOSE_MAKEFILE 0) + +SET(PROJECT_ROOT_DIR "${CMAKE_SOURCE_DIR}") +SET(PROJECT_RESOURCES_DIR "${PROJECT_ROOT_DIR}/res") + +INCLUDE(FindPkgConfig) +pkg_check_modules(APP_PKGS REQUIRED + dlog + aul + capi-appfw-application + capi-appfw-service-application + capi-system-peripheral-io +) + +FOREACH (flag ${APP_PKGS_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wall -Winline -g -fno-builtin-malloc -fPIE") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie") + +INCLUDE_DIRECTORIES(${PROJECT_ROOT_DIR}/inc) + +ADD_EXECUTABLE(${PROJECT_NAME} + ${PROJECT_ROOT_DIR}/src/thing_toggler.c +) + +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} -lm) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${APP_PKGS_LDFLAGS}) + +# Install +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${INSTALL_EXEC_PREFIX}) + +INSTALL(FILES ${PROJECT_ROOT_DIR}/tizen-manifest.xml DESTINATION ${SYS_PACKAGES_DIR} RENAME org.tizen.thing-toggler.xml) +INSTALL(DIRECTORY DESTINATION ${PREFIX}/data) +INSTALL(FILES ${PROJECT_ROOT_DIR}/shared/res/thing_toggler.png DESTINATION ${SYS_ICONS_DIR}) + +# End of a file diff --git a/inc/thing_toggler.h b/inc/thing_toggler.h new file mode 100644 index 0000000..7ca7e53 --- /dev/null +++ b/inc/thing_toggler.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Jin Yoon + * + * 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. + */ + +#ifndef __THING_TOGGLER_H__ +#define __THING_TOGGLER_H__ + +#include + +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "THING_TOGGLER" + +#endif /* __THING_TOGGLER_H__ */ diff --git a/org.tizen.thing-toggler.manifest b/org.tizen.thing-toggler.manifest new file mode 100755 index 0000000..af9b883 --- /dev/null +++ b/org.tizen.thing-toggler.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/packaging/org.tizen.thing-toggler.spec b/packaging/org.tizen.thing-toggler.spec new file mode 100644 index 0000000..5d0cab2 --- /dev/null +++ b/packaging/org.tizen.thing-toggler.spec @@ -0,0 +1,71 @@ +Name: org.tizen.thing-toggler +%define alias org.tizen.thing-toggler +Summary: Thing Toggler +Group: Applications/Core Applications +Version: 0.0.1 +Release: 1 +License: Apache-2.0 +Provides: org.tizen.thing-toggler = %{version}-%{release} +Source0: %{name}-%{version}.tar.gz + +BuildRequires: cmake +BuildRequires: hash-signer +BuildRequires: pkgconfig(capi-appfw-application) +BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(libtzplatform-config) +BuildRequires: pkgconfig(capi-appfw-service-application) +BuildRequires: pkgconfig(capi-system-peripheral-io) + +%description +Thing Toggler + +%prep +%setup -q + +%build + +%define _pkg_dir %{TZ_SYS_RO_APP}/%{alias} +%define _pkg_shared_dir %{_pkg_dir}/shared +%define _pkg_data_dir %{_pkg_dir}/data +%define _sys_icons_dir %{_pkg_shared_dir}/res +%define _sys_packages_dir %{TZ_SYS_RO_PACKAGES} +%define _sys_license_dir %{TZ_SYS_SHARE}/license + +%ifarch %{arm} +export CFLAGS="$CFLAGS -DTIZEN_BUILD_TARGET" +export CXXFLAGS="$CXXFLAGS -DTIZEN_BUILD_TARGET" +export FFLAGS="$FFLAGS -DTIZEN_BUILD_TARGET" +%else +export CFLAGS="$CFLAGS -DTIZEN_BUILD_EMULATOR" +export CXXFLAGS="$CXXFLAGS -DTIZEN_BUILD_EMULATOR" +export FFLAGS="$FFLAGS -DTIZEN_BUILD_EMULATOR" +%endif + +cmake . -DINSTALL_PREFIX=%{_pkg_dir} \ + -DSYS_ICONS_DIR=%{_sys_icons_dir} \ + -DSYS_PACKAGES_DIR=%{_sys_packages_dir} +make %{?jobs:-j%jobs} + +%install +%make_install + +%define tizen_sign 1 +%define tizen_sign_base %{_pkg_dir} +%define tizen_sign_level platform +%define tizen_author_sign 1 +%define tizen_dist_sign 1 +#%find_lang thing-toggler + +%post +/sbin/ldconfig + +%postun -p /sbin/ldconfig + +%files +%manifest org.tizen.thing-toggler.manifest +%defattr(-,root,root,-) +%{_pkg_dir}/bin/thing-toggler +%{_sys_packages_dir}/org.tizen.thing-toggler.xml +%{_sys_icons_dir}/thing_toggler.png +%{_pkg_dir}/author-signature.xml +%{_pkg_dir}/signature1.xml diff --git a/shared/res/thing_toggler.png b/shared/res/thing_toggler.png new file mode 100755 index 0000000..9765b1b Binary files /dev/null and b/shared/res/thing_toggler.png differ diff --git a/src/thing_toggler.c b/src/thing_toggler.c new file mode 100644 index 0000000..d77141e --- /dev/null +++ b/src/thing_toggler.c @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Jin Yoon + * + * 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 "thing_toggler.h" + +#define GPIO_NUM 25 + +bool service_app_create(void *data) +{ + // Todo: add your code here. + return true; +} + +void service_app_terminate(void *data) +{ + // Todo: add your code here. +} + +void service_app_control(app_control_h app_control, void *data) +{ + // Todo: add your code here. +} + +static void service_app_lang_changed(app_event_info_h event_info, void *user_data) +{ + /*APP_EVENT_LANGUAGE_CHANGED*/ +} + +static void service_app_region_changed(app_event_info_h event_info, void *user_data) +{ + /*APP_EVENT_REGION_FORMAT_CHANGED*/ +} + +static void service_app_low_battery(app_event_info_h event_info, void *user_data) +{ + /*APP_EVENT_LOW_BATTERY*/ +} + +static void service_app_low_memory(app_event_info_h event_info, void *user_data) +{ + /*APP_EVENT_LOW_MEMORY*/ +} + +static void _control_led(peripheral_gpio_context_h dev, int power_on) +{ + dlog_print(DLOG_INFO, LOG_TAG, "Write [%d] into GPIO."); + peripheral_gpio_write(dev, power_on); +} + +static gboolean _toggle_led(gpointer user_data) +{ + static int current_status = 0; + + if (current_status) current_status = 0; + else current_status = 1; + + _control_led(user_data, current_status); + + return TRUE; +} + +int main(int argc, char* argv[]) +{ + char ad[50] = {0,}; + service_app_lifecycle_callback_s event_callback; + app_event_handler_h handlers[5] = {NULL, }; + peripheral_gpio_context_h dev = NULL; + guint timer_id = 0; + int ret = 0; + + event_callback.create = service_app_create; + event_callback.terminate = service_app_terminate; + event_callback.app_control = service_app_control; + + service_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, service_app_low_battery, &ad); + service_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, service_app_low_memory, &ad); + service_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, service_app_lang_changed, &ad); + service_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, service_app_region_changed, &ad); + + dev = peripheral_gpio_open(GPIO_NUM); + if (!dev) { + dlog_print(DLOG_INFO, LOG_TAG, "The return value of peripheral_gpio_open is null."); + return 1; + } + + ret = peripheral_gpio_set_direction(dev, PERIPHERAL_GPIO_DIRECTION_OUT); + if (ret != 0) { + dlog_print(DLOG_INFO, LOG_TAG, "Cannot set direction error."); + return 1; + } + + // Return value : the ID (greater than 0) of the event source. + timer_id = g_timeout_add_seconds(1, _toggle_led, dev); + if (timer_id <= 0) { + dlog_print(DLOG_INFO, LOG_TAG, "Timer id : %d", timer_id); + return 1; + } + + ret = service_app_main(argc, argv, &event_callback, ad); + + g_source_remove(timer_id); + peripheral_gpio_close(dev); + + return ret; +} + diff --git a/tizen-manifest.xml b/tizen-manifest.xml new file mode 100644 index 0000000..5fac5bf --- /dev/null +++ b/tizen-manifest.xml @@ -0,0 +1,8 @@ + + + + + + thing_toggler.png + +