Modified internal value of the ultrasonic sensor
authorEunyoung Lee <ey928.lee@samsung.com>
Wed, 19 Jul 2017 07:34:36 +0000 (16:34 +0900)
committerEunyoung Lee <ey928.lee@samsung.com>
Wed, 19 Jul 2017 07:34:36 +0000 (16:34 +0900)
Change-Id: I41638df54ed300ff3aa59916345e1aedb9abf93c

src/resource/resource_ultrasonic_sensor.c

index 1dae292..2dd2b62 100644 (file)
@@ -52,34 +52,34 @@ static int _get_echo_value(int echo_pin_num)
        return value;
 }
 
-int resource_read_ultrasonic_sensor(int echo_pin_num, int trig_pin_num, double *out_value)
+int resource_read_ultrasonic_sensor(int trig_pin_num, int echo_pin_num, double *out_value)
 {
        int ret = 0;
        double duration = 0.0;
        struct timeval start_time, end_time, temp_start_time, temp_end_time;
 
-       if (!resource_get_info(echo_pin_num)->opened) {
-               _I("Ultrasonic sensor is initializing...");
+       if (!resource_get_info(trig_pin_num)->opened) {
+               _I("Ultrasonic sensor's trig is initializing...");
 
-               ret = peripheral_gpio_open(echo_pin_num, &resource_get_info(echo_pin_num)->sensor_h);
-               retv_if(!resource_get_info(echo_pin_num)->sensor_h, -1);
+               ret = peripheral_gpio_open(trig_pin_num, &resource_get_info(trig_pin_num)->sensor_h);
+               retv_if(!resource_get_info(trig_pin_num)->sensor_h, -1);
 
-               ret = peripheral_gpio_set_direction(resource_get_info(echo_pin_num)->sensor_h, PERIPHERAL_GPIO_DIRECTION_IN);
+               ret = peripheral_gpio_set_direction(resource_get_info(trig_pin_num)->sensor_h, PERIPHERAL_GPIO_DIRECTION_OUT);
                retv_if(ret != 0, -1);
 
-               resource_get_info(echo_pin_num)->opened = 1;
+               resource_get_info(trig_pin_num)->opened = 1;
        }
 
-       if (!resource_get_info(trig_pin_num)->opened) {
-               _I("Ultrasonic sensor is initializing...");
+       if (!resource_get_info(echo_pin_num)->opened) {
+               _I("Ultrasonic sensor's echo is initializing...");
 
-               ret = peripheral_gpio_open(trig_pin_num, &resource_get_info(trig_pin_num)->sensor_h);
-               retv_if(!resource_get_info(trig_pin_num)->sensor_h, -1);
+               ret = peripheral_gpio_open(echo_pin_num, &resource_get_info(echo_pin_num)->sensor_h);
+               retv_if(!resource_get_info(echo_pin_num)->sensor_h, -1);
 
-               ret = peripheral_gpio_set_direction(resource_get_info(trig_pin_num)->sensor_h, PERIPHERAL_GPIO_DIRECTION_IN);
+               ret = peripheral_gpio_set_direction(resource_get_info(echo_pin_num)->sensor_h, PERIPHERAL_GPIO_DIRECTION_IN);
                retv_if(ret != 0, -1);
 
-               resource_get_info(trig_pin_num)->opened = 1;
+               resource_get_info(echo_pin_num)->opened = 1;
        }
 
        ret = peripheral_gpio_write(resource_get_info(trig_pin_num)->sensor_h, 0);