ref_app_smart_presence.c
Go to the documentation of this file.
1 // Copyright (c) Acconeer AB, 2023-2025
2 // All rights reserved
3 // This file is subject to the terms and conditions defined in the file
4 // 'LICENSES/license_acconeer.txt', (BSD 3-Clause License) which is part
5 // of this source code package.
6
7 #include <stdbool.h>
8 #include <stdint.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12
13 #include "acc_definitions_a121.h"
14 #include "acc_definitions_common.h"
15 #include "acc_detector_presence.h"
16 #include "acc_hal_definitions_a121.h"
17 #include "acc_hal_integration_a121.h"
18 #include "acc_integration.h"
19 #include "acc_rss_a121.h"
20 #include "acc_sensor.h"
21
22 #include "acc_version.h"
23
24 typedef enum
25 {
26 SMART_PRESENCE_PRESET_CONFIG_NONE = 0,
27 SMART_PRESENCE_PRESET_CONFIG_SHORT_RANGE,
28 SMART_PRESENCE_PRESET_CONFIG_MEDIUM_RANGE,
29 SMART_PRESENCE_PRESET_CONFIG_LONG_RANGE,
30 SMART_PRESENCE_PRESET_CONFIG_CEILING,
31 SMART_PRESENCE_PRESET_CONFIG_LOW_POWER_WAKEUP,
32 } smart_presence_preset_config_t;
33
34 typedef enum
35 {
36 SMART_PRESENCE_MODE_WAKEUP = 0,
37 SMART_PRESENCE_MODE_NOMINAL,
38 } smart_presence_mode_t;
39
40 #define SENSOR_ID (1U)
41 #define SENSOR_CALIBRATION_TIMEOUT_MS (1000U)
42
43 #define DEFAULT_PRESET_CONFIG SMART_PRESENCE_PRESET_CONFIG_MEDIUM_RANGE
44
45 /**
46 * @brief Smart presence reference application results container for each zone
47 */
48 typedef struct
49 {
50 /**
51 * The upper zone limit in m
52 */
53 float zone_limit;
54 /**
55 * Detection result
56 */
57 bool zone_detection;
58 /**
59 * Slow motion presence detection result
60 */
61 bool inter_zone_detection;
62 /**
63 * Fast motion presence detection result
64 */
65 bool intra_zone_detection;
66 } acc_smart_presence_zone_result_t;
67
68 typedef struct
69 {
70 uint32_t num_zones;
71 uint32_t num_zones_for_wakeup;
72 acc_detector_presence_config_t *presence_config;
73 } acc_ref_app_smart_presence_wakeup_config_t;
74
75 typedef struct
76 {
77 uint32_t num_zones;
78 acc_detector_presence_config_t *presence_config;
79 } acc_ref_app_smart_presence_zone_config_t;
80
81 typedef struct
82 {
83 bool use_wakeup_mode;
84 bool show_all_detected_zones;
85 acc_ref_app_smart_presence_wakeup_config_t wakeup_config;
86 acc_ref_app_smart_presence_zone_config_t nominal_config;
87 } acc_ref_app_smart_presence_config_t;
88
89 /**
90 * @brief Smart presence reference application results container
91 */
92 typedef struct
93 {
94 /**
95 * true if presence was detected in any zone, false otherwise
96 */
97 bool presence_detected;
98 /**
99 * The zone for maximum presence score if presence detected, -1 when no presence
100 */
101 int32_t max_presence_zone;
102 /**
103 * A measure of the amount of fast motion detected
104 */
105 float intra_presence_score;
106 /**
107 * A measure of the amount of slow motion detected
108 */
109 float inter_presence_score;
110 /**
111 * The index of the zone with maximum slow motion presence score, -1 when no presence
112 */
113 int32_t max_inter_zone;
114 /**
115 * The index of the zone with maximum fast motion presence score, -1 when no presence
116 */
117 int32_t max_intra_zone;
118 /**
119 * The configuration used, see smart_presence_mode_t
120 */
121 uint32_t used_config;
122 /**
123 * True if data was collected during switch delay.
124 */
125 bool switch_delay;
126 /**
127 * Array of wakeup detections for each zone, is NULL if use_wakeup_mode is set
128 */
129 uint32_t *wakeup_detections;
130 /**
131 * Array of presence results for each zone
132 */
133 acc_smart_presence_zone_result_t *zone_results;
134 } acc_smart_presence_result_t;
135
136 typedef struct
137 {
138 acc_detector_presence_handle_t *detector_handle;
139 acc_detector_presence_metadata_t metadata;
140 uint32_t buffer_size;
141 } presence_detector_context_t;
142
143 typedef struct
144 {
145 acc_ref_app_smart_presence_config_t *app_config;
146 acc_detector_presence_config_t *current_presence_config;
147 uint32_t current_num_zones;
148 smart_presence_mode_t current_mode;
149 presence_detector_context_t wakeup_context;
150 presence_detector_context_t nominal_context;
151 presence_detector_context_t *current_context;
152 acc_sensor_t *sensor;
153 void *buffer;
154 acc_cal_result_t sensor_cal_result;
155 float *zone_limits;
156 float *distances;
157 uint32_t num_distances;
158 uint32_t delay_count;
159 uint32_t max_zone_time_n;
160 uint32_t max_switch_delay_n;
161 uint32_t *wakeup_detections;
162 acc_smart_presence_zone_result_t *zone_results;
163 uint32_t measure_timeout_ms;
164 } app_context_t;
165
166 static bool swap_config(app_context_t *context, smart_presence_mode_t new_mode);
167
168 static uint32_t get_max_buffer_size(app_context_t *context);
169
170 static uint16_t get_max_num_points(app_context_t *context);
171
172 static uint32_t get_max_num_zones(app_context_t *context);
173
174 static bool initialize_application_resources(app_context_t *context);
175
176 static void cleanup(app_context_t *context);
177
178 static bool initialize_sensor(app_context_t *context);
179
180 static bool sensor_prepare(app_context_t *context);
181
182 static bool sensor_calibration(app_context_t *context);
183
184 static bool detector_get_next(app_context_t *context, acc_detector_presence_result_t *detector_result);
185
186 static bool enter_hibernate(acc_sensor_t *sensor);
187
188 static bool exit_hibernate(acc_sensor_t *sensor);
189
190 static void set_config(acc_ref_app_smart_presence_config_t *app_config, smart_presence_preset_config_t preset);
191
192 static int32_t process_inter_intra(app_context_t *context,
193 acc_detector_presence_result_t *presence_result,
194 acc_smart_presence_result_t *result,
195 bool inter);
196
197 static bool process_detector_result(app_context_t *context,
198 acc_detector_presence_result_t *presence_result,
199 acc_smart_presence_result_t *result,
200 bool *swap_needed,
201 smart_presence_mode_t *new_mode);
202
203 static bool determine_config_swap(app_context_t *context, acc_smart_presence_result_t *result, smart_presence_mode_t *new_mode);
204
205 static void print_result(app_context_t *context, acc_smart_presence_result_t *result);
206
207 int acconeer_main(int argc, char *argv[]);
208
209 int acconeer_main(int argc, char *argv[])
210 {
211 (void)argc;
212 (void)argv;
213 app_context_t context = {0};
214 acc_ref_app_smart_presence_config_t app_config = {0};
215
216 context.app_config = &app_config;
217
218 printf("Acconeer software version %s\n", acc_version_get());
219
220 const acc_hal_a121_t *hal = acc_hal_rss_integration_get_implementation();
221
222 if (!acc_rss_hal_register(hal))
223 {
224 return EXIT_FAILURE;
225 }
226
227 context.app_config->nominal_config.presence_config = acc_detector_presence_config_create();
228 if (context.app_config->nominal_config.presence_config == NULL)
229 {
230 printf("acc_detector_presence_config_create() failed\n");
231 cleanup(&context);
232 return EXIT_FAILURE;
233 }
234
235 context.app_config->wakeup_config.presence_config = acc_detector_presence_config_create();
236 if (context.app_config->wakeup_config.presence_config == NULL)
237 {
238 printf("acc_detector_presence_config_create() failed\n");
239 cleanup(&context);
240 return EXIT_FAILURE;
241 }
242
243 set_config(context.app_config, DEFAULT_PRESET_CONFIG);
244
245 acc_detector_presence_config_log(context.app_config->nominal_config.presence_config);
246
247 acc_detector_presence_config_log(context.app_config->wakeup_config.presence_config);
248
249 if (!initialize_application_resources(&context))
250 {
251 printf("Initializing detector context failed\n");
252 cleanup(&context);
253 return EXIT_FAILURE;
254 }
255
256 /* Turn the sensor on */
257 acc_hal_integration_sensor_supply_on(SENSOR_ID);
258 acc_hal_integration_sensor_enable(SENSOR_ID);
259
260 if (!initialize_sensor(&context))
261 {
262 printf("Sensor initializaiton failed\n");
263 cleanup(&context);
264 return EXIT_FAILURE;
265 }
266
267 if (!sensor_calibration(&context))
268 {
269 printf("Sensor calibration failed\n");
270 cleanup(&context);
271 return EXIT_FAILURE;
272 }
273
274 if (!sensor_prepare(&context))
275 {
276 printf("Sensor prepare failed failed\n");
277 cleanup(&context);
278 return EXIT_FAILURE;
279 }
280
281 if (!enter_hibernate(context.sensor))
282 {
283 printf("enter_hibernate failed\n");
284 cleanup(&context);
285 return EXIT_FAILURE;
286 }
287
288 while (true)
289 {
290 acc_detector_presence_result_t detector_result;
291 acc_smart_presence_result_t result = {0};
292 bool swap_needed = false;
293 smart_presence_mode_t new_mode = context.app_config->use_wakeup_mode ? SMART_PRESENCE_MODE_WAKEUP : SMART_PRESENCE_MODE_NOMINAL;
294
295 if (!detector_get_next(&context, &detector_result))
296 {
297 printf("Could not get next result\n");
298 cleanup(&context);
299 return EXIT_FAILURE;
300 }
301
302 if (!process_detector_result(&context, &detector_result, &result, &swap_needed, &new_mode))
303 {
304 printf("Failed to process presence result\n");
305 cleanup(&context);
306 return EXIT_FAILURE;
307 }
308
309 print_result(&context, &result);
310
311 if (detector_result.processing_result.data_saturated)
312 {
313 printf("Data saturated. The detector result is not reliable.\n");
314 }
315
316 if (detector_result.processing_result.frame_delayed)
317 {
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");
320 }
321
322 if (detector_result.processing_result.calibration_needed)
323 {
324 printf("Sensor recalibration needed ... \n");
325
326 if (!exit_hibernate(context.sensor))
327 {
328 printf("exit_hibernate failed\n");
329 return EXIT_FAILURE;
330 }
331
332 if (!sensor_calibration(&context))
333 {
334 printf("Sensor calibration failed\n");
335 cleanup(&context);
336 return EXIT_FAILURE;
337 }
338
339 printf("Sensor recalibration done!\n");
340
341 // If we will swap config, prepare will be handled there
342 if (!swap_needed)
343 {
344 if (!sensor_prepare(&context))
345 {
346 printf("Sensor prepare failed failed\n");
347 cleanup(&context);
348 return EXIT_FAILURE;
349 }
350
351 if (!enter_hibernate(context.sensor))
352 {
353 printf("enter_hibernate failed\n");
354 return EXIT_FAILURE;
355 }
356 }
357 }
358
359 // Swap of config needs to be done after printing the result
360 if (swap_needed)
361 {
362 swap_config(&context, new_mode);
363
364 // If we have just calibrated, we're already out of hibernate
365 if (!detector_result.processing_result.calibration_needed)
366 {
367 if (!exit_hibernate(context.sensor))
368 {
369 printf("exit_hibernate failed\n");
370 return EXIT_FAILURE;
371 }
372 }
373
374 // Before measuring again, the sensor needs to be prepared through the detector
375 if (!sensor_prepare(&context))
376 {
377 printf("Sensor prepare failed failed\n");
378 cleanup(&context);
379 return EXIT_FAILURE;
380 }
381
382 if (!enter_hibernate(context.sensor))
383 {
384 printf("enter_hibernate failed\n");
385 return EXIT_FAILURE;
386 }
387 }
388
389 acc_integration_sleep_until_periodic_wakeup();
390 }
391
392 cleanup(&context);
393
394 printf("Application finished OK\n");
395
396 return EXIT_SUCCESS;
397 }
398
399 static bool swap_config(app_context_t *context, smart_presence_mode_t new_mode)
400 {
401 bool status = true;
402
403 switch (new_mode)
404 {
405 case SMART_PRESENCE_MODE_WAKEUP:
406 context->current_context = &context->wakeup_context;
407 context->current_presence_config = context->app_config->wakeup_config.presence_config;
408 context->current_num_zones = context->app_config->wakeup_config.num_zones;
409 break;
410
411 case SMART_PRESENCE_MODE_NOMINAL:
412 context->current_context = &context->nominal_context;
413 context->current_presence_config = context->app_config->nominal_config.presence_config;
414 context->current_num_zones = context->app_config->nominal_config.num_zones;
415 break;
416
417 default:
418 status = false;
419 break;
420 }
421
422 if (status)
423 {
424 uint32_t sleep_time_ms = (uint32_t)(1000.0f / acc_detector_presence_config_frame_rate_get(context->current_presence_config));
425 acc_integration_set_periodic_wakeup(sleep_time_ms);
426
427 context->measure_timeout_ms = sleep_time_ms + 1000U;
428 context->current_mode = new_mode;
429 context->num_distances = context->current_context->metadata.num_points;
430
431 float start_m = context->current_context->metadata.start_m;
432 float end_m = context->current_context->metadata.end_m;
433 float distance_delta = (end_m - start_m) / (context->num_distances - 1U);
434
435 // Create zones limits based on chosen range and number of zones
436 for (uint32_t distance = 0; distance < context->num_distances; distance++)
437 {
438 context->distances[distance] = start_m + distance_delta * distance;
439 if (context->current_num_zones == context->num_distances)
440 {
441 context->zone_limits[distance] = context->distances[distance];
442 }
443 }
444
445 if (context->current_num_zones < context->num_distances)
446 {
447 float zone_step_length = (context->distances[context->num_distances - 1] - start_m) / context->current_num_zones;
448
449 for (uint32_t zone = 0; zone < context->current_num_zones; zone++)
450 {
451 context->zone_limits[zone] = start_m + ((float)(zone + 1) * zone_step_length);
452 }
453 }
454 }
455
456 return status;
457 }
458
459 static uint32_t get_max_buffer_size(app_context_t *context)
460 {
461 uint32_t max_buffer_size = context->nominal_context.buffer_size;
462
463 if (context->app_config->use_wakeup_mode)
464 {
465 if (context->wakeup_context.buffer_size > max_buffer_size)
466 {
467 max_buffer_size = context->wakeup_context.buffer_size;
468 }
469 }
470
471 return max_buffer_size;
472 }
473
474 static uint16_t get_max_num_points(app_context_t *context)
475 {
476 uint16_t max_num_points = context->nominal_context.metadata.num_points;
477
478 if (context->app_config->use_wakeup_mode)
479 {
480 if (context->wakeup_context.metadata.num_points > max_num_points)
481 {
482 max_num_points = context->wakeup_context.metadata.num_points;
483 }
484 }
485
486 return max_num_points;
487 }
488
489 static uint32_t get_max_num_zones(app_context_t *context)
490 {
491 uint32_t max_num_zones = context->app_config->nominal_config.num_zones;
492
493 if (context->app_config->use_wakeup_mode)
494 {
495 if (context->app_config->wakeup_config.num_zones > max_num_zones)
496 {
497 max_num_zones = context->app_config->wakeup_config.num_zones;
498 }
499 }
500
501 return max_num_zones;
502 }
503
504 static bool initialize_wakeup_resources(app_context_t *context)
505 {
506 if (context->app_config->use_wakeup_mode)
507 {
508 context->wakeup_context.detector_handle =
509 acc_detector_presence_create(context->app_config->wakeup_config.presence_config, &context->wakeup_context.metadata);
510 if (context->wakeup_context.detector_handle == NULL)
511 {
512 printf("acc_detector_presence_create() failed\n");
513 return false;
514 }
515
516 if (!acc_detector_presence_get_buffer_size(context->wakeup_context.detector_handle, &context->wakeup_context.buffer_size))
517 {
518 printf("acc_detector_presence_get_buffer_size() failed\n");
519 return false;
520 }
521 }
522 else
523 {
524 context->wakeup_context.detector_handle = NULL;
525 context->wakeup_context.buffer_size = 0;
526 }
527
528 return true;
529 }
530
531 static bool initialize_application_resources(app_context_t *context)
532 {
533 context->nominal_context.detector_handle =
534 acc_detector_presence_create(context->app_config->nominal_config.presence_config, &context->nominal_context.metadata);
535 if (context->nominal_context.detector_handle == NULL)
536 {
537 printf("acc_detector_presence_create() failed\n");
538 return false;
539 }
540
541 if (!acc_detector_presence_get_buffer_size(context->nominal_context.detector_handle, &context->nominal_context.buffer_size))
542 {
543 printf("acc_detector_presence_get_buffer_size() failed\n");
544 return false;
545 }
546
547 if (!initialize_wakeup_resources(context))
548 {
549 printf("Failed to initialize resources for wakeup\n");
550 return false;
551 }
552
553 uint32_t max_buffer_size = get_max_buffer_size(context);
554 uint16_t max_num_points = get_max_num_points(context);
555 uint32_t max_num_zones = get_max_num_zones(context);
556
557 context->buffer = acc_integration_mem_alloc(max_buffer_size);
558 if (context->buffer == NULL)
559 {
560 printf("sensor buffer allocation failed\n");
561 return false;
562 }
563
564 context->distances = acc_integration_mem_alloc(sizeof(*context->distances) * max_num_points);
565 if (context->distances == NULL)
566 {
567 printf("distances allocation failed\n");
568 return false;
569 }
570
571 context->zone_limits = acc_integration_mem_alloc(sizeof(*context->zone_limits) * max_num_zones);
572 if (context->zone_limits == NULL)
573 {
574 printf("zone limits allocation failed\n");
575 return false;
576 }
577
578 context->zone_results = acc_integration_mem_alloc(sizeof(acc_smart_presence_zone_result_t) * max_num_zones);
579 if (context->zone_results == NULL)
580 {
581 printf("zone result allocation failed\n");
582 return false;
583 }
584
585 if (context->app_config->use_wakeup_mode)
586 {
587 context->wakeup_detections =
588 acc_integration_mem_calloc(1U, sizeof(*context->wakeup_detections) * context->app_config->wakeup_config.num_zones);
589
590 if (context->wakeup_detections == NULL)
591 {
592 printf("wake up detection allocation failed\n");
593 return false;
594 }
595
596 float frame_rate = acc_detector_presence_config_frame_rate_get(context->app_config->wakeup_config.presence_config);
597 context->max_zone_time_n = (uint32_t)((2.0f * frame_rate) + 0.5f);
598
599 swap_config(context, SMART_PRESENCE_MODE_WAKEUP);
600 }
601 else
602 {
603 context->wakeup_detections = NULL;
604 context->max_zone_time_n = 0;
605
606 swap_config(context, SMART_PRESENCE_MODE_NOMINAL);
607 }
608
609 float inter_frame_deviation_time_const =
610 acc_detector_presence_config_inter_frame_deviation_time_const_get(context->app_config->nominal_config.presence_config);
611 float inter_output_time_const = acc_detector_presence_config_inter_output_time_const_get(context->app_config->nominal_config.presence_config);
612 float intra_frame_time_const = acc_detector_presence_config_intra_frame_time_const_get(context->app_config->nominal_config.presence_config);
613 float intra_output_time_const = acc_detector_presence_config_intra_output_time_const_get(context->app_config->nominal_config.presence_config);
614 float frame_rate = acc_detector_presence_config_frame_rate_get(context->app_config->nominal_config.presence_config);
615
616 float max_switch_delay_n = inter_frame_deviation_time_const + inter_output_time_const;
617
618 if (max_switch_delay_n < (intra_frame_time_const + intra_output_time_const))
619 {
620 max_switch_delay_n = intra_frame_time_const + intra_output_time_const;
621 }
622
623 context->max_switch_delay_n = (uint32_t)(max_switch_delay_n * frame_rate);
624
625 return true;
626 }
627
628 static void cleanup(app_context_t *context)
629 {
630 acc_hal_integration_sensor_disable(SENSOR_ID);
631 acc_hal_integration_sensor_supply_off(SENSOR_ID);
632
633 if (context->app_config->nominal_config.presence_config != NULL)
634 {
635 acc_detector_presence_config_destroy(context->app_config->nominal_config.presence_config);
636 }
637
638 if (context->app_config->wakeup_config.presence_config != NULL)
639 {
640 acc_detector_presence_config_destroy(context->app_config->wakeup_config.presence_config);
641 }
642
643 if (context->nominal_context.detector_handle != NULL)
644 {
645 acc_detector_presence_destroy(context->nominal_context.detector_handle);
646 }
647
648 if (context->wakeup_context.detector_handle != NULL)
649 {
650 acc_detector_presence_destroy(context->wakeup_context.detector_handle);
651 }
652
653 if (context->sensor != NULL)
654 {
655 acc_sensor_destroy(context->sensor);
656 }
657
658 if (context->buffer != NULL)
659 {
660 acc_integration_mem_free(context->buffer);
661 }
662
663 if (context->zone_limits != NULL)
664 {
665 acc_integration_mem_free(context->zone_limits);
666 }
667
668 if (context->distances != NULL)
669 {
670 acc_integration_mem_free(context->distances);
671 }
672
673 if (context->zone_results != NULL)
674 {
675 acc_integration_mem_free(context->zone_results);
676 }
677
678 if (context->wakeup_detections != NULL)
679 {
680 acc_integration_mem_free(context->wakeup_detections);
681 }
682 }
683
684 static bool initialize_sensor(app_context_t *context)
685 {
686 context->sensor = acc_sensor_create(SENSOR_ID);
687 if (context->sensor == NULL)
688 {
689 printf("acc_sensor_create() failed\n");
690 return false;
691 }
692
693 return true;
694 }
695
696 static bool sensor_prepare(app_context_t *context)
697 {
698 bool status = true;
699
700 if (!acc_detector_presence_prepare(context->current_context->detector_handle,
701 context->current_presence_config,
702 context->sensor,
703 &context->sensor_cal_result,
704 context->buffer,
705 context->current_context->buffer_size))
706 {
707 printf("acc_detector_presence_prepare() failed\n");
708 status = false;
709 }
710
711 return status;
712 }
713
714 static bool sensor_calibration(app_context_t *context)
715 {
716 bool status = false;
717 bool cal_complete = false;
718 const uint16_t calibration_retries = 1U;
719
720 // Random disturbances may cause the calibration to fail. At failure, retry at least once.
721 for (uint16_t i = 0; !status && (i <= calibration_retries); i++)
722 {
723 // Reset sensor before calibration by disabling/enabling it
724 acc_hal_integration_sensor_disable(SENSOR_ID);
725 acc_hal_integration_sensor_enable(SENSOR_ID);
726
727 do
728 {
729 status = acc_sensor_calibrate(context->sensor,
730 &cal_complete,
731 &context->sensor_cal_result,
732 context->buffer,
733 context->current_context->buffer_size);
734
735 if (status && !cal_complete)
736 {
737 status = acc_hal_integration_wait_for_sensor_interrupt(SENSOR_ID, SENSOR_CALIBRATION_TIMEOUT_MS);
738 }
739 } while (status && !cal_complete);
740 }
741
742 if (status)
743 {
744 /* Reset sensor after calibration by disabling/enabling it */
745 acc_hal_integration_sensor_disable(SENSOR_ID);
746 acc_hal_integration_sensor_enable(SENSOR_ID);
747 }
748 else
749 {
750 printf("acc_sensor_calibrate() failed\n");
751 acc_sensor_status(context->sensor);
752 }
753
754 return status;
755 }
756
757 static bool detector_get_next(app_context_t *context, acc_detector_presence_result_t *detector_result)
758 {
759 if (!exit_hibernate(context->sensor))
760 {
761 printf("exit_hibernate failed\n");
762 return false;
763 }
764
765 if (!acc_sensor_measure(context->sensor))
766 {
767 printf("acc_sensor_measure failed\n");
768 return false;
769 }
770
771 if (!acc_hal_integration_wait_for_sensor_interrupt(SENSOR_ID, context->measure_timeout_ms))
772 {
773 printf("Sensor interrupt timeout\n");
774 return false;
775 }
776
777 if (!acc_sensor_read(context->sensor, context->buffer, context->current_context->buffer_size))
778 {
779 printf("acc_sensor_read failed\n");
780 return false;
781 }
782
783 if (!enter_hibernate(context->sensor))
784 {
785 printf("enter_hibernate failed\n");
786 return false;
787 }
788
789 if (!acc_detector_presence_process(context->current_context->detector_handle, context->buffer, detector_result))
790 {
791 printf("acc_detector_presence_process failed\n");
792 return false;
793 }
794
795 return true;
796 }
797
798 static bool enter_hibernate(acc_sensor_t *sensor)
799 {
800 bool status = true;
801
802 if (!acc_sensor_hibernate_on(sensor))
803 {
804 printf("acc_sensor_hibernate_on failed\n");
805 acc_sensor_status(sensor);
806 status = false;
807 }
808
809 acc_hal_integration_sensor_disable(SENSOR_ID);
810 return status;
811 }
812
813 static bool exit_hibernate(acc_sensor_t *sensor)
814 {
815 bool status = true;
816
817 acc_hal_integration_sensor_enable(SENSOR_ID);
818 if (!acc_sensor_hibernate_off(sensor))
819 {
820 printf("acc_sensor_hibernate_off failed\n");
821 acc_sensor_status(sensor);
822 status = false;
823 }
824
825 return status;
826 }
827
828 static void set_config(acc_ref_app_smart_presence_config_t *app_config, smart_presence_preset_config_t preset)
829 {
830
831 switch (preset)
832 {
833 case SMART_PRESENCE_PRESET_CONFIG_NONE:
834 // Add custom configuration of the reference application here
835 break;
836
837 case SMART_PRESENCE_PRESET_CONFIG_SHORT_RANGE:
838 app_config->show_all_detected_zones = false;
839 app_config->use_wakeup_mode = true;
840
841 // Wakeup config
842 app_config->wakeup_config.num_zones = 1;
843 app_config->wakeup_config.num_zones_for_wakeup = 1;
844 acc_detector_presence_config_start_set(app_config->wakeup_config.presence_config, 0.5f);
845 acc_detector_presence_config_end_set(app_config->wakeup_config.presence_config, 1.0f);
846 acc_detector_presence_config_inter_frame_idle_state_set(app_config->wakeup_config.presence_config, ACC_CONFIG_IDLE_STATE_DEEP_SLEEP);
847 acc_detector_presence_config_sweeps_per_frame_set(app_config->wakeup_config.presence_config, 16);
848 acc_detector_presence_config_automatic_subsweeps_set(app_config->wakeup_config.presence_config, true);
849 acc_detector_presence_config_signal_quality_set(app_config->wakeup_config.presence_config, 30.0f);
850 acc_detector_presence_config_frame_rate_set(app_config->wakeup_config.presence_config, 2.0f);
851 acc_detector_presence_config_frame_rate_app_driven_set(app_config->wakeup_config.presence_config, false);
852 acc_detector_presence_config_reset_filters_on_prepare_set(app_config->wakeup_config.presence_config, true);
853 acc_detector_presence_config_intra_detection_set(app_config->wakeup_config.presence_config, true);
854 acc_detector_presence_config_intra_detection_threshold_set(app_config->wakeup_config.presence_config, 1.5f);
855 acc_detector_presence_config_intra_frame_time_const_set(app_config->wakeup_config.presence_config, 0.15f);
856 acc_detector_presence_config_intra_output_time_const_set(app_config->wakeup_config.presence_config, 0.3f);
857 acc_detector_presence_config_inter_detection_set(app_config->wakeup_config.presence_config, true);
858 acc_detector_presence_config_inter_detection_threshold_set(app_config->wakeup_config.presence_config, 1.0f);
859 acc_detector_presence_config_inter_frame_deviation_time_const_set(app_config->wakeup_config.presence_config, 0.5f);
860 acc_detector_presence_config_inter_frame_fast_cutoff_set(app_config->wakeup_config.presence_config, 5.0f);
861 acc_detector_presence_config_inter_frame_slow_cutoff_set(app_config->wakeup_config.presence_config, 0.20f);
862 acc_detector_presence_config_inter_output_time_const_set(app_config->wakeup_config.presence_config, 2.0f);
863 acc_detector_presence_config_inter_frame_presence_timeout_set(app_config->wakeup_config.presence_config, 3);
864
865 // Nominal config
866 app_config->nominal_config.num_zones = 5;
867 acc_detector_presence_config_start_set(app_config->nominal_config.presence_config, 0.06f);
868 acc_detector_presence_config_end_set(app_config->nominal_config.presence_config, 1.0f);
869 acc_detector_presence_config_inter_frame_idle_state_set(app_config->nominal_config.presence_config, ACC_CONFIG_IDLE_STATE_DEEP_SLEEP);
870 acc_detector_presence_config_sweeps_per_frame_set(app_config->nominal_config.presence_config, 16);
871 acc_detector_presence_config_automatic_subsweeps_set(app_config->nominal_config.presence_config, true);
872 acc_detector_presence_config_signal_quality_set(app_config->nominal_config.presence_config, 30.0f);
873 acc_detector_presence_config_frame_rate_set(app_config->nominal_config.presence_config, 10.0f);
874 acc_detector_presence_config_frame_rate_app_driven_set(app_config->nominal_config.presence_config, false);
875 acc_detector_presence_config_reset_filters_on_prepare_set(app_config->nominal_config.presence_config, true);
876 acc_detector_presence_config_intra_detection_set(app_config->nominal_config.presence_config, true);
877 acc_detector_presence_config_intra_detection_threshold_set(app_config->nominal_config.presence_config, 1.4f);
878 acc_detector_presence_config_intra_frame_time_const_set(app_config->nominal_config.presence_config, 0.15f);
879 acc_detector_presence_config_intra_output_time_const_set(app_config->nominal_config.presence_config, 0.3f);
880 acc_detector_presence_config_inter_detection_set(app_config->nominal_config.presence_config, true);
881 acc_detector_presence_config_inter_detection_threshold_set(app_config->nominal_config.presence_config, 1.0f);
882 acc_detector_presence_config_inter_frame_deviation_time_const_set(app_config->nominal_config.presence_config, 0.5f);
883 acc_detector_presence_config_inter_frame_fast_cutoff_set(app_config->nominal_config.presence_config, 5.0f);
884 acc_detector_presence_config_inter_frame_slow_cutoff_set(app_config->nominal_config.presence_config, 0.20f);
885 acc_detector_presence_config_inter_output_time_const_set(app_config->nominal_config.presence_config, 2.0f);
886 acc_detector_presence_config_inter_frame_presence_timeout_set(app_config->nominal_config.presence_config, 3);
887
888 break;
889
890 case SMART_PRESENCE_PRESET_CONFIG_MEDIUM_RANGE:
891 app_config->show_all_detected_zones = false;
892 app_config->use_wakeup_mode = true;
893
894 // Wakeup config
895 app_config->wakeup_config.num_zones = 1;
896 app_config->wakeup_config.num_zones_for_wakeup = 1;
897 acc_detector_presence_config_start_set(app_config->wakeup_config.presence_config, 1.5f);
898 acc_detector_presence_config_end_set(app_config->wakeup_config.presence_config, 2.5f);
899 acc_detector_presence_config_inter_frame_idle_state_set(app_config->wakeup_config.presence_config, ACC_CONFIG_IDLE_STATE_DEEP_SLEEP);
900 acc_detector_presence_config_sweeps_per_frame_set(app_config->wakeup_config.presence_config, 16);
901 acc_detector_presence_config_automatic_subsweeps_set(app_config->wakeup_config.presence_config, true);
902 acc_detector_presence_config_signal_quality_set(app_config->wakeup_config.presence_config, 20.0f);
903 acc_detector_presence_config_frame_rate_set(app_config->wakeup_config.presence_config, 2.0f);
904 acc_detector_presence_config_frame_rate_app_driven_set(app_config->wakeup_config.presence_config, false);
905 acc_detector_presence_config_reset_filters_on_prepare_set(app_config->wakeup_config.presence_config, true);
906 acc_detector_presence_config_intra_detection_set(app_config->wakeup_config.presence_config, true);
907 acc_detector_presence_config_intra_detection_threshold_set(app_config->wakeup_config.presence_config, 1.5f);
908 acc_detector_presence_config_intra_frame_time_const_set(app_config->wakeup_config.presence_config, 0.15f);
909 acc_detector_presence_config_intra_output_time_const_set(app_config->wakeup_config.presence_config, 0.3f);
910 acc_detector_presence_config_inter_detection_set(app_config->wakeup_config.presence_config, true);
911 acc_detector_presence_config_inter_detection_threshold_set(app_config->wakeup_config.presence_config, 1.0f);
912 acc_detector_presence_config_inter_frame_deviation_time_const_set(app_config->wakeup_config.presence_config, 0.5f);
913 acc_detector_presence_config_inter_frame_fast_cutoff_set(app_config->wakeup_config.presence_config, 6.0f);
914 acc_detector_presence_config_inter_frame_slow_cutoff_set(app_config->wakeup_config.presence_config, 0.20f);
915 acc_detector_presence_config_inter_output_time_const_set(app_config->wakeup_config.presence_config, 2.0f);
916 acc_detector_presence_config_inter_frame_presence_timeout_set(app_config->wakeup_config.presence_config, 3);
917
918 // Nominal config
919 app_config->nominal_config.num_zones = 6;
920 acc_detector_presence_config_start_set(app_config->nominal_config.presence_config, 0.3f);
921 acc_detector_presence_config_end_set(app_config->nominal_config.presence_config, 2.5f);
922 acc_detector_presence_config_inter_frame_idle_state_set(app_config->nominal_config.presence_config, ACC_CONFIG_IDLE_STATE_DEEP_SLEEP);
923 acc_detector_presence_config_sweeps_per_frame_set(app_config->nominal_config.presence_config, 16);
924 acc_detector_presence_config_automatic_subsweeps_set(app_config->nominal_config.presence_config, true);
925 acc_detector_presence_config_signal_quality_set(app_config->nominal_config.presence_config, 20.0f);
926 acc_detector_presence_config_frame_rate_set(app_config->nominal_config.presence_config, 12.0f);
927 acc_detector_presence_config_frame_rate_app_driven_set(app_config->nominal_config.presence_config, false);
928 acc_detector_presence_config_reset_filters_on_prepare_set(app_config->nominal_config.presence_config, true);
929 acc_detector_presence_config_intra_detection_set(app_config->nominal_config.presence_config, true);
930 acc_detector_presence_config_intra_detection_threshold_set(app_config->nominal_config.presence_config, 1.3f);
931 acc_detector_presence_config_intra_frame_time_const_set(app_config->nominal_config.presence_config, 0.15f);
932 acc_detector_presence_config_intra_output_time_const_set(app_config->nominal_config.presence_config, 0.3f);
933 acc_detector_presence_config_inter_detection_set(app_config->nominal_config.presence_config, true);
934 acc_detector_presence_config_inter_detection_threshold_set(app_config->nominal_config.presence_config, 1.0f);
935 acc_detector_presence_config_inter_frame_deviation_time_const_set(app_config->nominal_config.presence_config, 0.5f);
936 acc_detector_presence_config_inter_frame_fast_cutoff_set(app_config->nominal_config.presence_config, 6.0f);
937 acc_detector_presence_config_inter_frame_slow_cutoff_set(app_config->nominal_config.presence_config, 0.20f);
938 acc_detector_presence_config_inter_output_time_const_set(app_config->nominal_config.presence_config, 2.0f);
939 acc_detector_presence_config_inter_frame_presence_timeout_set(app_config->nominal_config.presence_config, 3);
940
941 break;
942
943 case SMART_PRESENCE_PRESET_CONFIG_LONG_RANGE:
944 app_config->show_all_detected_zones = false;
945 app_config->use_wakeup_mode = true;
946
947 // Wakeup config
948 app_config->wakeup_config.num_zones = 5;
949 app_config->wakeup_config.num_zones_for_wakeup = 2;
950 acc_detector_presence_config_start_set(app_config->wakeup_config.presence_config, 3.0f);
951 acc_detector_presence_config_end_set(app_config->wakeup_config.presence_config, 5.0f);
952 acc_detector_presence_config_inter_frame_idle_state_set(app_config->wakeup_config.presence_config, ACC_CONFIG_IDLE_STATE_DEEP_SLEEP);
953 acc_detector_presence_config_sweeps_per_frame_set(app_config->wakeup_config.presence_config, 32);
954 acc_detector_presence_config_automatic_subsweeps_set(app_config->wakeup_config.presence_config, true);
955 acc_detector_presence_config_signal_quality_set(app_config->wakeup_config.presence_config, 10.0f);
956 acc_detector_presence_config_frame_rate_set(app_config->wakeup_config.presence_config, 2.0f);
957 acc_detector_presence_config_frame_rate_app_driven_set(app_config->wakeup_config.presence_config, false);
958 acc_detector_presence_config_reset_filters_on_prepare_set(app_config->wakeup_config.presence_config, true);
959 acc_detector_presence_config_intra_detection_set(app_config->wakeup_config.presence_config, true);
960 acc_detector_presence_config_intra_detection_threshold_set(app_config->wakeup_config.presence_config, 1.4f);
961 acc_detector_presence_config_intra_frame_time_const_set(app_config->wakeup_config.presence_config, 0.15f);
962 acc_detector_presence_config_intra_output_time_const_set(app_config->wakeup_config.presence_config, 0.3f);
963 acc_detector_presence_config_inter_detection_set(app_config->wakeup_config.presence_config, true);
964 acc_detector_presence_config_inter_detection_threshold_set(app_config->wakeup_config.presence_config, 1.0f);
965 acc_detector_presence_config_inter_frame_deviation_time_const_set(app_config->wakeup_config.presence_config, 0.5f);
966 acc_detector_presence_config_inter_frame_fast_cutoff_set(app_config->wakeup_config.presence_config, 6.0f);
967 acc_detector_presence_config_inter_frame_slow_cutoff_set(app_config->wakeup_config.presence_config, 0.20f);
968 acc_detector_presence_config_inter_output_time_const_set(app_config->wakeup_config.presence_config, 2.0f);
969 acc_detector_presence_config_inter_frame_presence_timeout_set(app_config->wakeup_config.presence_config, 3);
970
971 // Nominal config
972 app_config->nominal_config.num_zones = 5;
973 acc_detector_presence_config_start_set(app_config->nominal_config.presence_config, 5.0f);
974 acc_detector_presence_config_end_set(app_config->nominal_config.presence_config, 7.5f);
975 acc_detector_presence_config_inter_frame_idle_state_set(app_config->nominal_config.presence_config, ACC_CONFIG_IDLE_STATE_DEEP_SLEEP);
976 acc_detector_presence_config_sweeps_per_frame_set(app_config->nominal_config.presence_config, 32);
977 acc_detector_presence_config_automatic_subsweeps_set(app_config->nominal_config.presence_config, true);
978 acc_detector_presence_config_signal_quality_set(app_config->nominal_config.presence_config, 10.0f);
979 acc_detector_presence_config_frame_rate_set(app_config->nominal_config.presence_config, 12.0f);
980 acc_detector_presence_config_frame_rate_app_driven_set(app_config->nominal_config.presence_config, false);
981 acc_detector_presence_config_reset_filters_on_prepare_set(app_config->nominal_config.presence_config, true);
982 acc_detector_presence_config_intra_detection_set(app_config->nominal_config.presence_config, true);
983 acc_detector_presence_config_intra_detection_threshold_set(app_config->nominal_config.presence_config, 1.2f);
984 acc_detector_presence_config_intra_frame_time_const_set(app_config->nominal_config.presence_config, 0.15f);
985 acc_detector_presence_config_intra_output_time_const_set(app_config->nominal_config.presence_config, 0.3f);
986 acc_detector_presence_config_inter_detection_set(app_config->nominal_config.presence_config, true);
987 acc_detector_presence_config_inter_detection_threshold_set(app_config->nominal_config.presence_config, 0.8f);
988 acc_detector_presence_config_inter_frame_deviation_time_const_set(app_config->nominal_config.presence_config, 0.5f);
989 acc_detector_presence_config_inter_frame_fast_cutoff_set(app_config->nominal_config.presence_config, 6.0f);
990 acc_detector_presence_config_inter_frame_slow_cutoff_set(app_config->nominal_config.presence_config, 0.20f);
991 acc_detector_presence_config_inter_output_time_const_set(app_config->nominal_config.presence_config, 2.0f);
992 acc_detector_presence_config_inter_frame_presence_timeout_set(app_config->nominal_config.presence_config, 3);
993
994 break;
995
996 case SMART_PRESENCE_PRESET_CONFIG_CEILING:
997 app_config->show_all_detected_zones = false;
998 app_config->use_wakeup_mode = true;
999
1000 // Wakeup config
1001 app_config->wakeup_config.num_zones = 1;
1002 app_config->wakeup_config.num_zones_for_wakeup = 1;
1003 acc_detector_presence_config_start_set(app_config->wakeup_config.presence_config, 2.0f);
1004 acc_detector_presence_config_end_set(app_config->wakeup_config.presence_config, 3.5f);
1005 acc_detector_presence_config_inter_frame_idle_state_set(app_config->wakeup_config.presence_config, ACC_CONFIG_IDLE_STATE_DEEP_SLEEP);
1006 acc_detector_presence_config_sweeps_per_frame_set(app_config->wakeup_config.presence_config, 24);
1007 acc_detector_presence_config_automatic_subsweeps_set(app_config->wakeup_config.presence_config, true);
1008 acc_detector_presence_config_signal_quality_set(app_config->wakeup_config.presence_config, 13.0f);
1009 acc_detector_presence_config_frame_rate_set(app_config->wakeup_config.presence_config, 4.0f);
1010 acc_detector_presence_config_frame_rate_app_driven_set(app_config->wakeup_config.presence_config, false);
1011 acc_detector_presence_config_reset_filters_on_prepare_set(app_config->wakeup_config.presence_config, true);
1012 acc_detector_presence_config_intra_detection_set(app_config->wakeup_config.presence_config, true);
1013 acc_detector_presence_config_intra_detection_threshold_set(app_config->wakeup_config.presence_config, 1.5f);
1014 acc_detector_presence_config_intra_frame_time_const_set(app_config->wakeup_config.presence_config, 0.15f);
1015 acc_detector_presence_config_intra_output_time_const_set(app_config->wakeup_config.presence_config, 0.25f);
1016 acc_detector_presence_config_inter_detection_set(app_config->wakeup_config.presence_config, true);
1017 acc_detector_presence_config_inter_detection_threshold_set(app_config->wakeup_config.presence_config, 1.0f);
1018 acc_detector_presence_config_inter_frame_deviation_time_const_set(app_config->wakeup_config.presence_config, 0.5f);
1019 acc_detector_presence_config_inter_frame_fast_cutoff_set(app_config->wakeup_config.presence_config, 6.0f);
1020 acc_detector_presence_config_inter_frame_slow_cutoff_set(app_config->wakeup_config.presence_config, 0.20f);
1021 acc_detector_presence_config_inter_output_time_const_set(app_config->wakeup_config.presence_config, 2.0f);
1022 acc_detector_presence_config_inter_frame_presence_timeout_set(app_config->wakeup_config.presence_config, 3);
1023
1024 // Nominal config
1025 app_config->nominal_config.num_zones = 1;
1026 acc_detector_presence_config_start_set(app_config->nominal_config.presence_config, 1.5f);
1027 acc_detector_presence_config_end_set(app_config->nominal_config.presence_config, 3.5f);
1028 acc_detector_presence_config_inter_frame_idle_state_set(app_config->nominal_config.presence_config, ACC_CONFIG_IDLE_STATE_DEEP_SLEEP);
1029 acc_detector_presence_config_sweeps_per_frame_set(app_config->nominal_config.presence_config, 18);
1030 acc_detector_presence_config_automatic_subsweeps_set(app_config->nominal_config.presence_config, true);
1031 acc_detector_presence_config_signal_quality_set(app_config->nominal_config.presence_config, 13.0f);
1032 acc_detector_presence_config_frame_rate_set(app_config->nominal_config.presence_config, 12.0f);
1033 acc_detector_presence_config_frame_rate_app_driven_set(app_config->nominal_config.presence_config, false);
1034 acc_detector_presence_config_reset_filters_on_prepare_set(app_config->nominal_config.presence_config, true);
1035 acc_detector_presence_config_intra_detection_set(app_config->nominal_config.presence_config, true);
1036 acc_detector_presence_config_intra_detection_threshold_set(app_config->nominal_config.presence_config, 1.2f);
1037 acc_detector_presence_config_intra_frame_time_const_set(app_config->nominal_config.presence_config, 0.15f);
1038 acc_detector_presence_config_intra_output_time_const_set(app_config->nominal_config.presence_config, 0.3f);
1039 acc_detector_presence_config_inter_detection_set(app_config->nominal_config.presence_config, true);
1040 acc_detector_presence_config_inter_detection_threshold_set(app_config->nominal_config.presence_config, 0.8f);
1041 acc_detector_presence_config_inter_frame_deviation_time_const_set(app_config->nominal_config.presence_config, 0.5f);
1042 acc_detector_presence_config_inter_frame_fast_cutoff_set(app_config->nominal_config.presence_config, 6.0f);
1043 acc_detector_presence_config_inter_frame_slow_cutoff_set(app_config->nominal_config.presence_config, 0.20f);
1044 acc_detector_presence_config_inter_output_time_const_set(app_config->nominal_config.presence_config, 2.0f);
1045 acc_detector_presence_config_inter_frame_presence_timeout_set(app_config->nominal_config.presence_config, 3);
1046
1047 break;
1048
1049 case SMART_PRESENCE_PRESET_CONFIG_LOW_POWER_WAKEUP:
1050 app_config->show_all_detected_zones = false;
1051 app_config->use_wakeup_mode = true;
1052
1053 // Wakeup config
1054 app_config->wakeup_config.num_zones = 1;
1055 app_config->wakeup_config.num_zones_for_wakeup = 1;
1056 acc_detector_presence_config_start_set(app_config->wakeup_config.presence_config, 0.38f);
1057 acc_detector_presence_config_end_set(app_config->wakeup_config.presence_config, 0.67f);
1058 acc_detector_presence_config_auto_step_length_set(app_config->wakeup_config.presence_config, true);
1059 acc_detector_presence_config_auto_profile_set(app_config->wakeup_config.presence_config, false);
1060 acc_detector_presence_config_profile_set(app_config->wakeup_config.presence_config, ACC_CONFIG_PROFILE_5);
1061 acc_detector_presence_config_inter_frame_idle_state_set(app_config->wakeup_config.presence_config, ACC_CONFIG_IDLE_STATE_DEEP_SLEEP);
1062 acc_detector_presence_config_hwaas_set(app_config->wakeup_config.presence_config, 8);
1063 acc_detector_presence_config_sweeps_per_frame_set(app_config->wakeup_config.presence_config, 8);
1064 acc_detector_presence_config_automatic_subsweeps_set(app_config->wakeup_config.presence_config, false);
1065 acc_detector_presence_config_frame_rate_set(app_config->wakeup_config.presence_config, 0.7f);
1066 acc_detector_presence_config_frame_rate_app_driven_set(app_config->wakeup_config.presence_config, false);
1067 acc_detector_presence_config_reset_filters_on_prepare_set(app_config->wakeup_config.presence_config, true);
1068 acc_detector_presence_config_intra_detection_set(app_config->wakeup_config.presence_config, true);
1069 acc_detector_presence_config_intra_detection_threshold_set(app_config->wakeup_config.presence_config, 1.7f);
1070 acc_detector_presence_config_intra_frame_time_const_set(app_config->wakeup_config.presence_config, 0.3f);
1071 acc_detector_presence_config_intra_output_time_const_set(app_config->wakeup_config.presence_config, 0.3f);
1072 acc_detector_presence_config_inter_detection_set(app_config->wakeup_config.presence_config, true);
1073 acc_detector_presence_config_inter_detection_threshold_set(app_config->wakeup_config.presence_config, 1.2f);
1074 acc_detector_presence_config_inter_frame_deviation_time_const_set(app_config->wakeup_config.presence_config, 0.5f);
1075 acc_detector_presence_config_inter_frame_fast_cutoff_set(app_config->wakeup_config.presence_config, 5.0f);
1076 acc_detector_presence_config_inter_frame_slow_cutoff_set(app_config->wakeup_config.presence_config, 0.20f);
1077 acc_detector_presence_config_inter_output_time_const_set(app_config->wakeup_config.presence_config, 0.5f);
1078 acc_detector_presence_config_inter_frame_presence_timeout_set(app_config->wakeup_config.presence_config, 2);
1079
1080 // Nominal config
1081 app_config->nominal_config.num_zones = 1;
1082 acc_detector_presence_config_start_set(app_config->nominal_config.presence_config, 0.38f);
1083 acc_detector_presence_config_end_set(app_config->nominal_config.presence_config, 0.67f);
1084 acc_detector_presence_config_inter_frame_idle_state_set(app_config->nominal_config.presence_config, ACC_CONFIG_IDLE_STATE_DEEP_SLEEP);
1085 acc_detector_presence_config_sweeps_per_frame_set(app_config->nominal_config.presence_config, 16);
1086 acc_detector_presence_config_automatic_subsweeps_set(app_config->nominal_config.presence_config, true);
1087 acc_detector_presence_config_signal_quality_set(app_config->nominal_config.presence_config, 20.0f);
1088 acc_detector_presence_config_frame_rate_set(app_config->nominal_config.presence_config, 5.0f);
1089 acc_detector_presence_config_frame_rate_app_driven_set(app_config->nominal_config.presence_config, false);
1090 acc_detector_presence_config_reset_filters_on_prepare_set(app_config->nominal_config.presence_config, true);
1091 acc_detector_presence_config_intra_detection_set(app_config->nominal_config.presence_config, true);
1092 acc_detector_presence_config_intra_detection_threshold_set(app_config->nominal_config.presence_config, 1.4f);
1093 acc_detector_presence_config_intra_frame_time_const_set(app_config->nominal_config.presence_config, 0.15f);
1094 acc_detector_presence_config_intra_output_time_const_set(app_config->nominal_config.presence_config, 0.3f);
1095 acc_detector_presence_config_inter_detection_set(app_config->nominal_config.presence_config, true);
1096 acc_detector_presence_config_inter_detection_threshold_set(app_config->nominal_config.presence_config, 1.0f);
1097 acc_detector_presence_config_inter_frame_deviation_time_const_set(app_config->nominal_config.presence_config, 0.5f);
1098 acc_detector_presence_config_inter_frame_fast_cutoff_set(app_config->nominal_config.presence_config, 5.0f);
1099 acc_detector_presence_config_inter_frame_slow_cutoff_set(app_config->nominal_config.presence_config, 0.20f);
1100 acc_detector_presence_config_inter_output_time_const_set(app_config->nominal_config.presence_config, 2.0f);
1101 acc_detector_presence_config_inter_frame_presence_timeout_set(app_config->nominal_config.presence_config, 3);
1102
1103 break;
1104 }
1105
1106 acc_detector_presence_config_frame_rate_app_driven_set(app_config->wakeup_config.presence_config, true);
1107 acc_detector_presence_config_frame_rate_app_driven_set(app_config->nominal_config.presence_config, true);
1108 }
1109
1110 static int32_t process_inter_intra(app_context_t *context,
1111 acc_detector_presence_result_t *presence_result,
1112 acc_smart_presence_result_t *result,
1113 bool inter)
1114 {
1115 static int32_t max_inter_zone = -1;
1116 static int32_t max_intra_zone = -1;
1117
1118 bool detection;
1119 float threshold;
1120 float score;
1121 float *depthwise_scores;
1122 int32_t *max_presence_zone;
1123
1124 if (inter)
1125 {
1126 detection = acc_detector_presence_config_inter_detection_get(context->current_presence_config);
1127 threshold = acc_detector_presence_config_inter_detection_threshold_get(context->current_presence_config);
1128 score = presence_result->inter_presence_score;
1129
1130 depthwise_scores = presence_result->depthwise_inter_presence_scores;
1131 max_presence_zone = &max_inter_zone;
1132 }
1133 else
1134 {
1135 detection = acc_detector_presence_config_intra_detection_get(context->current_presence_config);
1136 threshold = acc_detector_presence_config_intra_detection_threshold_get(context->current_presence_config);
1137 score = presence_result->intra_presence_score;
1138
1139 depthwise_scores = presence_result->depthwise_intra_presence_scores;
1140 max_presence_zone = &max_intra_zone;
1141 }
1142
1143 /* Update zone detections for each detection type */
1144 if (detection)
1145 {
1146 if (score > threshold)
1147 {
1148 /* Get presence detection result for each zone */
1149 bool any_zone_detected = false;
1150 bool zone_detected = false;
1151 uint32_t limit_idx = 0;
1152
1153 for (uint32_t i = 0; i < context->num_distances; i++)
1154 {
1155 if (context->distances[i] > context->zone_limits[limit_idx])
1156 {
1157 limit_idx++;
1158 zone_detected = false;
1159 }
1160
1161 if (limit_idx >= context->current_num_zones)
1162 {
1163 break;
1164 }
1165
1166 if (!zone_detected)
1167 {
1168 zone_detected = (depthwise_scores[i] > threshold);
1169 if (inter)
1170 {
1171 result->zone_results[limit_idx].inter_zone_detection = zone_detected;
1172 }
1173 else
1174 {
1175 result->zone_results[limit_idx].intra_zone_detection = zone_detected;
1176 }
1177
1178 if (zone_detected)
1179 {
1180 any_zone_detected = true;
1181 }
1182 }
1183 }
1184
1185 /* If no presence is detected in the dephwise array we use the latest zone with detection */
1186 if (!any_zone_detected)
1187 {
1188 if (inter)
1189 {
1190 result->zone_results[*max_presence_zone].inter_zone_detection = true;
1191 }
1192 else
1193 {
1194 result->zone_results[*max_presence_zone].intra_zone_detection = true;
1195 }
1196 }
1197 else
1198 {
1199 /* Get the zone with maximum presence score */
1200 float max_score = 0.0f;
1201 float max_distance = 0.0f;
1202 uint32_t max_zone = 0;
1203
1204 for (uint32_t i = 0; i < context->num_distances; i++)
1205 {
1206 if (depthwise_scores[i] > max_score)
1207 {
1208 max_score = depthwise_scores[i];
1209 max_distance = context->distances[i];
1210 }
1211 }
1212
1213 while (max_zone < (context->current_num_zones - 1) && max_distance > context->zone_limits[max_zone])
1214 {
1215 max_zone++;
1216 }
1217
1218 *max_presence_zone = max_zone;
1219 }
1220 }
1221 else
1222 {
1223 *max_presence_zone = -1;
1224 }
1225 }
1226
1227 return *max_presence_zone;
1228 }
1229
1230 static bool process_detector_result(app_context_t *context,
1231 acc_detector_presence_result_t *presence_result,
1232 acc_smart_presence_result_t *result,
1233 bool *swap_needed,
1234 smart_presence_mode_t *new_mode)
1235 {
1236 bool status = true;
1237 int32_t max_inter_zone = -1;
1238 int32_t max_intra_zone = -1;
1239
1240 /* We need to clear the zone results array for every iteration */
1241 memset(context->zone_results, 0, sizeof(acc_smart_presence_zone_result_t) * context->current_num_zones);
1242
1243 result->zone_results = context->zone_results;
1244 result->max_presence_zone = -1;
1245
1246 if (presence_result->presence_detected)
1247 {
1248 /* Update zone detections for each detection type */
1249 max_inter_zone = process_inter_intra(context, presence_result, result, true);
1250 max_intra_zone = process_inter_intra(context, presence_result, result, false);
1251
1252 /* max intra zone is prioritized due to faster reaction time */
1253 if (max_intra_zone != -1)
1254 {
1255 result->max_presence_zone = max_intra_zone;
1256 }
1257 else
1258 {
1259 result->max_presence_zone = max_inter_zone;
1260 }
1261
1262 for (uint32_t i = 0; i < context->current_num_zones; i++)
1263 {
1264 if (result->zone_results[i].intra_zone_detection || result->zone_results[i].inter_zone_detection)
1265 {
1266 result->zone_results[i].zone_detection = true;
1267 }
1268 }
1269 }
1270
1271 for (uint32_t i = 0; i < context->current_num_zones; i++)
1272 {
1273 result->zone_results[i].zone_limit = context->zone_limits[i];
1274 }
1275
1276 result->presence_detected = presence_result->presence_detected;
1277 result->inter_presence_score = presence_result->inter_presence_score;
1278 result->intra_presence_score = presence_result->intra_presence_score;
1279 result->max_inter_zone = max_inter_zone;
1280 result->max_intra_zone = max_intra_zone;
1281 result->used_config = context->current_mode;
1282
1283 if (context->app_config->use_wakeup_mode)
1284 {
1285 *swap_needed = determine_config_swap(context, result, new_mode);
1286 }
1287
1288 // delay_count and wakeup_detections is updated in determine_config_swap
1289 result->switch_delay = true ? context->delay_count > 0 : false;
1290 result->wakeup_detections = context->wakeup_detections;
1291
1292 return status;
1293 }
1294
1295 static bool determine_config_swap(app_context_t *context, acc_smart_presence_result_t *result, smart_presence_mode_t *new_mode)
1296 {
1297 bool swap_config = false;
1298
1299 //
1300 if (context->delay_count == 0)
1301 {
1302 if (context->current_mode == SMART_PRESENCE_MODE_WAKEUP && result->presence_detected)
1303 {
1304 uint32_t num_detections = 0;
1305
1306 for (uint32_t i = 0; i < context->app_config->wakeup_config.num_zones; i++)
1307 {
1308 if (result->zone_results[i].zone_detection)
1309 {
1310 context->wakeup_detections[i] = context->max_zone_time_n;
1311 }
1312
1313 if (context->wakeup_detections[i] > 0)
1314 {
1315 num_detections++;
1316 context->wakeup_detections[i] -= 1;
1317 }
1318 }
1319
1320 if (num_detections >= context->app_config->wakeup_config.num_zones_for_wakeup)
1321 {
1322 *new_mode = SMART_PRESENCE_MODE_NOMINAL;
1323 swap_config = true;
1324
1325 context->delay_count++;
1326 }
1327 }
1328 else if (context->current_mode == SMART_PRESENCE_MODE_NOMINAL && !result->presence_detected)
1329 {
1330 *new_mode = SMART_PRESENCE_MODE_WAKEUP;
1331 swap_config = true;
1332 }
1333 }
1334 else
1335 {
1336 if (context->delay_count == 1)
1337 {
1338 memset(context->wakeup_detections, 0, (context->app_config->wakeup_config.num_zones * sizeof(*context->wakeup_detections)));
1339 }
1340
1341 context->delay_count++;
1342 if (context->delay_count >= (context->max_switch_delay_n + 1) || result->presence_detected)
1343 {
1344 context->delay_count = 0;
1345 }
1346 }
1347
1348 return swap_config;
1349 }
1350
1351 static void print_result(app_context_t *context, acc_smart_presence_result_t *result)
1352 {
1353 /* Format of output will look like this for four zones:
1354 *
1355 * show_all_detected_zones enabled
1356 * - intra presence in the first zone
1357 * - inter presence in the second
1358 * - both inter and intra in the third
1359 * - Wakeup mode
1360 *
1361 * --M:0---------------------------
1362 * <INTER> | # | | # | |
1363 * <INTRA> | | # | # | |
1364 * ---------------------------------
1365 *
1366 * show_all_detected_zones disabled
1367 * - Highest presence detected in the second zone
1368 * - Nominal mode
1369 *
1370 * --M:1----------------------------
1371 * <MAX> | | # | | |
1372 * ---------------------------------
1373 */
1374 printf(" --M:%" PRIu32 "-----", result->used_config);
1375 for (uint16_t i = 0; i < context->current_num_zones; i++)
1376 {
1377 printf("------");
1378 }
1379
1380 printf("\n");
1381
1382 if (context->app_config->show_all_detected_zones)
1383 {
1384 printf(" <INTER> |");
1385 for (uint16_t i = 0; i < context->current_num_zones; i++)
1386 {
1387 if (result->zone_results[i].inter_zone_detection)
1388 {
1389 printf(" # |");
1390 }
1391 else
1392 {
1393 printf(" |");
1394 }
1395 }
1396
1397 printf("\n");
1398 printf(" <INTRA> |");
1399 for (uint16_t i = 0; i < context->current_num_zones; i++)
1400 {
1401 if (result->zone_results[i].intra_zone_detection)
1402 {
1403 printf(" # |");
1404 }
1405 else
1406 {
1407 printf(" |");
1408 }
1409 }
1410
1411 printf("\n");
1412 }
1413 else
1414 {
1415 printf(" <MAX> |");
1416 for (uint16_t i = 0; i < context->current_num_zones; i++)
1417 {
1418 if (i == result->max_presence_zone)
1419 {
1420 printf(" # |");
1421 }
1422 else
1423 {
1424 printf(" |");
1425 }
1426 }
1427
1428 printf("\n");
1429 }
1430
1431 printf(" ---------");
1432 for (uint16_t i = 0; i < context->current_num_zones; i++)
1433 {
1434 printf("------");
1435 }
1436
1437 printf("\n");
1438 }
acc_detector_presence_result_t::inter_presence_score
float inter_presence_score
Definition: acc_detector_presence.h:59
enter_hibernate
static bool enter_hibernate(acc_sensor_t *sensor)
Definition: ref_app_smart_presence.c:798
acc_integration_mem_calloc
void * acc_integration_mem_calloc(size_t nmemb, size_t size)
Allocate dynamic memory.
Definition: acc_integration_stm32.c:597
acc_ref_app_smart_presence_wakeup_config_t::num_zones_for_wakeup
uint32_t num_zones_for_wakeup
Definition: ref_app_smart_presence.c:71
acc_detector_presence_config_inter_detection_set
void acc_detector_presence_config_inter_detection_set(acc_detector_presence_config_t *presence_config, bool enable)
Set inter-frame presence detection.
acc_detector_presence_config_sweeps_per_frame_set
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.
acc_ref_app_smart_presence_config_t::use_wakeup_mode
bool use_wakeup_mode
Definition: ref_app_smart_presence.c:83
app_context_t::distances
float * distances
Definition: ref_app_smart_presence.c:156
smart_presence_mode_t
smart_presence_mode_t
Definition: ref_app_smart_presence.c:34
acc_hal_integration_sensor_supply_off
void acc_hal_integration_sensor_supply_off(acc_sensor_id_t sensor_id)
Power off sensor supply.
Definition: acc_hal_integration_stm32cube_xm.c:104
acc_rss_a121.h
presence_detector_context_t::buffer_size
uint32_t buffer_size
Definition: ref_app_smart_presence.c:140
initialize_application_resources
static bool initialize_application_resources(app_context_t *context)
Definition: ref_app_smart_presence.c:531
acconeer_main
int acconeer_main(int argc, char *argv[])
Assembly test example.
Definition: ref_app_smart_presence.c:209
app_context_t::app_config
acc_ref_app_smart_presence_config_t * app_config
Definition: ref_app_smart_presence.c:145
SMART_PRESENCE_PRESET_CONFIG_NONE
@ SMART_PRESENCE_PRESET_CONFIG_NONE
Definition: ref_app_smart_presence.c:26
app_context_t::current_presence_config
acc_detector_presence_config_t * current_presence_config
Definition: ref_app_smart_presence.c:146
acc_hal_integration_sensor_supply_on
void acc_hal_integration_sensor_supply_on(acc_sensor_id_t sensor_id)
Power on sensor supply.
Definition: acc_hal_integration_stm32cube_xm.c:99
app_context_t::current_context
presence_detector_context_t * current_context
Definition: ref_app_smart_presence.c:151
acc_detector_presence_destroy
void acc_detector_presence_destroy(acc_detector_presence_handle_t *presence_handle)
Destroy a presence detector identified with the provided handle.
acc_detector_presence_config_hwaas_set
void acc_detector_presence_config_hwaas_set(acc_detector_presence_config_t *presence_config, uint16_t hwaas)
Set the hardware accelerated average samples (HWAAS)
acc_smart_presence_result_t::switch_delay
bool switch_delay
Definition: ref_app_smart_presence.c:125
acc_sensor_read
bool acc_sensor_read(const acc_sensor_t *sensor, void *buffer, uint32_t buffer_size)
Read out radar data.
acc_version.h
exit_hibernate
static bool exit_hibernate(acc_sensor_t *sensor)
Definition: ref_app_smart_presence.c:813
SENSOR_CALIBRATION_TIMEOUT_MS
#define SENSOR_CALIBRATION_TIMEOUT_MS
Definition: ref_app_smart_presence.c:41
acc_detector_presence_config_inter_frame_deviation_time_const_set
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_config_t::wakeup_config
acc_ref_app_smart_presence_wakeup_config_t wakeup_config
Definition: ref_app_smart_presence.c:85
app_context_t::zone_limits
float * zone_limits
Definition: ref_app_smart_presence.c:155
acc_detector_presence_config_auto_profile_set
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.
app_context_t::buffer
void * buffer
Definition: ref_app_smart_presence.c:153
app_context_t
Definition: ref_app_smart_presence.c:143
initialize_wakeup_resources
static bool initialize_wakeup_resources(app_context_t *context)
Definition: ref_app_smart_presence.c:504
acc_smart_presence_zone_result_t
Smart presence reference application results container for each zone.
Definition: ref_app_smart_presence.c:48
app_context_t::max_zone_time_n
uint32_t max_zone_time_n
Definition: ref_app_smart_presence.c:159
acc_detector_presence_result_t::processing_result
acc_processing_result_t processing_result
Definition: acc_detector_presence.h:82
acc_smart_presence_result_t::max_intra_zone
int32_t max_intra_zone
Definition: ref_app_smart_presence.c:117
acc_smart_presence_result_t::presence_detected
bool presence_detected
Definition: ref_app_smart_presence.c:97
app_context_t::wakeup_detections
uint32_t * wakeup_detections
Definition: ref_app_smart_presence.c:161
acc_cal_result_t
The result from a completed calibration.
Definition: acc_definitions_a121.h:30
acc_smart_presence_zone_result_t::inter_zone_detection
bool inter_zone_detection
Definition: ref_app_smart_presence.c:61
acc_detector_presence_config_frame_rate_set
void acc_detector_presence_config_frame_rate_set(acc_detector_presence_config_t *presence_config, float frame_rate)
Set the frame rate.
acc_smart_presence_zone_result_t::zone_limit
float zone_limit
Definition: ref_app_smart_presence.c:53
SMART_PRESENCE_PRESET_CONFIG_MEDIUM_RANGE
@ SMART_PRESENCE_PRESET_CONFIG_MEDIUM_RANGE
Definition: ref_app_smart_presence.c:28
acc_smart_presence_result_t::max_presence_zone
int32_t max_presence_zone
Definition: ref_app_smart_presence.c:101
acc_detector_presence_config_inter_output_time_const_get
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_detector_presence_metadata_t::start_m
float start_m
Definition: acc_detector_presence.h:95
ACC_CONFIG_IDLE_STATE_DEEP_SLEEP
@ ACC_CONFIG_IDLE_STATE_DEEP_SLEEP
Definition: acc_definitions_a121.h:73
detector_get_next
static bool detector_get_next(app_context_t *context, acc_detector_presence_result_t *detector_result)
Definition: ref_app_smart_presence.c:757
SMART_PRESENCE_MODE_NOMINAL
@ SMART_PRESENCE_MODE_NOMINAL
Definition: ref_app_smart_presence.c:37
ACC_CONFIG_PROFILE_5
@ ACC_CONFIG_PROFILE_5
Definition: acc_definitions_a121.h:57
acc_integration.h
presence_detector_context_t::detector_handle
acc_detector_presence_handle_t * detector_handle
Definition: ref_app_smart_presence.c:138
acc_detector_presence_get_buffer_size
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.
acc_ref_app_smart_presence_wakeup_config_t
Definition: ref_app_smart_presence.c:68
sensor_prepare
static bool sensor_prepare(app_context_t *context)
Definition: ref_app_smart_presence.c:696
swap_config
static bool swap_config(app_context_t *context, smart_presence_mode_t new_mode)
Definition: ref_app_smart_presence.c:399
SMART_PRESENCE_PRESET_CONFIG_LONG_RANGE
@ SMART_PRESENCE_PRESET_CONFIG_LONG_RANGE
Definition: ref_app_smart_presence.c:29
cargo_result_t::inter_presence_score
float inter_presence_score
Definition: example_cargo.h:137
acc_hal_rss_integration_get_implementation
const acc_hal_a121_t * acc_hal_rss_integration_get_implementation(void)
Get hal implementation reference.
Definition: acc_hal_integration_stm32cube_xm.c:152
acc_smart_presence_result_t::used_config
uint32_t used_config
Definition: ref_app_smart_presence.c:121
acc_detector_presence_result_t::presence_detected
bool presence_detected
Definition: acc_detector_presence.h:51
acc_detector_presence_config_intra_detection_threshold_set
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.
acc_integration_mem_alloc
void * acc_integration_mem_alloc(size_t size)
Allocate dynamic memory.
Definition: acc_integration_stm32.c:592
get_max_num_zones
static uint32_t get_max_num_zones(app_context_t *context)
Definition: ref_app_smart_presence.c:489
acc_ref_app_smart_presence_zone_config_t::num_zones
uint32_t num_zones
Definition: ref_app_smart_presence.c:77
presence_detector_context_t::metadata
acc_detector_presence_metadata_t metadata
Definition: ref_app_smart_presence.c:139
set_config
static void set_config(acc_ref_app_smart_presence_config_t *app_config, smart_presence_preset_config_t preset)
Definition: ref_app_smart_presence.c:828
acc_hal_a121_t
Definition: acc_hal_definitions_a121.h:82
app_context_t::zone_results
acc_smart_presence_zone_result_t * zone_results
Definition: ref_app_smart_presence.c:162
acc_detector_presence_config_inter_detection_get
bool acc_detector_presence_config_inter_detection_get(const acc_detector_presence_config_t *presence_config)
Get if inter-frame presence detection is enabled.
acc_smart_presence_zone_result_t::intra_zone_detection
bool intra_zone_detection
Definition: ref_app_smart_presence.c:65
acc_rss_hal_register
bool acc_rss_hal_register(const acc_hal_a121_t *hal)
Register an integration.
acc_integration_set_periodic_wakeup
void acc_integration_set_periodic_wakeup(uint32_t time_msec)
Set up a periodic timer used to wake up the system from sleep.
Definition: acc_integration_stm32.c:496
acc_sensor.h
acc_detector_presence_result_t
Presence detector results container.
Definition: acc_detector_presence.h:46
SENSOR_ID
#define SENSOR_ID
Definition: ref_app_smart_presence.c:40
acc_detector_presence_config_inter_frame_presence_timeout_set
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.
sensor
acc_sensor_t * sensor
Definition: i2c_example_cargo.c:33
acc_ref_app_smart_presence_wakeup_config_t::presence_config
acc_detector_presence_config_t * presence_config
Definition: ref_app_smart_presence.c:72
acc_detector_presence_metadata_t::num_points
uint16_t num_points
Definition: acc_detector_presence.h:115
app_context_t::current_mode
smart_presence_mode_t current_mode
Definition: ref_app_smart_presence.c:148
SMART_PRESENCE_PRESET_CONFIG_SHORT_RANGE
@ SMART_PRESENCE_PRESET_CONFIG_SHORT_RANGE
Definition: ref_app_smart_presence.c:27
acc_ref_app_smart_presence_zone_config_t
Definition: ref_app_smart_presence.c:75
app_context_t::max_switch_delay_n
uint32_t max_switch_delay_n
Definition: ref_app_smart_presence.c:160
acc_smart_presence_result_t::intra_presence_score
float intra_presence_score
Definition: ref_app_smart_presence.c:105
acc_detector_presence_config_destroy
void acc_detector_presence_config_destroy(acc_detector_presence_config_t *presence_config)
Destroy a presence detector configuration.
acc_smart_presence_result_t::wakeup_detections
uint32_t * wakeup_detections
Definition: ref_app_smart_presence.c:129
acc_detector_presence_metadata_t
Definition: acc_detector_presence.h:88
acc_detector_presence_config_intra_detection_get
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.
acc_hal_integration_wait_for_sensor_interrupt
bool acc_hal_integration_wait_for_sensor_interrupt(acc_sensor_id_t sensor_id, uint32_t timeout_ms)
Wait for a sensor interrupt.
Definition: acc_hal_integration_stm32cube_xm.c:130
acc_hal_integration_a121.h
acc_detector_presence_config_end_set
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.
acc_detector_presence_config_intra_output_time_const_set
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.
presence_detector_context_t
Definition: ref_app_smart_presence.c:136
acc_sensor_hibernate_off
bool acc_sensor_hibernate_off(const acc_sensor_t *sensor)
Restore sensor after exiting hibernation.
result
cargo_result_t result
Definition: i2c_example_cargo.c:43
acc_version_get
const char * acc_version_get(void)
Get the version of the Acconeer software.
printf
#define printf
Definition: printf.h:60
acc_detector_presence_metadata_t::end_m
float end_m
Definition: acc_detector_presence.h:101
acc_detector_presence_result_t::intra_presence_score
float intra_presence_score
Definition: acc_detector_presence.h:55
acc_detector_presence_config_inter_detection_threshold_get
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.
acc_smart_presence_result_t::inter_presence_score
float inter_presence_score
Definition: ref_app_smart_presence.c:109
acc_hal_integration_sensor_enable
void acc_hal_integration_sensor_enable(acc_sensor_id_t sensor_id)
Enable sensor.
Definition: acc_hal_integration_stm32cube_xm.c:109
acc_detector_presence_config_inter_frame_idle_state_set
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.
acc_detector_presence_result_t::depthwise_intra_presence_scores
float * depthwise_intra_presence_scores
Definition: acc_detector_presence.h:68
acc_ref_app_smart_presence_config_t
Definition: ref_app_smart_presence.c:81
acc_hal_definitions_a121.h
acc_detector_presence_process
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.
acc_detector_presence_config_inter_output_time_const_set
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.
print_result
static void print_result(app_context_t *context, acc_smart_presence_result_t *result)
Definition: ref_app_smart_presence.c:1351
app_context_t::sensor_cal_result
acc_cal_result_t sensor_cal_result
Definition: ref_app_smart_presence.c:154
acc_detector_presence_config_reset_filters_on_prepare_set
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.
acc_smart_presence_zone_result_t::zone_detection
bool zone_detection
Definition: ref_app_smart_presence.c:57
sensor_calibration
static bool sensor_calibration(app_context_t *context)
Definition: ref_app_smart_presence.c:714
acc_detector_presence_config_inter_frame_deviation_time_const_get
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.
app_context_t::num_distances
uint32_t num_distances
Definition: ref_app_smart_presence.c:157
acc_ref_app_smart_presence_config_t::nominal_config
acc_ref_app_smart_presence_zone_config_t nominal_config
Definition: ref_app_smart_presence.c:86
acc_smart_presence_result_t::zone_results
acc_smart_presence_zone_result_t * zone_results
Definition: ref_app_smart_presence.c:133
acc_detector_presence_prepare
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.
acc_detector_presence_config_intra_detection_set
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
@ SMART_PRESENCE_MODE_WAKEUP
Definition: ref_app_smart_presence.c:36
cargo_result_t::intra_presence_score
float intra_presence_score
Definition: example_cargo.h:140
acc_detector_presence_result_t::depthwise_inter_presence_scores
float * depthwise_inter_presence_scores
Definition: acc_detector_presence.h:73
acc_processing_result_t::frame_delayed
bool frame_delayed
Definition: acc_processing.h:80
acc_hal_integration_sensor_disable
void acc_hal_integration_sensor_disable(acc_sensor_id_t sensor_id)
Disable sensor.
Definition: acc_hal_integration_stm32cube_xm.c:119
acc_detector_presence_config_t
struct acc_detector_presence_config acc_detector_presence_config_t
Definition: acc_detector_presence.h:41
get_max_num_points
static uint16_t get_max_num_points(app_context_t *context)
Definition: ref_app_smart_presence.c:474
app_context_t::wakeup_context
presence_detector_context_t wakeup_context
Definition: ref_app_smart_presence.c:149
acc_detector_presence_config_inter_frame_slow_cutoff_set
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.
app_context_t::measure_timeout_ms
uint32_t measure_timeout_ms
Definition: ref_app_smart_presence.c:163
acc_smart_presence_result_t::max_inter_zone
int32_t max_inter_zone
Definition: ref_app_smart_presence.c:113
acc_sensor_hibernate_on
bool acc_sensor_hibernate_on(acc_sensor_t *sensor)
Prepare sensor for entering hibernation.
get_max_buffer_size
static uint32_t get_max_buffer_size(app_context_t *context)
Definition: ref_app_smart_presence.c:459
process_detector_result
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)
Definition: ref_app_smart_presence.c:1230
acc_sensor_status
void acc_sensor_status(const acc_sensor_t *sensor)
Check the status of the sensor.
SMART_PRESENCE_PRESET_CONFIG_CEILING
@ SMART_PRESENCE_PRESET_CONFIG_CEILING
Definition: ref_app_smart_presence.c:30
acc_detector_presence_config_log
void acc_detector_presence_config_log(acc_detector_presence_config_t *presence_config)
Print a configuration to the log.
determine_config_swap
static bool determine_config_swap(app_context_t *context, acc_smart_presence_result_t *result, smart_presence_mode_t *new_mode)
Definition: ref_app_smart_presence.c:1295
DEFAULT_PRESET_CONFIG
#define DEFAULT_PRESET_CONFIG
Definition: ref_app_smart_presence.c:43
acc_detector_presence_config_frame_rate_get
float acc_detector_presence_config_frame_rate_get(const acc_detector_presence_config_t *presence_config)
Get the frame rate.
acc_detector_presence_config_profile_set
void acc_detector_presence_config_profile_set(acc_detector_presence_config_t *presence_config, acc_config_profile_t profile)
Set a profile.
app_context_t::nominal_context
presence_detector_context_t nominal_context
Definition: ref_app_smart_presence.c:150
app_context_t::current_num_zones
uint32_t current_num_zones
Definition: ref_app_smart_presence.c:147
acc_integration_mem_free
void acc_integration_mem_free(void *ptr)
Free dynamic memory.
Definition: acc_integration_stm32.c:602
acc_integration_sleep_until_periodic_wakeup
void acc_integration_sleep_until_periodic_wakeup(void)
Put the system in sleep until the periodic timer triggers.
Definition: acc_integration_stm32.c:552
app_context_t::sensor
acc_sensor_t * sensor
Definition: ref_app_smart_presence.c:152
acc_definitions_common.h
process_inter_intra
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)
Definition: ref_app_smart_presence.c:1110
acc_detector_presence_create
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.
app_context_t::delay_count
uint32_t delay_count
Definition: ref_app_smart_presence.c:158
acc_detector_presence_config_intra_detection_threshold_get
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.
initialize_sensor
static bool initialize_sensor(app_context_t *context)
Definition: ref_app_smart_presence.c:684
acc_processing_result_t::data_saturated
bool data_saturated
Definition: acc_processing.h:76
acc_detector_presence_handle_t
struct acc_detector_presence_handle acc_detector_presence_handle_t
Definition: acc_detector_presence.h:34
acc_sensor_calibrate
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_create
acc_detector_presence_config_t * acc_detector_presence_config_create(void)
Create a configuration for a presence detector.
acc_ref_app_smart_presence_config_t::show_all_detected_zones
bool show_all_detected_zones
Definition: ref_app_smart_presence.c:84
acc_detector_presence_config_intra_frame_time_const_get
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.
cargo_result_t::presence_detected
bool presence_detected
Definition: example_cargo.h:134
acc_ref_app_smart_presence_wakeup_config_t::num_zones
uint32_t num_zones
Definition: ref_app_smart_presence.c:70
acc_detector_presence_config_signal_quality_set
void acc_detector_presence_config_signal_quality_set(acc_detector_presence_config_t *presence_config, float signal_quality)
Set signal quality.
acc_detector_presence_config_start_set
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.
acc_processing_result_t::calibration_needed
bool calibration_needed
Definition: acc_processing.h:84
acc_detector_presence.h
acc_detector_presence_config_intra_output_time_const_get
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
smart_presence_preset_config_t
Definition: ref_app_smart_presence.c:24
acc_detector_presence_config_inter_detection_threshold_set
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_ref_app_smart_presence_zone_config_t::presence_config
acc_detector_presence_config_t * presence_config
Definition: ref_app_smart_presence.c:78
acc_sensor_measure
bool acc_sensor_measure(acc_sensor_t *sensor)
Start a radar measurement with previously prepared configuration.
acc_detector_presence_config_auto_step_length_set
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.
cleanup
static void cleanup(app_context_t *context)
Definition: ref_app_smart_presence.c:628
acc_sensor_t
struct acc_sensor acc_sensor_t
Definition: acc_sensor.h:31
SMART_PRESENCE_PRESET_CONFIG_LOW_POWER_WAKEUP
@ SMART_PRESENCE_PRESET_CONFIG_LOW_POWER_WAKEUP
Definition: ref_app_smart_presence.c:31
acc_detector_presence_config_intra_frame_time_const_set
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.
acc_detector_presence_config_automatic_subsweeps_set
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.
acc_sensor_destroy
void acc_sensor_destroy(acc_sensor_t *sensor)
Destroy a sensor instance freeing any resources allocated.
acc_definitions_a121.h
acc_detector_presence_config_frame_rate_app_driven_set
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.
acc_smart_presence_result_t
Smart presence reference application results container.
Definition: ref_app_smart_presence.c:92
acc_detector_presence_config_inter_frame_fast_cutoff_set
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_create
acc_sensor_t * acc_sensor_create(acc_sensor_id_t sensor_id)
Create a sensor instance.