Skip to content

Commit a09f9a1

Browse files
committed
sample: env_sensing: use NODELABEL
Use NODELABEL and a unified label for all sensors set in overlays, this way we just address the temperature/humidity sensor using env_sensor. Learned that today in Marti's device tree talk :-) Signed-off-by: Anas Nashif <[email protected]>
1 parent 2dd7907 commit a09f9a1

15 files changed

+17
-50
lines changed

samples/sensor/env_sensing/sensor_overlay/bme280.overlay

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313
&arduino_i2c {
1414
status = "okay";
15-
bme280@77 {
15+
env_sensor: bme280@77 {
1616
compatible = "bosch,bme280";
1717
reg = <0x77>;
1818
label = "BME280_I2C";

samples/sensor/env_sensing/sensor_overlay/bme280_spi.overlay

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
&arduino_spi {
1010
status = "okay";
1111
cs-gpios = <&arduino_header 16 GPIO_ACTIVE_LOW>;
12-
bme280@0 {
12+
env_sensor: bme280@0 {
1313
compatible = "bosch,bme280";
1414
reg = <0>;
1515
label = "BME280_SPI";

samples/sensor/env_sensing/sensor_overlay/bme680.overlay

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
&arduino_i2c {
88
status = "okay";
9-
bme680@77 {
9+
env_sensor: bme680@77 {
1010
compatible = "bosch,bme680";
1111
reg = <0x77>;
1212
label = "BME680";

samples/sensor/env_sensing/sensor_overlay/dps310.overlay

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010

1111
&arduino_i2c {
12-
DPS310@77 {
12+
env_sensor: DPS310@77 {
1313
status = "okay";
1414
compatible = "infineon,dps310";
1515
reg = <0x77>;

samples/sensor/env_sensing/sensor_overlay/ens210.overlay

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
status = "okay";
88
clock-frequency = <I2C_BITRATE_FAST>;
99

10-
ens210: ens210@43 {
10+
env_sensor: ens210@43 {
1111
compatible = "ams,ens210";
1212
reg = <0x43>;
1313
label = "ENS210";

samples/sensor/env_sensing/sensor_overlay/hdc1080.overlay

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
&arduino_i2c {
88

9-
ti_hdc: ti_hdc@40 {
9+
env_sensor: ti_hdc@40 {
1010
compatible = "ti,hdc","ti,hdc1080";
1111
reg = <0x40>;
1212
label = "HDC1080";

samples/sensor/env_sensing/sensor_overlay/hts221.overlay

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
&arduino_i2c {
88

9-
hts221@5f {
9+
env_sensor: hts221@5f {
1010
compatible = "st,hts221";
1111
reg = <0x5f>;
1212
label = "HTS221";

samples/sensor/env_sensing/sensor_overlay/lps22hb-press.overlay

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
&arduino_i2c {
7-
lps22hb-press@5d {
7+
env_sensor: lps22hb-press@5d {
88
compatible = "st,lps22hb-press";
99
reg = <0x5d>;
1010
label = "LPS22HB";

samples/sensor/env_sensing/sensor_overlay/lps22hh.overlay

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
&arduino_i2c {
8-
lps22hh@5d {
8+
env_sensor: lps22hh@5d {
99
compatible = "st,lps22hh";
1010
reg = <0x5d>;
1111
drdy-gpios = <&arduino_header 12 GPIO_ACTIVE_HIGH>; /* D6 */

samples/sensor/env_sensing/sensor_overlay/max6675.overlay

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
&arduino_spi {
8-
max6675@0 {
8+
env_sensor: max6675@0 {
99
compatible = "maxim,max6675";
1010
reg = <0>;
1111
spi-max-frequency = <4300000>;

samples/sensor/env_sensing/sensor_overlay/mcp9808.overlay

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
&arduino_i2c {
8-
mcp9808@18 {
8+
env_sensor: mcp9808@18 {
99
compatible = "microchip,mcp9808";
1010
reg = <0x18>;
1111
int-gpios = <&gpioc 16 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;

samples/sensor/env_sensing/sensor_overlay/ms5837.overlay

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
&arduino_i2c {
88
status = "okay";
99
clock-frequency = <I2C_BITRATE_STANDARD>;
10-
ms5837@76 {
10+
env_sensor: ms5837@76 {
1111
compatible = "meas,ms5837";
1212
reg = <0x76>;
1313
label = "MS5837";

samples/sensor/env_sensing/sensor_overlay/sht3xd.overlay

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
&arduino_i2c { /* SDA PTE25, SCL PTE24, ALERT PTE26 */
8-
sht3xd@44 {
8+
env_sensor: sht3xd@44 {
99
compatible = "sensirion,sht3xd";
1010
reg = <0x44>;
1111
label = "SHT3XD";

samples/sensor/env_sensing/sensor_overlay/th02.overlay

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
&arduino_i2c {
8-
th02@40 {
8+
env_sensor: th02@40 {
99
compatible = "hoperf,th02";
1010
reg = <0x40>;
1111
label = "TH02";

samples/sensor/env_sensing/src/main.c

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ static void process_sample(void)
7070
sensor_log("Relative Humidity: %.1f%%\n", sensor_value_to_double(&hum));
7171
}
7272
if (IS_ENABLED(CONFIG_HAS_PRESSURE)) {
73-
sensor_log("Pressure: %.2f kPa", sensor_value_to_double(&press));
73+
sensor_log("Pressure: %.2f kPa\n", sensor_value_to_double(&press));
7474
}
7575
if (IS_ENABLED(CONFIG_HAS_GAS)) {
76-
sensor_log("Gas: %.2f", sensor_value_to_double(&gas));
76+
sensor_log("Gas: %.2f\n", sensor_value_to_double(&gas));
7777
}
7878
}
7979

@@ -86,40 +86,7 @@ static void handler_(const struct device *dev,
8686

8787
void main(void)
8888
{
89-
90-
#if defined(CONFIG_HTS221)
91-
sensor_dev = DEVICE_DT_GET_ANY(st_hts221);
92-
#elif defined(CONFIG_TH02)
93-
sensor_dev = DEVICE_DT_GET_ANY(hoperf_th02);
94-
#elif defined(CONFIG_BME280)
95-
sensor_dev = DEVICE_DT_GET_ANY(bosch_bme280);
96-
#elif defined(CONFIG_TMP007)
97-
sensor_dev = DEVICE_DT_GET_ANY(ti_tmp007);
98-
#elif defined(CONFIG_SHT3XD)
99-
sensor_dev = DEVICE_DT_GET_ANY(sensirion_sht3xd);
100-
#elif defined(CONFIG_BME680)
101-
sensor_dev = DEVICE_DT_GET_ANY(bosch_bme680);
102-
#elif defined(CONFIG_MCP9808)
103-
sensor_dev = DEVICE_DT_GET_ANY(microchip_mcp9808);
104-
#elif defined(CONFIG_DPS310)
105-
sensor_dev = DEVICE_DT_GET_ANY(infineon_dps310);
106-
#elif defined(CONFIG_TI_HDC)
107-
sensor_dev = DEVICE_DT_GET_ANY(ti_hdc);
108-
#elif defined(CONFIG_MAX6675)
109-
sensor_dev = DEVICE_DT_GET_ANY(maxim_max6675);
110-
#elif defined(CONFIG_LPS22HB)
111-
sensor_dev = DEVICE_DT_GET_ANY(st_lps22hb_press);
112-
#elif defined(CONFIG_LPS22HH)
113-
sensor_dev = DEVICE_DT_GET_ANY(st_lps22hh);
114-
#elif defined(CONFIG_ENS210)
115-
sensor_dev = DEVICE_DT_GET_ANY(ams_ens210);
116-
#elif defined(CONFIG_DHT)
117-
sensor_dev = DEVICE_DT_GET_ANY(aosong_dht);
118-
#elif defined(CONFIG_SI7006)
119-
sensor_dev = DEVICE_DT_GET_ANY(silabs_si7006);
120-
#else
121-
#error Not defined
122-
#endif
89+
sensor_dev = DEVICE_DT_GET(DT_NODELABEL(env_sensor));
12390

12491
if (sensor_dev == NULL) {
12592
LOG_ERR("Could not get sensor device");

0 commit comments

Comments
 (0)