struct _resource_s {
int opened;
peripheral_gpio_h sensor_h;
+ void (*close) (int);
};
typedef struct _resource_s resource_s;
#include "log.h"
#include "resource.h"
-static resource_s resource_info[PIN_MAX] = { {0, NULL}, };
+static resource_s resource_info[PIN_MAX] = { {0, NULL, NULL}, };
resource_s *resource_get_info(int pin_num)
{
for (i = 0; i < PIN_MAX; i++) {
if (!resource_info[i].opened) continue;
_I("GPIO[%d] is closing...", i);
- peripheral_gpio_close(resource_info[i].sensor_h);
- resource_info[i].opened = 0;
+
+ if (resource_info[i].close)
+ resource_info[i].close(i);
}
resource_close_illuminance_sensor();
}
retv_if(ret != 0, -1);
resource_get_info(pin_num)->opened = 1;
+ resource_get_info(pin_num)->close = resource_close_infrared_motion_sensor;
}
ret = peripheral_gpio_read(resource_get_info(pin_num)->sensor_h, out_value);
retv_if(ret != 0, -1);
resource_get_info(pin_num)->opened = 1;
+ resource_get_info(pin_num)->close = resource_close_infrared_obstacle_avoidance_sensor;
}
ret = peripheral_gpio_read(resource_get_info(pin_num)->sensor_h, out_value);
retv_if(ret != 0, -1);
resource_get_info(pin_num)->opened = 1;
+ resource_get_info(pin_num)->close = resource_close_led;
}
ret = peripheral_gpio_write(resource_get_info(pin_num)->sensor_h, write_value);
retv_if(ret != 0, -1);
resource_get_info(pin_num)->opened = 1;
+ resource_get_info(pin_num)->close = resource_close_touch_sensor;
}
ret = peripheral_gpio_read(resource_get_info(pin_num)->sensor_h, out_value);
#include "log.h"
#include "resource_internal.h"
-void resource_close_ultrasonic_sensor(int trig_pin_num, int echo_pin_num)
+void resource_close_ultrasonic_sensor_trig(int trig_pin_num)
{
- if (!resource_get_info(echo_pin_num)->opened) return;
if (!resource_get_info(trig_pin_num)->opened) return;
- _I("Ultrasonic sensor is finishing...");
+ _I("Ultrasonic sensor's trig is finishing...");
peripheral_gpio_close(resource_get_info(trig_pin_num)->sensor_h);
- peripheral_gpio_close(resource_get_info(echo_pin_num)->sensor_h);
-
resource_get_info(trig_pin_num)->opened = 0;
+}
+
+void resource_close_ultrasonic_sensor_echo(int echo_pin_num)
+{
+ if (!resource_get_info(echo_pin_num)->opened) return;
+
+ _I("Ultrasonic sensor's echo is finishing...");
+
+ peripheral_gpio_close(resource_get_info(echo_pin_num)->sensor_h);
resource_get_info(echo_pin_num)->opened = 0;
}
retv_if(ret != 0, -1);
resource_get_info(trig_pin_num)->opened = 1;
+ resource_get_info(trig_pin_num)->close = resource_close_ultrasonic_sensor_trig;
}
if (!resource_get_info(echo_pin_num)->opened) {
retv_if(ret != 0, -1);
resource_get_info(echo_pin_num)->opened = 1;
+ resource_get_info(echo_pin_num)->close = resource_close_ultrasonic_sensor_echo;
}
if (resource_get_info(echo_pin_num)->sensor_h) {