dwm_evt_wait
Used to wait for an event from the DWM module. First, the listener to the event must be the first registered by dwm_evt_listener_register. If the listener is registered and dwm_evt_wait is not used to consume events, the event buffer will overflow. When no events in the buffer, the dwm_evt_wait will block and sleep until next event.
-
void dwm_evt_wait(dwm_evt_t *evt)
- Parameters
input – (none)
output – Status code, evt
evt – loc_ready | usr_data_ready | usr_data_sent | uwb_scan_ready | bh_initialized_changed | uwbmac_joined_changed
C code example
void on_dwm_evt(dwm_evt_t *p_evt)
{
int i;
switch (p_evt->header.id) {
/* New location data */
case DWM_EVT_LOC_READY:
printf("\nT:%lu ", dwm_systime_us_get());
if (p_evt->loc.pos_available) {
printf("POS:[%ld,%ld,%ld,%u] ", p_evt->loc.pos.x,
p_evt->loc.pos.y, p_evt->loc.pos.z,
p_evt->loc.pos.qf);
} else {
printf("Location engine is disabled\n");
}
for (i = 0; i < p_evt->loc.anchors.dist.cnt; ++i) {
printf("DIST%d:", i);
printf("0x%04X", (unsigned int)(p_evt->loc.anchors.dist.addr[i] & 0xffff));
if (i < p_evt->loc.anchors.an_pos.cnt) {
printf("[%ld,%ld,%ld]", p_evt->loc.anchors.an_pos.pos[i].x, p_evt->loc.anchors.an_pos.pos[i].y, p_evt->loc.anchors.an_pos.pos[i].z);
}
printf("=[%lu,%u] ", p_evt->loc.anchors.dist.dist[i],
p_evt->loc.anchors.dist.qf[i]);
}
printf("\n");
break;
case DWM_EVT_USR_DATA_READY:
printf("hex:");
for (i = 0; i < p_evt->header.len - sizeof(dwm_evt_hdr_t); ++i) {
printf("%02x ", p_evt->usr_data[i]);
}
printf("\n");
break;
case DWM_EVT_USR_DATA_SENT:
printf("iot sent\n");
break;
case DWM_EVT_UWB_SCAN_READY:
printf("[mode,rssi]: ");
for (i = 0; i < p_evt->uwb_scan.cnt; ++i) {
printf("[%u, %d]", p_evt->uwb_scan.mode[i], p_evt->uwb_scan.rssi[i]);
}
printf("\n");
break;
case DWM_EVT_BH_INITIALIZED_CHANGED:
printf("backhaul available = %d\n", p_evt->bh_initialized);
break;
case DWM_EVT_UWBMAC_JOINED_CHANGED:
printf("UWBMAC joined = %d\n", p_evt->uwbmac_joined);
break;
default:
break;
}
/* Indicate the application has finished the tasks and can now */
dwm_sleep();
}
/* … */
int rv;
dwm_evt_t evt;
rv = dwm_evt_wait(&evt);
if (rv == DWM_ERR_OVERRUN) {
printf("event buffer overflow\n");
} else {
on_dwm_evt(&evt);
}
SPI/UART example
Not available on these interfaces