2 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <service_app.h>
25 #include "resource/resource_infrared_motion.h"
26 #include "resource/resource_led.h"
29 #define TIMER_GATHER_INTERVAL (2.0f)
31 // Motion sensor information
32 #define SENSOR_MOTION_GPIO_NUMBER (18)
34 // LED sensor information
35 #define SENSOR_LED_GPIO_NUMBER (24)
37 Ecore_Timer *getter_timer = NULL;
39 static int _change_led_state(int state) {
42 // Write state to LED light
43 ret = resource_write_led(SENSOR_LED_GPIO_NUMBER, state);
45 _E("cannot write led data");
49 _I("LED State : %s", state ? "ON":"OFF");
54 static Eina_Bool _get_motion_set_led(void *user_data)
59 // Get value from motion sensor
60 ret = resource_read_infrared_motion(SENSOR_MOTION_GPIO_NUMBER, &value);
62 _E("cannot read data from the infrared motion sensor");
63 return ECORE_CALLBACK_CANCEL;
66 _I("Detected motion value : %u", value);
68 // Set LED light with value
69 _change_led_state(value);
71 return ECORE_CALLBACK_RENEW;
74 static bool service_app_create(void *user_data)
79 static void service_app_control(app_control_h app_control, void *user_data)
81 // Delete old timer if there is one
83 ecore_timer_del(getter_timer);
87 // Create a timer to call the given function in given period of time
88 getter_timer = ecore_timer_add(TIMER_GATHER_INTERVAL, _get_motion_set_led, user_data);
90 _E("Failed to add getter timer");
95 static void service_app_terminate(void *user_data)
99 ecore_timer_del(getter_timer);
103 // Turn off LED light with __set_led()
104 _change_led_state(0);
106 // Close Motion and LED resources
107 resource_close_infrared_motion();
108 resource_close_led();
113 int main(int argc, char *argv[])
115 service_app_lifecycle_callback_s event_callback;
117 event_callback.create = service_app_create;
118 event_callback.terminate = service_app_terminate;
119 event_callback.app_control = service_app_control;
121 return service_app_main(argc, argv, &event_callback, NULL);