Mercurial > public > ostc4
annotate Discovery/Src/motion.c @ 578:beb4d47542f1
Rework pitch detection:
To improve separation between pos and neg moves the history memory is now evaluated starting from the last detected start condition. This was needed because a small "overshoot" of the end position causes e.g. a pos event to be detected as negative event.
author | Ideenmodellierer |
---|---|
date | Sun, 29 Nov 2020 23:02:11 +0100 |
parents | 01ee21dd311f |
children | 4dfdf230d8ba |
rev | line source |
---|---|
359
4258ea9b67fa
Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff
changeset
|
1 /* |
4258ea9b67fa
Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff
changeset
|
2 * motion.c |
4258ea9b67fa
Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff
changeset
|
3 * |
4258ea9b67fa
Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff
changeset
|
4 * Created on: 20.05.2019 |
4258ea9b67fa
Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff
changeset
|
5 * Author: Thorsten Sonntag |
4258ea9b67fa
Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff
changeset
|
6 */ |
4258ea9b67fa
Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff
changeset
|
7 |
4258ea9b67fa
Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff
changeset
|
8 #include <stdint.h> |
4258ea9b67fa
Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff
changeset
|
9 #include <string.h> |
373
7b981f8bdd41
Add scroll event by pitch angle detection:
ideenmodellierer
parents:
371
diff
changeset
|
10 #include <stdlib.h> |
359
4258ea9b67fa
Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff
changeset
|
11 #include <math.h> |
4258ea9b67fa
Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff
changeset
|
12 #include "motion.h" |
370
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
13 #include "data_central.h" |
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
14 #include "t7.h" |
384
427ae9f8e28e
Consider number of available t3 views in sector handling:
ideenmodellierer
parents:
383
diff
changeset
|
15 #include "t3.h" |
371
fca370f847f8
Added parameter for number of sectors to be defined
ideenmodellierer
parents:
370
diff
changeset
|
16 #include "settings.h" |
359
4258ea9b67fa
Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff
changeset
|
17 |
4258ea9b67fa
Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff
changeset
|
18 #define STABLE_STATE_COUNT 2 /* number of count to declare a state as stable (at the moment based on 100ms) */ |
363 | 19 #define STABLE_STATE_TIMEOUT 5 /* Detection shall be aborted if a movement state is stable for more than 500ms */ |
370
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
20 |
551 | 21 #define SECTOR_WINDOW 40.0 /* Pitch window which is used for custom view projection */ |
381 | 22 #define SECTOR_WINDOW_MAX 120.0 /* Pitch window which will be greater than the divers field of view */ |
385
0cd862e501f6
Finetune parameter for detection of small sectors as used for the pitch detection
ideenmodellierer
parents:
384
diff
changeset
|
23 #define SECTOR_HYSTERY 2 /* Additional offset to avoid fast changing displays */ |
370
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
24 #define SECTOR_BORDER 400.0 /* Define a value which is out of limit to avoid not wanted key events */ |
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
25 #define SECTOR_FILTER 10 /* Define speed for calculated angle to follow real value */ |
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
26 |
385
0cd862e501f6
Finetune parameter for detection of small sectors as used for the pitch detection
ideenmodellierer
parents:
384
diff
changeset
|
27 #define SECTOR_MAX 24 /* maximum number of sectors */ |
378
834e087505ec
Incremented "idle window" for scroll detection
ideenmodellierer
parents:
373
diff
changeset
|
28 #define SECTOR_SCROLL 7 /* number of sectors used for scroll detection */ |
359
4258ea9b67fa
Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff
changeset
|
29 |
551 | 30 #define MOTION_DELTA_STABLE 0 |
31 #define MOTION_DELTA_JITTER 1 | |
32 #define MOTION_DELTA_RAISE 2 | |
33 #define MOTION_DELTA_FALL 3 | |
34 | |
35 #define MOTION_DELTA_JITTER_LEVEL 3.0 /* lower values are considered as stable */ | |
574 | 36 #define MOTION_DELTA_RAISE_LEVEL 6.0 /* Movement causing a significant change detected */ |
551 | 37 #define MOTION_DELTA_FALL_LEVEL -6.0 /* Movement causing a significant change detected */ |
38 | |
39 #define MOTION_DELTA_HISTORY_SIZE 20 /* Number of history data sets */ | |
40 | |
385
0cd862e501f6
Finetune parameter for detection of small sectors as used for the pitch detection
ideenmodellierer
parents:
384
diff
changeset
|
41 detectionState_t detectionState = DETECT_NOTHING; |
0cd862e501f6
Finetune parameter for detection of small sectors as used for the pitch detection
ideenmodellierer
parents:
384
diff
changeset
|
42 SSector sectorDetection; |
370
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
43 |
551 | 44 static uint8_t motionDeltaHistory[3][MOTION_DELTA_HISTORY_SIZE]; /* Change history of roll, pitch and yaw */ |
45 static uint8_t motionDeltaHistoryIdx; /* Current index of history data */ | |
46 | |
47 static uint8_t focusCnt = 0; | |
48 static uint8_t inFocus = 0; | |
49 | |
50 void resetMotionDeltaHistory() | |
51 { | |
52 motionDeltaHistoryIdx = 0; | |
53 memset(motionDeltaHistory, 0, sizeof(motionDeltaHistory)); | |
54 } | |
55 | |
56 void evaluateMotionDelta(float roll, float pitch, float yaw) | |
57 { | |
58 static float lastValue[3] = {0.0,0.0,0.0}; | |
59 uint8_t nextIndex = motionDeltaHistoryIdx + 1; | |
60 uint8_t axis; | |
61 float curValue; | |
62 | |
63 if(nextIndex == MOTION_DELTA_HISTORY_SIZE) | |
64 { | |
65 nextIndex = 0; | |
66 } | |
67 for(axis=0; axis < 3; axis++) | |
68 { | |
69 switch(axis) | |
70 { | |
71 case MOTION_HISTORY_ROLL: curValue = roll; | |
72 break; | |
73 case MOTION_HISTORY_PITCH: curValue = pitch; | |
74 break; | |
75 default: | |
76 case MOTION_HISTORY_YAW: if((yaw < 90) && (lastValue[MOTION_HISTORY_YAW] > 270.0)) /* transition 360 => 0 */ | |
77 { | |
78 lastValue[MOTION_HISTORY_YAW] -= 360; | |
79 } | |
80 else if((yaw > 270) && (lastValue[MOTION_HISTORY_YAW] < 90.0)) /* transition 0 => 360 */ | |
81 { | |
82 lastValue[MOTION_HISTORY_YAW] += 360; | |
83 } | |
84 curValue = yaw; | |
85 break; | |
86 } | |
87 if(curValue - lastValue[axis] > MOTION_DELTA_RAISE_LEVEL) | |
88 { | |
89 motionDeltaHistory[axis][nextIndex] = MOTION_DELTA_RAISE; | |
90 } | |
91 if(fabsf(curValue - lastValue[axis]) < MOTION_DELTA_RAISE_LEVEL) | |
92 { | |
93 motionDeltaHistory[axis][nextIndex] = MOTION_DELTA_JITTER; | |
94 } | |
95 if(fabsf(curValue - lastValue[axis]) < MOTION_DELTA_JITTER_LEVEL) | |
96 { | |
97 motionDeltaHistory[axis][nextIndex] = MOTION_DELTA_STABLE; | |
98 } | |
99 if(curValue - lastValue[axis] < MOTION_DELTA_FALL_LEVEL) | |
100 { | |
101 motionDeltaHistory[axis][nextIndex] = MOTION_DELTA_FALL; | |
102 } | |
103 lastValue[axis] = curValue; | |
104 } | |
105 motionDeltaHistoryIdx = nextIndex; | |
106 } | |
107 | |
108 SDeltaHistory GetDeltaHistory(uint8_t stepback) | |
109 { | |
578 | 110 uint8_t loop; |
551 | 111 uint8_t index = motionDeltaHistoryIdx; |
112 | |
113 SDeltaHistory result = {0,0,0}; | |
114 | |
578 | 115 stepback++; /* motionDeltaHistoryIdx is pointing to future entry => step back one to get the latest */ |
116 loop = stepback; | |
551 | 117 if(stepback < MOTION_DELTA_HISTORY_SIZE) |
118 { | |
119 while(loop != 0) /* find requested entry */ | |
120 { | |
121 loop--; | |
122 index--; | |
123 if(index == 0) | |
124 { | |
125 index = MOTION_DELTA_HISTORY_SIZE - 1; | |
126 } | |
127 } | |
128 result.roll = motionDeltaHistory[MOTION_HISTORY_ROLL][index]; | |
129 result.pitch = motionDeltaHistory[MOTION_HISTORY_PITCH][index]; | |
130 result.yaw = motionDeltaHistory[MOTION_HISTORY_YAW][index]; | |
131 } | |
132 return result; | |
133 } | |
370
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
134 |
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
135 uint8_t GetSectorForPitch(float pitch) |
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
136 { |
383
49a02dea8ae3
Combine variables in a structure to improve readability of code
ideenmodellierer
parents:
381
diff
changeset
|
137 static uint8_t lastsector = 0; |
370
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
138 float newPitch; |
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
139 uint8_t sector = 0; |
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
140 |
383
49a02dea8ae3
Combine variables in a structure to improve readability of code
ideenmodellierer
parents:
381
diff
changeset
|
141 newPitch = pitch + sectorDetection.offset + sectorDetection.center; /* do not use negative values and consider offset to center position */ |
381 | 142 if (newPitch < 0.0) /* clip value */ |
370
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
143 { |
381 | 144 newPitch = 0.0; |
145 } | |
383
49a02dea8ae3
Combine variables in a structure to improve readability of code
ideenmodellierer
parents:
381
diff
changeset
|
146 if (newPitch > sectorDetection.window) /* clip value */ |
381 | 147 { |
383
49a02dea8ae3
Combine variables in a structure to improve readability of code
ideenmodellierer
parents:
381
diff
changeset
|
148 newPitch = sectorDetection.window; |
370
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
149 } |
381 | 150 |
151 /* switch to other sector? */ | |
383
49a02dea8ae3
Combine variables in a structure to improve readability of code
ideenmodellierer
parents:
381
diff
changeset
|
152 if((newPitch > sectorDetection.upperborder) || (newPitch <= sectorDetection.lowerborder)) |
381 | 153 { |
383
49a02dea8ae3
Combine variables in a structure to improve readability of code
ideenmodellierer
parents:
381
diff
changeset
|
154 sector = (uint16_t) newPitch / sectorDetection.size; |
49a02dea8ae3
Combine variables in a structure to improve readability of code
ideenmodellierer
parents:
381
diff
changeset
|
155 sectorDetection.lowerborder = sector * sectorDetection.size - SECTOR_HYSTERY; |
49a02dea8ae3
Combine variables in a structure to improve readability of code
ideenmodellierer
parents:
381
diff
changeset
|
156 sectorDetection.upperborder = (sector + 1) * sectorDetection.size + SECTOR_HYSTERY; |
381 | 157 lastsector = sector; |
158 } | |
159 | |
160 return lastsector; | |
370
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
161 } |
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
162 |
371
fca370f847f8
Added parameter for number of sectors to be defined
ideenmodellierer
parents:
370
diff
changeset
|
163 void DefinePitchSectors(float centerPitch,uint8_t numOfSectors) |
370
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
164 { |
371
fca370f847f8
Added parameter for number of sectors to be defined
ideenmodellierer
parents:
370
diff
changeset
|
165 if(numOfSectors == CUSTOMER_DEFINED_VIEWS) |
fca370f847f8
Added parameter for number of sectors to be defined
ideenmodellierer
parents:
370
diff
changeset
|
166 { |
384
427ae9f8e28e
Consider number of available t3 views in sector handling:
ideenmodellierer
parents:
383
diff
changeset
|
167 if(settingsGetPointer()->design == 3) /* Big font view ? */ |
427ae9f8e28e
Consider number of available t3 views in sector handling:
ideenmodellierer
parents:
383
diff
changeset
|
168 { |
427ae9f8e28e
Consider number of available t3 views in sector handling:
ideenmodellierer
parents:
383
diff
changeset
|
169 sectorDetection.count = t3_GetEnabled_customviews(); |
427ae9f8e28e
Consider number of available t3 views in sector handling:
ideenmodellierer
parents:
383
diff
changeset
|
170 } |
427ae9f8e28e
Consider number of available t3 views in sector handling:
ideenmodellierer
parents:
383
diff
changeset
|
171 else |
427ae9f8e28e
Consider number of available t3 views in sector handling:
ideenmodellierer
parents:
383
diff
changeset
|
172 { |
427ae9f8e28e
Consider number of available t3 views in sector handling:
ideenmodellierer
parents:
383
diff
changeset
|
173 sectorDetection.count = t7_GetEnabled_customviews(); |
427ae9f8e28e
Consider number of available t3 views in sector handling:
ideenmodellierer
parents:
383
diff
changeset
|
174 } |
383
49a02dea8ae3
Combine variables in a structure to improve readability of code
ideenmodellierer
parents:
381
diff
changeset
|
175 if(sectorDetection.count > 7) |
371
fca370f847f8
Added parameter for number of sectors to be defined
ideenmodellierer
parents:
370
diff
changeset
|
176 { |
383
49a02dea8ae3
Combine variables in a structure to improve readability of code
ideenmodellierer
parents:
381
diff
changeset
|
177 sectorDetection.count = 7; /* more views are hard to manually control */ |
371
fca370f847f8
Added parameter for number of sectors to be defined
ideenmodellierer
parents:
370
diff
changeset
|
178 } |
fca370f847f8
Added parameter for number of sectors to be defined
ideenmodellierer
parents:
370
diff
changeset
|
179 } |
fca370f847f8
Added parameter for number of sectors to be defined
ideenmodellierer
parents:
370
diff
changeset
|
180 else |
373
7b981f8bdd41
Add scroll event by pitch angle detection:
ideenmodellierer
parents:
371
diff
changeset
|
181 if(numOfSectors != CUSTOMER_KEEP_LAST_SECTORS) |
371
fca370f847f8
Added parameter for number of sectors to be defined
ideenmodellierer
parents:
370
diff
changeset
|
182 { |
383
49a02dea8ae3
Combine variables in a structure to improve readability of code
ideenmodellierer
parents:
381
diff
changeset
|
183 sectorDetection.count = numOfSectors; |
371
fca370f847f8
Added parameter for number of sectors to be defined
ideenmodellierer
parents:
370
diff
changeset
|
184 } |
370
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
185 |
383
49a02dea8ae3
Combine variables in a structure to improve readability of code
ideenmodellierer
parents:
381
diff
changeset
|
186 if(sectorDetection.count == SECTOR_MAX) |
370
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
187 { |
383
49a02dea8ae3
Combine variables in a structure to improve readability of code
ideenmodellierer
parents:
381
diff
changeset
|
188 sectorDetection.window = SECTOR_WINDOW_MAX; |
381 | 189 } |
190 else | |
191 { | |
383
49a02dea8ae3
Combine variables in a structure to improve readability of code
ideenmodellierer
parents:
381
diff
changeset
|
192 sectorDetection.window = SECTOR_WINDOW; |
370
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
193 } |
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
194 |
383
49a02dea8ae3
Combine variables in a structure to improve readability of code
ideenmodellierer
parents:
381
diff
changeset
|
195 sectorDetection.offset = (centerPitch - (sectorDetection.window / 2)) * -1.0; |
49a02dea8ae3
Combine variables in a structure to improve readability of code
ideenmodellierer
parents:
381
diff
changeset
|
196 sectorDetection.size = sectorDetection.window / sectorDetection.count; |
49a02dea8ae3
Combine variables in a structure to improve readability of code
ideenmodellierer
parents:
381
diff
changeset
|
197 sectorDetection.center = 0; |
370
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
198 |
383
49a02dea8ae3
Combine variables in a structure to improve readability of code
ideenmodellierer
parents:
381
diff
changeset
|
199 /* reset border values */ |
49a02dea8ae3
Combine variables in a structure to improve readability of code
ideenmodellierer
parents:
381
diff
changeset
|
200 sectorDetection.lowerborder = SECTOR_BORDER; |
49a02dea8ae3
Combine variables in a structure to improve readability of code
ideenmodellierer
parents:
381
diff
changeset
|
201 sectorDetection.upperborder = SECTOR_BORDER * -1.0; |
370
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
202 /* get the current sector */ |
383
49a02dea8ae3
Combine variables in a structure to improve readability of code
ideenmodellierer
parents:
381
diff
changeset
|
203 sectorDetection.current = GetSectorForPitch(stateRealGetPointer()->lifeData.compass_pitch); |
49a02dea8ae3
Combine variables in a structure to improve readability of code
ideenmodellierer
parents:
381
diff
changeset
|
204 sectorDetection.target = sectorDetection.current; |
49a02dea8ae3
Combine variables in a structure to improve readability of code
ideenmodellierer
parents:
381
diff
changeset
|
205 /* do a small adjustment to center pitch to make sure the actual pitch is in the center of the current sector */ |
49a02dea8ae3
Combine variables in a structure to improve readability of code
ideenmodellierer
parents:
381
diff
changeset
|
206 sectorDetection.center = (sectorDetection.upperborder) - ((sectorDetection.size + 2 *SECTOR_HYSTERY) / 2.0) - (centerPitch + sectorDetection.offset); |
49a02dea8ae3
Combine variables in a structure to improve readability of code
ideenmodellierer
parents:
381
diff
changeset
|
207 |
370
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
208 } |
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
209 |
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
210 void InitMotionDetection(void) |
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
211 { |
383
49a02dea8ae3
Combine variables in a structure to improve readability of code
ideenmodellierer
parents:
381
diff
changeset
|
212 sectorDetection.target = 0; |
49a02dea8ae3
Combine variables in a structure to improve readability of code
ideenmodellierer
parents:
381
diff
changeset
|
213 sectorDetection.current = 0; |
49a02dea8ae3
Combine variables in a structure to improve readability of code
ideenmodellierer
parents:
381
diff
changeset
|
214 sectorDetection.size = 0; |
49a02dea8ae3
Combine variables in a structure to improve readability of code
ideenmodellierer
parents:
381
diff
changeset
|
215 sectorDetection.count = 0; |
371
fca370f847f8
Added parameter for number of sectors to be defined
ideenmodellierer
parents:
370
diff
changeset
|
216 |
fca370f847f8
Added parameter for number of sectors to be defined
ideenmodellierer
parents:
370
diff
changeset
|
217 switch(settingsGetPointer()->MotionDetection) |
fca370f847f8
Added parameter for number of sectors to be defined
ideenmodellierer
parents:
370
diff
changeset
|
218 { |
551 | 219 case MOTION_DETECT_SECTOR: DefinePitchSectors(settingsGetPointer()->viewPitch,CUSTOMER_DEFINED_VIEWS); |
371
fca370f847f8
Added parameter for number of sectors to be defined
ideenmodellierer
parents:
370
diff
changeset
|
220 break; |
551 | 221 case MOTION_DETECT_MOVE: DefinePitchSectors(settingsGetPointer()->viewPitch,SECTOR_MAX); |
371
fca370f847f8
Added parameter for number of sectors to be defined
ideenmodellierer
parents:
370
diff
changeset
|
222 break; |
551 | 223 case MOTION_DETECT_SCROLL: DefinePitchSectors(settingsGetPointer()->viewPitch,SECTOR_SCROLL); |
373
7b981f8bdd41
Add scroll event by pitch angle detection:
ideenmodellierer
parents:
371
diff
changeset
|
224 break; |
371
fca370f847f8
Added parameter for number of sectors to be defined
ideenmodellierer
parents:
370
diff
changeset
|
225 default: |
fca370f847f8
Added parameter for number of sectors to be defined
ideenmodellierer
parents:
370
diff
changeset
|
226 break; |
fca370f847f8
Added parameter for number of sectors to be defined
ideenmodellierer
parents:
370
diff
changeset
|
227 } |
fca370f847f8
Added parameter for number of sectors to be defined
ideenmodellierer
parents:
370
diff
changeset
|
228 |
551 | 229 resetMotionDeltaHistory(); |
370
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
230 } |
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
231 |
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
232 /* Map the current pitch value to a sector and create button event in case the sector is left */ |
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
233 detectionState_t detectSectorButtonEvent(float curPitch) |
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
234 { |
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
235 static uint8_t lastTargetSector = 0; |
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
236 uint8_t newTargetSector; |
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
237 uint8_t PitchEvent = DETECT_NOTHING; |
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
238 |
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
239 /* only change sector if reading is stable */ |
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
240 newTargetSector = GetSectorForPitch(stateRealGetPointer()->lifeData.compass_pitch); |
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
241 if(lastTargetSector == newTargetSector) |
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
242 { |
383
49a02dea8ae3
Combine variables in a structure to improve readability of code
ideenmodellierer
parents:
381
diff
changeset
|
243 sectorDetection.target = newTargetSector; |
370
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
244 } |
381 | 245 lastTargetSector = newTargetSector; |
383
49a02dea8ae3
Combine variables in a structure to improve readability of code
ideenmodellierer
parents:
381
diff
changeset
|
246 if(sectorDetection.target != sectorDetection.current) |
370
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
247 { |
383
49a02dea8ae3
Combine variables in a structure to improve readability of code
ideenmodellierer
parents:
381
diff
changeset
|
248 if(sectorDetection.target > sectorDetection.current) |
370
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
249 { |
383
49a02dea8ae3
Combine variables in a structure to improve readability of code
ideenmodellierer
parents:
381
diff
changeset
|
250 sectorDetection.current++; |
370
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
251 PitchEvent = DETECT_POS_PITCH; |
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
252 } |
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
253 else |
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
254 { |
383
49a02dea8ae3
Combine variables in a structure to improve readability of code
ideenmodellierer
parents:
381
diff
changeset
|
255 sectorDetection.current--; |
370
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
256 PitchEvent = DETECT_NEG_PITCH; |
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
257 } |
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
258 } |
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
259 return PitchEvent; |
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
260 } |
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
261 |
373
7b981f8bdd41
Add scroll event by pitch angle detection:
ideenmodellierer
parents:
371
diff
changeset
|
262 /* Check if pitch is not in center position and trigger a button action if needed */ |
7b981f8bdd41
Add scroll event by pitch angle detection:
ideenmodellierer
parents:
371
diff
changeset
|
263 detectionState_t detectScrollButtonEvent(float curPitch) |
7b981f8bdd41
Add scroll event by pitch angle detection:
ideenmodellierer
parents:
371
diff
changeset
|
264 { |
378
834e087505ec
Incremented "idle window" for scroll detection
ideenmodellierer
parents:
373
diff
changeset
|
265 static uint8_t delayscroll = 0; /* slow down the number of scroll events */ |
370
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
266 |
373
7b981f8bdd41
Add scroll event by pitch angle detection:
ideenmodellierer
parents:
371
diff
changeset
|
267 uint8_t PitchEvent = DETECT_NOTHING; |
7b981f8bdd41
Add scroll event by pitch angle detection:
ideenmodellierer
parents:
371
diff
changeset
|
268 uint8_t newSector; |
7b981f8bdd41
Add scroll event by pitch angle detection:
ideenmodellierer
parents:
371
diff
changeset
|
269 |
7b981f8bdd41
Add scroll event by pitch angle detection:
ideenmodellierer
parents:
371
diff
changeset
|
270 if(delayscroll == 0) |
7b981f8bdd41
Add scroll event by pitch angle detection:
ideenmodellierer
parents:
371
diff
changeset
|
271 { |
7b981f8bdd41
Add scroll event by pitch angle detection:
ideenmodellierer
parents:
371
diff
changeset
|
272 newSector = GetSectorForPitch(stateRealGetPointer()->lifeData.compass_pitch); |
551 | 273 /* for scroll detection the motion window is split into 6 sectors => set event accoring to the sector number*/ |
373
7b981f8bdd41
Add scroll event by pitch angle detection:
ideenmodellierer
parents:
371
diff
changeset
|
274 switch(newSector) |
7b981f8bdd41
Add scroll event by pitch angle detection:
ideenmodellierer
parents:
371
diff
changeset
|
275 { |
574 | 276 case 0: PitchEvent = DETECT_POS_PITCH; |
373
7b981f8bdd41
Add scroll event by pitch angle detection:
ideenmodellierer
parents:
371
diff
changeset
|
277 break; |
378
834e087505ec
Incremented "idle window" for scroll detection
ideenmodellierer
parents:
373
diff
changeset
|
278 case 6: PitchEvent = DETECT_NEG_PITCH; |
373
7b981f8bdd41
Add scroll event by pitch angle detection:
ideenmodellierer
parents:
371
diff
changeset
|
279 break; |
7b981f8bdd41
Add scroll event by pitch angle detection:
ideenmodellierer
parents:
371
diff
changeset
|
280 default: |
7b981f8bdd41
Add scroll event by pitch angle detection:
ideenmodellierer
parents:
371
diff
changeset
|
281 break; |
7b981f8bdd41
Add scroll event by pitch angle detection:
ideenmodellierer
parents:
371
diff
changeset
|
282 } |
7b981f8bdd41
Add scroll event by pitch angle detection:
ideenmodellierer
parents:
371
diff
changeset
|
283 if(PitchEvent != DETECT_NOTHING) |
7b981f8bdd41
Add scroll event by pitch angle detection:
ideenmodellierer
parents:
371
diff
changeset
|
284 { |
574 | 285 delayscroll = 7; |
373
7b981f8bdd41
Add scroll event by pitch angle detection:
ideenmodellierer
parents:
371
diff
changeset
|
286 } |
7b981f8bdd41
Add scroll event by pitch angle detection:
ideenmodellierer
parents:
371
diff
changeset
|
287 } |
7b981f8bdd41
Add scroll event by pitch angle detection:
ideenmodellierer
parents:
371
diff
changeset
|
288 else |
7b981f8bdd41
Add scroll event by pitch angle detection:
ideenmodellierer
parents:
371
diff
changeset
|
289 { |
7b981f8bdd41
Add scroll event by pitch angle detection:
ideenmodellierer
parents:
371
diff
changeset
|
290 delayscroll--; |
7b981f8bdd41
Add scroll event by pitch angle detection:
ideenmodellierer
parents:
371
diff
changeset
|
291 } |
7b981f8bdd41
Add scroll event by pitch angle detection:
ideenmodellierer
parents:
371
diff
changeset
|
292 return PitchEvent; |
7b981f8bdd41
Add scroll event by pitch angle detection:
ideenmodellierer
parents:
371
diff
changeset
|
293 } |
7b981f8bdd41
Add scroll event by pitch angle detection:
ideenmodellierer
parents:
371
diff
changeset
|
294 |
7b981f8bdd41
Add scroll event by pitch angle detection:
ideenmodellierer
parents:
371
diff
changeset
|
295 |
370
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
296 /* Detect if user is generating an pitch including return to starting position */ |
359
4258ea9b67fa
Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff
changeset
|
297 /* This is done by feeding the past movements value per value into a state machine */ |
370
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
298 detectionState_t detectPitch(float currentPitch) |
359
4258ea9b67fa
Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff
changeset
|
299 { |
578 | 300 static int8_t lastStart = 0; |
551 | 301 uint8_t exit = 0; |
578 | 302 int8_t step = 0; |
574 | 303 uint8_t duration = 0; |
551 | 304 SDeltaHistory test; |
370
77cdfbdaca8c
Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents:
363
diff
changeset
|
305 |
578 | 306 if(lastStart < 0) |
307 { | |
308 detectionState = DETECT_NOTHING; | |
309 lastStart = 0; | |
310 } | |
311 else | |
312 { | |
313 detectionState = DETECT_START; | |
314 } | |
315 step = lastStart; | |
316 do | |
551 | 317 { |
318 test = GetDeltaHistory(step); | |
574 | 319 duration++; |
551 | 320 switch (detectionState) |
321 { | |
322 case DETECT_NOTHING: if(test.pitch > MOTION_DELTA_STABLE) | |
323 { | |
324 exit = 1; | |
578 | 325 lastStart = -2; |
551 | 326 } |
327 else | |
328 { | |
329 detectionState = DETECT_START; | |
578 | 330 lastStart = -1; |
551 | 331 } |
332 break; | |
333 case DETECT_START: if(test.pitch == MOTION_DELTA_RAISE) | |
334 { | |
335 detectionState = DETECT_POS_MOVE; | |
578 | 336 lastStart = step; |
551 | 337 } |
578 | 338 else |
551 | 339 if(test.pitch == MOTION_DELTA_FALL) |
340 { | |
341 detectionState = DETECT_NEG_MOVE; | |
578 | 342 lastStart = step; |
343 } | |
344 else | |
345 { | |
346 lastStart = -1; | |
551 | 347 } |
574 | 348 duration = 0; |
551 | 349 break; |
578 | 350 case DETECT_NEG_MOVE: if((test.pitch <= MOTION_DELTA_JITTER) || (test.pitch == MOTION_DELTA_RAISE)) |
351 { | |
352 detectionState++; | |
353 } | |
354 break; | |
355 case DETECT_POS_MOVE: if((test.pitch <= MOTION_DELTA_JITTER) || (test.pitch == MOTION_DELTA_FALL)) | |
551 | 356 { |
357 detectionState++; | |
358 } | |
359 break; | |
360 case DETECT_MAXIMA: if(test.pitch == MOTION_DELTA_FALL) | |
361 { | |
362 detectionState = DETECT_FALLBACK; | |
363 } | |
364 break; | |
365 case DETECT_MINIMA: if(test.pitch == MOTION_DELTA_RAISE) | |
366 { | |
367 detectionState = DETECT_RISEBACK; | |
368 } | |
369 break; | |
370 case DETECT_RISEBACK: | |
371 case DETECT_FALLBACK: if(test.pitch == MOTION_DELTA_STABLE) | |
372 { | |
578 | 373 if(duration > 4) /* avoid detection triggered by short moves */ |
574 | 374 { |
375 detectionState++; | |
376 } | |
578 | 377 exit = 1; |
378 lastStart = -2; | |
551 | 379 } |
380 break; | |
381 default: | |
382 detectionState = DETECT_NOTHING; | |
383 exit = 1; | |
384 break; | |
385 } | |
578 | 386 step--; |
387 } while((step >= 0) && (!exit)); | |
388 | |
389 if((lastStart < MOTION_DELTA_HISTORY_SIZE)) | |
390 { | |
391 lastStart++; /* prepare value for next iteration (history index will be increased) */ | |
392 } | |
393 else | |
394 { | |
395 lastStart = -1; | |
551 | 396 } |
397 if((detectionState != DETECT_POS_PITCH) && (detectionState != DETECT_NEG_PITCH)) /* nothing found */ | |
359
4258ea9b67fa
Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff
changeset
|
398 { |
4258ea9b67fa
Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff
changeset
|
399 detectionState = DETECT_NOTHING; |
4258ea9b67fa
Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff
changeset
|
400 } |
551 | 401 else /* dont detect the same event twice */ |
402 { | |
403 resetMotionDeltaHistory(); | |
404 } | |
405 return detectionState; | |
406 } | |
363 | 407 |
551 | 408 void anglesToCoord(float roll, float pitch, float yaw, SCoord *pCoord) |
409 { | |
410 pCoord->x = ((cosf(yaw) * cosf(pitch)) * pCoord->x + (cosf(yaw)*sinf(pitch)*sinf(roll) - (sinf(yaw)* cosf(roll))) * pCoord->y + (cosf(yaw)*sinf(pitch)*cosf(roll) + sinf(yaw)*sinf(roll)) * pCoord->z); | |
411 pCoord->y = ((sinf(yaw) * cosf(pitch)) * pCoord->x + (sinf(yaw)*sinf(pitch)*sinf(roll) + cosf(yaw) * cosf(roll)) * pCoord->y + ( sinf(yaw) * sinf(pitch) * cosf(roll) - cosf(yaw) * sinf(roll))* pCoord->z); | |
412 pCoord->z = ((-1*sinf(pitch)) * pCoord->x + (cosf(pitch) *sinf(roll)) * pCoord->y + (cosf(pitch) * cosf(roll))* pCoord->z); | |
413 } | |
414 | |
415 SCoord CoordAdd(SCoord cA, SCoord cB) | |
416 { | |
417 SCoord result; | |
418 | |
419 result.x = cA.x + cB.x; | |
420 result.y = cA.y + cB.y; | |
421 result.z = cA.z + cB.z; | |
422 return result; | |
423 } | |
424 | |
425 SCoord CoordSub(SCoord cA, SCoord cB) | |
426 { | |
427 SCoord result; | |
373
7b981f8bdd41
Add scroll event by pitch angle detection:
ideenmodellierer
parents:
371
diff
changeset
|
428 |
551 | 429 result.x = cA.x - cB.x; |
430 result.y = cA.y - cB.y; | |
431 result.z = cA.z - cB.z; | |
432 return result; | |
433 } | |
434 | |
435 SCoord CoordCross(SCoord cA, SCoord cB) | |
436 { | |
437 SCoord result; | |
438 | |
439 result.x = (cA.y * cB.z) - (cA.z * cB.y); | |
440 result.y = (cA.z * cB.x) - (cA.x * cB.z); | |
441 result.z = (cA.x * cB.y) - (cA.y * cB.x); | |
442 | |
443 return result; | |
444 | |
445 } | |
446 | |
447 SCoord CoordMulF(SCoord op, float factor) | |
448 { | |
449 SCoord result; | |
450 result.x = (op.x * factor); | |
451 result.y = (op.y * factor); | |
452 result.z = (op.z * factor); | |
453 | |
454 return result; | |
455 } | |
373
7b981f8bdd41
Add scroll event by pitch angle detection:
ideenmodellierer
parents:
371
diff
changeset
|
456 |
551 | 457 SCoord CoordDivF(SCoord op, float factor) |
458 { | |
459 SCoord result; | |
460 result.x = (op.x / factor); | |
461 result.y = (op.y / factor); | |
462 result.z = (op.z / factor); | |
463 | |
464 return result; | |
465 } | |
466 | |
467 float CoordDot(SCoord cA, SCoord cB) | |
468 { | |
469 float result; | |
470 | |
471 result = cA.x * cB.x + cA.y * cB.y + cB.z*cA.z; | |
472 return result; | |
473 } | |
474 | |
475 void calibrateViewport(float roll, float pitch, float yaw) | |
476 { | |
477 SSettings* pSettings = settingsGetPointer(); | |
478 | |
479 pSettings->viewPitch = pitch; | |
480 pSettings->viewRoll = roll; | |
481 pSettings->viewYaw = yaw; | |
482 } | |
483 | |
484 | |
485 float checkViewport(float roll, float pitch, float yaw) | |
486 { | |
574 | 487 static float freezeRoll = 0; |
488 static float freezeYaw = 0; | |
489 | |
551 | 490 uint8_t retval = 0; |
491 float angleYaw; | |
492 float anglePitch; | |
493 float angleRoll; | |
494 float distance = 0; | |
495 float _a, _b; | |
496 SCoord u,v,n; | |
497 float r; | |
498 | |
499 SCoord refVec; | |
500 SCoord axis_1; | |
501 SCoord axis_2; | |
502 SCoord curVec; | |
503 SCoord resultVec; | |
574 | 504 SDeltaHistory test; |
551 | 505 |
506 SSettings* pSettings = settingsGetPointer(); | |
507 | |
508 /* calculate base vector taking calibration delta into account yaw (heading) */ | |
509 float compYaw = yaw + pSettings->viewYaw; | |
574 | 510 |
511 compYaw = 360.0 - yaw; /* turn to 0° */ | |
512 compYaw += pSettings->viewYaw; /* consider calib yaw value */ | |
513 compYaw += yaw; | |
514 | |
551 | 515 if (compYaw < 0.0) |
516 { | |
517 compYaw = 360.0 + compYaw; | |
381 | 518 } |
551 | 519 |
520 if (compYaw > 360.0) | |
381 | 521 { |
574 | 522 compYaw = compYaw - 360.0; |
373
7b981f8bdd41
Add scroll event by pitch angle detection:
ideenmodellierer
parents:
371
diff
changeset
|
523 } |
574 | 524 if (compYaw > 360.0) |
525 { | |
526 compYaw = compYaw - 360.0; | |
527 } | |
528 angleYaw = pSettings->viewYaw * M_PI / 180.0; | |
551 | 529 anglePitch = pSettings->viewPitch * M_PI / 180.0; |
530 angleRoll = pSettings->viewRoll * M_PI / 180.0; | |
531 | |
532 refVec.x = 0; | |
533 refVec.y = 0; | |
534 refVec.z = 1.0; | |
535 | |
536 anglesToCoord(angleRoll,anglePitch,angleYaw, &refVec); | |
537 | |
538 anglePitch = pitch * M_PI / 180.0; | |
539 angleRoll = roll * M_PI / 180.0; | |
540 angleYaw = yaw * M_PI / 180.0; | |
541 | |
542 /* assume x = 0 and y = 1 => find matching vector so axis_1 is 90° to axis_2 */ | |
543 axis_1.x = 0; | |
544 if(refVec.y >=0) | |
545 { | |
546 axis_2.y = 1; /* => Spawn y == refVec y */ | |
547 } | |
548 else axis_1.y = -1; | |
549 axis_1.z = -1.0 * refVec.y / refVec.z; | |
550 axis_2 = CoordCross(refVec, axis_1); /* Cross is 90° to refVec and Spawn as well => Plane Spawn / cross */ | |
551 | |
552 /* check if detection plane is correct */ | |
553 u = CoordSub(axis_1,refVec); | |
554 v = CoordSub(axis_2,refVec); | |
555 n = CoordCross(u,v); | |
556 | |
557 if((fabsf(n.x) <= 0.0001) && (fabsf(n.y) <= 0.0001) && (fabsf(n.z) <= 0.0001)) | |
558 { | |
559 retval = 2; | |
560 } | |
561 else | |
562 { | |
574 | 563 angleYaw = compYaw * M_PI / 180.0; |
551 | 564 anglePitch = pitch * M_PI / 180.0; |
565 angleRoll = roll * M_PI / 180.0; | |
566 curVec.x = 0; | |
567 curVec.y = 0; | |
568 curVec.z = 1.0; | |
569 anglesToCoord(angleRoll,anglePitch,angleYaw, &curVec); | |
570 | |
571 _a = CoordDot(curVec,n); | |
572 _b = CoordDot(refVec,n); | |
573 | |
574 if(_b>=(-0.0001)&&_b<=0.0001) /* Check if view port is parallel (no matchpoint) */ | |
575 { | |
576 retval = 3; | |
577 } | |
578 else | |
579 { | |
580 r=_a/_b; | |
581 if(r<0.00||r>1.40) /* are we looking into wrong direction? */ | |
582 { | |
583 retval = 4; | |
584 } | |
585 } | |
586 distance = retval * 1.0; /* just for debugging */ | |
587 if(retval == 0) | |
588 { | |
589 | |
590 /* start calculating the matchpoint */ | |
591 curVec = CoordMulF(curVec,r); | |
592 resultVec = CoordSub(refVec,curVec); | |
593 | |
594 /* calculate the distance between reference and actual vector */ | |
595 resultVec.x = resultVec.x * resultVec.x; | |
596 resultVec.y = resultVec.y * resultVec.y; | |
597 resultVec.z = resultVec.z * resultVec.z; | |
598 | |
599 if((resultVec.x == 0) && (resultVec.y == 0) && (resultVec.z == 0)) | |
600 { | |
601 distance = 0.0; | |
602 } | |
603 else | |
604 { | |
605 distance = sqrtf((resultVec.x + resultVec.y + resultVec.z)); | |
606 } | |
607 } | |
608 } | |
609 | |
610 if(distance < 0.5) /* handle focus counter to avoid fast in/out focus changes */ | |
611 { | |
612 if(focusCnt < 10) | |
613 { | |
614 if((focusCnt == 9) && (inFocus == 0)) /* we will get into focus */ | |
615 { | |
616 resetMotionDeltaHistory(); | |
617 } | |
618 focusCnt++; | |
619 } | |
574 | 620 if((focusCnt == 10) && (inFocus == 0)) |
551 | 621 { |
622 inFocus = 1; | |
574 | 623 freezeRoll = roll; |
624 freezeYaw = yaw; | |
551 | 625 } |
626 } | |
627 else | |
628 { | |
574 | 629 if(focusCnt >= 5) /* Reset focus faster then setting focus */ |
551 | 630 { |
574 | 631 if(pSettings->MotionDetection != MOTION_DETECT_MOVE) /* only apply extended focus for methods using absolute pitch values */ |
632 { | |
633 test = GetDeltaHistory(0); | |
634 if((test.yaw == MOTION_DELTA_STABLE) && (test.roll == MOTION_DELTA_STABLE)) | |
635 { | |
636 if((fabsf(freezeRoll - roll) < MOTION_DELTA_JITTER_LEVEL) && (fabsf(freezeYaw - yaw) < MOTION_DELTA_JITTER_LEVEL)) | |
637 { | |
638 focusCnt++; | |
639 } | |
640 } | |
641 else | |
642 { | |
643 if(freezeRoll != 0.0) | |
644 { | |
645 focusCnt = 1; | |
646 } | |
647 } | |
648 } | |
551 | 649 focusCnt--; |
650 } | |
651 else | |
652 { | |
574 | 653 focusCnt = 0; |
551 | 654 inFocus = 0; |
574 | 655 freezeRoll = 0; |
656 freezeYaw = 0; | |
551 | 657 } |
658 } | |
659 return distance; | |
359
4258ea9b67fa
Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff
changeset
|
660 } |
551 | 661 uint8_t viewInFocus(void) |
662 { | |
663 return inFocus; | |
664 } | |
665 void resetFocusState(void) | |
666 { | |
667 inFocus = 0; | |
668 } |