example_hand_motion_detection.h
Go to the documentation of this file.
1 // Copyright (c) Acconeer AB, 2024
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 #ifndef EXAMPLE_HAND_MOTION_DETECTION_H_
8 #define EXAMPLE_HAND_MOTION_DETECTION_H_
9
10 #include <stdint.h>
11
12 #include "acc_config.h"
13 #include "acc_detector_presence.h"
14 #include "acc_processing.h"
15
16 /**
17 * @brief hand motion handle
18 */
19 typedef struct hand_motion_detection_handle hand_motion_detection_handle_t;
20
21 typedef enum
22 {
23 /*! No preset, user needs to set each specific parameter themselves */
24 HAND_MOTION_DETECTION_PRESET_NONE,
25 /*! Sensor placed on a faucet to detect hands and turn on water */
26 HAND_MOTION_DETECTION_PRESET_FAUCET,
27 } hand_motion_detection_preset_t;
28
29 typedef enum
30 {
31 HAND_MOTION_DETECTION_APP_MODE_PRESENCE,
32 HAND_MOTION_DETECTION_APP_MODE_HAND_MOTION,
33 } hand_motion_detection_app_mode_t;
34
35 typedef enum
36 {
37 HAND_MOTION_DETECTION_STATE_NO_DETECTION,
38 HAND_MOTION_DETECTION_STATE_DETECTION,
39 HAND_MOTION_DETECTION_STATE_RETENTION,
40 } hand_motion_detection_detection_state_t;
41
42 /**
43 * @brief Hand motion algo configuration
44 */
45 typedef struct
46 {
47 float sensor_to_water_distance;
48 float water_jet_width;
49 float measurement_range_end;
50 float filter_time_const;
51 float threshold;
52 float detection_retention_duration;
53 uint16_t hwaas;
54 uint16_t sweeps_per_frame;
55 float sweep_rate;
56 float frame_rate;
57 } hand_motion_detection_algo_config_t;
58
59 /**
60 * @brief Configuration for hand_motion
61 */
62 typedef struct
63 {
64 hand_motion_detection_algo_config_t algo_config;
65 acc_detector_presence_config_t *presence_config;
66 float hand_detection_timeout;
67 bool use_presence_detection;
68 } hand_motion_detection_config_t;
69
70 /**
71 * @brief Hand motion algo result
72 */
73 typedef struct
74 {
75 hand_motion_detection_detection_state_t detection_state;
76 } hand_motion_detection_algo_result_t;
77
78 /**
79 * @brief Result type
80 */
81 typedef struct
82 {
83 hand_motion_detection_app_mode_t app_mode;
84 bool presence_result_available;
85 acc_detector_presence_result_t presence_result;
86 bool algo_result_available;
87 hand_motion_detection_algo_result_t algo_result;
88 acc_processing_result_t proc_result;
89 } hand_motion_detection_result_t;
90
91 /**
92 * @brief Create a hand motion configuration
93 *
94 * @return Hand motion configuration if successful, otherwise false
95 */
96 hand_motion_detection_config_t *hand_motion_detection_config_create(void);
97
98 /**
99 * @brief Destroy a hand motion configuration
100 *
101 * @param[in] config Configuration to destroy
102 */
103 void hand_motion_detection_config_destroy(hand_motion_detection_config_t *config);
104
105 /**
106 * @brief Set config specified by the preset
107 *
108 * @param[in] preset The preset used to set hand motion config
109 * @param[out] config The hand motion config to be set
110 */
111 void hand_motion_detection_set_config(hand_motion_detection_preset_t preset, hand_motion_detection_config_t *config);
112
113 /**
114 * @brief Create a hand_motion handle
115 *
116 * The handle is used only for processing
117 *
118 * @param[in] hand_motion_detection_config hand motion configuration
119 * @param[in] sensor_id Sensor id
120 * @return A hand_motion handle, or NULL if creation failed
121 */
122 hand_motion_detection_handle_t *hand_motion_detection_handle_create(const hand_motion_detection_config_t *hand_motion_detection_config,
123 acc_sensor_id_t sensor_id);
124
125 /**
126 * @brief Destroy a hand_motion handle
127 *
128 * @param[in] handle The hand_motion handle to destroy
129 */
130 void hand_motion_detection_handle_destroy(hand_motion_detection_handle_t *handle);
131
132 /**
133 * @brief Print configuration
134 *
135 * @param[in] handle Handle to print config for
136 */
137 void hand_motion_detection_config_log(hand_motion_detection_handle_t *handle);
138
139 /**
140 * @brief Get buffer size needed
141 *
142 * @param[in] handle The hand motion handle
143 * @param[out] buffer_size Buffer size needed
144 * @return True if successful, otherwise false
145 */
146 bool hand_motion_detection_get_buffer_size(hand_motion_detection_handle_t *handle, uint32_t *buffer_size);
147
148 /**
149 * @brief Prepare hand motion
150 *
151 * @param[in] handle The hand motion handle
152 * @param[in] sensor Sensor to prepare
153 * @param[in] cal_result Sensor calibration result
154 * @param[in] buffer Data buffer
155 * @param[in] buffer_size Size of data buffer
156 * @param[in] force_prepare Force executing prepare
157 * @return True if successful, otherwise false
158 */
159 bool hand_motion_detection_prepare(hand_motion_detection_handle_t *handle,
160 acc_sensor_t *sensor,
161 const acc_cal_result_t *cal_result,
162 void *buffer,
163 uint32_t buffer_size,
164 bool force_prepare);
165
166 /**
167 * @brief Process Sparse IQ data
168 *
169 * @param[in] handle The hand_motion handle
170 * @param[in] buffer Data buffer
171 * @param[out] hand_motion_detection_result Result processed by hand_motion
172 */
173 void hand_motion_detection_process(hand_motion_detection_handle_t *handle,
174 void *buffer,
175 hand_motion_detection_result_t *hand_motion_detection_result);
176
177 #endif
HAND_MOTION_DETECTION_APP_MODE_HAND_MOTION
@ HAND_MOTION_DETECTION_APP_MODE_HAND_MOTION
Definition: example_hand_motion_detection.h:32
hand_motion_detection_algo_config_t::threshold
float threshold
Definition: example_hand_motion_detection.h:51
acc_processing_result_t
Result provided by the processing module.
Definition: acc_processing.h:71
hand_motion_detection_prepare
bool hand_motion_detection_prepare(hand_motion_detection_handle_t *handle, acc_sensor_t *sensor, const acc_cal_result_t *cal_result, void *buffer, uint32_t buffer_size, bool force_prepare)
Prepare hand motion.
Definition: example_hand_motion_detection.c:295
buffer
void * buffer
Definition: i2c_example_cargo.c:40
hand_motion_detection_algo_config_t::detection_retention_duration
float detection_retention_duration
Definition: example_hand_motion_detection.h:52
hand_motion_detection_algo_config_t::sweeps_per_frame
uint16_t sweeps_per_frame
Definition: example_hand_motion_detection.h:54
hand_motion_detection_config_create
hand_motion_detection_config_t * hand_motion_detection_config_create(void)
Create a hand motion configuration.
Definition: example_hand_motion_detection.c:63
hand_motion_detection_algo_config_t::hwaas
uint16_t hwaas
Definition: example_hand_motion_detection.h:53
hand_motion_detection_config_t::use_presence_detection
bool use_presence_detection
Definition: example_hand_motion_detection.h:67
hand_motion_detection_result_t::presence_result
acc_detector_presence_result_t presence_result
Definition: example_hand_motion_detection.h:85
hand_motion_detection_algo_config_t
Hand motion algo configuration.
Definition: example_hand_motion_detection.h:45
hand_motion_detection_config_t::algo_config
hand_motion_detection_algo_config_t algo_config
Definition: example_hand_motion_detection.h:64
acc_cal_result_t
The result from a completed calibration.
Definition: acc_definitions_a121.h:30
hand_motion_detection_config_destroy
void hand_motion_detection_config_destroy(hand_motion_detection_config_t *config)
Destroy a hand motion configuration.
Definition: example_hand_motion_detection.c:81
hand_motion_detection_algo_config_t::sensor_to_water_distance
float sensor_to_water_distance
Definition: example_hand_motion_detection.h:47
HAND_MOTION_DETECTION_STATE_RETENTION
@ HAND_MOTION_DETECTION_STATE_RETENTION
Definition: example_hand_motion_detection.h:39
hand_motion_detection_algo_config_t::measurement_range_end
float measurement_range_end
Definition: example_hand_motion_detection.h:49
hand_motion_detection_handle_create
hand_motion_detection_handle_t * hand_motion_detection_handle_create(const hand_motion_detection_config_t *hand_motion_detection_config, acc_sensor_id_t sensor_id)
Create a hand_motion handle.
Definition: example_hand_motion_detection.c:137
hand_motion_detection_result_t
Result type.
Definition: example_hand_motion_detection.h:81
hand_motion_detection_result_t::app_mode
hand_motion_detection_app_mode_t app_mode
Definition: example_hand_motion_detection.h:83
config
cargo_config_t config
Definition: i2c_example_cargo.c:34
hand_motion_detection_algo_result_t
Hand motion algo result.
Definition: example_hand_motion_detection.h:73
hand_motion_detection_handle::sensor_id
acc_sensor_id_t sensor_id
Definition: example_hand_motion_detection.c:32
hand_motion_detection_result_t::proc_result
acc_processing_result_t proc_result
Definition: example_hand_motion_detection.h:88
acc_detector_presence_result_t
Presence detector results container.
Definition: acc_detector_presence.h:46
buffer_size
uint32_t buffer_size
Definition: i2c_example_cargo.c:41
sensor
acc_sensor_t * sensor
Definition: i2c_example_cargo.c:33
hand_motion_detection_config_t::presence_config
acc_detector_presence_config_t * presence_config
Definition: example_hand_motion_detection.h:65
hand_motion_detection_algo_config_t::water_jet_width
float water_jet_width
Definition: example_hand_motion_detection.h:48
handle
cargo_handle_t * handle
Definition: i2c_example_cargo.c:35
HAND_MOTION_DETECTION_APP_MODE_PRESENCE
@ HAND_MOTION_DETECTION_APP_MODE_PRESENCE
Definition: example_hand_motion_detection.h:31
hand_motion_detection_process
void hand_motion_detection_process(hand_motion_detection_handle_t *handle, void *buffer, hand_motion_detection_result_t *hand_motion_detection_result)
Process Sparse IQ data.
Definition: example_hand_motion_detection.c:322
HAND_MOTION_DETECTION_PRESET_FAUCET
@ HAND_MOTION_DETECTION_PRESET_FAUCET
Definition: example_hand_motion_detection.h:26
hand_motion_detection_algo_config_t::sweep_rate
float sweep_rate
Definition: example_hand_motion_detection.h:55
hand_motion_detection_algo_config_t::frame_rate
float frame_rate
Definition: example_hand_motion_detection.h:56
HAND_MOTION_DETECTION_STATE_DETECTION
@ HAND_MOTION_DETECTION_STATE_DETECTION
Definition: example_hand_motion_detection.h:38
acc_detector_presence_config_t
struct acc_detector_presence_config acc_detector_presence_config_t
Definition: acc_detector_presence.h:41
acc_sensor_id_t
uint32_t acc_sensor_id_t
Type representing a sensor ID.
Definition: acc_definitions_common.h:13
hand_motion_detection_preset_t
hand_motion_detection_preset_t
Definition: example_hand_motion_detection.h:21
hand_motion_detection_get_buffer_size
bool hand_motion_detection_get_buffer_size(hand_motion_detection_handle_t *handle, uint32_t *buffer_size)
Get buffer size needed.
Definition: example_hand_motion_detection.c:269
hand_motion_detection_algo_result_t::detection_state
hand_motion_detection_detection_state_t detection_state
Definition: example_hand_motion_detection.h:75
hand_motion_detection_result_t::presence_result_available
bool presence_result_available
Definition: example_hand_motion_detection.h:84
HAND_MOTION_DETECTION_STATE_NO_DETECTION
@ HAND_MOTION_DETECTION_STATE_NO_DETECTION
Definition: example_hand_motion_detection.h:37
hand_motion_detection_result_t::algo_result
hand_motion_detection_algo_result_t algo_result
Definition: example_hand_motion_detection.h:87
hand_motion_detection_handle_destroy
void hand_motion_detection_handle_destroy(hand_motion_detection_handle_t *handle)
Destroy a hand_motion handle.
Definition: example_hand_motion_detection.c:207
hand_motion_detection_detection_state_t
hand_motion_detection_detection_state_t
Definition: example_hand_motion_detection.h:35
hand_motion_detection_set_config
void hand_motion_detection_set_config(hand_motion_detection_preset_t preset, hand_motion_detection_config_t *config)
Set config specified by the preset.
Definition: example_hand_motion_detection.c:94
acc_config.h
hand_motion_detection_app_mode_t
hand_motion_detection_app_mode_t
Definition: example_hand_motion_detection.h:29
hand_motion_detection_result_t::algo_result_available
bool algo_result_available
Definition: example_hand_motion_detection.h:86
hand_motion_detection_handle
Definition: example_hand_motion_detection.c:23
acc_detector_presence.h
HAND_MOTION_DETECTION_PRESET_NONE
@ HAND_MOTION_DETECTION_PRESET_NONE
Definition: example_hand_motion_detection.h:24
hand_motion_detection_config_t::hand_detection_timeout
float hand_detection_timeout
Definition: example_hand_motion_detection.h:66
hand_motion_detection_algo_config_t::filter_time_const
float filter_time_const
Definition: example_hand_motion_detection.h:50
acc_processing.h
acc_sensor_t
struct acc_sensor acc_sensor_t
Definition: acc_sensor.h:31
hand_motion_detection_config_log
void hand_motion_detection_config_log(hand_motion_detection_handle_t *handle)
Print configuration.
Definition: example_hand_motion_detection.c:240
hand_motion_detection_config_t
Configuration for hand_motion.
Definition: example_hand_motion_detection.h:62