2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Contact: Jin Yoon <jinny.yoon@samsung.com>
5 * Geunsun Lee <gs86.lee@samsung.com>
6 * Eunyoung Lee <ey928.lee@samsung.com>
7 * Junkyu Han <junkyu.han@samsung.com>
8 * Jeonghoon Park <jh1979.park@samsung.com>
10 * Licensed under the Flora License, Version 1.1 (the License);
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://floralicense.org/license/
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an AS IS BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
25 #include <service_app.h>
29 #include <iotcon.h> // Please remove this after test
33 #include "connectivity.h"
34 #include "controller.h"
36 #ifdef ENABLE_WEBNOTIFY
37 #include "webnotify.h"
39 #define RESOURCE_URI TEST_RES_URI
40 #endif /* RESOURCE_URI */
41 #endif /* ENABLE_WEBNOTIFY */
43 #define GPIO_ULTRASONIC_TRIG_NUM_1 20
44 #define GPIO_ULTRASONIC_ECHO_NUM_1 21
45 #define MULTIPLE_SENSOR_NUMBER 5
46 #define CONNECTIVITY_KEY "opened"
48 typedef struct app_data_s {
49 Ecore_Timer *getter_timer;
50 connectivity_resource_s *resource_info;
53 static Eina_Bool control_read_sensors_cb(void *data)
55 int value[MULTIPLE_SENSOR_NUMBER] = { 0, };
57 int gpio_num[MULTIPLE_SENSOR_NUMBER] = { 5, 6, 13, 19, 26 };
61 for (i = 0; i < MULTIPLE_SENSOR_NUMBER; i++) {
62 if (resource_read_infrared_motion_sensor(gpio_num[i], &value[i]) == -1) {
63 _E("Failed to get Infrared Motion value [GPIO:%d]", gpio_num[i]);
68 _I("[5:%d] | [6:%d] | [13:%d] | [19:%d] | [26:%d] = [Total:%d]", value[0], value[1], value[2], value[3], value[4], total);
70 if (connectivity_notify_bool(ad->resource_info, CONNECTIVITY_KEY, total) == -1)
71 _E("Cannot notify message");
73 #ifdef ENABLE_WEBNOTIFY
74 if (web_notify_bool(RESOURCE_URI, total) == -1)
75 _E("Cannot notify web message");
76 #endif /* ENABLE_WEBNOTIFY */
78 return ECORE_CALLBACK_RENEW;
81 static bool service_app_create(void *data)
86 controller_init_internal_functions();
87 ret = connectivity_set_resource("/door/1", "org.tizen.door", &ad->resource_info);
88 if (ret == -1) _E("Cannot broadcast resource");
90 ad->getter_timer = ecore_timer_add(0.5f, control_read_sensors_cb, ad);
91 if (!ad->getter_timer) {
92 _E("Failed to add infrared motion getter timer");
99 static void service_app_terminate(void *data)
101 app_data *ad = (app_data *)data;
103 for (int i = 0; i < PIN_MAX; i++) {
104 if (ad->getter_timer) {
105 ecore_timer_del(ad->getter_timer);
109 connectivity_unset_resource(ad->resource_info);
110 controller_fini_internal_functions();
115 static void service_app_control(app_control_h app_control, void *data)
117 // Todo: add your code here.
120 static void service_app_lang_changed(app_event_info_h event_info, void *user_data)
122 /*APP_EVENT_LANGUAGE_CHANGED*/
125 static void service_app_region_changed(app_event_info_h event_info, void *user_data)
127 /*APP_EVENT_REGION_FORMAT_CHANGED*/
130 static void service_app_low_battery(app_event_info_h event_info, void *user_data)
132 /*APP_EVENT_LOW_BATTERY*/
135 static void service_app_low_memory(app_event_info_h event_info, void *user_data)
137 /*APP_EVENT_LOW_MEMORY*/
140 int main(int argc, char* argv[])
144 service_app_lifecycle_callback_s event_callback;
145 app_event_handler_h handlers[5] = {NULL, };
147 ad = calloc(1, sizeof(app_data));
149 event_callback.create = service_app_create;
150 event_callback.terminate = service_app_terminate;
151 event_callback.app_control = service_app_control;
153 service_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, service_app_low_battery, &ad);
154 service_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, service_app_low_memory, &ad);
155 service_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, service_app_lang_changed, &ad);
156 service_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, service_app_region_changed, &ad);
158 ret = service_app_main(argc, argv, &event_callback, ad);