2 * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
4 * Contact: Jin Yoon <jinny.yoon@samsung.com>
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
22 #include <service_app.h>
27 #include "controller.h"
30 #define GPIO_NOT_USED -1
31 #define GPIO_ULTRASONIC_TRIG_NUM 20
32 #define GPIO_ULTRASONIC_ECHO_NUM 21
33 #define GPIO_INFRARED_MOTION_NUM 4
35 typedef struct app_data_s {
36 model_sensor_h sensor_info;
37 Ecore_Timer *getter_timer;
41 static Eina_Bool _ultrasonic_getter_timer(void *data)
47 retv_if(model_read_int_value(ad->sensor_info, &value) == -1, ECORE_CALLBACK_CANCEL);
48 _I("Ultrasonic Value is [%d]", value);
51 retv_if(model_read_double_value(ad->sensor_info, &value) == -1, ECORE_CALLBACK_RENEW);
52 _I("Value is [%f]", value);
55 return ECORE_CALLBACK_RENEW;
58 static Eina_Bool _infrared_motion_getter_timer(void *data)
64 retv_if(model_read_int_value(ad->sensor_info, &value) == -1, ECORE_CALLBACK_CANCEL);
65 _I("Infrared Motion Value is [%d]", value);
68 retv_if(model_read_double_value(ad->sensor_info, &value) == -1, ECORE_CALLBACK_RENEW);
69 _I("Value is [%f]", value);
72 return ECORE_CALLBACK_RENEW;
75 static bool service_app_create(void *data)
77 model_sensor_h sensor_info = NULL;
80 retv_if(model_init("Ultrasonic", SENSOR_TYPE_ULTRASONIC, GPIO_ULTRASONIC_TRIG_NUM, GPIO_ULTRASONIC_ECHO_NUM, &sensor_info) == -1, false);
81 ad->sensor_info = sensor_info;
83 ad->getter_timer = ecore_timer_add(3.0, _ultrasonic_getter_timer, ad);
84 if (!ad->getter_timer) {
85 _D("Failed to add getter timer");
89 retv_if(model_init("Infrared_motion", SENSOR_TYPE_INFRARED_MOTION, GPIO_INFRARED_MOTION_NUM, GPIO_NOT_USED, &sensor_info) == -1, false);
90 ad->sensor_info = sensor_info;
92 ad->getter_timer = ecore_timer_add(3.0, _infrared_motion_getter_timer, ad);
93 if (!ad->getter_timer) {
94 _D("Failed to add getter timer");
101 static void service_app_terminate(void *data)
103 app_data *ad = (app_data *)data;
104 ecore_timer_del(ad->getter_timer);
105 model_fini(ad->sensor_info);
109 static void service_app_control(app_control_h app_control, void *data)
111 // Todo: add your code here.
114 static void service_app_lang_changed(app_event_info_h event_info, void *user_data)
116 /*APP_EVENT_LANGUAGE_CHANGED*/
119 static void service_app_region_changed(app_event_info_h event_info, void *user_data)
121 /*APP_EVENT_REGION_FORMAT_CHANGED*/
124 static void service_app_low_battery(app_event_info_h event_info, void *user_data)
126 /*APP_EVENT_LOW_BATTERY*/
129 static void service_app_low_memory(app_event_info_h event_info, void *user_data)
131 /*APP_EVENT_LOW_MEMORY*/
134 int main(int argc, char* argv[])
138 service_app_lifecycle_callback_s event_callback;
139 app_event_handler_h handlers[5] = {NULL, };
141 ad = calloc(1, sizeof(app_data));
143 event_callback.create = service_app_create;
144 event_callback.terminate = service_app_terminate;
145 event_callback.app_control = service_app_control;
147 service_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, service_app_low_battery, &ad);
148 service_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, service_app_low_memory, &ad);
149 service_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, service_app_lang_changed, &ad);
150 service_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, service_app_region_changed, &ad);
152 ret = service_app_main(argc, argv, &event_callback, ad);