summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSeoghyun Kang <sh0708.kang@samsung.com>2019-06-17 13:36:29 +0900
committerSeoghyun Kang <sh0708.kang@samsung.com>2019-06-17 13:38:36 +0900
commit67bbc14d906f5788b10e32258c991a2d9afb1046 (patch)
tree9fd2d1b2b7b6eb3ba8602c46e1bc40b7b77dc526
parent94de57fad0c4f9ce373d79e6a3379fc145c8675a (diff)
downloadsmart-ruler-sdc.tar.gz
smart-ruler-sdc.tar.bz2
smart-ruler-sdc.zip
Add a simple Lidar featuresdc
Change-Id: I5245a00cd230ef2dd1288cd9dc8dc5deac559f34
-rw-r--r--src/smart-ruler.c29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/smart-ruler.c b/src/smart-ruler.c
index 99f76e6..5ad25cc 100644
--- a/src/smart-ruler.c
+++ b/src/smart-ruler.c
@@ -6,13 +6,31 @@
#include <Ecore.h>
peripheral_gpio_h led_sensor_h;
+peripheral_i2c_h lidar_sensor_h;
Ecore_Timer *getter_timer;
+#define I2C_BUS_DEF (1)
+#define LLV3_I2C_ADDR_DEF (0x62)
+#define LLV3_ACQ_CMD (0x00)
+#define LLv3_DISTANCE_HIGH (0x0f)
+#define LLv3_DISTANCE_LOW (0x10)
+#define CMD_WITH_BIAS_CORRECTION (0x04)
+
static Eina_Bool _lidar_value_read_cb(void *data)
{
- dlog_print(DLOG_INFO, LOG_TAG, "The timer is called.");
+ unsigned char val_h = 0;
+ unsigned char val_l = 0;
+ unsigned int value = 0;
+
+ peripheral_i2c_write_register_byte(lidar_sensor_h, LLV3_ACQ_CMD, CMD_WITH_BIAS_CORRECTION);
+ peripheral_i2c_read_register_byte(lidar_sensor_h, LLv3_DISTANCE_HIGH, &val_h);
+ peripheral_i2c_read_register_byte(lidar_sensor_h, LLv3_DISTANCE_LOW, &val_l);
+
+ value = ((val_h << 8) | val_l);
- return ECORE_CALLBACK_RENEW;
+ dlog_print(DLOG_INFO, LOG_TAG, "The distance is %d cm.", value);
+
+ return ECORE_CALLBACK_RENEW;
}
bool service_app_create(void *data)
@@ -22,6 +40,9 @@ bool service_app_create(void *data)
peripheral_gpio_set_direction(led_sensor_h, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW);
peripheral_gpio_write(led_sensor_h, 1);
+ // Open a Lidar
+ peripheral_i2c_open(I2C_BUS_DEF, LLV3_I2C_ADDR_DEF, &lidar_sensor_h);
+
// Start a Timer
getter_timer = ecore_timer_add(1.0, _lidar_value_read_cb, data);
@@ -34,6 +55,10 @@ void service_app_terminate(void *data)
peripheral_gpio_close(led_sensor_h);
led_sensor_h = NULL;
+ // Close the Lidar
+ peripheral_i2c_close(lidar_sensor_h);
+ lidar_sensor_h = NULL;
+
// Delete the Timer
ecore_timer_del(getter_timer);
getter_timer = NULL;