Fix sensor framework timer issue and update sensor sample (#917)

Fix the sensor framework timer issue reported by #884 when setting
`ms_to_next_check`, and unify the type of time related args/vars to
uint32 to avoid potential type conversion issues, and fix the compile
warnings.

And update the sensor sample by creating two sensors to confirm that
the fix works correctly.
This commit is contained in:
Wenyong Huang
2021-12-28 08:44:19 +08:00
committed by GitHub
parent 635084c9b2
commit 98bacfe6bb
7 changed files with 75 additions and 41 deletions

View File

@ -526,8 +526,10 @@ iwasm_main(int argc, char *argv[])
/* sensor framework */
init_sensor_framework();
// add the sys sensor objects
add_sys_sensor("sensor_test", "This is a sensor for test", 0, 1000,
/* add the sys sensor objects */
add_sys_sensor("sensor_test1", "This is a sensor for test", 0, 1000,
read_test_sensor, config_test_sensor);
add_sys_sensor("sensor_test2", "This is a sensor for test", 0, 1000,
read_test_sensor, config_test_sensor);
start_sensor_framework();

View File

@ -6,46 +6,78 @@
#include "wasm_app.h"
#include "wa-inc/sensor.h"
static sensor_t sensor = NULL;
static sensor_t sensor1 = NULL;
static sensor_t sensor2 = NULL;
static char *user_data = 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);
if (sensor == sensor1) {
printf("### app get sensor event from sensor1\n");
attr_container_dump(event);
}
else {
printf("### app get sensor event from sensor2\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);
if (!user_data) {
printf("allocate memory failed\n");
return;
}
printf("### app on_init 2\n");
sensor = sensor_open("sensor_test", 0, sensor_event_handler, user_data);
printf("### app on_init 3\n");
sensor1 = sensor_open("sensor_test1", 0, sensor_event_handler, user_data);
if (!sensor1) {
printf("open sensor1 failed\n");
return;
}
/* config the sensor */
sensor_config(sensor, 1000, 0, 0);
printf("### app on_init 4\n");
sensor_config(sensor1, 1000, 0, 0);
printf("### app on_init 3\n");
sensor2 = sensor_open("sensor_test2", 0, sensor_event_handler, user_data);
if (!sensor2) {
printf("open sensor2 failed\n");
return;
}
/* config the sensor */
sensor_config(sensor2, 5000, 0, 0);
printf("### app on_init 4\n");
/*
config = attr_container_create("sensor config");
sensor_config(sensor, config);
attr_container_destroy(config);
*/
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);
if (NULL != sensor1) {
sensor_config(sensor1, 0, 0, 0);
}
if (NULL != sensor2) {
sensor_config(sensor2, 0, 0, 0);
}
if (NULL != user_data) {
free(user_data);
}
/* real destroy work including killing timer and closing sensor is
accomplished in wasm app library version of on_destroy() */
}