From 7db27345c287fa9d0154237acfb5c1c2b0c10012 Mon Sep 17 00:00:00 2001 From: Willian Chan Date: Tue, 16 Jul 2019 18:29:05 +0800 Subject: [PATCH 1/2] [component][drivers][sensors]Increase the output of sensor information Signed-off-by: Willian Chan --- components/drivers/sensors/sensor.h | 1 + components/drivers/sensors/sensor_cmd.c | 100 +++++++++++++++++++++--- 2 files changed, 89 insertions(+), 12 deletions(-) diff --git a/components/drivers/sensors/sensor.h b/components/drivers/sensors/sensor.h index a9b6684457..9c6e5ecc55 100755 --- a/components/drivers/sensors/sensor.h +++ b/components/drivers/sensors/sensor.h @@ -55,6 +55,7 @@ extern "C" { #define RT_SENSOR_VENDOR_SEMTECH (4) /* Semtech */ #define RT_SENSOR_VENDOR_GOERTEK (5) /* Goertek */ #define RT_SENSOR_VENDOR_MIRAMEMS (6) /* MiraMEMS */ +#define RT_SENSOR_VENDOR_DALLAS (7) /* Dallas */ /* Sensor unit types */ diff --git a/components/drivers/sensors/sensor_cmd.c b/components/drivers/sensors/sensor_cmd.c index ea9e56a3d3..ec9470386d 100755 --- a/components/drivers/sensors/sensor_cmd.c +++ b/components/drivers/sensors/sensor_cmd.c @@ -4,8 +4,9 @@ * SPDX-License-Identifier: Apache-2.0 * * Change Logs: - * Date Author Notes - * 2019-01-31 flybreak first version + * Date Author Notes + * 2019-01-31 flybreak first version + * 2019-07-16 WillianChan Increase the output of sensor information */ #include "sensor.h" @@ -55,7 +56,7 @@ static void sensor_show_data(rt_size_t num, rt_sensor_t sensor, struct rt_sensor } } -static rt_err_t rx_callback(rt_device_t dev, rt_size_t size) +rt_err_t rx_callback(rt_device_t dev, rt_size_t size) { rt_sem_release(sensor_rx_sem); return 0; @@ -63,15 +64,15 @@ static rt_err_t rx_callback(rt_device_t dev, rt_size_t size) static void sensor_fifo_rx_entry(void *parameter) { - rt_device_t dev = (rt_device_t)parameter; - rt_sensor_t sensor = (rt_sensor_t)parameter; + rt_device_t dev = parameter; + rt_sensor_t sensor = parameter; struct rt_sensor_data *data = RT_NULL; struct rt_sensor_info info; rt_size_t res, i; rt_device_control(dev, RT_SENSOR_CTRL_GET_INFO, &info); - data = (struct rt_sensor_data *)rt_malloc(sizeof(struct rt_sensor_data) * info.fifo_max); + data = rt_malloc(sizeof(struct rt_sensor_data) * info.fifo_max); if (data == RT_NULL) { LOG_E("Memory allocation failed!"); @@ -137,8 +138,8 @@ MSH_CMD_EXPORT(sensor_fifo, Sensor fifo mode test function); static void sensor_irq_rx_entry(void *parameter) { - rt_device_t dev = (rt_device_t)parameter; - rt_sensor_t sensor = (rt_sensor_t)parameter; + rt_device_t dev = parameter; + rt_sensor_t sensor = parameter; struct rt_sensor_data data; rt_size_t res, i = 0; @@ -268,13 +269,88 @@ static void sensor(int argc, char **argv) else if (!strcmp(argv[1], "info")) { struct rt_sensor_info info; + if (dev == RT_NULL) + { + LOG_W("Please probe sensor device first!"); + return ; + } rt_device_control(dev, RT_SENSOR_CTRL_GET_INFO, &info); - rt_kprintf("vendor :%d\n", info.vendor); - rt_kprintf("model :%s\n", info.model); - rt_kprintf("unit :%d\n", info.unit); + switch (info.vendor) + { + case 0: + rt_kprintf("vendor :unknown vendor\n"); + break; + case 1: + rt_kprintf("vendor :STMicroelectronics\n"); + break; + case 2: + rt_kprintf("vendor :Bosch\n"); + break; + case 3: + rt_kprintf("vendor :Invensense\n"); + break; + case 4: + rt_kprintf("vendor :Semtech\n"); + break; + case 5: + rt_kprintf("vendor :Goertek\n"); + break; + case 6: + rt_kprintf("vendor :MiraMEMS\n"); + break; + case 7: + rt_kprintf("vendor :Dallas\n"); + break; + } + rt_kprintf("model :%s\n", info.model); + switch (info.unit) + { + case 0: + rt_kprintf("unit :none\n"); + break; + case 1: + rt_kprintf("unit :mG\n"); + break; + case 2: + rt_kprintf("unit :mdps\n"); + break; + case 3: + rt_kprintf("unit :mGauss\n"); + break; + case 4: + rt_kprintf("unit :lux\n"); + break; + case 5: + rt_kprintf("unit :cm\n"); + break; + case 6: + rt_kprintf("unit :pa\n"); + break; + case 7: + rt_kprintf("unit :permillage\n"); + break; + case 8: + rt_kprintf("unit :Celsius\n"); + break; + case 9: + rt_kprintf("unit :HZ\n"); + break; + case 10: + rt_kprintf("unit :1\n"); + break; + case 11: + rt_kprintf("unit :bpm\n"); + break; + case 12: + rt_kprintf("unit :mm\n"); + break; + case 13: + rt_kprintf("unit :mN\n"); + break; + } rt_kprintf("range_max :%d\n", info.range_max); rt_kprintf("range_min :%d\n", info.range_min); - rt_kprintf("period_min:%d\n", info.period_min); + rt_kprintf("period_min:%dms\n", info.period_min); rt_kprintf("fifo_max :%d\n", info.fifo_max); } else if (!strcmp(argv[1], "read")) From 06b4a0611d0816373e72b0bdca6562265f1d1b9e Mon Sep 17 00:00:00 2001 From: Willian Chan Date: Wed, 17 Jul 2019 09:26:40 +0800 Subject: [PATCH 2/2] [component][drivers][sensors]Fix compilation warnings Signed-off-by: Willian Chan --- components/drivers/sensors/sensor_cmd.c | 56 ++++++++++++------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/components/drivers/sensors/sensor_cmd.c b/components/drivers/sensors/sensor_cmd.c index ec9470386d..dd1aa1ef95 100755 --- a/components/drivers/sensors/sensor_cmd.c +++ b/components/drivers/sensors/sensor_cmd.c @@ -56,7 +56,7 @@ static void sensor_show_data(rt_size_t num, rt_sensor_t sensor, struct rt_sensor } } -rt_err_t rx_callback(rt_device_t dev, rt_size_t size) +static rt_err_t rx_callback(rt_device_t dev, rt_size_t size) { rt_sem_release(sensor_rx_sem); return 0; @@ -64,15 +64,15 @@ rt_err_t rx_callback(rt_device_t dev, rt_size_t size) static void sensor_fifo_rx_entry(void *parameter) { - rt_device_t dev = parameter; - rt_sensor_t sensor = parameter; + rt_device_t dev = (rt_device_t)parameter; + rt_sensor_t sensor = (rt_sensor_t)parameter; struct rt_sensor_data *data = RT_NULL; struct rt_sensor_info info; rt_size_t res, i; rt_device_control(dev, RT_SENSOR_CTRL_GET_INFO, &info); - data = rt_malloc(sizeof(struct rt_sensor_data) * info.fifo_max); + data = (struct rt_sensor_data *)rt_malloc(sizeof(struct rt_sensor_data) * info.fifo_max); if (data == RT_NULL) { LOG_E("Memory allocation failed!"); @@ -138,8 +138,8 @@ MSH_CMD_EXPORT(sensor_fifo, Sensor fifo mode test function); static void sensor_irq_rx_entry(void *parameter) { - rt_device_t dev = parameter; - rt_sensor_t sensor = parameter; + rt_device_t dev = (rt_device_t)parameter; + rt_sensor_t sensor = (rt_sensor_t)parameter; struct rt_sensor_data data; rt_size_t res, i = 0; @@ -277,74 +277,74 @@ static void sensor(int argc, char **argv) rt_device_control(dev, RT_SENSOR_CTRL_GET_INFO, &info); switch (info.vendor) { - case 0: + case RT_SENSOR_VENDOR_UNKNOWN: rt_kprintf("vendor :unknown vendor\n"); break; - case 1: + case RT_SENSOR_VENDOR_STM: rt_kprintf("vendor :STMicroelectronics\n"); break; - case 2: + case RT_SENSOR_VENDOR_BOSCH: rt_kprintf("vendor :Bosch\n"); break; - case 3: + case RT_SENSOR_VENDOR_INVENSENSE: rt_kprintf("vendor :Invensense\n"); break; - case 4: + case RT_SENSOR_VENDOR_SEMTECH: rt_kprintf("vendor :Semtech\n"); break; - case 5: + case RT_SENSOR_VENDOR_GOERTEK: rt_kprintf("vendor :Goertek\n"); break; - case 6: + case RT_SENSOR_VENDOR_MIRAMEMS: rt_kprintf("vendor :MiraMEMS\n"); break; - case 7: + case RT_SENSOR_VENDOR_DALLAS: rt_kprintf("vendor :Dallas\n"); break; } rt_kprintf("model :%s\n", info.model); switch (info.unit) { - case 0: + case RT_SENSOR_UNIT_NONE: rt_kprintf("unit :none\n"); break; - case 1: + case RT_SENSOR_UNIT_MG: rt_kprintf("unit :mG\n"); break; - case 2: + case RT_SENSOR_UNIT_MDPS: rt_kprintf("unit :mdps\n"); break; - case 3: + case RT_SENSOR_UNIT_MGAUSS: rt_kprintf("unit :mGauss\n"); break; - case 4: + case RT_SENSOR_UNIT_LUX: rt_kprintf("unit :lux\n"); break; - case 5: + case RT_SENSOR_UNIT_CM: rt_kprintf("unit :cm\n"); break; - case 6: + case RT_SENSOR_UNIT_PA: rt_kprintf("unit :pa\n"); break; - case 7: + case RT_SENSOR_UNIT_PERMILLAGE: rt_kprintf("unit :permillage\n"); break; - case 8: + case RT_SENSOR_UNIT_DCELSIUS: rt_kprintf("unit :Celsius\n"); break; - case 9: + case RT_SENSOR_UNIT_HZ: rt_kprintf("unit :HZ\n"); break; - case 10: + case RT_SENSOR_UNIT_ONE: rt_kprintf("unit :1\n"); break; - case 11: + case RT_SENSOR_UNIT_BPM: rt_kprintf("unit :bpm\n"); break; - case 12: + case RT_SENSOR_UNIT_MM: rt_kprintf("unit :mm\n"); break; - case 13: + case RT_SENSOR_UNIT_MN: rt_kprintf("unit :mN\n"); break; }