prova
Dependencies: X_NUCLEO_53L0A1 mbed
Fork of 53L0A1_HandGestureRecognition by
Middlewares/ST/Gestures/GesturesDetect/Inc/ring_buffer.h@7:d79cbeda2982, 2017-12-15 (annotated)
- Committer:
- mapellil
- Date:
- Fri Dec 15 14:16:16 2017 +0000
- Revision:
- 7:d79cbeda2982
Added hand gesture (L-Rswipe) with L+R sensors
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mapellil | 7:d79cbeda2982 | 1 | /******************************************************************************* |
mapellil | 7:d79cbeda2982 | 2 | Copyright © 2015, STMicroelectronics International N.V. |
mapellil | 7:d79cbeda2982 | 3 | All rights reserved. |
mapellil | 7:d79cbeda2982 | 4 | |
mapellil | 7:d79cbeda2982 | 5 | Use and Redistribution are permitted only in accordance with licensing terms |
mapellil | 7:d79cbeda2982 | 6 | available at www.st.com under software reference X-CUBE-6180XA1, and provided |
mapellil | 7:d79cbeda2982 | 7 | that the following conditions are met: |
mapellil | 7:d79cbeda2982 | 8 | * Redistributions of source code must retain the above copyright |
mapellil | 7:d79cbeda2982 | 9 | notice, this list of conditions and the following disclaimer. |
mapellil | 7:d79cbeda2982 | 10 | * Redistributions in binary form must reproduce the above copyright |
mapellil | 7:d79cbeda2982 | 11 | notice, this list of conditions and the following disclaimer in the |
mapellil | 7:d79cbeda2982 | 12 | documentation and/or other materials provided with the distribution. |
mapellil | 7:d79cbeda2982 | 13 | * Neither the name of STMicroelectronics nor the |
mapellil | 7:d79cbeda2982 | 14 | names of its contributors may be used to endorse or promote products |
mapellil | 7:d79cbeda2982 | 15 | derived from this software without specific prior written permission. |
mapellil | 7:d79cbeda2982 | 16 | |
mapellil | 7:d79cbeda2982 | 17 | THIS SOFTWARE IS PROTECTED BY STMICROELECTRONICS PATENTS AND COPYRIGHTS. |
mapellil | 7:d79cbeda2982 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
mapellil | 7:d79cbeda2982 | 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
mapellil | 7:d79cbeda2982 | 20 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND |
mapellil | 7:d79cbeda2982 | 21 | NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED. |
mapellil | 7:d79cbeda2982 | 22 | IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY |
mapellil | 7:d79cbeda2982 | 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
mapellil | 7:d79cbeda2982 | 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
mapellil | 7:d79cbeda2982 | 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
mapellil | 7:d79cbeda2982 | 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
mapellil | 7:d79cbeda2982 | 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
mapellil | 7:d79cbeda2982 | 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mapellil | 7:d79cbeda2982 | 29 | ********************************************************************************/ |
mapellil | 7:d79cbeda2982 | 30 | /* |
mapellil | 7:d79cbeda2982 | 31 | * @file ring_buffer.h |
mapellil | 7:d79cbeda2982 | 32 | * $Date: 2015-11-10 11:21:53 +0100 (Tue, 10 Nov 2015) $ |
mapellil | 7:d79cbeda2982 | 33 | * $Revision: 2612 $ |
mapellil | 7:d79cbeda2982 | 34 | */ |
mapellil | 7:d79cbeda2982 | 35 | |
mapellil | 7:d79cbeda2982 | 36 | #ifndef RING_BUFFER_H_ |
mapellil | 7:d79cbeda2982 | 37 | #define RING_BUFFER_H_ |
mapellil | 7:d79cbeda2982 | 38 | |
mapellil | 7:d79cbeda2982 | 39 | #include "tof_gestures_platform.h" |
mapellil | 7:d79cbeda2982 | 40 | |
mapellil | 7:d79cbeda2982 | 41 | #ifdef __cplusplus |
mapellil | 7:d79cbeda2982 | 42 | extern "C" { |
mapellil | 7:d79cbeda2982 | 43 | #endif |
mapellil | 7:d79cbeda2982 | 44 | |
mapellil | 7:d79cbeda2982 | 45 | /** @defgroup misc_ring_buffer Ring Buffer |
mapellil | 7:d79cbeda2982 | 46 | * @brief Simple ring buffer implementation |
mapellil | 7:d79cbeda2982 | 47 | @par Description |
mapellil | 7:d79cbeda2982 | 48 | Ring buffer is implemented as a static array of integers of size #RB_MAX_SIZE. The functional size of the ring buffer is |
mapellil | 7:d79cbeda2982 | 49 | programmable. When the ring_buffer is full, new elements added are replacing the older elements. This is typically used |
mapellil | 7:d79cbeda2982 | 50 | to keep an history of the last ranging values measured from the ToF device. |
mapellil | 7:d79cbeda2982 | 51 | * @ingroup misc |
mapellil | 7:d79cbeda2982 | 52 | * @{ |
mapellil | 7:d79cbeda2982 | 53 | */ |
mapellil | 7:d79cbeda2982 | 54 | |
mapellil | 7:d79cbeda2982 | 55 | /** Ring Buffer maximum size */ |
mapellil | 7:d79cbeda2982 | 56 | #define RB_MAX_SIZE 16 |
mapellil | 7:d79cbeda2982 | 57 | |
mapellil | 7:d79cbeda2982 | 58 | /** |
mapellil | 7:d79cbeda2982 | 59 | * @struct ring_buffer |
mapellil | 7:d79cbeda2982 | 60 | * @brief Simple ring buffer of int with a programmable size (max size is #RB_MAX_SIZE) |
mapellil | 7:d79cbeda2982 | 61 | */ |
mapellil | 7:d79cbeda2982 | 62 | typedef struct |
mapellil | 7:d79cbeda2982 | 63 | { |
mapellil | 7:d79cbeda2982 | 64 | int buffer[RB_MAX_SIZE]; |
mapellil | 7:d79cbeda2982 | 65 | int* buffer_end; |
mapellil | 7:d79cbeda2982 | 66 | int* data_start; |
mapellil | 7:d79cbeda2982 | 67 | int* data_end; |
mapellil | 7:d79cbeda2982 | 68 | int count; |
mapellil | 7:d79cbeda2982 | 69 | int size; |
mapellil | 7:d79cbeda2982 | 70 | } ring_buffer; |
mapellil | 7:d79cbeda2982 | 71 | |
mapellil | 7:d79cbeda2982 | 72 | /** |
mapellil | 7:d79cbeda2982 | 73 | * @brief Initialize Ring Buffer |
mapellil | 7:d79cbeda2982 | 74 | * @param rb Ring Buffer pointer |
mapellil | 7:d79cbeda2982 | 75 | * @param size Number of int elements (max size is #RB_MAX_SIZE) |
mapellil | 7:d79cbeda2982 | 76 | * @return 0 on success or -1 if size is greater than #RB_MAX_SIZE |
mapellil | 7:d79cbeda2982 | 77 | */ |
mapellil | 7:d79cbeda2982 | 78 | int RB_init(ring_buffer* rb, int size); |
mapellil | 7:d79cbeda2982 | 79 | |
mapellil | 7:d79cbeda2982 | 80 | /** |
mapellil | 7:d79cbeda2982 | 81 | * @brief Push one element in Ring Buffer (after the last element) |
mapellil | 7:d79cbeda2982 | 82 | * @par Function Description |
mapellil | 7:d79cbeda2982 | 83 | * If ring buffer is full, added element is replacing the oldest element in the ring buffer |
mapellil | 7:d79cbeda2982 | 84 | * @param rb Ring Buffer pointer |
mapellil | 7:d79cbeda2982 | 85 | * @param data Element to add |
mapellil | 7:d79cbeda2982 | 86 | * @return 0 on success |
mapellil | 7:d79cbeda2982 | 87 | */ |
mapellil | 7:d79cbeda2982 | 88 | int RB_push(ring_buffer* rb, int data); |
mapellil | 7:d79cbeda2982 | 89 | |
mapellil | 7:d79cbeda2982 | 90 | /** |
mapellil | 7:d79cbeda2982 | 91 | * @brief pop one element in Ring Buffer (the last element) |
mapellil | 7:d79cbeda2982 | 92 | * @param rb Ring Buffer pointer |
mapellil | 7:d79cbeda2982 | 93 | * @return element |
mapellil | 7:d79cbeda2982 | 94 | */ |
mapellil | 7:d79cbeda2982 | 95 | int RB_pop(ring_buffer* rb); |
mapellil | 7:d79cbeda2982 | 96 | |
mapellil | 7:d79cbeda2982 | 97 | /** |
mapellil | 7:d79cbeda2982 | 98 | * @brief Check if ring buffer is full |
mapellil | 7:d79cbeda2982 | 99 | * @param rb Ring Buffer pointer |
mapellil | 7:d79cbeda2982 | 100 | * @return true if full else false |
mapellil | 7:d79cbeda2982 | 101 | */ |
mapellil | 7:d79cbeda2982 | 102 | bool RB_full(ring_buffer* rb); |
mapellil | 7:d79cbeda2982 | 103 | |
mapellil | 7:d79cbeda2982 | 104 | /** |
mapellil | 7:d79cbeda2982 | 105 | * @brief print/trace all elements in the ring buffer |
mapellil | 7:d79cbeda2982 | 106 | * @param rb Ring Buffer pointer |
mapellil | 7:d79cbeda2982 | 107 | * @note The TRACE key must be defined in the project |
mapellil | 7:d79cbeda2982 | 108 | */ |
mapellil | 7:d79cbeda2982 | 109 | void RB_trace(ring_buffer*rb); |
mapellil | 7:d79cbeda2982 | 110 | |
mapellil | 7:d79cbeda2982 | 111 | /** |
mapellil | 7:d79cbeda2982 | 112 | * @brief Return the sum of elements in the ring buffer |
mapellil | 7:d79cbeda2982 | 113 | * @param rb Ring Buffer pointer |
mapellil | 7:d79cbeda2982 | 114 | * @return The sum |
mapellil | 7:d79cbeda2982 | 115 | */ |
mapellil | 7:d79cbeda2982 | 116 | int RB_sum(ring_buffer*rb); |
mapellil | 7:d79cbeda2982 | 117 | |
mapellil | 7:d79cbeda2982 | 118 | /** |
mapellil | 7:d79cbeda2982 | 119 | * @brief Return the mean of all elements in the ring buffer |
mapellil | 7:d79cbeda2982 | 120 | * @param rb Ring Buffer pointer |
mapellil | 7:d79cbeda2982 | 121 | * @return The mean (rounded to integer) |
mapellil | 7:d79cbeda2982 | 122 | */ |
mapellil | 7:d79cbeda2982 | 123 | int RB_mean(ring_buffer*rb); |
mapellil | 7:d79cbeda2982 | 124 | |
mapellil | 7:d79cbeda2982 | 125 | /** |
mapellil | 7:d79cbeda2982 | 126 | * @brief Return the mean of the absolute differences of each element with the mean |
mapellil | 7:d79cbeda2982 | 127 | * @param rb Ring Buffer pointer |
mapellil | 7:d79cbeda2982 | 128 | * @return The mad (rounded to integer) |
mapellil | 7:d79cbeda2982 | 129 | */ |
mapellil | 7:d79cbeda2982 | 130 | int RB_mad(ring_buffer*rb); |
mapellil | 7:d79cbeda2982 | 131 | |
mapellil | 7:d79cbeda2982 | 132 | /** |
mapellil | 7:d79cbeda2982 | 133 | * @brief Return the direction of the curve of points stored in the buffer |
mapellil | 7:d79cbeda2982 | 134 | * @param rb Ring Buffer pointer |
mapellil | 7:d79cbeda2982 | 135 | * @return 1 if constantly increase, -1 if constantly decrease, 0 otherwise |
mapellil | 7:d79cbeda2982 | 136 | */ |
mapellil | 7:d79cbeda2982 | 137 | int RB_dir(ring_buffer*rb); |
mapellil | 7:d79cbeda2982 | 138 | |
mapellil | 7:d79cbeda2982 | 139 | /** @} */ |
mapellil | 7:d79cbeda2982 | 140 | |
mapellil | 7:d79cbeda2982 | 141 | #ifdef __cplusplus |
mapellil | 7:d79cbeda2982 | 142 | } |
mapellil | 7:d79cbeda2982 | 143 | #endif |
mapellil | 7:d79cbeda2982 | 144 | #endif /* RING_BUFFER_H_ */ |
mapellil | 7:d79cbeda2982 | 145 |