2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Contact: Jeonghoon Park <jh1979.park@samsung.com>
6 * Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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.
22 #include <service_app.h>
26 typedef struct app_data_s {
30 static void service_app_control(app_control_h app_control, void *data)
35 static void service_app_lang_changed(app_event_info_h event_info, void *user_data)
40 static void service_app_region_changed(app_event_info_h event_info, void *user_data)
45 static void service_app_low_battery(app_event_info_h event_info, void *user_data)
50 static void service_app_low_memory(app_event_info_h event_info, void *user_data)
55 static inline int __get_r_val(int val)
63 static gboolean __control_dcmotor_cb(gpointer user_data)
65 static int value = -2000;
68 value = __get_r_val(value);
70 dc_motor_speed_set(DC_MOTOR_ID_L, 0);
71 dc_motor_speed_set(DC_MOTOR_ID_R, 0);
75 dc_motor_speed_set(DC_MOTOR_ID_L, value);
76 dc_motor_speed_set(DC_MOTOR_ID_R, value);
80 value2 = value + 1000;
82 value2 = value - 1000;
84 dc_motor_speed_set(DC_MOTOR_ID_L, value2);
85 dc_motor_speed_set(DC_MOTOR_ID_R, value2);
87 return G_SOURCE_CONTINUE;
90 static bool service_app_create(void *data)
94 ret = dc_motor_init();
96 _E("failed init motor, terminating this application");
100 ad->timer_id = g_timeout_add_seconds(10, __control_dcmotor_cb, ad);
105 static void service_app_terminate(void *data)
110 g_source_remove(ad->timer_id);
122 int main(int argc, char* argv[])
126 service_app_lifecycle_callback_s event_callback;
127 app_event_handler_h handlers[5] = {NULL, };
129 log_type_set(LOG_TYPE_DLOG);
131 ad = calloc(1, sizeof(app_data));
134 event_callback.create = service_app_create;
135 event_callback.terminate = service_app_terminate;
136 event_callback.app_control = service_app_control;
138 service_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY],
139 APP_EVENT_LOW_BATTERY, service_app_low_battery, &ad);
140 service_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY],
141 APP_EVENT_LOW_MEMORY, service_app_low_memory, &ad);
142 service_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED],
143 APP_EVENT_LANGUAGE_CHANGED, service_app_lang_changed, &ad);
144 service_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED],
145 APP_EVENT_REGION_FORMAT_CHANGED, service_app_region_changed, &ad);
147 ret = service_app_main(argc, argv, &event_callback, ad);
149 _E("failed to start app");