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.
20 #include <service_app.h>
23 #include <peripheral_io.h>
25 #include "thing_toggler.h"
29 bool service_app_create(void *data)
31 // Todo: add your code here.
35 void service_app_terminate(void *data)
37 // Todo: add your code here.
40 void service_app_control(app_control_h app_control, void *data)
42 // Todo: add your code here.
45 static void service_app_lang_changed(app_event_info_h event_info, void *user_data)
47 /*APP_EVENT_LANGUAGE_CHANGED*/
50 static void service_app_region_changed(app_event_info_h event_info, void *user_data)
52 /*APP_EVENT_REGION_FORMAT_CHANGED*/
55 static void service_app_low_battery(app_event_info_h event_info, void *user_data)
57 /*APP_EVENT_LOW_BATTERY*/
60 static void service_app_low_memory(app_event_info_h event_info, void *user_data)
62 /*APP_EVENT_LOW_MEMORY*/
65 static void _control_led(peripheral_gpio_context_h dev, int power_on)
67 dlog_print(DLOG_INFO, LOG_TAG, "Write [%d] into GPIO.");
68 peripheral_gpio_write(dev, power_on);
71 static gboolean _toggle_led(gpointer user_data)
73 static int current_status = 0;
75 if (current_status) current_status = 0;
76 else current_status = 1;
78 _control_led(user_data, current_status);
83 int main(int argc, char* argv[])
86 service_app_lifecycle_callback_s event_callback;
87 app_event_handler_h handlers[5] = {NULL, };
88 peripheral_gpio_context_h dev = NULL;
92 event_callback.create = service_app_create;
93 event_callback.terminate = service_app_terminate;
94 event_callback.app_control = service_app_control;
96 service_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, service_app_low_battery, &ad);
97 service_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, service_app_low_memory, &ad);
98 service_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, service_app_lang_changed, &ad);
99 service_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, service_app_region_changed, &ad);
101 dev = peripheral_gpio_open(GPIO_NUM);
103 dlog_print(DLOG_INFO, LOG_TAG, "The return value of peripheral_gpio_open is null.");
107 ret = peripheral_gpio_set_direction(dev, PERIPHERAL_GPIO_DIRECTION_OUT);
109 dlog_print(DLOG_INFO, LOG_TAG, "Cannot set direction error.");
113 // Return value : the ID (greater than 0) of the event source.
114 timer_id = g_timeout_add_seconds(1, _toggle_led, dev);
116 dlog_print(DLOG_INFO, LOG_TAG, "Timer id : %d", timer_id);
120 ret = service_app_main(argc, argv, &event_callback, ad);
122 g_source_remove(timer_id);
123 peripheral_gpio_close(dev);