sensor.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. #include "wa-inc/sensor.h"
  7. static sensor_t sensor = NULL;
  8. /* Sensor event callback*/
  9. void
  10. sensor_event_handler(sensor_t sensor, attr_container_t *event, void *user_data)
  11. {
  12. printf("### app get sensor event\n");
  13. attr_container_dump(event);
  14. }
  15. void
  16. on_init()
  17. {
  18. char *user_data;
  19. attr_container_t *config;
  20. printf("### app on_init 1\n");
  21. /* open a sensor */
  22. user_data = malloc(100);
  23. printf("### app on_init 2\n");
  24. sensor = sensor_open("sensor_test", 0, sensor_event_handler, user_data);
  25. printf("### app on_init 3\n");
  26. /* config the sensor */
  27. sensor_config(sensor, 1000, 0, 0);
  28. printf("### app on_init 4\n");
  29. /*
  30. config = attr_container_create("sensor config");
  31. sensor_config(sensor, config);
  32. attr_container_destroy(config);
  33. */
  34. }
  35. void
  36. on_destroy()
  37. {
  38. if (NULL != sensor) {
  39. sensor_config(sensor, 0, 0, 0);
  40. }
  41. /* real destroy work including killing timer and closing sensor is
  42. accomplished in wasm app library version of on_destroy() */
  43. }