/* * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved * * Contact: Jin Yoon * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include #include #include #include "thing_toggler.h" #define GPIO_NUM 25 bool service_app_create(void *data) { // Todo: add your code here. return true; } void service_app_terminate(void *data) { // Todo: add your code here. } void service_app_control(app_control_h app_control, void *data) { // Todo: add your code here. } static void service_app_lang_changed(app_event_info_h event_info, void *user_data) { /*APP_EVENT_LANGUAGE_CHANGED*/ } static void service_app_region_changed(app_event_info_h event_info, void *user_data) { /*APP_EVENT_REGION_FORMAT_CHANGED*/ } static void service_app_low_battery(app_event_info_h event_info, void *user_data) { /*APP_EVENT_LOW_BATTERY*/ } static void service_app_low_memory(app_event_info_h event_info, void *user_data) { /*APP_EVENT_LOW_MEMORY*/ } static void _control_led(peripheral_gpio_h gpio, int power_on) { dlog_print(DLOG_INFO, LOG_TAG, "Write [%d] into GPIO."); peripheral_gpio_write(gpio, power_on); } static gboolean _toggle_led(gpointer user_data) { static int current_status = 0; if (current_status) current_status = 0; else current_status = 1; _control_led(user_data, current_status); return TRUE; } int main(int argc, char* argv[]) { char ad[50] = {0,}; service_app_lifecycle_callback_s event_callback; app_event_handler_h handlers[5] = {NULL, }; peripheral_gpio_h gpio = NULL; guint timer_id = 0; int ret = 0; event_callback.create = service_app_create; event_callback.terminate = service_app_terminate; event_callback.app_control = service_app_control; service_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, service_app_low_battery, &ad); service_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, service_app_low_memory, &ad); service_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, service_app_lang_changed, &ad); service_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, service_app_region_changed, &ad); peripheral_gpio_open(GPIO_NUM, &gpio); if (!gpio) { dlog_print(DLOG_INFO, LOG_TAG, "The return value of peripheral_gpio_open is null."); return 1; } ret = peripheral_gpio_set_direction(gpio, PERIPHERAL_GPIO_DIRECTION_OUT); if (ret != 0) { dlog_print(DLOG_INFO, LOG_TAG, "Cannot set direction error."); return 1; } // Return value : the ID (greater than 0) of the event source. timer_id = g_timeout_add_seconds(1, _toggle_led, gpio); if (timer_id <= 0) { dlog_print(DLOG_INFO, LOG_TAG, "Timer id : %d", timer_id); return 1; } ret = service_app_main(argc, argv, &event_callback, ad); g_source_remove(timer_id); peripheral_gpio_close(gpio); return ret; }