annotate Discovery/Src/motion.c @ 599:5a8f9126e4cb

Bugfix T3 skip deactivated views: I previous version the OSTC hangs if only conditional views (like decoplan which is only displayed in case of deco time) are switched. Rootcause was that the select function could never switch to another view because no visible view was available. To avoid this use case a fallback option has been added. In case no other view is available, the current view will be kept. In case no view at all (even no conditional view) is available then a switch to the "None" view will be done independend if it is enabled or not. T3_Profile: Added functionalty to show max depth and divetime of a profile provided by the replay block.
author Ideenmodellierer
date Mon, 04 Jan 2021 21:48:31 +0100
parents fd0b60dee6f3
children 916998f90e39
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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"
592
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
17 #include "base.h"
359
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
18
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
19 #define STABLE_STATE_COUNT 2 /* number of count to declare a state as stable (at the moment based on 100ms) */
363
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
20 #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
21
585
4dfdf230d8ba Reduced view angle and number of vusiualized custom views in setor mode:
Ideenmodellierer
parents: 578
diff changeset
22 #define SECTOR_WINDOW 30.0 /* Pitch window which is used for custom view projection */
381
695434a6dcf6 Simplified pitch detection state machine:
ideenmodellierer
parents: 378
diff changeset
23 #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
24 #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
25 #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
26 #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
27
385
0cd862e501f6 Finetune parameter for detection of small sectors as used for the pitch detection
ideenmodellierer
parents: 384
diff changeset
28 #define SECTOR_MAX 24 /* maximum number of sectors */
378
834e087505ec Incremented "idle window" for scroll detection
ideenmodellierer
parents: 373
diff changeset
29 #define SECTOR_SCROLL 7 /* number of sectors used for scroll detection */
592
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
30 #define SECTOR_MAX_CNT 5 /* max number of views used for sector control */
359
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
31
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
32 #define MOTION_DELTA_STABLE 0
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
33 #define MOTION_DELTA_JITTER 1
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
34 #define MOTION_DELTA_RAISE 2
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
35 #define MOTION_DELTA_FALL 3
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
36
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
37 #define MOTION_DELTA_JITTER_LEVEL 3.0 /* lower values are considered as stable */
574
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
38 #define MOTION_DELTA_RAISE_LEVEL 6.0 /* Movement causing a significant change detected */
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
39 #define MOTION_DELTA_FALL_LEVEL -6.0 /* Movement causing a significant change detected */
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
40
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
41 #define MOTION_DELTA_HISTORY_SIZE 20 /* Number of history data sets */
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
42
385
0cd862e501f6 Finetune parameter for detection of small sectors as used for the pitch detection
ideenmodellierer
parents: 384
diff changeset
43 detectionState_t detectionState = DETECT_NOTHING;
0cd862e501f6 Finetune parameter for detection of small sectors as used for the pitch detection
ideenmodellierer
parents: 384
diff changeset
44 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
45
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
46 static uint8_t motionDeltaHistory[3][MOTION_DELTA_HISTORY_SIZE]; /* Change history of roll, pitch and yaw */
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
47 static uint8_t motionDeltaHistoryIdx; /* Current index of history data */
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
48
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
49 static uint8_t focusCnt = 0;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
50 static uint8_t inFocus = 0;
592
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
51 static uint8_t sectorMap[SECTOR_MAX_CNT];
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
52
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
53 void resetMotionDeltaHistory()
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
54 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
55 motionDeltaHistoryIdx = 0;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
56 memset(motionDeltaHistory, 0, sizeof(motionDeltaHistory));
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
57 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
58
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
59 void evaluateMotionDelta(float roll, float pitch, float yaw)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
60 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
61 static float lastValue[3] = {0.0,0.0,0.0};
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
62 uint8_t nextIndex = motionDeltaHistoryIdx + 1;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
63 uint8_t axis;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
64 float curValue;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
65
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
66 if(nextIndex == MOTION_DELTA_HISTORY_SIZE)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
67 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
68 nextIndex = 0;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
69 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
70 for(axis=0; axis < 3; axis++)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
71 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
72 switch(axis)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
73 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
74 case MOTION_HISTORY_ROLL: curValue = roll;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
75 break;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
76 case MOTION_HISTORY_PITCH: curValue = pitch;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
77 break;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
78 default:
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
79 case MOTION_HISTORY_YAW: if((yaw < 90) && (lastValue[MOTION_HISTORY_YAW] > 270.0)) /* transition 360 => 0 */
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
80 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
81 lastValue[MOTION_HISTORY_YAW] -= 360;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
82 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
83 else if((yaw > 270) && (lastValue[MOTION_HISTORY_YAW] < 90.0)) /* transition 0 => 360 */
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
84 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
85 lastValue[MOTION_HISTORY_YAW] += 360;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
86 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
87 curValue = yaw;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
88 break;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
89 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
90 if(curValue - lastValue[axis] > MOTION_DELTA_RAISE_LEVEL)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
91 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
92 motionDeltaHistory[axis][nextIndex] = MOTION_DELTA_RAISE;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
93 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
94 if(fabsf(curValue - lastValue[axis]) < MOTION_DELTA_RAISE_LEVEL)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
95 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
96 motionDeltaHistory[axis][nextIndex] = MOTION_DELTA_JITTER;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
97 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
98 if(fabsf(curValue - lastValue[axis]) < MOTION_DELTA_JITTER_LEVEL)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
99 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
100 motionDeltaHistory[axis][nextIndex] = MOTION_DELTA_STABLE;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
101 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
102 if(curValue - lastValue[axis] < MOTION_DELTA_FALL_LEVEL)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
103 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
104 motionDeltaHistory[axis][nextIndex] = MOTION_DELTA_FALL;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
105 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
106 lastValue[axis] = curValue;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
107 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
108 motionDeltaHistoryIdx = nextIndex;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
109 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
110
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
111 SDeltaHistory GetDeltaHistory(uint8_t stepback)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
112 {
578
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
113 uint8_t loop;
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
114 uint8_t index = motionDeltaHistoryIdx;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
115
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
116 SDeltaHistory result = {0,0,0};
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
117
578
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
118 stepback++; /* motionDeltaHistoryIdx is pointing to future entry => step back one to get the latest */
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
119 loop = stepback;
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
120 if(stepback < MOTION_DELTA_HISTORY_SIZE)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
121 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
122 while(loop != 0) /* find requested entry */
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
123 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
124 loop--;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
125 index--;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
126 if(index == 0)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
127 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
128 index = MOTION_DELTA_HISTORY_SIZE - 1;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
129 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
130 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
131 result.roll = motionDeltaHistory[MOTION_HISTORY_ROLL][index];
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
132 result.pitch = motionDeltaHistory[MOTION_HISTORY_PITCH][index];
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
133 result.yaw = motionDeltaHistory[MOTION_HISTORY_YAW][index];
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
134 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
135 return result;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
136 }
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
137
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 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
139 {
383
49a02dea8ae3 Combine variables in a structure to improve readability of code
ideenmodellierer
parents: 381
diff changeset
140 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
141 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
142 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
143
383
49a02dea8ae3 Combine variables in a structure to improve readability of code
ideenmodellierer
parents: 381
diff changeset
144 newPitch = pitch + sectorDetection.offset + sectorDetection.center; /* do not use negative values and consider offset to center position */
381
695434a6dcf6 Simplified pitch detection state machine:
ideenmodellierer
parents: 378
diff changeset
145 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
146 {
381
695434a6dcf6 Simplified pitch detection state machine:
ideenmodellierer
parents: 378
diff changeset
147 newPitch = 0.0;
695434a6dcf6 Simplified pitch detection state machine:
ideenmodellierer
parents: 378
diff changeset
148 }
383
49a02dea8ae3 Combine variables in a structure to improve readability of code
ideenmodellierer
parents: 381
diff changeset
149 if (newPitch > sectorDetection.window) /* clip value */
381
695434a6dcf6 Simplified pitch detection state machine:
ideenmodellierer
parents: 378
diff changeset
150 {
383
49a02dea8ae3 Combine variables in a structure to improve readability of code
ideenmodellierer
parents: 381
diff changeset
151 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
152 }
381
695434a6dcf6 Simplified pitch detection state machine:
ideenmodellierer
parents: 378
diff changeset
153
695434a6dcf6 Simplified pitch detection state machine:
ideenmodellierer
parents: 378
diff changeset
154 /* switch to other sector? */
383
49a02dea8ae3 Combine variables in a structure to improve readability of code
ideenmodellierer
parents: 381
diff changeset
155 if((newPitch > sectorDetection.upperborder) || (newPitch <= sectorDetection.lowerborder))
381
695434a6dcf6 Simplified pitch detection state machine:
ideenmodellierer
parents: 378
diff changeset
156 {
383
49a02dea8ae3 Combine variables in a structure to improve readability of code
ideenmodellierer
parents: 381
diff changeset
157 sector = (uint16_t) newPitch / sectorDetection.size;
49a02dea8ae3 Combine variables in a structure to improve readability of code
ideenmodellierer
parents: 381
diff changeset
158 sectorDetection.lowerborder = sector * sectorDetection.size - SECTOR_HYSTERY;
49a02dea8ae3 Combine variables in a structure to improve readability of code
ideenmodellierer
parents: 381
diff changeset
159 sectorDetection.upperborder = (sector + 1) * sectorDetection.size + SECTOR_HYSTERY;
381
695434a6dcf6 Simplified pitch detection state machine:
ideenmodellierer
parents: 378
diff changeset
160 lastsector = sector;
695434a6dcf6 Simplified pitch detection state machine:
ideenmodellierer
parents: 378
diff changeset
161 }
695434a6dcf6 Simplified pitch detection state machine:
ideenmodellierer
parents: 378
diff changeset
162
695434a6dcf6 Simplified pitch detection state machine:
ideenmodellierer
parents: 378
diff changeset
163 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
164 }
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
165
371
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
166 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
167 {
371
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
168 if(numOfSectors == CUSTOMER_DEFINED_VIEWS)
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
169 {
384
427ae9f8e28e Consider number of available t3 views in sector handling:
ideenmodellierer
parents: 383
diff changeset
170 if(settingsGetPointer()->design == 3) /* Big font view ? */
427ae9f8e28e Consider number of available t3 views in sector handling:
ideenmodellierer
parents: 383
diff changeset
171 {
427ae9f8e28e Consider number of available t3 views in sector handling:
ideenmodellierer
parents: 383
diff changeset
172 sectorDetection.count = t3_GetEnabled_customviews();
427ae9f8e28e Consider number of available t3 views in sector handling:
ideenmodellierer
parents: 383
diff changeset
173 }
427ae9f8e28e Consider number of available t3 views in sector handling:
ideenmodellierer
parents: 383
diff changeset
174 else
427ae9f8e28e Consider number of available t3 views in sector handling:
ideenmodellierer
parents: 383
diff changeset
175 {
427ae9f8e28e Consider number of available t3 views in sector handling:
ideenmodellierer
parents: 383
diff changeset
176 sectorDetection.count = t7_GetEnabled_customviews();
427ae9f8e28e Consider number of available t3 views in sector handling:
ideenmodellierer
parents: 383
diff changeset
177 }
592
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
178 if(sectorDetection.count > SECTOR_MAX_CNT)
371
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
179 {
592
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
180 sectorDetection.count = SECTOR_MAX_CNT; /* more views are hard to manually control */
371
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
181 }
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
182 }
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
183 else
373
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
184 if(numOfSectors != CUSTOMER_KEEP_LAST_SECTORS)
371
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
185 {
383
49a02dea8ae3 Combine variables in a structure to improve readability of code
ideenmodellierer
parents: 381
diff changeset
186 sectorDetection.count = numOfSectors;
371
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
187 }
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
188
383
49a02dea8ae3 Combine variables in a structure to improve readability of code
ideenmodellierer
parents: 381
diff changeset
189 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
190 {
383
49a02dea8ae3 Combine variables in a structure to improve readability of code
ideenmodellierer
parents: 381
diff changeset
191 sectorDetection.window = SECTOR_WINDOW_MAX;
381
695434a6dcf6 Simplified pitch detection state machine:
ideenmodellierer
parents: 378
diff changeset
192 }
695434a6dcf6 Simplified pitch detection state machine:
ideenmodellierer
parents: 378
diff changeset
193 else
695434a6dcf6 Simplified pitch detection state machine:
ideenmodellierer
parents: 378
diff changeset
194 {
383
49a02dea8ae3 Combine variables in a structure to improve readability of code
ideenmodellierer
parents: 381
diff changeset
195 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
196 }
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
197
383
49a02dea8ae3 Combine variables in a structure to improve readability of code
ideenmodellierer
parents: 381
diff changeset
198 sectorDetection.offset = (centerPitch - (sectorDetection.window / 2)) * -1.0;
49a02dea8ae3 Combine variables in a structure to improve readability of code
ideenmodellierer
parents: 381
diff changeset
199 sectorDetection.size = sectorDetection.window / sectorDetection.count;
49a02dea8ae3 Combine variables in a structure to improve readability of code
ideenmodellierer
parents: 381
diff changeset
200 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
201
383
49a02dea8ae3 Combine variables in a structure to improve readability of code
ideenmodellierer
parents: 381
diff changeset
202 /* reset border values */
49a02dea8ae3 Combine variables in a structure to improve readability of code
ideenmodellierer
parents: 381
diff changeset
203 sectorDetection.lowerborder = SECTOR_BORDER;
49a02dea8ae3 Combine variables in a structure to improve readability of code
ideenmodellierer
parents: 381
diff changeset
204 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
205 /* get the current sector */
383
49a02dea8ae3 Combine variables in a structure to improve readability of code
ideenmodellierer
parents: 381
diff changeset
206 sectorDetection.current = GetSectorForPitch(stateRealGetPointer()->lifeData.compass_pitch);
49a02dea8ae3 Combine variables in a structure to improve readability of code
ideenmodellierer
parents: 381
diff changeset
207 sectorDetection.target = sectorDetection.current;
49a02dea8ae3 Combine variables in a structure to improve readability of code
ideenmodellierer
parents: 381
diff changeset
208 /* 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
209 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
210
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
211 }
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
212
592
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
213
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
214 uint8_t GetCVForSector(uint8_t selSector)
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
215 {
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
216 if(selSector < sectorDetection.count)
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
217 {
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
218 return sectorMap[selSector];
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
219 }
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
220 else
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
221 {
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
222 return 0;
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
223 }
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
224 }
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
225 void MapCVToSector()
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
226 {
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
227 uint8_t centerView = 0;
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
228
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
229 memset(sectorMap, 0, sizeof(sectorMap));
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
230
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
231 switch(sectorDetection.count)
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
232 {
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
233 case 1: centerView = 0; break;
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
234 case 2: centerView = 0; break;
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
235 case 3: centerView = 1; break;
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
236 case 4: centerView = 1; break;
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
237 case 5: centerView = 2; break;
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
238 default: centerView = sectorDetection.count / 2 - 1;
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
239 break;
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
240 }
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
241 if(settingsGetPointer()->design == 3) /* Big font view ? */
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
242 {
595
fd0b60dee6f3 Bugfix Selection of primary view:
Ideenmodellierer
parents: 592
diff changeset
243 t3_set_customview_to_primary();
fd0b60dee6f3 Bugfix Selection of primary view:
Ideenmodellierer
parents: 592
diff changeset
244 sectorMap[centerView] = t3_change_customview(ACTION_END);
592
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
245 }
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
246 else
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
247 {
595
fd0b60dee6f3 Bugfix Selection of primary view:
Ideenmodellierer
parents: 592
diff changeset
248 t7_set_customview_to_primary();
fd0b60dee6f3 Bugfix Selection of primary view:
Ideenmodellierer
parents: 592
diff changeset
249 sectorMap[centerView] = t7_change_customview(ACTION_END);
fd0b60dee6f3 Bugfix Selection of primary view:
Ideenmodellierer
parents: 592
diff changeset
250
592
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
251 }
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
252
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
253 centerView++;
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
254 while(sectorMap[centerView] == 0)
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
255 {
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
256 if(settingsGetPointer()->design == 3) /* Big font view ? */
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
257 {
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
258 sectorMap[centerView] = t3_change_customview(ACTION_BUTTON_ENTER);
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
259 }
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
260 else
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
261 {
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
262 sectorMap[centerView] = t7_change_customview(ACTION_BUTTON_ENTER);
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
263 }
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
264 centerView++;
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
265 if(centerView == sectorDetection.count)
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
266 {
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
267 centerView = 0;
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
268 }
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
269 }
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
270
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
271 }
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
272
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
273 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
274 {
383
49a02dea8ae3 Combine variables in a structure to improve readability of code
ideenmodellierer
parents: 381
diff changeset
275 sectorDetection.target = 0;
49a02dea8ae3 Combine variables in a structure to improve readability of code
ideenmodellierer
parents: 381
diff changeset
276 sectorDetection.current = 0;
49a02dea8ae3 Combine variables in a structure to improve readability of code
ideenmodellierer
parents: 381
diff changeset
277 sectorDetection.size = 0;
49a02dea8ae3 Combine variables in a structure to improve readability of code
ideenmodellierer
parents: 381
diff changeset
278 sectorDetection.count = 0;
371
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
279
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
280 switch(settingsGetPointer()->MotionDetection)
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
281 {
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
282 case MOTION_DETECT_SECTOR: DefinePitchSectors(settingsGetPointer()->viewPitch,CUSTOMER_DEFINED_VIEWS);
592
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
283 MapCVToSector();
371
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
284 break;
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
285 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
286 break;
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
287 case MOTION_DETECT_SCROLL: DefinePitchSectors(settingsGetPointer()->viewPitch,SECTOR_SCROLL);
373
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
288 break;
371
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
289 default:
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
290 break;
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
291 }
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
292
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
293 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
294 }
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
295
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 /* 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
297 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
298 {
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
299 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
300
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
301 newTargetSector = GetSectorForPitch(stateRealGetPointer()->lifeData.compass_pitch);
592
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
302
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
303 if(settingsGetPointer()->design == 3) /* Big font view ? */
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
304 {
592
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
305 t3_select_customview(GetCVForSector(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
306 }
592
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
307 else
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
308 {
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
309 t7_select_customview(GetCVForSector(newTargetSector));
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
310 }
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
311
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
312 return DETECT_NOTHING;
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
313 }
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
314
373
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
315 /* 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
316 detectionState_t detectScrollButtonEvent(float curPitch)
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
317 {
378
834e087505ec Incremented "idle window" for scroll detection
ideenmodellierer
parents: 373
diff changeset
318 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
319
373
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
320 uint8_t PitchEvent = DETECT_NOTHING;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
321 uint8_t newSector;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
322
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
323 if(delayscroll == 0)
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
324 {
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
325 newSector = GetSectorForPitch(stateRealGetPointer()->lifeData.compass_pitch);
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
326 /* 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
327 switch(newSector)
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
328 {
574
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
329 case 0: PitchEvent = DETECT_POS_PITCH;
373
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
330 break;
378
834e087505ec Incremented "idle window" for scroll detection
ideenmodellierer
parents: 373
diff changeset
331 case 6: PitchEvent = DETECT_NEG_PITCH;
373
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
332 break;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
333 default:
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
334 break;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
335 }
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
336 if(PitchEvent != DETECT_NOTHING)
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
337 {
574
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
338 delayscroll = 7;
373
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
339 }
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
340 }
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
341 else
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
342 {
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
343 delayscroll--;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
344 }
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
345 return PitchEvent;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
346 }
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
347
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
348
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
349 /* 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
350 /* 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
351 detectionState_t detectPitch(float currentPitch)
359
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
352 {
578
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
353 static int8_t lastStart = 0;
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
354 uint8_t exit = 0;
578
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
355 int8_t step = 0;
574
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
356 uint8_t duration = 0;
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
357 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
358
578
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
359 if(lastStart < 0)
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
360 {
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
361 detectionState = DETECT_NOTHING;
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
362 lastStart = 0;
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
363 }
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
364 else
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
365 {
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
366 detectionState = DETECT_START;
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
367 }
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
368 step = lastStart;
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
369 do
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
370 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
371 test = GetDeltaHistory(step);
574
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
372 duration++;
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
373 switch (detectionState)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
374 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
375 case DETECT_NOTHING: if(test.pitch > MOTION_DELTA_STABLE)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
376 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
377 exit = 1;
578
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
378 lastStart = -2;
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
379 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
380 else
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
381 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
382 detectionState = DETECT_START;
578
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
383 lastStart = -1;
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
384 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
385 break;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
386 case DETECT_START: if(test.pitch == MOTION_DELTA_RAISE)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
387 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
388 detectionState = DETECT_POS_MOVE;
578
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
389 lastStart = step;
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
390 }
578
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
391 else
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
392 if(test.pitch == MOTION_DELTA_FALL)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
393 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
394 detectionState = DETECT_NEG_MOVE;
578
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
395 lastStart = step;
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
396 }
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
397 else
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
398 {
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
399 lastStart = -1;
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
400 }
574
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
401 duration = 0;
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
402 break;
578
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
403 case DETECT_NEG_MOVE: if((test.pitch <= MOTION_DELTA_JITTER) || (test.pitch == MOTION_DELTA_RAISE))
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
404 {
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
405 detectionState++;
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
406 }
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
407 break;
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
408 case DETECT_POS_MOVE: if((test.pitch <= MOTION_DELTA_JITTER) || (test.pitch == MOTION_DELTA_FALL))
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
409 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
410 detectionState++;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
411 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
412 break;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
413 case DETECT_MAXIMA: if(test.pitch == MOTION_DELTA_FALL)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
414 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
415 detectionState = DETECT_FALLBACK;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
416 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
417 break;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
418 case DETECT_MINIMA: if(test.pitch == MOTION_DELTA_RAISE)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
419 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
420 detectionState = DETECT_RISEBACK;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
421 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
422 break;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
423 case DETECT_RISEBACK:
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
424 case DETECT_FALLBACK: if(test.pitch == MOTION_DELTA_STABLE)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
425 {
578
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
426 if(duration > 4) /* avoid detection triggered by short moves */
574
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
427 {
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
428 detectionState++;
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
429 }
578
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
430 exit = 1;
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
431 lastStart = -2;
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
432 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
433 break;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
434 default:
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
435 detectionState = DETECT_NOTHING;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
436 exit = 1;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
437 break;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
438 }
578
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
439 step--;
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
440 } while((step >= 0) && (!exit));
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
441
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
442 if((lastStart < MOTION_DELTA_HISTORY_SIZE))
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
443 {
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
444 lastStart++; /* prepare value for next iteration (history index will be increased) */
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
445 }
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
446 else
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
447 {
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
448 lastStart = -1;
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
449 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
450 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
451 {
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
452 detectionState = DETECT_NOTHING;
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
453 }
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
454 else /* dont detect the same event twice */
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
455 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
456 resetMotionDeltaHistory();
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
457 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
458 return detectionState;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
459 }
363
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
460
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
461 void anglesToCoord(float roll, float pitch, float yaw, SCoord *pCoord)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
462 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
463 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);
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
464 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);
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
465 pCoord->z = ((-1*sinf(pitch)) * pCoord->x + (cosf(pitch) *sinf(roll)) * pCoord->y + (cosf(pitch) * cosf(roll))* pCoord->z);
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
466 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
467
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
468 SCoord CoordAdd(SCoord cA, SCoord cB)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
469 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
470 SCoord result;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
471
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
472 result.x = cA.x + cB.x;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
473 result.y = cA.y + cB.y;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
474 result.z = cA.z + cB.z;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
475 return result;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
476 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
477
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
478 SCoord CoordSub(SCoord cA, SCoord cB)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
479 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
480 SCoord result;
373
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
481
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
482 result.x = cA.x - cB.x;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
483 result.y = cA.y - cB.y;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
484 result.z = cA.z - cB.z;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
485 return result;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
486 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
487
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
488 SCoord CoordCross(SCoord cA, SCoord cB)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
489 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
490 SCoord result;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
491
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
492 result.x = (cA.y * cB.z) - (cA.z * cB.y);
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
493 result.y = (cA.z * cB.x) - (cA.x * cB.z);
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
494 result.z = (cA.x * cB.y) - (cA.y * cB.x);
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
495
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
496 return result;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
497
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
498 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
499
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
500 SCoord CoordMulF(SCoord op, float factor)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
501 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
502 SCoord result;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
503 result.x = (op.x * factor);
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
504 result.y = (op.y * factor);
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
505 result.z = (op.z * factor);
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
506
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
507 return result;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
508 }
373
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
509
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
510 SCoord CoordDivF(SCoord op, float factor)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
511 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
512 SCoord result;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
513 result.x = (op.x / factor);
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
514 result.y = (op.y / factor);
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
515 result.z = (op.z / factor);
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
516
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
517 return result;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
518 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
519
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
520 float CoordDot(SCoord cA, SCoord cB)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
521 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
522 float result;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
523
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
524 result = cA.x * cB.x + cA.y * cB.y + cB.z*cA.z;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
525 return result;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
526 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
527
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
528 void calibrateViewport(float roll, float pitch, float yaw)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
529 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
530 SSettings* pSettings = settingsGetPointer();
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
531
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
532 pSettings->viewPitch = pitch;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
533 pSettings->viewRoll = roll;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
534 pSettings->viewYaw = yaw;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
535 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
536
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
537
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
538 float checkViewport(float roll, float pitch, float yaw)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
539 {
574
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
540 static float freezeRoll = 0;
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
541 static float freezeYaw = 0;
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
542
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
543 uint8_t retval = 0;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
544 float angleYaw;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
545 float anglePitch;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
546 float angleRoll;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
547 float distance = 0;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
548 float _a, _b;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
549 SCoord u,v,n;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
550 float r;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
552 SCoord refVec;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
553 SCoord axis_1;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
554 SCoord axis_2;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
555 SCoord curVec;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
556 SCoord resultVec;
574
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
557 SDeltaHistory test;
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
558
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
559 SSettings* pSettings = settingsGetPointer();
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
560
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
561 /* calculate base vector taking calibration delta into account yaw (heading) */
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
562 float compYaw = yaw + pSettings->viewYaw;
574
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
563
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
564 compYaw = 360.0 - yaw; /* turn to 0° */
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
565 compYaw += pSettings->viewYaw; /* consider calib yaw value */
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
566 compYaw += yaw;
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
567
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
568 if (compYaw < 0.0)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
569 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
570 compYaw = 360.0 + compYaw;
381
695434a6dcf6 Simplified pitch detection state machine:
ideenmodellierer
parents: 378
diff changeset
571 }
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
572
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
573 if (compYaw > 360.0)
381
695434a6dcf6 Simplified pitch detection state machine:
ideenmodellierer
parents: 378
diff changeset
574 {
574
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
575 compYaw = compYaw - 360.0;
373
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
576 }
574
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
577 if (compYaw > 360.0)
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
578 {
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
579 compYaw = compYaw - 360.0;
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
580 }
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
581 angleYaw = pSettings->viewYaw * M_PI / 180.0;
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
582 anglePitch = pSettings->viewPitch * M_PI / 180.0;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
583 angleRoll = pSettings->viewRoll * M_PI / 180.0;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
584
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
585 refVec.x = 0;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
586 refVec.y = 0;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
587 refVec.z = 1.0;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
588
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
589 anglesToCoord(angleRoll,anglePitch,angleYaw, &refVec);
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
590
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
591 anglePitch = pitch * M_PI / 180.0;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
592 angleRoll = roll * M_PI / 180.0;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
593 angleYaw = yaw * M_PI / 180.0;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
594
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
595 /* assume x = 0 and y = 1 => find matching vector so axis_1 is 90° to axis_2 */
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
596 axis_1.x = 0;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
597 if(refVec.y >=0)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
598 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
599 axis_2.y = 1; /* => Spawn y == refVec y */
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
600 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
601 else axis_1.y = -1;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
602 axis_1.z = -1.0 * refVec.y / refVec.z;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
603 axis_2 = CoordCross(refVec, axis_1); /* Cross is 90° to refVec and Spawn as well => Plane Spawn / cross */
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
604
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
605 /* check if detection plane is correct */
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
606 u = CoordSub(axis_1,refVec);
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
607 v = CoordSub(axis_2,refVec);
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
608 n = CoordCross(u,v);
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
609
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
610 if((fabsf(n.x) <= 0.0001) && (fabsf(n.y) <= 0.0001) && (fabsf(n.z) <= 0.0001))
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
611 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
612 retval = 2;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
613 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
614 else
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
615 {
574
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
616 angleYaw = compYaw * M_PI / 180.0;
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
617 anglePitch = pitch * M_PI / 180.0;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
618 angleRoll = roll * M_PI / 180.0;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
619 curVec.x = 0;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
620 curVec.y = 0;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
621 curVec.z = 1.0;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
622 anglesToCoord(angleRoll,anglePitch,angleYaw, &curVec);
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
623
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
624 _a = CoordDot(curVec,n);
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
625 _b = CoordDot(refVec,n);
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
626
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
627 if(_b>=(-0.0001)&&_b<=0.0001) /* Check if view port is parallel (no matchpoint) */
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
628 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
629 retval = 3;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
630 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
631 else
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
632 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
633 r=_a/_b;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
634 if(r<0.00||r>1.40) /* are we looking into wrong direction? */
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
635 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
636 retval = 4;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
637 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
638 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
639 distance = retval * 1.0; /* just for debugging */
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
640 if(retval == 0)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
641 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
642
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
643 /* start calculating the matchpoint */
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
644 curVec = CoordMulF(curVec,r);
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
645 resultVec = CoordSub(refVec,curVec);
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
646
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
647 /* calculate the distance between reference and actual vector */
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
648 resultVec.x = resultVec.x * resultVec.x;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
649 resultVec.y = resultVec.y * resultVec.y;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
650 resultVec.z = resultVec.z * resultVec.z;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
651
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
652 if((resultVec.x == 0) && (resultVec.y == 0) && (resultVec.z == 0))
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
653 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
654 distance = 0.0;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
655 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
656 else
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
657 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
658 distance = sqrtf((resultVec.x + resultVec.y + resultVec.z));
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
659 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
660 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
661 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
662
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
663 if(distance < 0.5) /* handle focus counter to avoid fast in/out focus changes */
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
664 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
665 if(focusCnt < 10)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
666 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
667 if((focusCnt == 9) && (inFocus == 0)) /* we will get into focus */
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
668 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
669 resetMotionDeltaHistory();
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
670 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
671 focusCnt++;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
672 }
574
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
673 if((focusCnt == 10) && (inFocus == 0))
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
674 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
675 inFocus = 1;
574
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
676 freezeRoll = roll;
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
677 freezeYaw = yaw;
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
678 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
679 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
680 else
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
681 {
574
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
682 if(focusCnt >= 5) /* Reset focus faster then setting focus */
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
683 {
574
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
684 if(pSettings->MotionDetection != MOTION_DETECT_MOVE) /* only apply extended focus for methods using absolute pitch values */
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
685 {
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
686 test = GetDeltaHistory(0);
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
687 if((test.yaw == MOTION_DELTA_STABLE) && (test.roll == MOTION_DELTA_STABLE))
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
688 {
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
689 if((fabsf(freezeRoll - roll) < MOTION_DELTA_JITTER_LEVEL) && (fabsf(freezeYaw - yaw) < MOTION_DELTA_JITTER_LEVEL))
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
690 {
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
691 focusCnt++;
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
692 }
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
693 }
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
694 else
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
695 {
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
696 if(freezeRoll != 0.0)
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
697 {
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
698 focusCnt = 1;
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
699 }
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
700 }
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
701 }
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
702 focusCnt--;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
703 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
704 else
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
705 {
574
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
706 focusCnt = 0;
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
707 inFocus = 0;
574
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
708 freezeRoll = 0;
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
709 freezeYaw = 0;
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
710 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
711 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
712 return distance;
359
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
713 }
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
714 uint8_t viewInFocus(void)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
715 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
716 return inFocus;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
717 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
718 void resetFocusState(void)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
719 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
720 inFocus = 0;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
721 }