1. add comments for app lib
2. fix bug of sensor_config_with_attr
This commit is contained in:
@ -28,7 +28,7 @@ typedef struct _sensor {
|
||||
static sensor_t g_sensors = NULL;
|
||||
|
||||
sensor_t sensor_open(const char* name, int index,
|
||||
void (*sensor_event_handler)(sensor_t, attr_container_t *, void *),
|
||||
sensor_event_handler_f sensor_event_handler,
|
||||
void *user_data)
|
||||
{
|
||||
uint32 id = wasm_sensor_open(name, index);
|
||||
@ -63,12 +63,10 @@ sensor_t sensor_open(const char* name, int index,
|
||||
|
||||
bool sensor_config_with_attr_container(sensor_t sensor, attr_container_t *cfg)
|
||||
{
|
||||
char * buffer;
|
||||
int len;
|
||||
char *buffer = (char *)cfg;
|
||||
int len = attr_container_get_serialize_length(cfg);
|
||||
|
||||
bool ret = wasm_sensor_config_with_attr_container(sensor->handle, buffer,
|
||||
len);
|
||||
return ret;
|
||||
return wasm_sensor_config_with_attr_container(sensor->handle, buffer, len);
|
||||
}
|
||||
|
||||
bool sensor_config(sensor_t sensor, int interval, int bit_cfg, int delay)
|
||||
@ -79,7 +77,6 @@ bool sensor_config(sensor_t sensor, int interval, int bit_cfg, int delay)
|
||||
|
||||
bool sensor_close(sensor_t sensor)
|
||||
{
|
||||
|
||||
wasm_sensor_close(sensor->handle);
|
||||
|
||||
// remove local node
|
||||
@ -114,8 +111,6 @@ void on_sensor_event(uint32 sensor_id, char * buffer, int len)
|
||||
{
|
||||
attr_container_t * sensor_data = (attr_container_t *) buffer;
|
||||
|
||||
// ??? use buffer or the attributs struct?
|
||||
|
||||
// lookup the sensor and call the handlers
|
||||
sensor_t s = g_sensors;
|
||||
sensor_t prev = NULL;
|
||||
|
||||
@ -23,19 +23,77 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//TODO:
|
||||
#define bh_queue_t void
|
||||
|
||||
/* board producer define sensor */
|
||||
struct _sensor;
|
||||
typedef struct _sensor *sensor_t;
|
||||
|
||||
// Sensor APIs
|
||||
sensor_t sensor_open(const char* name, int index,
|
||||
void (*on_sensor_event)(sensor_t, attr_container_t *, void *),
|
||||
void *user_data);
|
||||
/**
|
||||
* @typedef sensor_event_handler_f
|
||||
*
|
||||
* @brief Define the signature of callback function for API
|
||||
* sensor_open() to handle sensor event.
|
||||
*
|
||||
* @param sensor the sensor which the event belong to
|
||||
* @param sensor_event the sensor event
|
||||
* @param user_data user data associated with the sensor which is set when
|
||||
* calling sensor_open().
|
||||
*
|
||||
* @see sensor_open
|
||||
*/
|
||||
typedef void (*sensor_event_handler_f)(sensor_t sensor,
|
||||
attr_container_t *sensor_event,
|
||||
void *user_data);
|
||||
|
||||
/*
|
||||
*****************
|
||||
* Sensor APIs
|
||||
*****************
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Open sensor.
|
||||
*
|
||||
* @param name sensor name
|
||||
* @param index sensor index
|
||||
* @param handler callback function to handle the sensor event
|
||||
* @param user_data user data
|
||||
*
|
||||
* @return the sensor opened if success, NULL otherwise
|
||||
*/
|
||||
sensor_t sensor_open(const char* name,
|
||||
int index,
|
||||
sensor_event_handler_f handler,
|
||||
void *user_data);
|
||||
|
||||
/**
|
||||
* @brief Configure sensor with interval/bit_cfg/delay values.
|
||||
*
|
||||
* @param sensor the sensor to be configured
|
||||
* @param interval sensor event interval
|
||||
* @param bit_cfg sensor bit config
|
||||
* @param delay sensor delay
|
||||
*
|
||||
* @return true if success, false otherwise
|
||||
*/
|
||||
bool sensor_config(sensor_t sensor, int interval, int bit_cfg, int delay);
|
||||
|
||||
/**
|
||||
* @brief Configure sensor with attr_container_t object.
|
||||
*
|
||||
* @param sensor the sensor to be configured
|
||||
* @param cfg the configuration
|
||||
*
|
||||
* @return true if success, false otherwise
|
||||
*/
|
||||
bool sensor_config_with_attr_container(sensor_t sensor, attr_container_t *cfg);
|
||||
|
||||
/**
|
||||
* @brief Close sensor.
|
||||
*
|
||||
* @param sensor the sensor to be closed
|
||||
*
|
||||
* @return true if success, false otherwise
|
||||
*/
|
||||
bool sensor_close(sensor_t sensor);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
Reference in New Issue
Block a user