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>
9 * Licensed under the Flora License, Version 1.1 (the License);
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://floralicense.org/license/
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an AS IS BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
24 #include <service_app.h>
28 #include <iotcon.h> // Please remove this after test
32 #include "connectivity.h"
33 #include "controller.h"
35 #define GPIO_ULTRASONIC_TRIG_NUM_1 20
36 #define GPIO_ULTRASONIC_ECHO_NUM_1 21
37 #define MULTIPLE_SENSOR_NUMBER 5
39 typedef struct app_data_s {
40 Ecore_Timer *getter_timer;
41 connectivity_resource_s *resource_info;
44 static Eina_Bool control_read_sensors_cb(void *data)
46 int value[MULTIPLE_SENSOR_NUMBER] = { 0, };
48 int gpio_num[MULTIPLE_SENSOR_NUMBER] = { 5, 6, 13, 19, 26 };
52 for (i = 0; i < MULTIPLE_SENSOR_NUMBER; i++) {
53 if (resource_read_infrared_motion_sensor(gpio_num[i], &value[i]) == -1) {
54 _E("Failed to get Infrared Motion value [GPIO:%d]", gpio_num[i]);
60 if (connectivity_notify(ad->resource_info, total) == -1)
61 _E("Cannot notify message");
63 _I("[5:%d] | [6:%d] | [13:%d] | [19:%d] | [26:%d] = [Total:%d]", value[0], value[1], value[2], value[3], value[4], total);
65 return ECORE_CALLBACK_RENEW;
68 static bool service_app_create(void *data)
73 controller_init_internal_functions();
74 ret = connectivity_set_resource("/door/1", "org.tizen.door", &ad->resource_info);
75 if (ret == -1) _E("Cannot broadcast resource");
77 ad->getter_timer = ecore_timer_add(0.5f, control_read_sensors_cb, ad);
78 if (!ad->getter_timer) {
79 _E("Failed to add infrared motion getter timer");
86 static void service_app_terminate(void *data)
88 app_data *ad = (app_data *)data;
90 for (int i = 0; i < PIN_MAX; i++) {
91 if (ad->getter_timer) {
92 ecore_timer_del(ad->getter_timer);
96 connectivity_unset_resource(ad->resource_info);
97 controller_fini_internal_functions();
102 static void service_app_control(app_control_h app_control, void *data)
104 // Todo: add your code here.
107 static void service_app_lang_changed(app_event_info_h event_info, void *user_data)
109 /*APP_EVENT_LANGUAGE_CHANGED*/
112 static void service_app_region_changed(app_event_info_h event_info, void *user_data)
114 /*APP_EVENT_REGION_FORMAT_CHANGED*/
117 static void service_app_low_battery(app_event_info_h event_info, void *user_data)
119 /*APP_EVENT_LOW_BATTERY*/
122 static void service_app_low_memory(app_event_info_h event_info, void *user_data)
124 /*APP_EVENT_LOW_MEMORY*/
127 int main(int argc, char* argv[])
131 service_app_lifecycle_callback_s event_callback;
132 app_event_handler_h handlers[5] = {NULL, };
134 ad = calloc(1, sizeof(app_data));
136 event_callback.create = service_app_create;
137 event_callback.terminate = service_app_terminate;
138 event_callback.app_control = service_app_control;
140 service_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, service_app_low_battery, &ad);
141 service_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, service_app_low_memory, &ad);
142 service_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, service_app_lang_changed, &ad);
143 service_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, service_app_region_changed, &ad);
145 ret = service_app_main(argc, argv, &event_callback, ad);