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