2 * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
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 Apache License, Version 2.0 (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://www.apache.org/licenses/LICENSE-2.0
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.
25 #include <service_app.h>
30 #include "controller.h"
34 #define GPIO_NOT_USED -1
35 #define GPIO_ULTRASONIC_TRIG_NUM_1 20
36 #define GPIO_ULTRASONIC_ECHO_NUM_1 21
37 #define GPIO_INFRARED_MOTION_NUM_1 4
38 #define I2C_ILLUMINANCE_FIRST_PIN_1 3
40 typedef struct app_data_s {
41 Ecore_Timer *getter_timer[PIN_MAX];
44 static Eina_Bool _infrared_motion_getter_timer(void *data)
48 retv_if(resource_read_infrared_motion_sensor(GPIO_INFRARED_MOTION_NUM_1, &value) == -1, ECORE_CALLBACK_CANCEL);
49 _I("Infrared Motion Value is [%d]", value);
51 return ECORE_CALLBACK_RENEW;
54 static Eina_Bool _ultrasonic_getter_timer(void *data)
58 retv_if(resource_read_ultrasonic_sensor(GPIO_ULTRASONIC_TRIG_NUM_1, GPIO_ULTRASONIC_ECHO_NUM_1, &value) == -1, ECORE_CALLBACK_CANCEL);
59 _I("Ultra Sonic Distance is [%d cm]", value);
61 return ECORE_CALLBACK_RENEW;
64 static Eina_Bool _illuminance_getter_timer(void *data)
68 retv_if(resource_read_illuminance_sensor(I2C_BUS_1, &value) == -1, ECORE_CALLBACK_CANCEL);
69 _I("Ultra Sonic Distance is [%d lux]", value);
71 return ECORE_CALLBACK_RENEW;
74 static bool service_app_create(void *data)
79 ad->getter_timer[GPIO_INFRARED_MOTION_NUM_1] = ecore_timer_add(3.0, _infrared_motion_getter_timer, ad);
80 if (!ad->getter_timer[GPIO_INFRARED_MOTION_NUM_1]) {
81 _D("Failed to add infrared motion getter timer");
86 ad->getter_timer[GPIO_ULTRASONIC_TRIG_NUM_1] = ecore_timer_add(1.0, _ultrasonic_getter_timer, ad);
87 if (!ad->getter_timer[GPIO_ULTRASONIC_TRIG_NUM_1]) {
88 _D("Failed to add ultra sonic getter timer");
92 /* I2C Protocol Sensor */
93 ad->getter_timer[I2C_ILLUMINANCE_FIRST_PIN_1] = ecore_timer_add(1.0, _illuminance_getter_timer, ad);
94 if (!ad->getter_timer[I2C_ILLUMINANCE_FIRST_PIN_1]) {
95 _D("Failed to add ultra sonic getter timer");
102 static void service_app_terminate(void *data)
104 app_data *ad = (app_data *)data;
106 for (int i = 0; i < PIN_MAX; i++) {
107 if (ad->getter_timer[i]) {
108 ecore_timer_del(ad->getter_timer[i]);
111 resource_close_all();
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);