Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Listen To Local Sensor
- int start_sensor_listener(void) {
- // Set the sensor polling time to 10 seconds. SENSOR_DEVICE is either "bme280_0" or "temp_stm32_0"
- int rc = sensor_set_poll_rate_ms(SENSOR_DEVICE, SENSOR_POLL_TIME);
- assert(rc == 0);
- // Fetch the sensor by name, without locking the driver for exclusive access.
- struct sensor *listen_sensor = sensor_mgr_find_next_bydevname(SENSOR_DEVICE, NULL);
- assert(listen_sensor != NULL);
- // Define the listener function to be called after polling the temperature sensor.
- struct sensor_listener listener;
- listener.sl_sensor_type = TEMP_SENSOR_TYPE, // Type of sensor: ambient temperature. Either computed (floating-point) or raw (integer)
- listener.sl_func = read_temperature, // Listener function to be called with the sensor data
- listener.sl_arg = (void *) LISTENER_CB, // Indicate to the listener function that this is a listener callback
- // Register the Listener Function to be called every 10 seconds, with the polled sensor data.
- rc = sensor_register_listener(listen_sensor, &listener);
- assert(rc == 0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement