sensor.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "wasm_app.h"
  17. static sensor_t sensor = NULL;
  18. /* Sensor event callback*/
  19. void sensor_event_handler(sensor_t sensor, attr_container_t *event,
  20. void *user_data)
  21. {
  22. printf("### app get sensor event\n");
  23. attr_container_dump(event);
  24. }
  25. void on_init()
  26. {
  27. char *user_data;
  28. attr_container_t *config;
  29. printf("### app on_init 1\n");
  30. /* open a sensor */
  31. user_data = malloc(100);
  32. printf("### app on_init 2\n");
  33. sensor = sensor_open("sensor_test", 0, sensor_event_handler, user_data);
  34. printf("### app on_init 3\n");
  35. /* config the sensor */
  36. sensor_config(sensor, 1000, 0, 0);
  37. printf("### app on_init 4\n");
  38. /*
  39. config = attr_container_create("sensor config");
  40. sensor_config(sensor, config);
  41. attr_container_destroy(config);
  42. */
  43. }
  44. void on_destroy()
  45. {
  46. if (NULL != sensor) {
  47. sensor_config(sensor, 0, 0, 0);
  48. }
  49. /* real destroy work including killing timer and closing sensor is
  50. accomplished in wasm app library version of on_destroy() */
  51. }