/* This API sets the power mode of the sensor.  */
int8_t bme280_set_sensor_mode(uint8_t sensor_mode, struct bme280_dev *dev)
/* This API sets the power mode of the sensor.  */
int8_t bme280_set_sensor_mode(uint8_t sensor_mode, struct bme280_dev *dev)
{
    int8_t rslt;
    uint8_t last_set_mode;
    rslt = null_ptr_check(dev);
    if (rslt == BME280_OK)
    {
        rslt = bme280_get_sensor_mode(&last_set_mode, dev);
        if ((rslt == BME280_OK) && (last_set_mode != BME280_SLEEP_MODE))
        {
            rslt = put_device_to_sleep(dev);
        }
        if (rslt == BME280_OK)
        {
            rslt = write_power_mode(sensor_mode, dev);
        }
    }
    return rslt;
}