Developer World
Spresense SDK Library v1.4.2-3df2e9d
tap.h
Go to the documentation of this file.
1 /****************************************************************************
2  * modules/include/sensing/tap.h
3  *
4  * Copyright 2018 Sony Semiconductor Solutions Corporation
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in
14  * the documentation and/or other materials provided with the
15  * distribution.
16  * 3. Neither the name of Sony Semiconductor Solutions Corporation nor
17  * the names of its contributors may be used to endorse or promote
18  * products derived from this software without specific prior written
19  * permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  ****************************************************************************/
39 #ifndef __INCLUDE_SENSING_TAP_H
40 #define __INCLUDE_SENSING_TAP_H
41 
47 /* --------------------------------------------------------------------------
48  Included Files
49  -------------------------------------------------------------------------- */
50 
51 #include <sys/time.h>
52 
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 
57 /* --------------------------------------------------------------------------
58  Pre-Processor Definitions
59  -------------------------------------------------------------------------- */
70 #define TAP_BUF_LEN 16
71 
76 #define D_SA_STATUS_OK 0
77 
82 #define D_SA_STATUS_E_INVALID_ARGS -1
83 
88 #define D_SA_STATUS_E_UNEXPECTED -8
89 
94 #define SEC_PER_US 1000000
95 
100 #define NS_PER_US 1000
101 
104 /* --------------------------------------------------------------------------
105  Enumerations
106  -------------------------------------------------------------------------- */
117 typedef enum {
120 } E_TAP_STATE;
121 
122 /* --------------------------------------------------------------------------
123  Command Structures
124  -------------------------------------------------------------------------- */
125 
130 typedef struct
131 {
132  float tap_period;
133  float peak_thres;
136  float long_thres;
142 } ST_TAP_OPEN;
143 
148 typedef struct
149 {
150  float accel_x;
151  float accel_y;
152  float accel_z;
153 } ST_TAP_ACCEL;
154 
157 /*--------------------------------------------------------------------
158  Tap Class
159  --------------------------------------------------------------------*/
165 class TapClass {
166 
167 public:
168 
169  /* public methods */
170 
171  int open(ST_TAP_OPEN*);
172  int close(void);
173  int write(ST_TAP_ACCEL*);
174  int write(ST_TAP_ACCEL*, uint64_t);
175 
176  TapClass();
177  ~TapClass(){};
178 
179 private:
180 
181  /* private members */
182 
183  uint64_t mTapPeriod;
184  float mPeakThres; /* (G) The minimum value of vibration tapping
185  * shall be deemed. range 0.0 - 4.0
186  */
187  float mLongThres; /* (G) The maximum vibration indicates that
188  * vibration of the tap. range 0.0 - 4.0
189  */
190  int mStabFrame; /* (64Hz frame num) time of PEAK_THRES -> LONG_THRES.
191  * range 0 - 32
192  */
193 
194  int mTapCnt;
195  E_TAP_STATE mState;
197  float mR[TAP_BUF_LEN];
198  float mX[TAP_BUF_LEN];
199  float mY[TAP_BUF_LEN];
200  float mZ[TAP_BUF_LEN];
202  int mIndex;
203  int mDetectionCount;
204  int mStab; /* When it becomes larger than mStabFrame,
205  * tap detection
206  */
207 
208  uint64_t mStartTime;
210  /* private methods */
211  float calcR(int i0, int j0);
212  bool detect(float x, float y, float z);
213  float getIndex(int idx);
214 
215 };
216 
217 /*--------------------------------------------------------------------
218  External Interface
219  --------------------------------------------------------------------*/
220 
226 TapClass* TapCreate(void);
227 
234 int TapOpen(FAR TapClass *ins, FAR ST_TAP_OPEN *OpenParam);
235 
241 int TapClose(FAR TapClass *ins);
242 
249 int TapWrite(FAR TapClass *ins, FAR ST_TAP_ACCEL *accelData);
250 
258 int TapWrite_timestamp(FAR TapClass *ins, FAR ST_TAP_ACCEL *accelData,
259  uint64_t time_stamp);
260 
264 #ifdef __cplusplus
265 }
266 #endif
267 
268 #endif /* __INCLUDE_SENSING_TAP_H */
Definition: tap.h:119
int TapWrite_timestamp(FAR TapClass *ins, FAR ST_TAP_ACCEL *accelData, uint64_t time_stamp)
Detect tap.
Coefficient required for tap detection.
Definition: tap.h:130
float accel_z
Definition: tap.h:152
int stab_frame
Definition: tap.h:139
#define TAP_BUF_LEN
Maximum number of data of accel sensor to save.
Definition: tap.h:70
int TapOpen(FAR TapClass *ins, FAR ST_TAP_OPEN *OpenParam)
Set coefficients necessary for parameter initialization and tap detection.
int TapWrite(FAR TapClass *ins, FAR ST_TAP_ACCEL *accelData)
Detect tap.
float accel_x
Definition: tap.h:150
float accel_y
Definition: tap.h:151
Definition: tap.h:118
float long_thres
Definition: tap.h:136
float tap_period
Definition: tap.h:132
accel data
Definition: tap.h:148
E_TAP_STATE
tap status
Definition: tap.h:117
TapClass * TapCreate(void)
Create TapClass instance. return Address for instance of TapClass.
int TapClose(FAR TapClass *ins)
None.
Definition: tap.h:165