Merge pull request #2404 from Guozhanxin/temp_1

完善 sensor 框架
This commit is contained in:
Bernard Xiong 2019-03-08 20:36:26 +08:00 committed by GitHub
commit d9a8cc71f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 6 deletions

View File

@ -43,6 +43,11 @@ void rt_sensor_cb(rt_sensor_t sen)
{
return;
}
if (sen->irq_handle != RT_NULL)
{
sen->irq_handle(sen);
}
/* The buffer is not empty. Read the data in the buffer first */
if (sen->data_len > 0)

View File

@ -68,6 +68,7 @@ extern "C" {
#define RT_SENSOR_UNIT_HZ (9) /* Frequency unit: HZ */
#define RT_SENSOR_UNIT_ONE (10) /* Dimensionless quantity unit: 1 */
#define RT_SENSOR_UNIT_BPM (11) /* Heart rate unit: bpm */
#define RT_SENSOR_UNIT_MM (12) /* Distance unit: mm */
/* Sensor communication interface types */
@ -131,6 +132,8 @@ struct rt_sensor_config
rt_int32_t range; /* sensor range of measurement */
};
typedef struct rt_sensor_device *rt_sensor_t;
struct rt_sensor_device
{
struct rt_device parent; /* The standard device */
@ -144,8 +147,9 @@ struct rt_sensor_device
const struct rt_sensor_ops *ops; /* The sensor ops */
struct rt_sensor_module *module; /* The sensor module */
rt_err_t (*irq_handle)(rt_sensor_t sensor); /* Called when an interrupt is generated, registered by the driver */
};
typedef struct rt_sensor_device *rt_sensor_t;
struct rt_sensor_module
{

View File

@ -44,6 +44,9 @@ static void sensor_show_data(rt_size_t num, rt_sensor_t sensor, struct rt_sensor
case RT_SENSOR_CLASS_STEP:
LOG_I("num:%3d, step:%5d, timestamp:%5d", num, sensor_data->data.step, sensor_data->timestamp);
break;
case RT_SENSOR_CLASS_PROXIMITY:
LOG_I("num:%3d, distance:%5d, timestamp:%5d", num, sensor_data->data.proximity, sensor_data->timestamp);
break;
default:
break;
}
@ -96,6 +99,12 @@ static void sensor_fifo(int argc, char **argv)
return;
}
sensor = (rt_sensor_t)dev;
if (rt_device_open(dev, RT_DEVICE_FLAG_FIFO_RX) != RT_EOK)
{
LOG_E("open device failed!");
return;
}
if (sensor_rx_sem == RT_NULL)
{
@ -117,11 +126,6 @@ static void sensor_fifo(int argc, char **argv)
rt_device_set_rx_indicate(dev, rx_callback);
if (rt_device_open(dev, RT_DEVICE_FLAG_FIFO_RX) != RT_EOK)
{
LOG_E("open device failed!");
return;
}
rt_device_control(dev, RT_SENSOR_CTRL_SET_ODR, (void *)20);
}
#ifdef FINSH_USING_MSH