2 * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
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.
19 #include <service_app.h>
23 #include "sensor-data.h"
25 #define SENSORING_TIME_INTERVAL (0.5)
27 // For using SmartThings SDK
31 #include "st-master.h"
32 #include "st-resource.h"
33 #endif /* USE_ST_SDK */
35 typedef struct app_data_s {
36 Ecore_Timer *getter_timer;
37 sensor_data *lidar_data;
40 static Eina_Bool _lidar_value_read_cb(void *user_data)
42 app_data *ad = user_data;
45 unsigned int lidar_value = 0;
48 _E("app_data is NULL");
52 resource_write_led(5, 1);
53 ret = resource_read_lidar_v3(&lidar_value);
54 retv_if(ret != 0, ECORE_CALLBACK_RENEW);
55 resource_write_led(5, 0);
57 _D("distance : %u cm", lidar_value);
58 sensor_data_set_uint(ad->lidar_data, lidar_value);
60 return ECORE_CALLBACK_RENEW;
63 static void service_app_control(app_control_h app_control, void *user_data)
65 app_data *ad = user_data;
68 ecore_timer_del(ad->getter_timer);
70 ad->getter_timer = ecore_timer_add(SENSORING_TIME_INTERVAL, _lidar_value_read_cb, ad);
71 if (!ad->getter_timer) {
72 _E("Failed to add getter timer");
77 static bool service_app_create(void *user_data)
79 app_data *ad = user_data;
81 ad->lidar_data = sensor_data_new(SENSOR_DATA_TYPE_UINT);
82 retv_if(!ad->lidar_data, false);
85 if (st_master_create())
88 if (st_resource_create(ad->lidar_data)) {
97 static void service_app_terminate(void *user_data)
99 app_data *ad = user_data;
102 st_resource_destroy();
106 sensor_data_free(ad->lidar_data);
107 ad->lidar_data = NULL;
109 if (ad->getter_timer) {
110 ecore_timer_del(ad->getter_timer);
111 ad->getter_timer = NULL;
114 resource_close_all();
117 int main(int argc, char* argv[])
121 service_app_lifecycle_callback_s event_callback;
123 ad.getter_timer = NULL;
124 ad.lidar_data = NULL;
126 event_callback.create = service_app_create;
127 event_callback.terminate = service_app_terminate;
128 event_callback.app_control = service_app_control;
130 ret = service_app_main(argc, argv, &event_callback, &ad);