diff --git a/drivers/sensors/bmi088_uorb.c b/drivers/sensors/bmi088_uorb.c index 57acb836349..b3497568326 100644 --- a/drivers/sensors/bmi088_uorb.c +++ b/drivers/sensors/bmi088_uorb.c @@ -735,8 +735,7 @@ static int bmi088_register_accel(int devno, #endif priv->lower.ops = &g_bmi088_accel_ops; - priv->lower.type = SENSOR_TYPE_ACCELEROMETER; - priv->lower.uncalibrated = true; + priv->lower.type = SENSOR_TYPE_ACCELEROMETER_UNCALIBRATED; priv->interval = BMI088_DEFAULT_INTERVAL; priv->lower.nbuffer = 1; @@ -818,8 +817,7 @@ static int bmi088_register_gyro(int devno, #endif priv->lower.ops = &g_bmi088_gyro_ops; - priv->lower.type = SENSOR_TYPE_GYROSCOPE; - priv->lower.uncalibrated = true; + priv->lower.type = SENSOR_TYPE_GYROSCOPE_UNCALIBRATED; priv->interval = BMI088_DEFAULT_INTERVAL; priv->lower.nbuffer = 1; diff --git a/drivers/sensors/bmi160_uorb.c b/drivers/sensors/bmi160_uorb.c index fff3c713f5c..0de92f12c61 100644 --- a/drivers/sensors/bmi160_uorb.c +++ b/drivers/sensors/bmi160_uorb.c @@ -602,8 +602,7 @@ static int bmi160_register_accel(int devno, #endif priv->lower.ops = &g_bmi160_accel_ops; - priv->lower.type = SENSOR_TYPE_ACCELEROMETER; - priv->lower.uncalibrated = true; + priv->lower.type = SENSOR_TYPE_ACCELEROMETER_UNCALIBRATED; priv->interval = BMI160_DEFAULT_INTERVAL; priv->lower.nbuffer = 1; @@ -687,8 +686,7 @@ static int bmi160_register_gyro(int devno, #endif priv->lower.ops = &g_bmi160_gyro_ops; - priv->lower.type = SENSOR_TYPE_GYROSCOPE; - priv->lower.uncalibrated = true; + priv->lower.type = SENSOR_TYPE_GYROSCOPE_UNCALIBRATED; priv->interval = BMI160_DEFAULT_INTERVAL; priv->lower.nbuffer = 1; diff --git a/drivers/sensors/ds18b20_uorb.c b/drivers/sensors/ds18b20_uorb.c index 2224d089bce..8430343726f 100644 --- a/drivers/sensors/ds18b20_uorb.c +++ b/drivers/sensors/ds18b20_uorb.c @@ -973,7 +973,6 @@ int ds18b20_register(int devno, FAR struct onewire_master_s *onewire, #endif tmp->lower.ops = &g_ds18b20_ops; tmp->lower.type = SENSOR_TYPE_AMBIENT_TEMPERATURE; - tmp->lower.uncalibrated = false; tmp->lower.nbuffer = 1; ret = sensor_register(&tmp->lower, devno); if (ret < 0) diff --git a/drivers/sensors/goldfish_sensor_uorb.c b/drivers/sensors/goldfish_sensor_uorb.c index 736293afe54..f108e7a5e3c 100644 --- a/drivers/sensors/goldfish_sensor_uorb.c +++ b/drivers/sensors/goldfish_sensor_uorb.c @@ -52,7 +52,7 @@ #define GOLDFISH_PRESSURE 7 #define GOLDFISH_RELATIVE_HUMIDITY 8 #define GOLDFISH_MAGNETIC_FIELD_UNCALIBRATED 9 -#define GOLDFISH_GYROSCOPE_FIELD_UNCALIBRATED 10 +#define GOLDFISH_GYROSCOPE_UNCALIBRATED 10 #define GOLDFISH_HINGE_ANGLE0 11 #define GOLDFISH_HINGE_ANGLE1 12 #define GOLDFISH_HINGE_ANGLE2 13 @@ -620,45 +620,27 @@ static int goldfish_get_priv(FAR struct sensor_lowerhalf_s *lower, { switch (lower->type) { + case SENSOR_TYPE_ACCELEROMETER_UNCALIBRATED: + priv = container_of(lower, struct goldfish_sensor_s, + lower_accel_uncalibrated); + return GOLDFISH_ACCELERATION_UNCALIBRATED; case SENSOR_TYPE_ACCELEROMETER: - if (lower->uncalibrated) - { - *priv = container_of(lower, struct goldfish_sensor_s, - lower_accel_uncalibrated); - return GOLDFISH_ACCELERATION_UNCALIBRATED; - } - else - { - *priv = container_of(lower, struct goldfish_sensor_s, lower_accel); - return GOLDFISH_ACCELERATION; - } - + priv = container_of(lower, struct goldfish_sensor_s, lower_accel); + return GOLDFISH_ACCELERATION; + case SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED: + priv = container_of(lower, struct goldfish_sensor_s, + lower_mag_uncalibrated); + return GOLDFISH_MAGNETIC_FIELD_UNCALIBRATED; case SENSOR_TYPE_MAGNETIC_FIELD: - if (lower->uncalibrated) - { - *priv = container_of(lower, struct goldfish_sensor_s, - lower_mag_uncalibrated); - return GOLDFISH_MAGNETIC_FIELD_UNCALIBRATED; - } - else - { - *priv = container_of(lower, struct goldfish_sensor_s, lower_mag); - return GOLDFISH_MAGNETIC_FIELD; - } - + priv = container_of(lower, struct goldfish_sensor_s, lower_mag); + return GOLDFISH_MAGNETIC_FIELD; + case SENSOR_TYPE_GYROSCOPE_UNCALIBRATED: + priv = container_of(lower, struct goldfish_sensor_s, + lower_gyro_uncalibrated); + return GOLDFISH_GYROSCOPE_UNCALIBRATED; case SENSOR_TYPE_GYROSCOPE: - if (lower->uncalibrated) - { - *priv = container_of(lower, struct goldfish_sensor_s, - lower_gyro_uncalibrated); - return GOLDFISH_GYROSCOPE_FIELD_UNCALIBRATED; - } - else - { - *priv = container_of(lower, struct goldfish_sensor_s, lower_gyro); - return GOLDFISH_GYROSCOPE; - } - + priv = container_of(lower, struct goldfish_sensor_s, lower_gyro); + return GOLDFISH_GYROSCOPE; case SENSOR_TYPE_PROXIMITY: *priv = container_of(lower, struct goldfish_sensor_s, lower_prox); return GOLDFISH_PROXIMITY; @@ -868,20 +850,20 @@ int goldfish_sensor_init(int devno, uint32_t batch_number) sensor->lower_gyro.ops = &g_goldfish_sensor_ops; sensor->lower_gyro.nbuffer = batch_number; - sensor->lower_accel_uncalibrated.type = SENSOR_TYPE_ACCELEROMETER; + sensor->lower_accel_uncalibrated.type = + SENSOR_TYPE_ACCELEROMETER_UNCALIBRATED; sensor->lower_accel_uncalibrated.ops = &g_goldfish_sensor_ops; sensor->lower_accel_uncalibrated.nbuffer = batch_number; - sensor->lower_accel_uncalibrated.uncalibrated = true; - sensor->lower_mag_uncalibrated.type = SENSOR_TYPE_MAGNETIC_FIELD; + sensor->lower_mag_uncalibrated.type = + SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED; sensor->lower_mag_uncalibrated.ops = &g_goldfish_sensor_ops; sensor->lower_mag_uncalibrated.nbuffer = batch_number; - sensor->lower_mag_uncalibrated.uncalibrated = true; - sensor->lower_gyro_uncalibrated.type = SENSOR_TYPE_GYROSCOPE; + sensor->lower_gyro_uncalibrated.type = + SENSOR_TYPE_GYROSCOPE_UNCALIBRATED; sensor->lower_gyro_uncalibrated.ops = &g_goldfish_sensor_ops; sensor->lower_gyro_uncalibrated.nbuffer = batch_number; - sensor->lower_gyro_uncalibrated.uncalibrated = true; sensor->lower_prox.type = SENSOR_TYPE_PROXIMITY; sensor->lower_prox.ops = &g_goldfish_sensor_ops; diff --git a/drivers/sensors/hyt271_uorb.c b/drivers/sensors/hyt271_uorb.c index 9f4557a077f..caaef85d3f1 100644 --- a/drivers/sensors/hyt271_uorb.c +++ b/drivers/sensors/hyt271_uorb.c @@ -942,7 +942,6 @@ int hyt271_register(int devno, FAR struct i2c_master_s *i2c, uint8_t addr, tmp->buffer_size = sizeof(struct sensor_humi); tmp->lower.ops = &g_hyt271_ops; tmp->lower.type = SENSOR_TYPE_RELATIVE_HUMIDITY; - tmp->lower.uncalibrated = false; tmp->lower.nbuffer = 1; ret = sensor_register(&tmp->lower, devno); if (ret < 0) @@ -960,7 +959,6 @@ int hyt271_register(int devno, FAR struct i2c_master_s *i2c, uint8_t addr, tmp->buffer_size = sizeof(struct sensor_temp); tmp->lower.ops = &g_hyt271_ops; tmp->lower.type = SENSOR_TYPE_AMBIENT_TEMPERATURE; - tmp->lower.uncalibrated = false; tmp->lower.nbuffer = 1; ret = sensor_register(&tmp->lower, devno); if (ret < 0) diff --git a/drivers/sensors/l3gd20_uorb.c b/drivers/sensors/l3gd20_uorb.c index 3d8c29cdee7..089575be8a1 100644 --- a/drivers/sensors/l3gd20_uorb.c +++ b/drivers/sensors/l3gd20_uorb.c @@ -562,10 +562,9 @@ int l3gd20_register(int devno, FAR struct spi_dev_s *spi, #endif priv->timestamp = 0; - priv->lower.type = SENSOR_TYPE_GYROSCOPE; + priv->lower.type = SENSOR_TYPE_GYROSCOPE_UNCALIBRATED; priv->lower.nbuffer = CONFIG_SENSORS_L3GD20_BUFFER_SIZE; priv->lower.ops = &g_l2gd20_ops; - priv->lower.uncalibrated = true; /* Setup SPI frequency and mode */ diff --git a/drivers/sensors/sensor.c b/drivers/sensors/sensor.c index 461b77af1ef..89bd6bbbf21 100644 --- a/drivers/sensors/sensor.c +++ b/drivers/sensors/sensor.c @@ -50,8 +50,7 @@ /* Device naming ************************************************************/ #define ROUND_DOWN(x, y) (((x) / (y)) * (y)) -#define DEVNAME_FMT "/dev/uorb/sensor_%s%s%d" -#define DEVNAME_UNCAL "_uncal" +#define DEVNAME_FMT "/dev/uorb/sensor_%s%d" #define TIMING_BUF_ESIZE (sizeof(uint32_t)) /**************************************************************************** @@ -168,16 +167,16 @@ static const struct sensor_meta_s g_sensor_meta[] = {sizeof(struct sensor_gyro), "gyro"}, {sizeof(struct sensor_light), "light"}, {sizeof(struct sensor_baro), "baro"}, - {sizeof(struct sensor_noise), "noise"}, + {sizeof(struct sensor_temp), "temp"}, {sizeof(struct sensor_prox), "prox"}, {sizeof(struct sensor_rgb), "rgb"}, {sizeof(struct sensor_accel), "linear_accel"}, {sizeof(struct sensor_rotation), "rotation"}, {sizeof(struct sensor_humi), "humi"}, - {sizeof(struct sensor_temp), "temp"}, - {sizeof(struct sensor_pm25), "pm25"}, + {sizeof(struct sensor_temp), "ambient_temp"}, + {sizeof(struct sensor_mag), "mag_uncal"}, {sizeof(struct sensor_pm1p0), "pm1p0"}, - {sizeof(struct sensor_pm10), "pm10"}, + {sizeof(struct sensor_gyro), "gyro_uncal"}, {sizeof(struct sensor_event), "motion_detect"}, {sizeof(struct sensor_event), "step_detector"}, {sizeof(struct sensor_step_counter), "step_counter"}, @@ -196,7 +195,7 @@ static const struct sensor_meta_s g_sensor_meta[] = {sizeof(struct sensor_force), "force"}, {sizeof(struct sensor_hall), "hall"}, {sizeof(struct sensor_event), "offbody_detector"}, - {sizeof(struct sensor_uv), "uv"}, + {sizeof(struct sensor_accel), "accel_uncal"}, {sizeof(struct sensor_angle), "hinge_angle"}, {sizeof(struct sensor_ir), "ir"}, {sizeof(struct sensor_hcho), "hcho"}, @@ -215,6 +214,10 @@ static const struct sensor_meta_s g_sensor_meta[] = {sizeof(struct sensor_gnss_clock), "gnss_clock"}, {sizeof(struct sensor_gnss_geofence_event), "gnss_geofence_event"}, {sizeof(struct sensor_velocity), "velocity"}, + {sizeof(struct sensor_noise), "noise"}, + {sizeof(struct sensor_pm25), "pm25"}, + {sizeof(struct sensor_pm10), "pm10"}, + {sizeof(struct sensor_uv), "uv"}, }; static const struct file_operations g_sensor_fops = @@ -1255,7 +1258,6 @@ int sensor_register(FAR struct sensor_lowerhalf_s *lower, int devno) snprintf(path, PATH_MAX, DEVNAME_FMT, g_sensor_meta[lower->type].name, - lower->uncalibrated ? DEVNAME_UNCAL : "", devno); ret = sensor_custom_register(lower, path, g_sensor_meta[lower->type].esize); @@ -1403,7 +1405,6 @@ void sensor_unregister(FAR struct sensor_lowerhalf_s *lower, int devno) snprintf(path, PATH_MAX, DEVNAME_FMT, g_sensor_meta[lower->type].name, - lower->uncalibrated ? DEVNAME_UNCAL : "", devno); sensor_custom_unregister(lower, path); lib_put_pathbuffer(path); diff --git a/drivers/sensors/sht4x_uorb.c b/drivers/sensors/sht4x_uorb.c index 9303e833ecd..31888afe13d 100644 --- a/drivers/sensors/sht4x_uorb.c +++ b/drivers/sensors/sht4x_uorb.c @@ -875,7 +875,6 @@ int sht4x_register(FAR struct i2c_master_s *i2c, int devno, uint8_t addr) priv->hum.sensor_lower.ops = &g_sensor_ops; priv->hum.sensor_lower.type = SENSOR_TYPE_RELATIVE_HUMIDITY; - priv->hum.sensor_lower.uncalibrated = false; priv->hum.enabled = false; priv->hum.dev = priv; @@ -895,7 +894,6 @@ int sht4x_register(FAR struct i2c_master_s *i2c, int devno, uint8_t addr) priv->temp.sensor_lower.ops = &g_sensor_ops; priv->temp.sensor_lower.type = SENSOR_TYPE_AMBIENT_TEMPERATURE; - priv->temp.sensor_lower.uncalibrated = false; priv->temp.enabled = false; priv->temp.dev = priv; diff --git a/include/nuttx/sensors/sensor.h b/include/nuttx/sensors/sensor.h index d84b8483d8e..77b78056704 100644 --- a/include/nuttx/sensors/sensor.h +++ b/include/nuttx/sensors/sensor.h @@ -532,13 +532,6 @@ struct sensor_lowerhalf_s uint32_t nbuffer; - /* The uncalibrated use to describe whether the sensor event is - * uncalibrated. True is uncalibrated data, false is calibrated data, - * default false. - */ - - bool uncalibrated; - /* The lower half sensor driver operations */ FAR const struct sensor_ops_s *ops; diff --git a/include/nuttx/uorb.h b/include/nuttx/uorb.h index cd14a8bb30d..8a201b2bdc5 100644 --- a/include/nuttx/uorb.h +++ b/include/nuttx/uorb.h @@ -42,6 +42,14 @@ /* sensor type definition */ +/* Note: Some of the types of these sensors are aligned with Android, and + * the refs link is https://cs.android.com/android/_/android/platform/\ + * hardware/libhardware/+/0e67aa0caee9500b61b9c1c8b6e5cab18301364c:\ + * include_all/hardware/sensors-base.h. + * + * If you need to make modifications, please align with Android standards + */ + /* Custom Sensor * Some special sensor whose event size is not fixed or dynamically change, * are called sensor of custom type. You should treat its events as byte @@ -99,11 +107,12 @@ #define SENSOR_TYPE_BAROMETER 6 -/* Noise Loudness - * A sensor of this type returns the loudness of noise in SI units (db) +/* Temperature + * A sensor of this type returns the measurement temperature in degree + * Celsius. */ -#define SENSOR_TYPE_NOISE 7 +#define SENSOR_TYPE_TEMPERAUTRE 7 /* Proximity * The values correspond to the distance to the nearest @@ -153,12 +162,12 @@ #define SENSOR_TYPE_AMBIENT_TEMPERATURE 13 -/* PM25 - * A sensor of this type returns the content of pm2.5 in the air - * This value is in SI units (ug/m^3) +/* Magneric Field Uncalibrated + * Similar to MAGNETIC_FIELD, all values are in micro-Tesla (uT) + * and measure the geomagnetic field in X, Y and Z axis. */ -#define SENSOR_TYPE_PM25 14 +#define SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED 14 /* PM1P0 * A sensor of this type returns the content of pm1.0 in the air @@ -167,12 +176,12 @@ #define SENSOR_TYPE_PM1P0 15 -/* PM10 - * A sensor of this type returns the content of pm10 in the air - * This value is in SI units (ug/m^3) +/* Gyroscope Uncalibrated + * All values are in radians/second and measure the rate of rotation around + * the X, Y and Z axis. */ -#define SENSOR_TYPE_PM10 16 +#define SENSOR_TYPE_GYROSCOPE_UNCALIBRATED 16 /* Significant motion * A significant motion detector triggers when detecting a significant @@ -335,12 +344,12 @@ #define SENSOR_TYPE_LOW_LATENCY_OFFBODY_DETECT 34 -/* Ultraviolet light sensor - * This sensor can identify the UV index in ambient light help people - * to effectively protect themselves from sunburns, cancer or eye damage. - * This value range is 0 - 15. +/* Accelerometer Uncalibrate + * All values are in SI units (m/s^2), and measure the acceleration of the + * device minus the acceleration dut to gravity. */ -#define SENSOR_TYPE_ULTRAVIOLET 35 + +#define SENSOR_TYPE_ACCELEROMETER_UNCALIBRATED 35 /* Hinge angle * A hinge angle sensor measures the angle, in degrees, between two integral @@ -474,11 +483,39 @@ #define SENSOR_TYPE_VELOCITY 53 +/* Noise Loudness + * A sensor of this type returns the loudness of noise in SI units (db) + */ + +#define SENSOR_TYPE_NOISE 54 + +/* PM25 + * A sensor of this type returns the content of pm2.5 in the air + * This value is in SI units (ug/m^3) + */ + +#define SENSOR_TYPE_PM25 55 + +/* PM10 + * A sensor of this type returns the content of pm10 in the air + * This value is in SI units (ug/m^3) + */ + +#define SENSOR_TYPE_PM10 56 + +/* Ultraviolet light sensor + * This sensor can identify the UV index in ambient light help people + * to effectively protect themselves from sunburns, cancer or eye damage. + * This value range is 0 - 15. + */ + +#define SENSOR_TYPE_ULTRAVIOLET 57 + /* The total number of sensor * please increase it if you added a new sensor type! */ -#define SENSOR_TYPE_COUNT 54 +#define SENSOR_TYPE_COUNT 58 /* The additional sensor open flags */