Altimeter API¶
The altimeter API abstracts away the need to specify a specific sensor’s init/read/write/etc functions in order to gather pressure and altitude data.
In order to use this API, the sensors
object must be present in the project’s config.json file,
along with one of the supported child sensors. An example is given below:
{
"sensors": {
"bme280": {
"spi_bus": "K_SPI1"
}
}
}
This would enable the sensor API and the BME280 sensor code and configure it for the SPI bus K_SPI1.
See the Kubos Sensor Example for an example of how to use this interface.
-
KSensorStatus
k_initialize_altitude_sensor
(void)¶ Setup the altimeter interface and any related sensors.
- Return
- KSensorStatus SENSOR_OK on success, SENSOR_WRITE_ERROR or SENSOR_NOT_FOUND on error
-
KSensorStatus
k_get_pressure
(float *press)¶ Reads back pressure data from related sensor.
- Return
- KSensorStatus SENSOR_OK on success, SENSOR_ERROR or SENSOR_READ_ERROR on error
- Parameters
press
: Pointer to pressure data in Pa (101325.0 - 0.0)
-
KSensorStatus
k_get_altitude
(float *alt)¶ Reads back altitude from related sensors.
- Return
- KSensorStatus SENSOR_OK on success, SENSOR_ERROR or SENSOR_READ_ERROR on error
- Parameters
alt
: Pointer to altitude in meters (m)