Go to the documentation of this file.
40 #define SENSOR_ID (1U)
41 #define SENSOR_CALIBRATION_TIMEOUT_MS (1000U)
43 #define DEFAULT_PRESET_CONFIG SMART_PRESENCE_PRESET_CONFIG_MEDIUM_RANGE
230 printf(
"acc_detector_presence_config_create() failed\n");
238 printf(
"acc_detector_presence_config_create() failed\n");
251 printf(
"Initializing detector context failed\n");
262 printf(
"Sensor initializaiton failed\n");
269 printf(
"Sensor calibration failed\n");
276 printf(
"Sensor prepare failed failed\n");
283 printf(
"enter_hibernate failed\n");
292 bool swap_needed =
false;
297 printf(
"Could not get next result\n");
304 printf(
"Failed to process presence result\n");
313 printf(
"Data saturated. The detector result is not reliable.\n");
318 printf(
"Frame delayed. Could not read data fast enough.\n");
319 printf(
"Try lowering the frame rate or call 'acc_sensor_read' more frequently.\n");
324 printf(
"Sensor recalibration needed ... \n");
328 printf(
"exit_hibernate failed\n");
334 printf(
"Sensor calibration failed\n");
339 printf(
"Sensor recalibration done!\n");
346 printf(
"Sensor prepare failed failed\n");
353 printf(
"enter_hibernate failed\n");
369 printf(
"exit_hibernate failed\n");
377 printf(
"Sensor prepare failed failed\n");
384 printf(
"enter_hibernate failed\n");
394 printf(
"Application finished OK\n");
433 float distance_delta = (end_m - start_m) / (context->
num_distances - 1U);
436 for (uint32_t distance = 0; distance < context->
num_distances; distance++)
438 context->
distances[distance] = start_m + distance_delta * distance;
451 context->
zone_limits[zone] = start_m + ((float)(zone + 1) * zone_step_length);
471 return max_buffer_size;
486 return max_num_points;
501 return max_num_zones;
512 printf(
"acc_detector_presence_create() failed\n");
518 printf(
"acc_detector_presence_get_buffer_size() failed\n");
537 printf(
"acc_detector_presence_create() failed\n");
543 printf(
"acc_detector_presence_get_buffer_size() failed\n");
549 printf(
"Failed to initialize resources for wakeup\n");
558 if (context->
buffer == NULL)
560 printf(
"sensor buffer allocation failed\n");
567 printf(
"distances allocation failed\n");
574 printf(
"zone limits allocation failed\n");
581 printf(
"zone result allocation failed\n");
592 printf(
"wake up detection allocation failed\n");
609 float inter_frame_deviation_time_const =
616 float max_switch_delay_n = inter_frame_deviation_time_const + inter_output_time_const;
618 if (max_switch_delay_n < (intra_frame_time_const + intra_output_time_const))
620 max_switch_delay_n = intra_frame_time_const + intra_output_time_const;
653 if (context->
sensor != NULL)
658 if (context->
buffer != NULL)
687 if (context->
sensor == NULL)
689 printf(
"acc_sensor_create() failed\n");
707 printf(
"acc_detector_presence_prepare() failed\n");
717 bool cal_complete =
false;
718 const uint16_t calibration_retries = 1U;
721 for (uint16_t i = 0; !status && (i <= calibration_retries); i++)
735 if (status && !cal_complete)
739 }
while (status && !cal_complete);
750 printf(
"acc_sensor_calibrate() failed\n");
761 printf(
"exit_hibernate failed\n");
767 printf(
"acc_sensor_measure failed\n");
773 printf(
"Sensor interrupt timeout\n");
779 printf(
"acc_sensor_read failed\n");
785 printf(
"enter_hibernate failed\n");
791 printf(
"acc_detector_presence_process failed\n");
804 printf(
"acc_sensor_hibernate_on failed\n");
820 printf(
"acc_sensor_hibernate_off failed\n");
1115 static int32_t max_inter_zone = -1;
1116 static int32_t max_intra_zone = -1;
1121 float *depthwise_scores;
1122 int32_t *max_presence_zone;
1131 max_presence_zone = &max_inter_zone;
1140 max_presence_zone = &max_intra_zone;
1146 if (score > threshold)
1149 bool any_zone_detected =
false;
1150 bool zone_detected =
false;
1151 uint32_t limit_idx = 0;
1158 zone_detected =
false;
1168 zone_detected = (depthwise_scores[i] > threshold);
1171 result->zone_results[limit_idx].inter_zone_detection = zone_detected;
1175 result->zone_results[limit_idx].intra_zone_detection = zone_detected;
1180 any_zone_detected =
true;
1186 if (!any_zone_detected)
1190 result->zone_results[*max_presence_zone].inter_zone_detection =
true;
1194 result->zone_results[*max_presence_zone].intra_zone_detection =
true;
1200 float max_score = 0.0f;
1201 float max_distance = 0.0f;
1202 uint32_t max_zone = 0;
1206 if (depthwise_scores[i] > max_score)
1208 max_score = depthwise_scores[i];
1218 *max_presence_zone = max_zone;
1223 *max_presence_zone = -1;
1227 return *max_presence_zone;
1237 int32_t max_inter_zone = -1;
1238 int32_t max_intra_zone = -1;
1244 result->max_presence_zone = -1;
1253 if (max_intra_zone != -1)
1255 result->max_presence_zone = max_intra_zone;
1259 result->max_presence_zone = max_inter_zone;
1264 if (
result->zone_results[i].intra_zone_detection ||
result->zone_results[i].inter_zone_detection)
1266 result->zone_results[i].zone_detection =
true;
1279 result->max_inter_zone = max_inter_zone;
1280 result->max_intra_zone = max_intra_zone;
1304 uint32_t num_detections = 0;
1308 if (
result->zone_results[i].zone_detection)
1387 if (
result->zone_results[i].inter_zone_detection)
1401 if (
result->zone_results[i].intra_zone_detection)
1418 if (i ==
result->max_presence_zone)
float inter_presence_score
static bool enter_hibernate(acc_sensor_t *sensor)
void * acc_integration_mem_calloc(size_t nmemb, size_t size)
Allocate dynamic memory.
uint32_t num_zones_for_wakeup
void acc_detector_presence_config_inter_detection_set(acc_detector_presence_config_t *presence_config, bool enable)
Set inter-frame presence detection.
void acc_detector_presence_config_sweeps_per_frame_set(acc_detector_presence_config_t *presence_config, uint16_t sweeps_per_frame)
Set the number of sweeps per frame.
void acc_hal_integration_sensor_supply_off(acc_sensor_id_t sensor_id)
Power off sensor supply.
static bool initialize_application_resources(app_context_t *context)
int acconeer_main(int argc, char *argv[])
Assembly test example.
acc_ref_app_smart_presence_config_t * app_config
@ SMART_PRESENCE_PRESET_CONFIG_NONE
acc_detector_presence_config_t * current_presence_config
void acc_hal_integration_sensor_supply_on(acc_sensor_id_t sensor_id)
Power on sensor supply.
presence_detector_context_t * current_context
void acc_detector_presence_destroy(acc_detector_presence_handle_t *presence_handle)
Destroy a presence detector identified with the provided handle.
void acc_detector_presence_config_hwaas_set(acc_detector_presence_config_t *presence_config, uint16_t hwaas)
Set the hardware accelerated average samples (HWAAS)
bool acc_sensor_read(const acc_sensor_t *sensor, void *buffer, uint32_t buffer_size)
Read out radar data.
static bool exit_hibernate(acc_sensor_t *sensor)
#define SENSOR_CALIBRATION_TIMEOUT_MS
void acc_detector_presence_config_inter_frame_deviation_time_const_set(acc_detector_presence_config_t *presence_config, float inter_frame_deviation_time_const)
Set the time constant of the low pass filter for the inter-frame deviation between fast and slow.
acc_ref_app_smart_presence_wakeup_config_t wakeup_config
void acc_detector_presence_config_auto_profile_set(acc_detector_presence_config_t *presence_config, bool enable)
Enable automatic selection of profile based on start point of measurement.
static bool initialize_wakeup_resources(app_context_t *context)
Smart presence reference application results container for each zone.
acc_processing_result_t processing_result
uint32_t * wakeup_detections
The result from a completed calibration.
bool inter_zone_detection
void acc_detector_presence_config_frame_rate_set(acc_detector_presence_config_t *presence_config, float frame_rate)
Set the frame rate.
@ SMART_PRESENCE_PRESET_CONFIG_MEDIUM_RANGE
int32_t max_presence_zone
float acc_detector_presence_config_inter_output_time_const_get(const acc_detector_presence_config_t *presence_config)
Get the time constant for the output in the inter-frame part.
@ ACC_CONFIG_IDLE_STATE_DEEP_SLEEP
static bool detector_get_next(app_context_t *context, acc_detector_presence_result_t *detector_result)
@ SMART_PRESENCE_MODE_NOMINAL
acc_detector_presence_handle_t * detector_handle
bool acc_detector_presence_get_buffer_size(const acc_detector_presence_handle_t *presence_handle, uint32_t *buffer_size)
Get the buffer size needed for the provided presence detector handle.
static bool sensor_prepare(app_context_t *context)
static bool swap_config(app_context_t *context, smart_presence_mode_t new_mode)
@ SMART_PRESENCE_PRESET_CONFIG_LONG_RANGE
float inter_presence_score
const acc_hal_a121_t * acc_hal_rss_integration_get_implementation(void)
Get hal implementation reference.
void acc_detector_presence_config_intra_detection_threshold_set(acc_detector_presence_config_t *presence_config, float intra_detection_threshold)
Set the detection threshold for the intra-frame presence detection.
void * acc_integration_mem_alloc(size_t size)
Allocate dynamic memory.
static uint32_t get_max_num_zones(app_context_t *context)
acc_detector_presence_metadata_t metadata
static void set_config(acc_ref_app_smart_presence_config_t *app_config, smart_presence_preset_config_t preset)
acc_smart_presence_zone_result_t * zone_results
bool acc_detector_presence_config_inter_detection_get(const acc_detector_presence_config_t *presence_config)
Get if inter-frame presence detection is enabled.
bool intra_zone_detection
void acc_integration_set_periodic_wakeup(uint32_t time_msec)
Set up a periodic timer used to wake up the system from sleep.
Presence detector results container.
void acc_detector_presence_config_inter_frame_presence_timeout_set(acc_detector_presence_config_t *presence_config, uint16_t inter_frame_presence_timeout)
Set the inter-frame presence timeout in seconds.
acc_detector_presence_config_t * presence_config
smart_presence_mode_t current_mode
@ SMART_PRESENCE_PRESET_CONFIG_SHORT_RANGE
uint32_t max_switch_delay_n
float intra_presence_score
void acc_detector_presence_config_destroy(acc_detector_presence_config_t *presence_config)
Destroy a presence detector configuration.
uint32_t * wakeup_detections
bool acc_detector_presence_config_intra_detection_get(const acc_detector_presence_config_t *presence_config)
Get if frame intra-frame presence detection is enabled.
bool acc_hal_integration_wait_for_sensor_interrupt(acc_sensor_id_t sensor_id, uint32_t timeout_ms)
Wait for a sensor interrupt.
void acc_detector_presence_config_end_set(acc_detector_presence_config_t *presence_config, float end)
Set the end point of measurement interval in meters.
void acc_detector_presence_config_intra_output_time_const_set(acc_detector_presence_config_t *presence_config, float intra_output_time_const)
Set the time constant for the output in the intra-frame part.
bool acc_sensor_hibernate_off(const acc_sensor_t *sensor)
Restore sensor after exiting hibernation.
const char * acc_version_get(void)
Get the version of the Acconeer software.
float intra_presence_score
float acc_detector_presence_config_inter_detection_threshold_get(const acc_detector_presence_config_t *presence_config)
Get the detection threshold for the inter-frame presence detection.
float inter_presence_score
void acc_hal_integration_sensor_enable(acc_sensor_id_t sensor_id)
Enable sensor.
void acc_detector_presence_config_inter_frame_idle_state_set(acc_detector_presence_config_t *presence_config, acc_config_idle_state_t idle_state)
Set inter frame idle state.
float * depthwise_intra_presence_scores
bool acc_detector_presence_process(acc_detector_presence_handle_t *presence_handle, void *buffer, acc_detector_presence_result_t *result)
Process the data according to the configuration used in acc_detector_presence_config_create.
void acc_detector_presence_config_inter_output_time_const_set(acc_detector_presence_config_t *presence_config, float inter_output_time_const)
Set the time constant for the output in the inter-frame part.
static void print_result(app_context_t *context, acc_smart_presence_result_t *result)
acc_cal_result_t sensor_cal_result
void acc_detector_presence_config_reset_filters_on_prepare_set(acc_detector_presence_config_t *presence_config, bool enable)
Set if the presence filters should reset on prepare.
static bool sensor_calibration(app_context_t *context)
float acc_detector_presence_config_inter_frame_deviation_time_const_get(const acc_detector_presence_config_t *presence_config)
Get the time constant of the low pass filter for the inter-frame deviation between fast and slow.
acc_ref_app_smart_presence_zone_config_t nominal_config
acc_smart_presence_zone_result_t * zone_results
bool acc_detector_presence_prepare(const acc_detector_presence_handle_t *presence_handle, acc_detector_presence_config_t *presence_config, acc_sensor_t *sensor, const acc_cal_result_t *cal_result, void *buffer, uint32_t buffer_size)
Prepare the detector to do a measurement.
void acc_detector_presence_config_intra_detection_set(acc_detector_presence_config_t *presence_config, bool enable)
Set intra-frame presence detection.
@ SMART_PRESENCE_MODE_WAKEUP
float intra_presence_score
float * depthwise_inter_presence_scores
void acc_hal_integration_sensor_disable(acc_sensor_id_t sensor_id)
Disable sensor.
struct acc_detector_presence_config acc_detector_presence_config_t
static uint16_t get_max_num_points(app_context_t *context)
presence_detector_context_t wakeup_context
void acc_detector_presence_config_inter_frame_slow_cutoff_set(acc_detector_presence_config_t *presence_config, float inter_frame_slow_cutoff)
Set the cutoff frequency of the low pass filter for the slow filtered absolute sweep mean.
uint32_t measure_timeout_ms
bool acc_sensor_hibernate_on(acc_sensor_t *sensor)
Prepare sensor for entering hibernation.
static uint32_t get_max_buffer_size(app_context_t *context)
static bool process_detector_result(app_context_t *context, acc_detector_presence_result_t *presence_result, acc_smart_presence_result_t *result, bool *swap_needed, smart_presence_mode_t *new_mode)
void acc_sensor_status(const acc_sensor_t *sensor)
Check the status of the sensor.
@ SMART_PRESENCE_PRESET_CONFIG_CEILING
void acc_detector_presence_config_log(acc_detector_presence_config_t *presence_config)
Print a configuration to the log.
static bool determine_config_swap(app_context_t *context, acc_smart_presence_result_t *result, smart_presence_mode_t *new_mode)
#define DEFAULT_PRESET_CONFIG
float acc_detector_presence_config_frame_rate_get(const acc_detector_presence_config_t *presence_config)
Get the frame rate.
void acc_detector_presence_config_profile_set(acc_detector_presence_config_t *presence_config, acc_config_profile_t profile)
Set a profile.
presence_detector_context_t nominal_context
uint32_t current_num_zones
void acc_integration_mem_free(void *ptr)
Free dynamic memory.
void acc_integration_sleep_until_periodic_wakeup(void)
Put the system in sleep until the periodic timer triggers.
static int32_t process_inter_intra(app_context_t *context, acc_detector_presence_result_t *presence_result, acc_smart_presence_result_t *result, bool inter)
acc_detector_presence_handle_t * acc_detector_presence_create(acc_detector_presence_config_t *presence_config, acc_detector_presence_metadata_t *metadata)
Create a presence detector with the provided configuration.
float acc_detector_presence_config_intra_detection_threshold_get(const acc_detector_presence_config_t *presence_config)
Get the detection threshold for the intra-frame presence detection.
static bool initialize_sensor(app_context_t *context)
struct acc_detector_presence_handle acc_detector_presence_handle_t
bool acc_sensor_calibrate(acc_sensor_t *sensor, bool *cal_complete, acc_cal_result_t *cal_result, void *buffer, uint32_t buffer_size)
Calibrate a sensor.
acc_detector_presence_config_t * acc_detector_presence_config_create(void)
Create a configuration for a presence detector.
bool show_all_detected_zones
float acc_detector_presence_config_intra_frame_time_const_get(const acc_detector_presence_config_t *presence_config)
Get the time constant for the depthwise filtering in the intra-frame part.
void acc_detector_presence_config_signal_quality_set(acc_detector_presence_config_t *presence_config, float signal_quality)
Set signal quality.
void acc_detector_presence_config_start_set(acc_detector_presence_config_t *presence_config, float start)
Set the start point of measurement interval in meters.
float acc_detector_presence_config_intra_output_time_const_get(const acc_detector_presence_config_t *presence_config)
Get the time constant for the output in the intra-frame part.
smart_presence_preset_config_t
void acc_detector_presence_config_inter_detection_threshold_set(acc_detector_presence_config_t *presence_config, float inter_detection_threshold)
Set the detection threshold for the inter-frame presence detection.
acc_detector_presence_config_t * presence_config
bool acc_sensor_measure(acc_sensor_t *sensor)
Start a radar measurement with previously prepared configuration.
void acc_detector_presence_config_auto_step_length_set(acc_detector_presence_config_t *presence_config, bool enable)
Enable automatic selection of step length based on the profile.
static void cleanup(app_context_t *context)
struct acc_sensor acc_sensor_t
@ SMART_PRESENCE_PRESET_CONFIG_LOW_POWER_WAKEUP
void acc_detector_presence_config_intra_frame_time_const_set(acc_detector_presence_config_t *presence_config, float intra_frame_time_const)
Set the time constant for the depthwise filtering in the intra-frame part.
void acc_detector_presence_config_automatic_subsweeps_set(acc_detector_presence_config_t *presence_config, bool automatic_subsweeps)
Set if automatic subsweeps should be used.
void acc_sensor_destroy(acc_sensor_t *sensor)
Destroy a sensor instance freeing any resources allocated.
void acc_detector_presence_config_frame_rate_app_driven_set(acc_detector_presence_config_t *presence_config, bool enable)
Set if the application should maintain the requested frame rate.
Smart presence reference application results container.
void acc_detector_presence_config_inter_frame_fast_cutoff_set(acc_detector_presence_config_t *presence_config, float inter_frame_fast_cutoff)
Set the cutoff frequency of the low pass filter for the fast filtered absolute sweep mean.
acc_sensor_t * acc_sensor_create(acc_sensor_id_t sensor_id)
Create a sensor instance.