summaryrefslogtreecommitdiff
path: root/src/resource
diff options
context:
space:
mode:
Diffstat (limited to 'src/resource')
-rw-r--r--src/resource/resource_flame_sensor.c2
-rw-r--r--src/resource/resource_gas_detection_sensor.c2
-rw-r--r--src/resource/resource_illuminance_sensor.c5
-rw-r--r--src/resource/resource_infrared_motion_sensor.c2
-rw-r--r--src/resource/resource_infrared_obstacle_avoidance_sensor.c2
-rw-r--r--src/resource/resource_led.c4
-rwxr-xr-xsrc/resource/resource_rain_sensor.c2
-rw-r--r--src/resource/resource_sound_detection_sensor.c2
-rw-r--r--src/resource/resource_tilt_sensor.c2
-rw-r--r--src/resource/resource_touch_sensor.c2
-rw-r--r--src/resource/resource_ultrasonic_sensor.c27
-rw-r--r--src/resource/resource_vibration_sensor.c2
12 files changed, 33 insertions, 21 deletions
diff --git a/src/resource/resource_flame_sensor.c b/src/resource/resource_flame_sensor.c
index 9ff1c8a..ec30f78 100644
--- a/src/resource/resource_flame_sensor.c
+++ b/src/resource/resource_flame_sensor.c
@@ -36,7 +36,7 @@ void resource_close_flame_sensor(int pin_num)
resource_get_info(pin_num)->opened = 0;
}
-int resource_read_flame_sensor(int pin_num, int *out_value)
+int resource_read_flame_sensor(int pin_num, uint32_t *out_value)
{
int ret = PERIPHERAL_ERROR_NONE;
diff --git a/src/resource/resource_gas_detection_sensor.c b/src/resource/resource_gas_detection_sensor.c
index 97c283c..ebab0a0 100644
--- a/src/resource/resource_gas_detection_sensor.c
+++ b/src/resource/resource_gas_detection_sensor.c
@@ -36,7 +36,7 @@ void resource_close_gas_detection_sensor(int pin_num)
resource_get_info(pin_num)->opened = 0;
}
-int resource_read_gas_detection_sensor(int pin_num, int *out_value)
+int resource_read_gas_detection_sensor(int pin_num, uint32_t *out_value)
{
int ret = PERIPHERAL_ERROR_NONE;
diff --git a/src/resource/resource_illuminance_sensor.c b/src/resource/resource_illuminance_sensor.c
index 8d1d9d8..1bbf662 100644
--- a/src/resource/resource_illuminance_sensor.c
+++ b/src/resource/resource_illuminance_sensor.c
@@ -47,7 +47,7 @@ void resource_close_illuminance_sensor(void)
resource_sensor_s.opened = 0;
}
-int resource_read_illuminance_sensor(int i2c_bus, int *out_value)
+int resource_read_illuminance_sensor(int i2c_bus, uint32_t *out_value)
{
int ret = PERIPHERAL_ERROR_NONE;
unsigned char buf[10] = { 0, };
@@ -58,7 +58,8 @@ int resource_read_illuminance_sensor(int i2c_bus, int *out_value)
resource_sensor_s.opened = 1;
}
- ret = peripheral_i2c_write_byte(resource_sensor_s.sensor_h, GY30_CONT_HIGH_RES_MODE);
+ buf[0] = GY30_CONT_HIGH_RES_MODE;
+ ret = peripheral_i2c_write(resource_sensor_s.sensor_h, buf, 1);
retv_if(ret < 0, -1);
ret = peripheral_i2c_read(resource_sensor_s.sensor_h, buf, 2);
diff --git a/src/resource/resource_infrared_motion_sensor.c b/src/resource/resource_infrared_motion_sensor.c
index 6caaf9e..460fa45 100644
--- a/src/resource/resource_infrared_motion_sensor.c
+++ b/src/resource/resource_infrared_motion_sensor.c
@@ -36,7 +36,7 @@ void resource_close_infrared_motion_sensor(int pin_num)
resource_get_info(pin_num)->opened = 0;
}
-int resource_read_infrared_motion_sensor(int pin_num, int *out_value)
+int resource_read_infrared_motion_sensor(int pin_num, uint32_t *out_value)
{
int ret = PERIPHERAL_ERROR_NONE;
diff --git a/src/resource/resource_infrared_obstacle_avoidance_sensor.c b/src/resource/resource_infrared_obstacle_avoidance_sensor.c
index 1bbfb38..c5c43e8 100644
--- a/src/resource/resource_infrared_obstacle_avoidance_sensor.c
+++ b/src/resource/resource_infrared_obstacle_avoidance_sensor.c
@@ -36,7 +36,7 @@ void resource_close_infrared_obstacle_avoidance_sensor(int pin_num)
resource_get_info(pin_num)->opened = 0;
}
-int resource_read_infrared_obstacle_avoidance_sensor(int pin_num, int *out_value)
+int resource_read_infrared_obstacle_avoidance_sensor(int pin_num, uint32_t *out_value)
{
int ret = PERIPHERAL_ERROR_NONE;
diff --git a/src/resource/resource_led.c b/src/resource/resource_led.c
index 7c10836..341b71f 100644
--- a/src/resource/resource_led.c
+++ b/src/resource/resource_led.c
@@ -43,7 +43,7 @@ int resource_write_led(int pin_num, int write_value)
ret = peripheral_gpio_open(pin_num, &resource_get_info(pin_num)->sensor_h);
retv_if(!resource_get_info(pin_num)->sensor_h, -1);
- ret = peripheral_gpio_set_direction(resource_get_info(pin_num)->sensor_h, PERIPHERAL_GPIO_DIRECTION_OUT);
+ ret = peripheral_gpio_set_direction(resource_get_info(pin_num)->sensor_h, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW);
retv_if(ret != 0, -1);
resource_get_info(pin_num)->opened = 1;
@@ -53,7 +53,7 @@ int resource_write_led(int pin_num, int write_value)
ret = peripheral_gpio_write(resource_get_info(pin_num)->sensor_h, write_value);
retv_if(ret < 0, -1);
- _I("LED Value : %s", write_value ? "ON" : "OFF");
+ _I("LED Value : %s", write_value ? "ON":"OFF");
return 0;
}
diff --git a/src/resource/resource_rain_sensor.c b/src/resource/resource_rain_sensor.c
index 32e6daf..b73003f 100755
--- a/src/resource/resource_rain_sensor.c
+++ b/src/resource/resource_rain_sensor.c
@@ -34,7 +34,7 @@ void resource_close_rain_sensor(int pin_num)
resource_get_info(pin_num)->opened = 0;
}
-int resource_read_rain_sensor(int pin_num, int *out_value)
+int resource_read_rain_sensor(int pin_num, uint32_t *out_value)
{
int ret = PERIPHERAL_ERROR_NONE;
diff --git a/src/resource/resource_sound_detection_sensor.c b/src/resource/resource_sound_detection_sensor.c
index 1cf6a77..c03c7b8 100644
--- a/src/resource/resource_sound_detection_sensor.c
+++ b/src/resource/resource_sound_detection_sensor.c
@@ -36,7 +36,7 @@ void resource_close_sound_detection_sensor(int pin_num)
resource_get_info(pin_num)->opened = 0;
}
-int resource_read_sound_detection_sensor(int pin_num, int *out_value)
+int resource_read_sound_detection_sensor(int pin_num, uint32_t *out_value)
{
int ret = PERIPHERAL_ERROR_NONE;
diff --git a/src/resource/resource_tilt_sensor.c b/src/resource/resource_tilt_sensor.c
index 5a946c4..f47c3c7 100644
--- a/src/resource/resource_tilt_sensor.c
+++ b/src/resource/resource_tilt_sensor.c
@@ -36,7 +36,7 @@ void resource_close_tilt_sensor(int pin_num)
resource_get_info(pin_num)->opened = 0;
}
-int resource_read_tilt_sensor(int pin_num, int *out_value)
+int resource_read_tilt_sensor(int pin_num, uint32_t *out_value)
{
int ret = PERIPHERAL_ERROR_NONE;
diff --git a/src/resource/resource_touch_sensor.c b/src/resource/resource_touch_sensor.c
index 07be4be..fc946e4 100644
--- a/src/resource/resource_touch_sensor.c
+++ b/src/resource/resource_touch_sensor.c
@@ -36,7 +36,7 @@ void resource_close_touch_sensor(int pin_num)
resource_get_info(pin_num)->opened = 0;
}
-int resource_read_touch_sensor(int pin_num, int *out_value)
+int resource_read_touch_sensor(int pin_num, uint32_t *out_value)
{
int ret = PERIPHERAL_ERROR_NONE;
diff --git a/src/resource/resource_ultrasonic_sensor.c b/src/resource/resource_ultrasonic_sensor.c
index d749503..550caf6 100644
--- a/src/resource/resource_ultrasonic_sensor.c
+++ b/src/resource/resource_ultrasonic_sensor.c
@@ -48,26 +48,37 @@ void resource_close_ultrasonic_sensor_echo(int echo_pin_num)
resource_get_info(echo_pin_num)->opened = 0;
}
-static void _resource_read_ultrasonic_sensor_cb(gpio_isr_cb_s *data, void *user_data)
+static unsigned long long _get_timestamp(void)
+{
+ struct timespec t;
+ clock_gettime(CLOCK_REALTIME, &t);
+ return ((unsigned long long)(t.tv_sec)*1000000000LL + t.tv_nsec) / 1000;
+}
+
+static void _resource_read_ultrasonic_sensor_cb(peripheral_gpio_h gpio, peripheral_error_e error, void *user_data)
{
float dist = 0;
- static unsigned long long timestamp = 0;
+ uint32_t value;
+ static unsigned long long prev = 0;
+ unsigned long long now = _get_timestamp();
resource_read_s *resource_read_info = user_data;
ret_if(!resource_read_info);
ret_if(!resource_read_info->cb);
- if (timestamp > 0 && data->value == 0) {
- dist = data->timestamp - timestamp;
+ peripheral_gpio_read(gpio, &value);
+
+ if (prev > 0 && value == 0) {
+ dist = now - prev;
dist = (dist * 34300) / 2000000;
_I("Measured Distance : %0.2fcm\n", dist);
resource_read_info->cb(dist, resource_read_info->data);
- peripheral_gpio_unregister_cb(resource_get_info(resource_read_info->pin_num)->sensor_h);
+ peripheral_gpio_unset_interrupted_cb(resource_get_info(resource_read_info->pin_num)->sensor_h);
free(resource_read_info);
}
- timestamp = data->timestamp;
+ prev = now;
}
int resource_read_ultrasonic_sensor(int trig_pin_num, int echo_pin_num, resource_read_cb cb, void *data)
@@ -87,7 +98,7 @@ int resource_read_ultrasonic_sensor(int trig_pin_num, int echo_pin_num, resource
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(trig_pin_num)->sensor_h, PERIPHERAL_GPIO_DIRECTION_OUT);
+ ret = peripheral_gpio_set_direction(resource_get_info(trig_pin_num)->sensor_h, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW);
retv_if(ret != 0, -1);
resource_get_info(trig_pin_num)->opened = 1;
@@ -111,7 +122,7 @@ int resource_read_ultrasonic_sensor(int trig_pin_num, int echo_pin_num, resource
}
if (resource_get_info(echo_pin_num)->sensor_h) {
- ret = peripheral_gpio_register_cb(resource_get_info(echo_pin_num)->sensor_h, _resource_read_ultrasonic_sensor_cb, resource_read_info);
+ ret = peripheral_gpio_set_interrupted_cb(resource_get_info(echo_pin_num)->sensor_h, _resource_read_ultrasonic_sensor_cb, resource_read_info);
retv_if(ret != 0, -1);
}
diff --git a/src/resource/resource_vibration_sensor.c b/src/resource/resource_vibration_sensor.c
index 8e59882..686e8f7 100644
--- a/src/resource/resource_vibration_sensor.c
+++ b/src/resource/resource_vibration_sensor.c
@@ -36,7 +36,7 @@ void resource_close_vibration_sensor(int pin_num)
resource_get_info(pin_num)->opened = 0;
}
-int resource_read_vibration_sensor(int pin_num, int *out_value)
+int resource_read_vibration_sensor(int pin_num, uint32_t *out_value)
{
int ret = PERIPHERAL_ERROR_NONE;