Initial version
authorJin Yoon <jinny.yoon@samsung.com>
Wed, 19 Apr 2017 08:18:00 +0000 (17:18 +0900)
committerJin Yoon <jinny.yoon@samsung.com>
Wed, 19 Apr 2017 08:18:00 +0000 (17:18 +0900)
CMakeLists.txt [new file with mode: 0644]
inc/thing_illumination.h [new file with mode: 0644]
org.tizen.thing-illumination.manifest [new file with mode: 0755]
packaging/org.tizen.thing-illumination.spec [new file with mode: 0644]
shared/res/thing_illumination.png [new file with mode: 0755]
src/thing_illumination.c [new file with mode: 0644]
tizen-manifest.xml [new file with mode: 0644]

diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644 (file)
index 0000000..60f3872
--- /dev/null
@@ -0,0 +1,44 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(thing-illumination 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_illumination.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-illumination.xml)
+INSTALL(DIRECTORY DESTINATION ${PREFIX}/data)
+INSTALL(FILES ${PROJECT_ROOT_DIR}/shared/res/thing_illumination.png DESTINATION ${SYS_ICONS_DIR})
+
+# End of a file
diff --git a/inc/thing_illumination.h b/inc/thing_illumination.h
new file mode 100644 (file)
index 0000000..80e0347
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Jin Yoon <jinny.yoon@samsung.com>
+ *
+ * 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_ILLUMINATION_H__
+#define __THING_ILLUMINATION_H__
+
+#include <dlog.h>
+
+#ifdef  LOG_TAG
+#undef  LOG_TAG
+#endif
+#define LOG_TAG "THING_ILLUMINATION"
+
+#endif /* __THING_ILLUMINATION_H__ */
diff --git a/org.tizen.thing-illumination.manifest b/org.tizen.thing-illumination.manifest
new file mode 100755 (executable)
index 0000000..af9b883
--- /dev/null
@@ -0,0 +1,5 @@
+<manifest>\r
+       <request>\r
+               <domain name="_" />\r
+       </request>\r
+</manifest>\r
diff --git a/packaging/org.tizen.thing-illumination.spec b/packaging/org.tizen.thing-illumination.spec
new file mode 100644 (file)
index 0000000..9a0ba34
--- /dev/null
@@ -0,0 +1,71 @@
+Name:       org.tizen.thing-illumination
+%define alias org.tizen.thing-illumination
+Summary:    Thing Illumination
+Group:      Applications/Core Applications
+Version:    0.0.1
+Release:    1
+License:    Apache-2.0
+Provides:   org.tizen.thing-illumination = %{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 Illumination
+
+%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-illumination
+
+%post
+/sbin/ldconfig
+
+%postun -p /sbin/ldconfig
+
+%files
+%manifest org.tizen.thing-illumination.manifest
+%defattr(-,root,root,-)
+%{_pkg_dir}/bin/thing-illumination
+%{_sys_packages_dir}/org.tizen.thing-illumination.xml
+%{_sys_icons_dir}/thing_illumination.png
+%{_pkg_dir}/author-signature.xml
+%{_pkg_dir}/signature1.xml
diff --git a/shared/res/thing_illumination.png b/shared/res/thing_illumination.png
new file mode 100755 (executable)
index 0000000..9765b1b
Binary files /dev/null and b/shared/res/thing_illumination.png differ
diff --git a/src/thing_illumination.c b/src/thing_illumination.c
new file mode 100644 (file)
index 0000000..1d6658e
--- /dev/null
@@ -0,0 +1,178 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Jin Yoon <jinny.yoon@samsung.com>
+ *
+ * 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 <tizen.h>
+#include <service_app.h>
+#include <unistd.h>
+#include <glib.h>
+#include <peripheral_io.h>
+
+#include "thing_illumination.h"
+
+#define TOGGLE_FUNCTION 0 /* 0 : Toggle, 1 : Sensoring */
+#define THRESHOLD_OF_DARKNESS 100
+#define DURATION 500 /* msec */
+
+/* I2C */
+#define I2C_BUS 0x1 /* I2C Bus number */
+#define GY30_ADDR 0x23 /* Address of GY30 light sensor */
+#define GY30_CONT_HIGH_RES_MODE 0x10 /* Start measurement at 11x resolution. Measurement time is approx 120ms. */
+#define GY30_READ_INTENSITY(buf) ((buf[0] << 8 | buf[1]) / 1.2)
+
+/* GPIO */
+#define GPIO_NUM 25
+
+struct _peripheral {
+       peripheral_i2c_context_h i2c_dev;
+       peripheral_gpio_context_h gpio_dev;
+};
+typedef struct _peripheral peripheral_s;
+
+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_s *info, int power_on)
+{
+       dlog_print(DLOG_INFO, LOG_TAG, "Write [%d] into GPIO...", power_on);
+       peripheral_gpio_write(info->gpio_dev, power_on);
+}
+
+static gboolean _check_and_turn_on_light(gpointer user_data)
+{
+       unsigned char buf[10];
+       static int status = 0;
+       peripheral_s *info = user_data;
+       int result = -1;
+
+       dlog_print(DLOG_INFO, LOG_TAG, "Check the sensor...");
+
+       buf[0] = GY30_CONT_HIGH_RES_MODE;
+       if (peripheral_i2c_write(info->i2c_dev, buf, 1) != 0) {
+               dlog_print(DLOG_INFO, LOG_TAG, "Cannot write into the buffer.");
+               return FALSE;
+       }
+
+       peripheral_i2c_read(info->i2c_dev, buf, 2);
+       result = GY30_READ_INTENSITY(buf);
+
+       dlog_print(DLOG_INFO, LOG_TAG, "The result is [%d].", result);
+       if (result > THRESHOLD_OF_DARKNESS) {
+               if (status != 0) {
+                       _control_led(info, 0);
+                       status = 0;
+               }
+       } else {
+               if (status != 1) {
+                       _control_led(info, 1);
+                       status = 1;
+               }
+       }
+
+       return TRUE;
+}
+
+int main(int argc, char* argv[])
+{
+    char ad[50] = {0, };
+       peripheral_s info = {0, };
+       service_app_lifecycle_callback_s event_callback;
+       app_event_handler_h handlers[5] = {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);
+
+       info.i2c_dev = peripheral_i2c_init(I2C_BUS);
+       if (!info.i2c_dev) {
+               dlog_print(DLOG_INFO, LOG_TAG, "Cannot initialize the peripheral i2c.");
+               return 1;
+       }
+
+       if (peripheral_i2c_set_address(info.i2c_dev, GY30_ADDR) != 0) {
+               dlog_print(DLOG_INFO, LOG_TAG, "Cannot set the address.");
+               return 1;
+       }
+
+       info.gpio_dev = peripheral_gpio_open(GPIO_NUM);
+       if (!info.gpio_dev) {
+               dlog_print(DLOG_INFO, LOG_TAG, "The return value of peripheral_gpio_open is null.");
+               return 1;
+       }
+
+       ret = peripheral_gpio_set_direction(info.gpio_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(DURATION, _check_and_turn_on_light, &info);
+       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_i2c_stop(info.i2c_dev);
+       peripheral_gpio_close(info.gpio_dev);
+
+       return ret;
+}
+
diff --git a/tizen-manifest.xml b/tizen-manifest.xml
new file mode 100644 (file)
index 0000000..6bda9b2
--- /dev/null
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>\r
+<manifest xmlns="http://tizen.org/ns/packages" api-version="3.0" package="org.tizen.thing-illumination" version="1.0.0">\r
+    <profile name="mobile"/>\r
+    <service-application appid="org.tizen.thing-illumination" auto-restart="true" exec="thing-illumination" multiple="false" nodisplay="true" on-boot="true" taskmanage="false" type="capp">\r
+        <label>Illumination</label>\r
+        <icon>thing_illumination.png</icon>\r
+    </service-application>\r
+</manifest>\r