Skip to content

samples: sensor: pressure_polling: Log altitude only if the sensor supports it #93607

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

ttmut
Copy link
Contributor

@ttmut ttmut commented Jul 23, 2025

Most pressure sensors in the Zephyr tree do not provide altitude data. This change adds a check to ensure altitude is printed only when the sensor supports it. A delay is also added between reads to avoid flooding the console.

ttmut added 2 commits July 23, 2025 19:08
Most pressure sensors provide temperature and pressure data, but only a
few support altitude readings. This change adds a check to ensure
altitude is logged only when the sensor supports it.

Signed-off-by: Tahsin Mutlugun <[email protected]>
Introduce a 1000 ms delay between consecutive sensor readings to prevent
logging overflow and reduce console clutter.

Signed-off-by: Tahsin Mutlugun <[email protected]>
Copy link

Copy link
Contributor

@kartben kartben left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for keeping the doc in sync!
Wasn't quite sure initially why you dropped logging and switched to printk's but I think I get it now.

@ttmut
Copy link
Contributor Author

ttmut commented Jul 24, 2025

Thanks for keeping the doc in sync! Wasn't quite sure initially why you dropped logging and switched to printk's but I think I get it now.

I wanted to avoid code duplication but now I am not sure if it is actually worth it. This was the inital change:

if (ret == 0) {
    LOG_INF("temp %.2f Cel, pressure %f kPa, altitude %f m",
	   	   sensor_value_to_double(&temperature),
	   	   sensor_value_to_double(&pressure),
	   	   sensor_value_to_double(&altitude));
} else {
    LOG_INF("temp %.2f Cel, pressure %f kPa",
	   	   sensor_value_to_double(&temperature),
	   	   sensor_value_to_double(&pressure));
}

I can revert it to this if you wish.

@kartben
Copy link
Contributor

kartben commented Jul 25, 2025

Thanks for keeping the doc in sync! Wasn't quite sure initially why you dropped logging and switched to printk's but I think I get it now.

I wanted to avoid code duplication but now I am not sure if it is actually worth it. This was the inital change:

if (ret == 0) {
    LOG_INF("temp %.2f Cel, pressure %f kPa, altitude %f m",
	   	   sensor_value_to_double(&temperature),
	   	   sensor_value_to_double(&pressure),
	   	   sensor_value_to_double(&altitude));
} else {
    LOG_INF("temp %.2f Cel, pressure %f kPa",
	   	   sensor_value_to_double(&temperature),
	   	   sensor_value_to_double(&pressure));
}

I can revert it to this if you wish.

no it's alright :) Thanks!

@kartben kartben merged commit 4c1c954 into zephyrproject-rtos:main Jul 25, 2025
25 checks passed
@ttmut ttmut deleted the refactor/pressure_polling branch July 26, 2025 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants