comparison Discovery/Src/motion.c @ 362:7b8c87a39c0e MotionDetection

Parameter update
author Ideenmodellierer
date Tue, 11 Jun 2019 05:31:07 +0200
parents 4258ea9b67fa
children bdf978d2a5d4
comparison
equal deleted inserted replaced
361:b111fc4250e9 362:7b8c87a39c0e
10 #include <math.h> 10 #include <math.h>
11 #include "motion.h" 11 #include "motion.h"
12 12
13 #define PITCH_HISTORY_ENTRIES 20 /* number of pitch value stored in buffer */ 13 #define PITCH_HISTORY_ENTRIES 20 /* number of pitch value stored in buffer */
14 #define STABLE_STATE_COUNT 2 /* number of count to declare a state as stable (at the moment based on 100ms) */ 14 #define STABLE_STATE_COUNT 2 /* number of count to declare a state as stable (at the moment based on 100ms) */
15 #define MOVE_DELTA_COUNT 5 /* Delta count needed to identify a valid movement */ 15 #define MOVE_DELTA_COUNT 10 /* Delta count needed to identify a valid movement */
16 #define SHAKE_DELTA_COUNT 30 /* Delta count needed to identify a valid minima / maxima */ 16 #define SHAKE_DELTA_COUNT 30 /* Delta count needed to identify a valid minima / maxima */
17 17
18 18
19 typedef enum 19 typedef enum
20 { 20 {
41 pitchHistory[tmp] = 0; 41 pitchHistory[tmp] = 0;
42 } 42 }
43 pitchWriteIdx = 0; 43 pitchWriteIdx = 0;
44 44
45 } 45 }
46
47 detectionState_t detectionState = DETECT_NOTHING;
46 48
47 /* Detect if user is generating an pitch including return to starting position (shake) */ 49 /* Detect if user is generating an pitch including return to starting position (shake) */
48 /* This is done by feeding the past movements value per value into a state machine */ 50 /* This is done by feeding the past movements value per value into a state machine */
49 detectionState_t detectShake(float currentPitch) 51 detectionState_t detectShake(float currentPitch)
50 { 52 {
52 static uint8_t stableCnt = 0; 54 static uint8_t stableCnt = 0;
53 static float lastPitch = 0.0; 55 static float lastPitch = 0.0;
54 static float startPitch = 0.0; 56 static float startPitch = 0.0;
55 57
56 relativeMove_t relativeMove = RELATIVE_MOVE_INVALID; 58 relativeMove_t relativeMove = RELATIVE_MOVE_INVALID;
57 static detectionState_t detectionState = DETECT_NOTHING; 59
58 60
59 pitchHistory[pitchWriteIdx] = currentPitch; 61 pitchHistory[pitchWriteIdx] = currentPitch;
60 runningIdx = pitchWriteIdx; 62 runningIdx = pitchWriteIdx;
61 #if 0 63 #if 0
62 runningIdx = pitchWriteIdx + 1; 64 runningIdx = pitchWriteIdx + 1;