 |
xensiv-radar-sensing
|
- Following code snippet shows example usage of RadarSensing library APIs for presence detection application.
#include "mtb_radar_sensing.h"
cyhal_spi_t mSPI;
{
.reset = CYBSP_GPIO11,
.ldo_en = CYBSP_GPIO5,
.irq = CYBSP_GPIO10,
.spi = &mSPI
};
cyhal_gpio_init(hw_cfg.
reset, CYHAL_GPIO_DIR_OUTPUT, CYHAL_GPIO_DRIVE_STRONG,
true);
cyhal_gpio_init(hw_cfg.
ldo_en, CYHAL_GPIO_DIR_OUTPUT, CYHAL_GPIO_DRIVE_STRONG,
true);
cyhal_gpio_init(hw_cfg.
irq, CYHAL_GPIO_DIR_INPUT, CYHAL_GPIO_DRIVE_PULLDOWN,
false);
cyhal_gpio_init(hw_cfg.
spi_cs, CYHAL_GPIO_DIR_OUTPUT, CYHAL_GPIO_DRIVE_STRONG,
true);
if (cyhal_spi_init(hw_cfg.
spi, CYBSP_SPI_MOSI, CYBSP_SPI_MISO, CYBSP_SPI_CLK, NC, NULL, 8,
CYHAL_SPI_MODE_00_MSB, false) != CY_RSLT_SUCCESS )
{
CY_ASSERT(0);
}
if (cyhal_spi_set_frequency(hw_cfg.
spi, SPI_FREQUENCY) != CY_RSLT_SUCCESS)
{
CY_ASSERT(0);
}
{
printf("mtb_radar_sensing_init error - Radar Wingboard not connected?\n");
CY_ASSERT(0);
return;
}
{
CY_ASSERT(0);
return;
}
{
CY_ASSERT(0);
return;
}
void* data)
{
switch (event) {
printf("%.3f: Presence IN %.2f-%.2f\r\n",
break;
printf(
"%.3f: Presence OUT\r\n", (
float) event_info->
timestamp / 1000);
break;
}
}
{
CY_ASSERT(0);
return;
}
{
CY_ASSERT(0);
return;
}
for (;;)
{
uint64_t currenttime = (uint64_t)xTaskGetTickCount() * 1000LL / configTICK_RATE_HZ;
{
printf("mtb_radar_sensing_process error\n");
CY_ASSERT(0);
}
}
- Note
- mtb_radar_sensing_process should be called every ~2ms (use MTB_RADAR_SENSING_PROCESS_DELAY constant).
- Users should replace currenttime initialization with their own APIs that provide system time in ms.
- For a complete demonstration of the above code snippet using FreeRTOS, please refer to the Modus Toolbox Code Example on presence detection and entrance counter.
- For a MCU other than PSoC, users will have to configure SPI, HW accordingly.
- A similar approach can be taken to demonstrate the use of RadarSensing library APIs for entrance counter. However, there are a few changes that need to be made to the above code snippet:
{
printf("mtb_radar_sensing_init error - Radar Wingboard not connected?\n");
CY_ASSERT(0);
return;
}
{
CY_ASSERT(0);
return;
}
{
CY_ASSERT(0);
return;
}
void* data)
{
switch (event)
{
printf("%.2f: Counter IN detected, IN: %d, OUT: %d\r\n",
break;
printf("%.2f: Counter OUT detected, IN: %d, OUT: %d\r\n",
break;
printf("%.2f: Counter occupied detected, IN: %d, OUT: %d\r\n",
break;
printf("%.2f: Counter free detected, IN: %d, OUT: %d\r\n",
break;
default:
break;
}
}
For details on high-level function, used data structures and callback definition, please refer to:
#define MTB_RADAR_SENSING_PROCESS_DELAY
Recommended delay time (ms) after each call to mtb_radar_sensing_process.
Definition: mtb_radar_sensing.h:501
#define MTB_RADAR_SENSING_SUCCESS
Result success
Definition: mtb_radar_sensing.h:503
Context object of the radar.
Definition: mtb_radar_sensing.h:629
@ MTB_RADAR_SENSING_EVENT_PRESENCE_IN
Presence event: one or more people were detected in radar field of view within maximum range.
Definition: mtb_radar_sensing.h:555
@ MTB_RADAR_SENSING_MASK_PRESENCE_EVENTS
Events for presence detection.
Definition: mtb_radar_sensing.h:570
cyhal_spi_t * spi
spi
Definition: mtb_radar_sensing.h:620
Structure to hold information of entrance counter events.
Definition: mtb_radar_sensing.h:603
cyhal_gpio_t reset
reset
Definition: mtb_radar_sensing.h:617
@ MTB_RADAR_SENSING_EVENT_COUNTER_IN
Counter in event: a person has entered through the counter.
Definition: mtb_radar_sensing.h:557
cyhal_gpio_t spi_cs
spi_cs
Definition: mtb_radar_sensing.h:616
@ MTB_RADAR_SENSING_EVENT_COUNTER_OCCUPIED
Counter occupied: a person is still present in the traffic light zone.
Definition: mtb_radar_sensing.h:559
cyhal_gpio_t irq
irq
Definition: mtb_radar_sensing.h:619
mtb_radar_sensing_timestamp_t timestamp
Timestamp of event.
Definition: mtb_radar_sensing.h:582
mtb_radar_sensing_event_t
Type of events that are detected.
Definition: mtb_radar_sensing.h:554
@ MTB_RADAR_SENSING_EVENT_COUNTER_OUT
Counter out event: a person has exited through the counter.
Definition: mtb_radar_sensing.h:558
Structure to hold information of RadarSensing event.
Definition: mtb_radar_sensing.h:581
cy_rslt_t mtb_radar_sensing_init(mtb_radar_sensing_context_t *context, const mtb_radar_sensing_hw_cfg_t *hw_cfg, mtb_radar_sensing_mask_t event_mask)
Export Functions.
Definition: mtb_radar_sensing.c:135
@ MTB_RADAR_SENSING_EVENT_PRESENCE_OUT
Absence event: no human presence was detected in radar field of view within maximum range.
Definition: mtb_radar_sensing.h:556
Structure to hold information of presence detection events.
Definition: mtb_radar_sensing.h:591
cy_rslt_t mtb_radar_sensing_enable(const mtb_radar_sensing_context_t *context)
This function enables RadarSensing.
Definition: mtb_radar_sensing.c:539
@ MTB_RADAR_SENSING_MASK_COUNTER_EVENTS
Events for entrance counter.
Definition: mtb_radar_sensing.h:571
cy_rslt_t mtb_radar_sensing_process(const mtb_radar_sensing_context_t *context, mtb_radar_sensing_timestamp_t timestamp)
This function processes time domain data acquired from radar.
Definition: mtb_radar_sensing.c:510
Structure to hold hw resources.
Definition: mtb_radar_sensing.h:615
cy_rslt_t mtb_radar_sensing_register_callback(mtb_radar_sensing_context_t *context, mtb_radar_sensing_callback_t callback, void *data)
This function registers callback for radar service.
Definition: mtb_radar_sensing.c:490
cyhal_gpio_t ldo_en
ldo_en
Definition: mtb_radar_sensing.h:618
@ MTB_RADAR_SENSING_EVENT_COUNTER_FREE
Counter free: no human presence in the traffic light zone
Definition: mtb_radar_sensing.h:560
cy_rslt_t mtb_radar_sensing_set_parameter(const mtb_radar_sensing_context_t *context, const char *key, const char *value)
This function sets the value for a configuration parameter.
Definition: mtb_radar_sensing.c:244