Code fixes. Some logs added 52/193952/1
authorMichal Skorupinski <m.skorupinsk@samsung.com>
Tue, 27 Nov 2018 18:58:19 +0000 (19:58 +0100)
committerMichal Skorupinski <m.skorupinsk@samsung.com>
Tue, 27 Nov 2018 18:58:19 +0000 (19:58 +0100)
Change-Id: I7b09eb2e59cc2ea558db5d61b19a1b24b02e82ee
Signed-off-by: Michal Skorupinski <m.skorupinsk@samsung.com>
inc/log.h
src/app.c
src/resource/resource_motor_driver_L298N.c

index 3aee407..974ca98 100644 (file)
--- a/inc/log.h
+++ b/inc/log.h
@@ -42,6 +42,9 @@
 #define _E(fmt, arg...) log_print(DLOG_ERROR, LOG_TAG, "[%s:%d] " fmt "\n", __func__, __LINE__, ##arg)
 #endif
 
+#define FUNCTION_START _D("\033[0;32m ***************************** START ***************************** \033[0m")
+#define FUNCTION_END   _D("\033[0;32m *****************************  END  ***************************** \033[0m")
+
 #define retvm_if(expr, val, fmt, arg...) do { \
        if (expr) { \
                _E(fmt, ##arg); \
index 8c4f0bd..0330a21 100644 (file)
--- a/src/app.c
+++ b/src/app.c
@@ -319,6 +319,8 @@ static void _initialize_config()
 
 static void _initialize_components(app_data *ad)
 {
+       FUNCTION_START;
+
        net_util_init();
        _initialize_config();
        cloud_communication_init();
@@ -338,10 +340,14 @@ static void _initialize_components(app_data *ad)
                        s_info.stering_pin, s_info.azimuth_pin, s_info.elevation_pin,
                        s_info.engine_1_forward_pin, s_info.engine_1_back_pin, s_info.engine_1_channel,
                        s_info.engine_2_forward_pin, s_info.engine_2_back_pin, s_info.engine_2_channel);
+
+       FUNCTION_END;
 }
 
 static bool service_app_create(void *data)
 {
+       FUNCTION_START;
+
        int ret = 0;
        app_data *ad = data;
 
@@ -351,6 +357,8 @@ static bool service_app_create(void *data)
        _D("-----------------------=======================================================================-----------------------");
        _D("-----------------------=======================================================================-----------------------");
 
+       _initialize_components(ad);
+
        /*
         * if you want to use default configuration,
         * Do not need to call resource_set_motor_driver_L298N_configuration(),
@@ -369,7 +377,6 @@ static bool service_app_create(void *data)
        }
 #endif
 
-       _initialize_components(ad);
        resource_lap_counter_init();
        cloud_communication_start(CLOUD_REQUESTS_FREQUENCY);
 
@@ -381,21 +388,24 @@ static bool service_app_create(void *data)
                        CONFIG_DEFAULT_LED_24BIT_INIT,
                        LED_COLOR_RED);
 
+       FUNCTION_END;
        return true;
 }
 
 static void service_app_control(app_control_h app_control, void *data)
 {
+       FUNCTION_START;
 
 #if ENABLE_MOTOR
        /* set speed 0, to reduce delay of initializing motor driver */
        resource_set_motor_driver_L298N_speed(MOTOR_ID_1, 0);
        resource_set_motor_driver_L298N_speed(MOTOR_ID_2, 0);
-       resource_set_servo_motor_value(s_info.stering_pin, STERING_SERVO_CENTER);
-       resource_set_servo_motor_value(s_info.elevation_pin, ELEVATION_MIN);
-       resource_set_servo_motor_value(s_info.azimuth_pin, (AZIMUTH_MIN + AZIMUTH_MAX) / 2);
+       resource_set_servo_motor_value(s_info.stering_pin, s_info.stering_center);
+       resource_set_servo_motor_value(s_info.elevation_pin, s_info.camera_elevation_min);
+       resource_set_servo_motor_value(s_info.azimuth_pin, s_info.camera_azimuth_center);
 #endif
 
+       FUNCTION_END;
        return;
 }
 
@@ -407,9 +417,9 @@ static void service_app_terminate(void *data)
                        CONFIG_DEFAULT_LED_24BIT_OFF,
                        LED_COLOR_NONE);
 
-       resource_set_servo_motor_value(s_info.stering_pin, STERING_SERVO_CENTER);
-       resource_set_servo_motor_value(s_info.elevation_pin, ELEVATION_MIN);
-       resource_set_servo_motor_value(s_info.azimuth_pin, (AZIMUTH_MIN + AZIMUTH_MAX) / 2);
+       resource_set_servo_motor_value(s_info.stering_pin, s_info.stering_center);
+       resource_set_servo_motor_value(s_info.elevation_pin, s_info.camera_elevation_min);
+       resource_set_servo_motor_value(s_info.azimuth_pin, s_info.camera_azimuth_center);
 
        resource_lap_counter_destroy();
        resource_led_destroy();
index 972a9ac..6d434dc 100644 (file)
@@ -95,6 +95,8 @@ static int __motor_brake_n_stop_by_id(motor_id_e id)
 
 static int __set_default_configuration_by_id(motor_id_e id)
 {
+       FUNCTION_START;
+
        unsigned int pin_1, pin_2, en_ch;
 
        switch (id) {
@@ -130,6 +132,7 @@ static int __set_default_configuration_by_id(motor_id_e id)
        g_md_h[id].en_ch = en_ch;
        g_md_h[id].motor_state = MOTOR_STATE_CONFIGURED;
 
+       FUNCTION_END;
        return 0;
 }
 
@@ -181,7 +184,7 @@ static int __init_motor_by_id(motor_id_e id)
                peripheral_gpio_set_direction(g_md_h[id].pin1_h,
                        PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW);
        else {
-               _E("failed to open Motor[%d] gpio pin1[%u]", id, g_md_h[id].pin_1);
+               _E("failed to open Motor[%d] gpio pin1[%u]. Error: %s", id, g_md_h[id].pin_1, get_error_message(ret));
                goto ERROR;
        }
 
@@ -190,7 +193,7 @@ static int __init_motor_by_id(motor_id_e id)
                peripheral_gpio_set_direction(g_md_h[id].pin2_h,
                        PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW);
        else {
-               _E("failed to open Motor[%d] gpio pin2[%u]", id, g_md_h[id].pin_2);
+               _E("failed to open Motor[%d] gpio pin2[%u]. Error: %s", id, g_md_h[id].pin_2, get_error_message(ret));
                goto ERROR;
        }
 
@@ -201,6 +204,8 @@ static int __init_motor_by_id(motor_id_e id)
 ERROR:
        resource_pca9685_fini(g_md_h[id].en_ch);
 
+       _E("Motor init error: %s", get_error_message(ret));
+
        if (g_md_h[id].pin1_h) {
                peripheral_gpio_close(g_md_h[id].pin1_h);
                g_md_h[id].pin1_h = NULL;