Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. // Listen To Local Sensor
  2. int start_sensor_listener(void) {
  3. // Set the sensor polling time to 10 seconds. SENSOR_DEVICE is either "bme280_0" or "temp_stm32_0"
  4. int rc = sensor_set_poll_rate_ms(SENSOR_DEVICE, SENSOR_POLL_TIME);
  5. assert(rc == 0);
  6.  
  7. // Fetch the sensor by name, without locking the driver for exclusive access.
  8. struct sensor *listen_sensor = sensor_mgr_find_next_bydevname(SENSOR_DEVICE, NULL);
  9. assert(listen_sensor != NULL);
  10.  
  11. // Define the listener function to be called after polling the temperature sensor.
  12. struct sensor_listener listener;
  13. listener.sl_sensor_type = TEMP_SENSOR_TYPE, // Type of sensor: ambient temperature. Either computed (floating-point) or raw (integer)
  14. listener.sl_func = read_temperature, // Listener function to be called with the sensor data
  15. listener.sl_arg = (void *) LISTENER_CB, // Indicate to the listener function that this is a listener callback
  16.  
  17. // Register the Listener Function to be called every 10 seconds, with the polled sensor data.
  18. rc = sensor_register_listener(listen_sensor, &listener);
  19. assert(rc == 0);
  20. return 0;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement