sensor.c 1.2 KB

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