sensor.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #include "wasm_app.h"
  6. static sensor_t sensor = NULL;
  7. /* Sensor event callback*/
  8. void sensor_event_handler(sensor_t sensor, attr_container_t *event,
  9. void *user_data)
  10. {
  11. printf("### app get sensor event\n");
  12. attr_container_dump(event);
  13. }
  14. void on_init()
  15. {
  16. char *user_data;
  17. attr_container_t *config;
  18. printf("### app on_init 1\n");
  19. /* open a sensor */
  20. user_data = malloc(100);
  21. printf("### app on_init 2\n");
  22. sensor = sensor_open("sensor_test", 0, sensor_event_handler, user_data);
  23. printf("### app on_init 3\n");
  24. /* config the sensor */
  25. sensor_config(sensor, 1000, 0, 0);
  26. printf("### app on_init 4\n");
  27. /*
  28. config = attr_container_create("sensor config");
  29. sensor_config(sensor, config);
  30. attr_container_destroy(config);
  31. */
  32. }
  33. void on_destroy()
  34. {
  35. if (NULL != sensor) {
  36. sensor_config(sensor, 0, 0, 0);
  37. }
  38. /* real destroy work including killing timer and closing sensor is
  39. accomplished in wasm app library version of on_destroy() */
  40. }