/* * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved * * 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 "log.h" #include "resource.h" #include "sensor-data.h" #define SENSORING_TIME_INTERVAL (0.5) // For using SmartThings SDK #define USE_ST_SDK #ifdef USE_ST_SDK #include "st-master.h" #include "st-resource.h" #endif /* USE_ST_SDK */ typedef struct app_data_s { Ecore_Timer *getter_timer; sensor_data *lidar_data; } app_data; static Eina_Bool _lidar_value_read_cb(void *user_data) { app_data *ad = user_data; int ret = 0; unsigned int lidar_value = 0; if (!ad) { _E("app_data is NULL"); service_app_exit(); } resource_write_led(5, 1); ret = resource_read_lidar_v3(&lidar_value); retv_if(ret != 0, ECORE_CALLBACK_RENEW); resource_write_led(5, 0); _D("distance : %u cm", lidar_value); sensor_data_set_uint(ad->lidar_data, lidar_value); return ECORE_CALLBACK_RENEW; } static void service_app_control(app_control_h app_control, void *user_data) { app_data *ad = user_data; if (ad->getter_timer) ecore_timer_del(ad->getter_timer); ad->getter_timer = ecore_timer_add(SENSORING_TIME_INTERVAL, _lidar_value_read_cb, ad); if (!ad->getter_timer) { _E("Failed to add getter timer"); return; } } static bool service_app_create(void *user_data) { app_data *ad = user_data; ad->lidar_data = sensor_data_new(SENSOR_DATA_TYPE_UINT); retv_if(!ad->lidar_data, false); #ifdef USE_ST_SDK if (st_master_create()) return false; if (st_resource_create(ad->lidar_data)) { st_master_destroy(); return false; } #endif return true; } static void service_app_terminate(void *user_data) { app_data *ad = user_data; #ifdef USE_ST_SDK st_resource_destroy(); st_master_destroy(); #endif sensor_data_free(ad->lidar_data); ad->lidar_data = NULL; if (ad->getter_timer) { ecore_timer_del(ad->getter_timer); ad->getter_timer = NULL; } resource_close_all(); } int main(int argc, char* argv[]) { app_data ad; int ret = 0; service_app_lifecycle_callback_s event_callback; ad.getter_timer = NULL; ad.lidar_data = NULL; event_callback.create = service_app_create; event_callback.terminate = service_app_terminate; event_callback.app_control = service_app_control; ret = service_app_main(argc, argv, &event_callback, &ad); return ret; }