From 571f52c9d3797cea048458922eac543d8c21d649 Mon Sep 17 00:00:00 2001 From: jinxudong Date: Mon, 27 Feb 2023 14:23:46 +0800 Subject: [PATCH] feature: sensor: add force sensor A sensor of this type measures the force on it, and additionally compares the force with one or more specified thresholds. The sensor can output the force value directly. Moreover, it's usually applied as a press key. In that case, when it detects a force greater than some given threshold, a corresponding event is reported. Signed-off-by: jinxudong --- drivers/sensors/sensor.c | 3 ++- include/nuttx/sensors/sensor.h | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/drivers/sensors/sensor.c b/drivers/sensors/sensor.c index eab7ec94a5..ddebe96593 100644 --- a/drivers/sensors/sensor.c +++ b/drivers/sensors/sensor.c @@ -157,7 +157,8 @@ static const struct sensor_info_s g_sensor_info[] = {sizeof(struct sensor_gps_satellite), "gps_satellite"}, {sizeof(struct sensor_wake_gesture), "wake_gesture"}, {sizeof(struct sensor_cap), "cap"}, - {sizeof(struct sensor_gas), "gas"} + {sizeof(struct sensor_gas), "gas"}, + {sizeof(struct sensor_force), "force"}, }; static const struct file_operations g_sensor_fops = diff --git a/include/nuttx/sensors/sensor.h b/include/nuttx/sensors/sensor.h index 5f6830138c..e4edae2e7f 100644 --- a/include/nuttx/sensors/sensor.h +++ b/include/nuttx/sensors/sensor.h @@ -297,9 +297,19 @@ #define SENSOR_TYPE_GAS 33 +/* Force + * A sensor of this type measures the force on it, and additionally + * compares the force with one or more specified thresholds. The sensor + * can output the force value directly. Moreover, it's usually applied + * as a press key. In that case, when it detects a force greater than + * some given threshold, a corresponding event is reported. + */ + +#define SENSOR_TYPE_FORCE 34 + /* The total number of sensor */ -#define SENSOR_TYPE_COUNT 34 +#define SENSOR_TYPE_COUNT 35 /* The additional sensor open flags */ @@ -608,6 +618,13 @@ struct sensor_gas /* Type: Gas */ float gas_resistance; /* Gas resistance in kOhm */ }; +struct sensor_force /* Type: Force */ +{ + uint64_t timestamp; /* Unit is microseconds */ + float force; /* Force value, units is N */ + int32_t event; /* Force event */ +}; + /* The sensor lower half driver interface */ struct sensor_lowerhalf_s;