This repository has been archived on 2023-11-05. You can view files and clone it, but cannot push or open issues or pull requests.
wasm-micro-runtime/samples/simple/wasm-apps/sensor.c
Josh Triplett b0b0789dca Relicense to Apache-2.0 with the LLVM-exception (#137)
With agreement from contributors.
2019-11-12 07:45:21 +08:00

49 lines
1.2 KiB
C

/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include "wasm_app.h"
static sensor_t sensor = NULL;
/* Sensor event callback*/
void sensor_event_handler(sensor_t sensor, attr_container_t *event,
void *user_data)
{
printf("### app get sensor event\n");
attr_container_dump(event);
}
void on_init()
{
char *user_data;
attr_container_t *config;
printf("### app on_init 1\n");
/* open a sensor */
user_data = malloc(100);
printf("### app on_init 2\n");
sensor = sensor_open("sensor_test", 0, sensor_event_handler, user_data);
printf("### app on_init 3\n");
/* config the sensor */
sensor_config(sensor, 1000, 0, 0);
printf("### app on_init 4\n");
/*
config = attr_container_create("sensor config");
sensor_config(sensor, config);
attr_container_destroy(config);
*/
}
void on_destroy()
{
if (NULL != sensor) {
sensor_config(sensor, 0, 0, 0);
}
/* real destroy work including killing timer and closing sensor is
accomplished in wasm app library version of on_destroy() */
}