From 67bbc14d906f5788b10e32258c991a2d9afb1046 Mon Sep 17 00:00:00 2001 From: Seoghyun Kang Date: Mon, 17 Jun 2019 13:36:29 +0900 Subject: Add a simple Lidar feature Change-Id: I5245a00cd230ef2dd1288cd9dc8dc5deac559f34 --- src/smart-ruler.c | 29 +++++++++++++++++++++++++++-- 1 file 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 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; -- cgit v1.2.3