Skip to content

Commit 007ad49

Browse files
committed
drivers/sensor: add new sensot type to align android sensor type
new sensor type: SENSOR_TEMPERATURE SENSOR_TYPE_ACCELEROMETER_UNCALIBRATED SENSOR_TYPE_GYROSCOPE_UNCALIBRATED SENSOR_TYPE_MAGNETIC_FILED_UNCALIBRATED refs: https://cs.android.com/android/_/android/platform/hardware/libhardware/+/ 0e67aa0caee9500b61b9c1c8b6e5cab18301364c:include_all/hardware/sensors-base.h Signed-off-by: dongjiuzhu1 <[email protected]>
1 parent e177ff9 commit 007ad49

10 files changed

+85
-91
lines changed

drivers/sensors/bmi088_uorb.c

+2-4
Original file line numberDiff line numberDiff line change
@@ -735,8 +735,7 @@ static int bmi088_register_accel(int devno,
735735
#endif
736736

737737
priv->lower.ops = &g_bmi088_accel_ops;
738-
priv->lower.type = SENSOR_TYPE_ACCELEROMETER;
739-
priv->lower.uncalibrated = true;
738+
priv->lower.type = SENSOR_TYPE_ACCELEROMETER_UNCALIBRATED;
740739
priv->interval = BMI088_DEFAULT_INTERVAL;
741740
priv->lower.nbuffer = 1;
742741

@@ -818,8 +817,7 @@ static int bmi088_register_gyro(int devno,
818817
#endif
819818

820819
priv->lower.ops = &g_bmi088_gyro_ops;
821-
priv->lower.type = SENSOR_TYPE_GYROSCOPE;
822-
priv->lower.uncalibrated = true;
820+
priv->lower.type = SENSOR_TYPE_GYROSCOPE_UNCALIBRATED;
823821
priv->interval = BMI088_DEFAULT_INTERVAL;
824822
priv->lower.nbuffer = 1;
825823

drivers/sensors/bmi160_uorb.c

+2-4
Original file line numberDiff line numberDiff line change
@@ -602,8 +602,7 @@ static int bmi160_register_accel(int devno,
602602
#endif
603603

604604
priv->lower.ops = &g_bmi160_accel_ops;
605-
priv->lower.type = SENSOR_TYPE_ACCELEROMETER;
606-
priv->lower.uncalibrated = true;
605+
priv->lower.type = SENSOR_TYPE_ACCELEROMETER_UNCALIBRATED;
607606
priv->interval = BMI160_DEFAULT_INTERVAL;
608607
priv->lower.nbuffer = 1;
609608

@@ -687,8 +686,7 @@ static int bmi160_register_gyro(int devno,
687686
#endif
688687

689688
priv->lower.ops = &g_bmi160_gyro_ops;
690-
priv->lower.type = SENSOR_TYPE_GYROSCOPE;
691-
priv->lower.uncalibrated = true;
689+
priv->lower.type = SENSOR_TYPE_GYROSCOPE_UNCALIBRATED;
692690
priv->interval = BMI160_DEFAULT_INTERVAL;
693691
priv->lower.nbuffer = 1;
694692

drivers/sensors/ds18b20_uorb.c

-1
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,6 @@ int ds18b20_register(int devno, FAR struct onewire_master_s *onewire,
973973
#endif
974974
tmp->lower.ops = &g_ds18b20_ops;
975975
tmp->lower.type = SENSOR_TYPE_AMBIENT_TEMPERATURE;
976-
tmp->lower.uncalibrated = false;
977976
tmp->lower.nbuffer = 1;
978977
ret = sensor_register(&tmp->lower, devno);
979978
if (ret < 0)

drivers/sensors/goldfish_sensor_uorb.c

+25-43
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
#define GOLDFISH_PRESSURE 7
5353
#define GOLDFISH_RELATIVE_HUMIDITY 8
5454
#define GOLDFISH_MAGNETIC_FIELD_UNCALIBRATED 9
55-
#define GOLDFISH_GYROSCOPE_FIELD_UNCALIBRATED 10
55+
#define GOLDFISH_GYROSCOPE_UNCALIBRATED 10
5656
#define GOLDFISH_HINGE_ANGLE0 11
5757
#define GOLDFISH_HINGE_ANGLE1 12
5858
#define GOLDFISH_HINGE_ANGLE2 13
@@ -620,45 +620,27 @@ static int goldfish_get_priv(FAR struct sensor_lowerhalf_s *lower,
620620
{
621621
switch (lower->type)
622622
{
623+
case SENSOR_TYPE_ACCELEROMETER_UNCALIBRATED:
624+
priv = container_of(lower, struct goldfish_sensor_s,
625+
lower_accel_uncalibrated);
626+
return GOLDFISH_ACCELERATION_UNCALIBRATED;
623627
case SENSOR_TYPE_ACCELEROMETER:
624-
if (lower->uncalibrated)
625-
{
626-
*priv = container_of(lower, struct goldfish_sensor_s,
627-
lower_accel_uncalibrated);
628-
return GOLDFISH_ACCELERATION_UNCALIBRATED;
629-
}
630-
else
631-
{
632-
*priv = container_of(lower, struct goldfish_sensor_s, lower_accel);
633-
return GOLDFISH_ACCELERATION;
634-
}
635-
628+
priv = container_of(lower, struct goldfish_sensor_s, lower_accel);
629+
return GOLDFISH_ACCELERATION;
630+
case SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED:
631+
priv = container_of(lower, struct goldfish_sensor_s,
632+
lower_mag_uncalibrated);
633+
return GOLDFISH_MAGNETIC_FIELD_UNCALIBRATED;
636634
case SENSOR_TYPE_MAGNETIC_FIELD:
637-
if (lower->uncalibrated)
638-
{
639-
*priv = container_of(lower, struct goldfish_sensor_s,
640-
lower_mag_uncalibrated);
641-
return GOLDFISH_MAGNETIC_FIELD_UNCALIBRATED;
642-
}
643-
else
644-
{
645-
*priv = container_of(lower, struct goldfish_sensor_s, lower_mag);
646-
return GOLDFISH_MAGNETIC_FIELD;
647-
}
648-
635+
priv = container_of(lower, struct goldfish_sensor_s, lower_mag);
636+
return GOLDFISH_MAGNETIC_FIELD;
637+
case SENSOR_TYPE_GYROSCOPE_UNCALIBRATED:
638+
priv = container_of(lower, struct goldfish_sensor_s,
639+
lower_gyro_uncalibrated);
640+
return GOLDFISH_GYROSCOPE_UNCALIBRATED;
649641
case SENSOR_TYPE_GYROSCOPE:
650-
if (lower->uncalibrated)
651-
{
652-
*priv = container_of(lower, struct goldfish_sensor_s,
653-
lower_gyro_uncalibrated);
654-
return GOLDFISH_GYROSCOPE_FIELD_UNCALIBRATED;
655-
}
656-
else
657-
{
658-
*priv = container_of(lower, struct goldfish_sensor_s, lower_gyro);
659-
return GOLDFISH_GYROSCOPE;
660-
}
661-
642+
priv = container_of(lower, struct goldfish_sensor_s, lower_gyro);
643+
return GOLDFISH_GYROSCOPE;
662644
case SENSOR_TYPE_PROXIMITY:
663645
*priv = container_of(lower, struct goldfish_sensor_s, lower_prox);
664646
return GOLDFISH_PROXIMITY;
@@ -868,20 +850,20 @@ int goldfish_sensor_init(int devno, uint32_t batch_number)
868850
sensor->lower_gyro.ops = &g_goldfish_sensor_ops;
869851
sensor->lower_gyro.nbuffer = batch_number;
870852

871-
sensor->lower_accel_uncalibrated.type = SENSOR_TYPE_ACCELEROMETER;
853+
sensor->lower_accel_uncalibrated.type =
854+
SENSOR_TYPE_ACCELEROMETER_UNCALIBRATED;
872855
sensor->lower_accel_uncalibrated.ops = &g_goldfish_sensor_ops;
873856
sensor->lower_accel_uncalibrated.nbuffer = batch_number;
874-
sensor->lower_accel_uncalibrated.uncalibrated = true;
875857

876-
sensor->lower_mag_uncalibrated.type = SENSOR_TYPE_MAGNETIC_FIELD;
858+
sensor->lower_mag_uncalibrated.type =
859+
SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED;
877860
sensor->lower_mag_uncalibrated.ops = &g_goldfish_sensor_ops;
878861
sensor->lower_mag_uncalibrated.nbuffer = batch_number;
879-
sensor->lower_mag_uncalibrated.uncalibrated = true;
880862

881-
sensor->lower_gyro_uncalibrated.type = SENSOR_TYPE_GYROSCOPE;
863+
sensor->lower_gyro_uncalibrated.type =
864+
SENSOR_TYPE_GYROSCOPE_UNCALIBRATED;
882865
sensor->lower_gyro_uncalibrated.ops = &g_goldfish_sensor_ops;
883866
sensor->lower_gyro_uncalibrated.nbuffer = batch_number;
884-
sensor->lower_gyro_uncalibrated.uncalibrated = true;
885867

886868
sensor->lower_prox.type = SENSOR_TYPE_PROXIMITY;
887869
sensor->lower_prox.ops = &g_goldfish_sensor_ops;

drivers/sensors/hyt271_uorb.c

-2
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,6 @@ int hyt271_register(int devno, FAR struct i2c_master_s *i2c, uint8_t addr,
942942
tmp->buffer_size = sizeof(struct sensor_humi);
943943
tmp->lower.ops = &g_hyt271_ops;
944944
tmp->lower.type = SENSOR_TYPE_RELATIVE_HUMIDITY;
945-
tmp->lower.uncalibrated = false;
946945
tmp->lower.nbuffer = 1;
947946
ret = sensor_register(&tmp->lower, devno);
948947
if (ret < 0)
@@ -960,7 +959,6 @@ int hyt271_register(int devno, FAR struct i2c_master_s *i2c, uint8_t addr,
960959
tmp->buffer_size = sizeof(struct sensor_temp);
961960
tmp->lower.ops = &g_hyt271_ops;
962961
tmp->lower.type = SENSOR_TYPE_AMBIENT_TEMPERATURE;
963-
tmp->lower.uncalibrated = false;
964962
tmp->lower.nbuffer = 1;
965963
ret = sensor_register(&tmp->lower, devno);
966964
if (ret < 0)

drivers/sensors/l3gd20_uorb.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -562,10 +562,9 @@ int l3gd20_register(int devno, FAR struct spi_dev_s *spi,
562562
#endif
563563
priv->timestamp = 0;
564564

565-
priv->lower.type = SENSOR_TYPE_GYROSCOPE;
565+
priv->lower.type = SENSOR_TYPE_GYROSCOPE_UNCALIBRATED;
566566
priv->lower.nbuffer = CONFIG_SENSORS_L3GD20_BUFFER_SIZE;
567567
priv->lower.ops = &g_l2gd20_ops;
568-
priv->lower.uncalibrated = true;
569568

570569
/* Setup SPI frequency and mode */
571570

drivers/sensors/sensor.c

+10-9
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@
5050
/* Device naming ************************************************************/
5151

5252
#define ROUND_DOWN(x, y) (((x) / (y)) * (y))
53-
#define DEVNAME_FMT "/dev/uorb/sensor_%s%s%d"
54-
#define DEVNAME_UNCAL "_uncal"
53+
#define DEVNAME_FMT "/dev/uorb/sensor_%s%d"
5554
#define TIMING_BUF_ESIZE (sizeof(uint32_t))
5655

5756
/****************************************************************************
@@ -168,16 +167,16 @@ static const struct sensor_meta_s g_sensor_meta[] =
168167
{sizeof(struct sensor_gyro), "gyro"},
169168
{sizeof(struct sensor_light), "light"},
170169
{sizeof(struct sensor_baro), "baro"},
171-
{sizeof(struct sensor_noise), "noise"},
170+
{sizeof(struct sensor_temp), "temp"},
172171
{sizeof(struct sensor_prox), "prox"},
173172
{sizeof(struct sensor_rgb), "rgb"},
174173
{sizeof(struct sensor_accel), "linear_accel"},
175174
{sizeof(struct sensor_rotation), "rotation"},
176175
{sizeof(struct sensor_humi), "humi"},
177-
{sizeof(struct sensor_temp), "temp"},
178-
{sizeof(struct sensor_pm25), "pm25"},
176+
{sizeof(struct sensor_temp), "ambient_temp"},
177+
{sizeof(struct sensor_mag), "mag_uncal"},
179178
{sizeof(struct sensor_pm1p0), "pm1p0"},
180-
{sizeof(struct sensor_pm10), "pm10"},
179+
{sizeof(struct sensor_gyro), "gyro_uncal"},
181180
{sizeof(struct sensor_event), "motion_detect"},
182181
{sizeof(struct sensor_event), "step_detector"},
183182
{sizeof(struct sensor_step_counter), "step_counter"},
@@ -196,7 +195,7 @@ static const struct sensor_meta_s g_sensor_meta[] =
196195
{sizeof(struct sensor_force), "force"},
197196
{sizeof(struct sensor_hall), "hall"},
198197
{sizeof(struct sensor_event), "offbody_detector"},
199-
{sizeof(struct sensor_uv), "uv"},
198+
{sizeof(struct sensor_accel), "accel_uncal"},
200199
{sizeof(struct sensor_angle), "hinge_angle"},
201200
{sizeof(struct sensor_ir), "ir"},
202201
{sizeof(struct sensor_hcho), "hcho"},
@@ -215,6 +214,10 @@ static const struct sensor_meta_s g_sensor_meta[] =
215214
{sizeof(struct sensor_gnss_clock), "gnss_clock"},
216215
{sizeof(struct sensor_gnss_geofence_event), "gnss_geofence_event"},
217216
{sizeof(struct sensor_velocity), "velocity"},
217+
{sizeof(struct sensor_noise), "noise"},
218+
{sizeof(struct sensor_pm25), "pm25"},
219+
{sizeof(struct sensor_pm10), "pm10"},
220+
{sizeof(struct sensor_uv), "uv"},
218221
};
219222

220223
static const struct file_operations g_sensor_fops =
@@ -1255,7 +1258,6 @@ int sensor_register(FAR struct sensor_lowerhalf_s *lower, int devno)
12551258

12561259
snprintf(path, PATH_MAX, DEVNAME_FMT,
12571260
g_sensor_meta[lower->type].name,
1258-
lower->uncalibrated ? DEVNAME_UNCAL : "",
12591261
devno);
12601262
ret = sensor_custom_register(lower, path,
12611263
g_sensor_meta[lower->type].esize);
@@ -1403,7 +1405,6 @@ void sensor_unregister(FAR struct sensor_lowerhalf_s *lower, int devno)
14031405

14041406
snprintf(path, PATH_MAX, DEVNAME_FMT,
14051407
g_sensor_meta[lower->type].name,
1406-
lower->uncalibrated ? DEVNAME_UNCAL : "",
14071408
devno);
14081409
sensor_custom_unregister(lower, path);
14091410
lib_put_pathbuffer(path);

drivers/sensors/sht4x_uorb.c

-2
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,6 @@ int sht4x_register(FAR struct i2c_master_s *i2c, int devno, uint8_t addr)
875875

876876
priv->hum.sensor_lower.ops = &g_sensor_ops;
877877
priv->hum.sensor_lower.type = SENSOR_TYPE_RELATIVE_HUMIDITY;
878-
priv->hum.sensor_lower.uncalibrated = false;
879878
priv->hum.enabled = false;
880879
priv->hum.dev = priv;
881880

@@ -895,7 +894,6 @@ int sht4x_register(FAR struct i2c_master_s *i2c, int devno, uint8_t addr)
895894

896895
priv->temp.sensor_lower.ops = &g_sensor_ops;
897896
priv->temp.sensor_lower.type = SENSOR_TYPE_AMBIENT_TEMPERATURE;
898-
priv->temp.sensor_lower.uncalibrated = false;
899897
priv->temp.enabled = false;
900898
priv->temp.dev = priv;
901899

include/nuttx/sensors/sensor.h

-7
Original file line numberDiff line numberDiff line change
@@ -532,13 +532,6 @@ struct sensor_lowerhalf_s
532532

533533
uint32_t nbuffer;
534534

535-
/* The uncalibrated use to describe whether the sensor event is
536-
* uncalibrated. True is uncalibrated data, false is calibrated data,
537-
* default false.
538-
*/
539-
540-
bool uncalibrated;
541-
542535
/* The lower half sensor driver operations */
543536

544537
FAR const struct sensor_ops_s *ops;

include/nuttx/uorb.h

+45-17
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@
9999

100100
#define SENSOR_TYPE_BAROMETER 6
101101

102-
/* Noise Loudness
103-
* A sensor of this type returns the loudness of noise in SI units (db)
102+
/* Temperature
103+
* A sensor of this type returns the measurement temperature in degree Celsius.
104104
*/
105105

106-
#define SENSOR_TYPE_NOISE 7
106+
#define SENSOR_TYPE_TEMPERAUTRE 7
107107

108108
/* Proximity
109109
* The values correspond to the distance to the nearest
@@ -153,12 +153,12 @@
153153

154154
#define SENSOR_TYPE_AMBIENT_TEMPERATURE 13
155155

156-
/* PM25
157-
* A sensor of this type returns the content of pm2.5 in the air
158-
* This value is in SI units (ug/m^3)
156+
/* Magneric Field Uncalibrated
157+
* Similar to MAGNETIC_FIELD, all values are in micro-Tesla (uT)
158+
* and measure the geomagnetic field in X, Y and Z axis.
159159
*/
160160

161-
#define SENSOR_TYPE_PM25 14
161+
#define SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED 14
162162

163163
/* PM1P0
164164
* A sensor of this type returns the content of pm1.0 in the air
@@ -167,12 +167,12 @@
167167

168168
#define SENSOR_TYPE_PM1P0 15
169169

170-
/* PM10
171-
* A sensor of this type returns the content of pm10 in the air
172-
* This value is in SI units (ug/m^3)
170+
/* Gyroscope Uncalibrated
171+
* All values are in radians/second and measure the rate of rotation around
172+
* the X, Y and Z axis.
173173
*/
174174

175-
#define SENSOR_TYPE_PM10 16
175+
#define SENSOR_TYPE_GYROSCOPE_UNCALIBRATED 16
176176

177177
/* Significant motion
178178
* A significant motion detector triggers when detecting a significant
@@ -335,12 +335,12 @@
335335

336336
#define SENSOR_TYPE_LOW_LATENCY_OFFBODY_DETECT 34
337337

338-
/* Ultraviolet light sensor
339-
* This sensor can identify the UV index in ambient light help people
340-
* to effectively protect themselves from sunburns, cancer or eye damage.
341-
* This value range is 0 - 15.
338+
/* Accelerometer Uncalibrate
339+
* All values are in SI units (m/s^2), and measure the acceleration of the
340+
* device minus the acceleration dut to gravity.
342341
*/
343-
#define SENSOR_TYPE_ULTRAVIOLET 35
342+
343+
#define SENSOR_TYPE_ACCELEROMETER_UNCALIBRATED 35
344344

345345
/* Hinge angle
346346
* A hinge angle sensor measures the angle, in degrees, between two integral
@@ -474,11 +474,39 @@
474474

475475
#define SENSOR_TYPE_VELOCITY 53
476476

477+
/* Noise Loudness
478+
* A sensor of this type returns the loudness of noise in SI units (db)
479+
*/
480+
481+
#define SENSOR_TYPE_NOISE 54
482+
483+
/* PM25
484+
* A sensor of this type returns the content of pm2.5 in the air
485+
* This value is in SI units (ug/m^3)
486+
*/
487+
488+
#define SENSOR_TYPE_PM25 55
489+
490+
/* PM10
491+
* A sensor of this type returns the content of pm10 in the air
492+
* This value is in SI units (ug/m^3)
493+
*/
494+
495+
#define SENSOR_TYPE_PM10 56
496+
497+
/* Ultraviolet light sensor
498+
* This sensor can identify the UV index in ambient light help people
499+
* to effectively protect themselves from sunburns, cancer or eye damage.
500+
* This value range is 0 - 15.
501+
*/
502+
503+
#define SENSOR_TYPE_ULTRAVIOLET 57
504+
477505
/* The total number of sensor
478506
* please increase it if you added a new sensor type!
479507
*/
480508

481-
#define SENSOR_TYPE_COUNT 54
509+
#define SENSOR_TYPE_COUNT 58
482510

483511
/* The additional sensor open flags */
484512

0 commit comments

Comments
 (0)