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.
26 #include <service_app.h>
30 #include "connectivity.h"
31 #include "controller.h"
32 #include "controller_util.h"
37 * DO NOT EDIT: please don't edit the time interval.
39 #define SENSORING_TIME_INTERVAL 2.0f
42 * TODO: You have to use the pin numbers below.
43 * You can change the pin numbers freely.
45 #define TRIG_PIN_NUMBER 20
46 #define ECHO_PIN_NUMBER 21
48 typedef struct app_data_s {
49 Ecore_Timer *getter_timer;
50 connectivity_resource_s *resource_info;
53 static void _ultrasonic_sensor_read_cb(float value, void *data)
58 * TODO: Send the value of the ultrasonic sensor to the Client.
67 static Eina_Bool _control_sensors_cb(void *data)
72 * TODO: Prepare to read the value of the ultrasonic sensor.
79 return ECORE_CALLBACK_RENEW;
82 static bool service_app_create(void *data)
85 const char *path = NULL;
88 * DO NOT EDIT: please don't edit the function below.
89 * Access only when modifying internal functions.
91 controller_init_internal_functions();
94 * TODO: Get a path of the box.
95 * Get a predefined path based on where the box is placed.(e.g. "/door/1")
96 * The path is a string value that is passed as the first argument to the connectivity_set_resource().
104 * Creates a connectivity resource and registers the resource in server.
112 * Creates a timer to call the given function in the given period of time.
113 * In the control_sensors_cb(), each sensor reads the measured value or writes a specific value to the sensor.
115 ad->getter_timer = ecore_timer_add(SENSORING_TIME_INTERVAL, _control_sensors_cb, ad);
116 if (!ad->getter_timer) {
117 _E("Failed to add infrared motion getter timer");
124 static void service_app_terminate(void *data)
126 app_data *ad = (app_data *)data;
128 if (ad->getter_timer)
129 ecore_timer_del(ad->getter_timer);
132 * Releases the resource about connectivity.
134 connectivity_unset_resource(ad->resource_info);
137 * DO NOT EDIT: please don't edit the function below.
138 * Access only when modifying internal functions.
140 controller_fini_internal_functions();
145 static void service_app_control(app_control_h app_control, void *data)
150 static void service_app_lang_changed(app_event_info_h event_info, void *user_data)
152 /*APP_EVENT_LANGUAGE_CHANGED*/
155 static void service_app_region_changed(app_event_info_h event_info, void *user_data)
157 /*APP_EVENT_REGION_FORMAT_CHANGED*/
160 static void service_app_low_battery(app_event_info_h event_info, void *user_data)
162 /*APP_EVENT_LOW_BATTERY*/
165 static void service_app_low_memory(app_event_info_h event_info, void *user_data)
167 /*APP_EVENT_LOW_MEMORY*/
170 int main(int argc, char* argv[])
174 service_app_lifecycle_callback_s event_callback;
175 app_event_handler_h handlers[5] = {NULL, };
177 ad = calloc(1, sizeof(app_data));
180 event_callback.create = service_app_create;
181 event_callback.terminate = service_app_terminate;
182 event_callback.app_control = service_app_control;
184 service_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, service_app_low_battery, &ad);
185 service_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, service_app_low_memory, &ad);
186 service_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, service_app_lang_changed, &ad);
187 service_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, service_app_region_changed, &ad);
189 ret = service_app_main(argc, argv, &event_callback, ad);