annotate Discovery/Src/motion.c @ 868:db92692c014f Evo_2_23

Introduce speed dependend coloring of depth: The depth value in the will now be colored based on the current ascent speed. The color code matches the one of the bar graph which was already used for visualization of the ascent speed. To keep color code consistent the existing color selection functions have been merged to one common Gfx function (T3/T7 - bar graph and color text)
author Ideenmodellierer
date Mon, 12 Aug 2024 15:14:19 +0200
parents ff2b393e290f
children
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
385
0cd862e501f6 Finetune parameter for detection of small sectors as used for the pitch detection
ideenmodellierer
parents: 384
diff changeset
22 #define SECTOR_MAX 24 /* maximum number of sectors */
378
834e087505ec Incremented "idle window" for scroll detection
ideenmodellierer
parents: 373
diff changeset
23 #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
24 #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
25
627
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
26
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
27 typedef enum
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
28 {
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
29 MOTION_DELTA_STABLE = 0,
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
30 MOTION_DELTA_JITTER,
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
31 MOTION_DELTA_RAISE,
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
32 MOTION_DELTA_RAISE_FAST,
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
33 MOTION_DELTA_FALL,
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
34 MOTION_DELTA_FALL_FAST
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
35 } MotionDeltaState_t;
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
36
625
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
37 #define MOTION_DELTA_JITTER_LEVEL 2.0 /* lower values are considered as stable */
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
38 #define MOTION_DELTA_RAISE_LEVEL 4.0 /* Movement causing a significant change detected */
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
39 #define MOTION_DELTA_FALL_LEVEL -4.0 /* Movement causing a significant change detected */
627
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
40 #define MOTION_DELTA_FAST_LEVEL 6.0 /* Movement causing a fast change detected */
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
41
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
42 #define MOTION_DELTA_HISTORY_SIZE 20 /* Number of history data sets */
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
43
627
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
44 #define MOTION_FOCUS_LIMIT 0.5 /* +/- value which defines the border of the focus area */
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
45 #define MOTION_FOCUS_USE_SECTOR 0.4 /* +/- value for the focus area used to map secors to views */
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
46 #define MOTION_FOCUS_SCROLL_IDLE 0.3 /* +/- value for starting generation of scroll events */
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
47
385
0cd862e501f6 Finetune parameter for detection of small sectors as used for the pitch detection
ideenmodellierer
parents: 384
diff changeset
48 detectionState_t detectionState = DETECT_NOTHING;
0cd862e501f6 Finetune parameter for detection of small sectors as used for the pitch detection
ideenmodellierer
parents: 384
diff changeset
49 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
50
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
51 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
52 static uint8_t motionDeltaHistoryIdx; /* Current index of history data */
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
53
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
54 static uint8_t focusCnt = 0;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
55 static uint8_t inFocus = 0;
592
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
56 static uint8_t sectorMap[SECTOR_MAX_CNT];
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
57
611
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
58 static uint8_t suspendMotionDetectionSec = 0;
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
59
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
60 void resetMotionDeltaHistory()
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
61 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
62 motionDeltaHistoryIdx = 0;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
63 memset(motionDeltaHistory, 0, sizeof(motionDeltaHistory));
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
64 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
65
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
66 void evaluateMotionDelta(float roll, float pitch, float yaw)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
67 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
68 static float lastValue[3] = {0.0,0.0,0.0};
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
69 uint8_t nextIndex = motionDeltaHistoryIdx + 1;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
70 uint8_t axis;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
71 float curValue;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
72
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
73 if(nextIndex == MOTION_DELTA_HISTORY_SIZE)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
74 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
75 nextIndex = 0;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
76 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
77 for(axis=0; axis < 3; axis++)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
78 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
79 switch(axis)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
80 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
81 case MOTION_HISTORY_ROLL: curValue = roll;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
82 break;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
83 case MOTION_HISTORY_PITCH: curValue = pitch;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
84 break;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
85 default:
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
86 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
87 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
88 lastValue[MOTION_HISTORY_YAW] -= 360;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
89 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
90 else if((yaw > 270) && (lastValue[MOTION_HISTORY_YAW] < 90.0)) /* transition 0 => 360 */
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
91 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
92 lastValue[MOTION_HISTORY_YAW] += 360;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
93 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
94 curValue = yaw;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
95 break;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
96 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
97 if(curValue - lastValue[axis] > MOTION_DELTA_RAISE_LEVEL)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
98 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
99 motionDeltaHistory[axis][nextIndex] = MOTION_DELTA_RAISE;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
100 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
101 if(fabsf(curValue - lastValue[axis]) < MOTION_DELTA_RAISE_LEVEL)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
102 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
103 motionDeltaHistory[axis][nextIndex] = MOTION_DELTA_JITTER;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
104 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
105 if(fabsf(curValue - lastValue[axis]) < MOTION_DELTA_JITTER_LEVEL)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
106 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
107 motionDeltaHistory[axis][nextIndex] = MOTION_DELTA_STABLE;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
108 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
109 if(curValue - lastValue[axis] < MOTION_DELTA_FALL_LEVEL)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
110 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
111 motionDeltaHistory[axis][nextIndex] = MOTION_DELTA_FALL;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
112 }
627
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
113
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
114 if(fabsf(curValue - lastValue[axis]) > MOTION_DELTA_FAST_LEVEL)
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
115 {
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
116 motionDeltaHistory[axis][nextIndex]++;
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
117 }
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
118
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
119 lastValue[axis] = curValue;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
120 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
121 motionDeltaHistoryIdx = nextIndex;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
122 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
123
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
124 SDeltaHistory GetDeltaHistory(uint8_t stepback)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
125 {
578
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
126 uint8_t loop;
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
127 uint8_t index = motionDeltaHistoryIdx;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
128
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
129 SDeltaHistory result = {0,0,0};
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
130
627
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
131 loop = stepback + 1; /* motionDeltaHistoryIdx is pointing to future entry => step back one more to get the latest */
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
132 if(stepback < MOTION_DELTA_HISTORY_SIZE)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
133 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
134 while(loop != 0) /* find requested entry */
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
135 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
136 loop--;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
137 index--;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
138 if(index == 0)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
139 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
140 index = MOTION_DELTA_HISTORY_SIZE - 1;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
141 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
142 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
143 result.roll = motionDeltaHistory[MOTION_HISTORY_ROLL][index];
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
144 result.pitch = motionDeltaHistory[MOTION_HISTORY_PITCH][index];
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
145 result.yaw = motionDeltaHistory[MOTION_HISTORY_YAW][index];
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
146 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
147 return result;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
148 }
370
77cdfbdaca8c Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents: 363
diff changeset
149
625
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
150 uint8_t GetSectorForFocus(float focusOffset)
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
151 {
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 uint8_t sector = 0;
627
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
153 float compare = -1.0 * MOTION_FOCUS_USE_SECTOR + sectorDetection.size ; /* start with first sector upper limit */
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
154
627
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
155 while(compare <= MOTION_FOCUS_USE_SECTOR)
381
695434a6dcf6 Simplified pitch detection state machine:
ideenmodellierer
parents: 378
diff changeset
156 {
625
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
157 if(focusOffset > compare)
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
158 {
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
159 sector++;
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
160 }
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
161 else
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
162 {
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
163 break;
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
164 }
627
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
165 compare += sectorDetection.size;
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
166 }
627
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
167 if(sector >= sectorDetection.count)
381
695434a6dcf6 Simplified pitch detection state machine:
ideenmodellierer
parents: 378
diff changeset
168 {
627
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
169 sector = sectorDetection.count - 1;
381
695434a6dcf6 Simplified pitch detection state machine:
ideenmodellierer
parents: 378
diff changeset
170 }
625
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
171 return sector;
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
172 }
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
173
625
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
174 void DefineSectorCount(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
175 {
371
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
176 if(numOfSectors == CUSTOMER_DEFINED_VIEWS)
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
177 {
384
427ae9f8e28e Consider number of available t3 views in sector handling:
ideenmodellierer
parents: 383
diff changeset
178 if(settingsGetPointer()->design == 3) /* Big font view ? */
427ae9f8e28e Consider number of available t3 views in sector handling:
ideenmodellierer
parents: 383
diff changeset
179 {
427ae9f8e28e Consider number of available t3 views in sector handling:
ideenmodellierer
parents: 383
diff changeset
180 sectorDetection.count = t3_GetEnabled_customviews();
427ae9f8e28e Consider number of available t3 views in sector handling:
ideenmodellierer
parents: 383
diff changeset
181 }
427ae9f8e28e Consider number of available t3 views in sector handling:
ideenmodellierer
parents: 383
diff changeset
182 else
427ae9f8e28e Consider number of available t3 views in sector handling:
ideenmodellierer
parents: 383
diff changeset
183 {
427ae9f8e28e Consider number of available t3 views in sector handling:
ideenmodellierer
parents: 383
diff changeset
184 sectorDetection.count = t7_GetEnabled_customviews();
427ae9f8e28e Consider number of available t3 views in sector handling:
ideenmodellierer
parents: 383
diff changeset
185 }
592
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
186 if(sectorDetection.count > SECTOR_MAX_CNT)
371
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
187 {
592
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
188 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
189 }
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
190 }
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
191 else
373
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
192 if(numOfSectors != CUSTOMER_KEEP_LAST_SECTORS)
371
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
193 {
383
49a02dea8ae3 Combine variables in a structure to improve readability of code
ideenmodellierer
parents: 381
diff changeset
194 sectorDetection.count = numOfSectors;
371
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
195 }
627
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
196 sectorDetection.size = MOTION_FOCUS_USE_SECTOR * 2.0 / sectorDetection.count;
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
197 }
77cdfbdaca8c Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents: 363
diff changeset
198
592
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
199
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
200 uint8_t GetCVForSector(uint8_t selSector)
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
201 {
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
202 if(selSector < sectorDetection.count)
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
203 {
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
204 return sectorMap[selSector];
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
205 }
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
206 else
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
207 {
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
208 return 0;
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
209 }
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
210 }
625
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
211
592
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
212 void MapCVToSector()
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
213 {
625
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
214 uint8_t ViewIndex = 0;
627
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
215 memset(sectorMap, 0, sizeof(sectorMap));
592
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
216
627
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
217 while(ViewIndex < (sectorDetection.count / 2)) /* define center sector */
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
218 {
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
219 ViewIndex++;
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
220 }
592
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 if(settingsGetPointer()->design == 3) /* Big font view ? */
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
223 {
595
fd0b60dee6f3 Bugfix Selection of primary view:
Ideenmodellierer
parents: 592
diff changeset
224 t3_set_customview_to_primary();
625
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
225 sectorMap[ViewIndex] = t3_change_customview(ACTION_END);
592
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 else
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
228 {
595
fd0b60dee6f3 Bugfix Selection of primary view:
Ideenmodellierer
parents: 592
diff changeset
229 t7_set_customview_to_primary();
625
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
230 sectorMap[ViewIndex] = t7_change_customview(ACTION_END);
595
fd0b60dee6f3 Bugfix Selection of primary view:
Ideenmodellierer
parents: 592
diff changeset
231
592
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
625
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
234 ViewIndex++;
627
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
235 while(sectorMap[ViewIndex] == 0)
592
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
236 {
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
237 if(settingsGetPointer()->design == 3) /* Big font view ? */
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
238 {
625
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
239 sectorMap[ViewIndex] = t3_change_customview(ACTION_BUTTON_ENTER);
592
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 else
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
242 {
625
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
243 sectorMap[ViewIndex] = t7_change_customview(ACTION_BUTTON_ENTER);
592
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
244 }
625
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
245 ViewIndex++;
627
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
246 if(ViewIndex == sectorDetection.count)
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
247 {
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
248 ViewIndex = 0;
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
249 }
592
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
250 }
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
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
254 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
255 {
383
49a02dea8ae3 Combine variables in a structure to improve readability of code
ideenmodellierer
parents: 381
diff changeset
256 sectorDetection.target = 0;
49a02dea8ae3 Combine variables in a structure to improve readability of code
ideenmodellierer
parents: 381
diff changeset
257 sectorDetection.current = 0;
49a02dea8ae3 Combine variables in a structure to improve readability of code
ideenmodellierer
parents: 381
diff changeset
258 sectorDetection.size = 0;
49a02dea8ae3 Combine variables in a structure to improve readability of code
ideenmodellierer
parents: 381
diff changeset
259 sectorDetection.count = 0;
371
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
260
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
261 switch(settingsGetPointer()->MotionDetection)
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
262 {
625
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
263 case MOTION_DETECT_SECTOR: DefineSectorCount(CUSTOMER_DEFINED_VIEWS);
592
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
264 MapCVToSector();
371
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
265 break;
625
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
266 case MOTION_DETECT_MOVE: DefineSectorCount(SECTOR_MAX);
371
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
267 break;
625
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
268 case MOTION_DETECT_SCROLL: DefineSectorCount(SECTOR_SCROLL);
373
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
269 break;
371
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
270 default:
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
271 break;
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
272 }
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
273
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
274 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
275 }
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
276
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
277 /* Map the current pitch value to a sector and create button event in case the sector is left */
625
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
278 detectionState_t detectSectorButtonEvent(float focusOffset)
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
279 {
642
c737cf5d9067 Do not show focus indicator in case motion detection is suspended:
Ideenmodellierer
parents: 627
diff changeset
280 static uint8_t lastTargetSector = 0xFF;
648
ff2b393e290f Motion detection: Enable focus after focus calibration:
Ideenmodellierer
parents: 642
diff changeset
281 static float lastfocusOffset = 1000.0;
642
c737cf5d9067 Do not show focus indicator in case motion detection is suspended:
Ideenmodellierer
parents: 627
diff changeset
282
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
283 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
284
625
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
285 newTargetSector = GetSectorForFocus(focusOffset);
592
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
286
642
c737cf5d9067 Do not show focus indicator in case motion detection is suspended:
Ideenmodellierer
parents: 627
diff changeset
287 /* take a small hysteresis into account to avoid fast display changes (flicker) */
c737cf5d9067 Do not show focus indicator in case motion detection is suspended:
Ideenmodellierer
parents: 627
diff changeset
288 if((newTargetSector != lastTargetSector) && (fabsf(focusOffset - lastfocusOffset) > (sectorDetection.size / 3)))
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
289 {
642
c737cf5d9067 Do not show focus indicator in case motion detection is suspended:
Ideenmodellierer
parents: 627
diff changeset
290 lastfocusOffset = focusOffset;
648
ff2b393e290f Motion detection: Enable focus after focus calibration:
Ideenmodellierer
parents: 642
diff changeset
291 lastTargetSector = newTargetSector;
642
c737cf5d9067 Do not show focus indicator in case motion detection is suspended:
Ideenmodellierer
parents: 627
diff changeset
292 if(settingsGetPointer()->design == 3) /* Big font view ? */
c737cf5d9067 Do not show focus indicator in case motion detection is suspended:
Ideenmodellierer
parents: 627
diff changeset
293 {
c737cf5d9067 Do not show focus indicator in case motion detection is suspended:
Ideenmodellierer
parents: 627
diff changeset
294 t3_select_customview(GetCVForSector(newTargetSector));
c737cf5d9067 Do not show focus indicator in case motion detection is suspended:
Ideenmodellierer
parents: 627
diff changeset
295 }
c737cf5d9067 Do not show focus indicator in case motion detection is suspended:
Ideenmodellierer
parents: 627
diff changeset
296 else
c737cf5d9067 Do not show focus indicator in case motion detection is suspended:
Ideenmodellierer
parents: 627
diff changeset
297 {
c737cf5d9067 Do not show focus indicator in case motion detection is suspended:
Ideenmodellierer
parents: 627
diff changeset
298 t7_select_customview(GetCVForSector(newTargetSector));
c737cf5d9067 Do not show focus indicator in case motion detection is suspended:
Ideenmodellierer
parents: 627
diff changeset
299 }
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
300 }
592
f52bc70e380f MotionCtrl - Sectorview Map sectors directly to custom views:
Ideenmodellierer
parents: 585
diff changeset
301 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
302 }
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
303
373
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
304 /* Check if pitch is not in center position and trigger a button action if needed */
625
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
305 detectionState_t detectScrollButtonEvent(float focusOffset)
373
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
306 {
378
834e087505ec Incremented "idle window" for scroll detection
ideenmodellierer
parents: 373
diff changeset
307 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
308
373
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
309 uint8_t PitchEvent = DETECT_NOTHING;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
310
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
311 if(delayscroll == 0)
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
312 {
627
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
313 if(focusOffset > MOTION_FOCUS_SCROLL_IDLE)
373
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
314 {
625
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
315 PitchEvent = DETECT_POS_PITCH;
574
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
316 delayscroll = 7;
373
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
317 }
627
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
318 if(focusOffset < (-1.0 * MOTION_FOCUS_SCROLL_IDLE))
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
319 {
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
320 PitchEvent = DETECT_NEG_PITCH;
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
321 delayscroll = 7;
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
322 }
373
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
323 }
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
324 else
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
325 {
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
326 delayscroll--;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
327 }
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
328 return PitchEvent;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
329 }
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
330
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
331
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
332 /* 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
333 /* 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
334 detectionState_t detectPitch(float currentPitch)
359
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
335 {
578
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
336 static int8_t lastStart = 0;
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
337 uint8_t exit = 0;
578
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
338 int8_t step = 0;
574
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
339 uint8_t duration = 0;
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
340 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
341
578
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
342 if(lastStart < 0)
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
343 {
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
344 detectionState = DETECT_NOTHING;
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
345 lastStart = 0;
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
346 }
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
347 else
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
348 {
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
349 detectionState = DETECT_START;
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
350 }
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
351 step = lastStart;
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
352 do
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
353 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
354 test = GetDeltaHistory(step);
574
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
355 duration++;
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
356 switch (detectionState)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
357 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
358 case DETECT_NOTHING: if(test.pitch > MOTION_DELTA_STABLE)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
359 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
360 exit = 1;
578
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
361 lastStart = -2;
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
362 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
363 else
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
364 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
365 detectionState = DETECT_START;
578
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
366 lastStart = -1;
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
367 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
368 break;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
369 case DETECT_START: if(test.pitch == MOTION_DELTA_RAISE)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
370 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
371 detectionState = DETECT_POS_MOVE;
578
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
372 lastStart = step;
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
373 }
578
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
374 else
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
375 if(test.pitch == MOTION_DELTA_FALL)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
376 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
377 detectionState = DETECT_NEG_MOVE;
578
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
378 lastStart = step;
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
379 }
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
380 else
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
381 {
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
382 lastStart = -1;
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
383 }
574
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
384 duration = 0;
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
385 break;
627
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
386 case DETECT_NEG_MOVE: if((test.pitch <= MOTION_DELTA_JITTER) || (test.pitch == MOTION_DELTA_RAISE) || (test.pitch == MOTION_DELTA_RAISE_FAST))
578
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
387 {
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
388 detectionState++;
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
389 }
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
390 break;
627
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
391 case DETECT_POS_MOVE: if((test.pitch <= MOTION_DELTA_JITTER) || (test.pitch == MOTION_DELTA_FALL) || (test.pitch == MOTION_DELTA_FALL_FAST))
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
392 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
393 detectionState++;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
394 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
395 break;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
396 case DETECT_MAXIMA: if(test.pitch == MOTION_DELTA_FALL)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
397 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
398 detectionState = DETECT_FALLBACK;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
399 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
400 break;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
401 case DETECT_MINIMA: if(test.pitch == MOTION_DELTA_RAISE)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
402 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
403 detectionState = DETECT_RISEBACK;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
404 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
405 break;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
406 case DETECT_RISEBACK:
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
407 case DETECT_FALLBACK: if(test.pitch == MOTION_DELTA_STABLE)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
408 {
578
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
409 if(duration > 4) /* avoid detection triggered by short moves */
574
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
410 {
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
411 detectionState++;
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
412 }
578
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
413 exit = 1;
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
414 lastStart = -2;
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
415 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
416 break;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
417 default:
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
418 detectionState = DETECT_NOTHING;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
419 exit = 1;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
420 break;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
421 }
578
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
422 step--;
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
423 } while((step >= 0) && (!exit));
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
424
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
425 if((lastStart < MOTION_DELTA_HISTORY_SIZE))
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
426 {
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
427 lastStart++; /* prepare value for next iteration (history index will be increased) */
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
428 }
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
429 else
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
430 {
beb4d47542f1 Rework pitch detection:
Ideenmodellierer
parents: 574
diff changeset
431 lastStart = -1;
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
432 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
433 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
434 {
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
435 detectionState = DETECT_NOTHING;
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
436 }
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
437 else /* dont detect the same event twice */
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
438 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
439 resetMotionDeltaHistory();
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
440 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
441 return detectionState;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
442 }
363
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
443
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
444 void anglesToCoord(float roll, float pitch, float yaw, SCoord *pCoord)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
445 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
446 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
447 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
448 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
449 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
450
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
451 SCoord CoordAdd(SCoord cA, SCoord cB)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
452 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
453 SCoord result;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
454
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
455 result.x = cA.x + cB.x;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
456 result.y = cA.y + cB.y;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
457 result.z = cA.z + cB.z;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
458 return result;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
459 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
460
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
461 SCoord CoordSub(SCoord cA, SCoord cB)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
462 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
463 SCoord result;
373
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
464
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
465 result.x = cA.x - cB.x;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
466 result.y = cA.y - cB.y;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
467 result.z = cA.z - cB.z;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
468 return result;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
469 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
470
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
471 SCoord CoordCross(SCoord cA, SCoord cB)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
472 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
473 SCoord result;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
474
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
475 result.x = (cA.y * cB.z) - (cA.z * cB.y);
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
476 result.y = (cA.z * cB.x) - (cA.x * cB.z);
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
477 result.z = (cA.x * cB.y) - (cA.y * cB.x);
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
478
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
479 return result;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
480
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
481 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
482
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
483 SCoord CoordMulF(SCoord op, float factor)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
484 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
485 SCoord result;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
486 result.x = (op.x * factor);
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
487 result.y = (op.y * factor);
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
488 result.z = (op.z * factor);
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
489
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
490 return result;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
491 }
373
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
492
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
493 SCoord CoordDivF(SCoord op, float factor)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
494 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
495 SCoord result;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
496 result.x = (op.x / factor);
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
497 result.y = (op.y / factor);
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
498 result.z = (op.z / factor);
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
499
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
500 return result;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
501 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
502
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
503 float CoordDot(SCoord cA, SCoord cB)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
504 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
505 float result;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
506
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
507 result = cA.x * cB.x + cA.y * cB.y + cB.z*cA.z;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
508 return result;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
509 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
510
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
511 void calibrateViewport(float roll, float pitch, float yaw)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
512 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
513 SSettings* pSettings = settingsGetPointer();
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
514
621
6826731ff2be Use roll and pitch agles in 0-360 format:
Ideenmodellierer
parents: 618
diff changeset
515 pSettings->viewPitch = pitch + 180;
6826731ff2be Use roll and pitch agles in 0-360 format:
Ideenmodellierer
parents: 618
diff changeset
516 pSettings->viewRoll = roll+ 180;
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
517 pSettings->viewYaw = yaw;
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
625
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
521 float checkViewport(float roll, float pitch, float yaw, uint8_t enableAxis)
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
522 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
523 uint8_t retval = 0;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
524 float angleYaw;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
525 float anglePitch;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
526 float angleRoll;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
527 float distance = 0;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
528 float _a, _b;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
529 SCoord u,v,n;
627
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
530 float r = 0.0;
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
531 float focusLimit = 0;
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
532
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
533 SCoord refVec;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
534 SCoord axis_1;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
535 SCoord axis_2;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
536 SCoord curVec;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
537 SCoord resultVec;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
538
627
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
539 SDeltaHistory movementDelta;
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
540
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
541 SSettings* pSettings = settingsGetPointer();
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
542
621
6826731ff2be Use roll and pitch agles in 0-360 format:
Ideenmodellierer
parents: 618
diff changeset
543 roll += 180;
6826731ff2be Use roll and pitch agles in 0-360 format:
Ideenmodellierer
parents: 618
diff changeset
544 pitch += 180;
6826731ff2be Use roll and pitch agles in 0-360 format:
Ideenmodellierer
parents: 618
diff changeset
545
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
546 /* calculate base vector taking calibration delta into account yaw (heading) */
621
6826731ff2be Use roll and pitch agles in 0-360 format:
Ideenmodellierer
parents: 618
diff changeset
547 float compYaw;
574
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
548
625
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
549 if(enableAxis & MOTION_ENABLE_YAW)
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
550 {
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
551 compYaw = 360.0 - yaw; /* turn to 0° */
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
552 compYaw += pSettings->viewYaw; /* consider calib yaw value */
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
553 compYaw += yaw;
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
554
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
555 if (compYaw < 0.0)
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
556 {
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
557 compYaw = 360.0 + compYaw;
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
558 }
574
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
559
625
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
560 if (compYaw > 360.0)
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
561 {
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
562 compYaw = compYaw - 360.0;
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
563 }
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
564 if (compYaw > 360.0)
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
565 {
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
566 compYaw = compYaw - 360.0;
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
567 }
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
568 angleYaw = pSettings->viewYaw * M_PI / 180.0;
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
569 }
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
570 else
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
571 {
625
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
572 compYaw = 0.0;
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
573 angleYaw = 0.0;
381
695434a6dcf6 Simplified pitch detection state machine:
ideenmodellierer
parents: 378
diff changeset
574 }
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
575
625
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
576 if(enableAxis & MOTION_ENABLE_PITCH)
381
695434a6dcf6 Simplified pitch detection state machine:
ideenmodellierer
parents: 378
diff changeset
577 {
625
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
578 anglePitch = pSettings->viewPitch * M_PI / 180.0;
373
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
579 }
625
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
580 else
574
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
581 {
625
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
582 anglePitch = 0;
574
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
583 }
625
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
584 if(enableAxis & MOTION_ENABLE_ROLL)
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
585 {
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
586 angleRoll = pSettings->viewRoll * M_PI / 180.0;
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
587 }
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
588 else
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
589 {
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
590 angleRoll = 0;
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
591 }
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
592
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
593 refVec.x = 0;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
594 refVec.y = 0;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
595 refVec.z = 1.0;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
596
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
597 anglesToCoord(angleRoll,anglePitch,angleYaw, &refVec);
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
598
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
599 /* 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
600 axis_1.x = 0;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
601 if(refVec.y >=0)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
602 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
603 axis_2.y = 1; /* => Spawn y == refVec y */
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
604 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
605 else axis_1.y = -1;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
606 axis_1.z = -1.0 * refVec.y / refVec.z;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
607 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
608
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
609 /* check if detection plane is correct */
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
610 u = CoordSub(axis_1,refVec);
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
611 v = CoordSub(axis_2,refVec);
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
612 n = CoordCross(u,v);
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
613
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
614 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
615 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
616 retval = 2;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
617 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
618 else
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
619 {
625
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
620 if(enableAxis & MOTION_ENABLE_PITCH)
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
621 {
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
622 anglePitch = pitch * M_PI / 180.0;
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
623 }
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
624 else
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
625 {
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
626 anglePitch = 0.0;
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
627 }
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
628 if(enableAxis & MOTION_ENABLE_ROLL)
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
629 {
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
630 angleRoll = roll * M_PI / 180.0;
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
631 }
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
632 else
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
633 {
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
634 angleRoll = 0.0;
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
635 }
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
636 if(enableAxis & MOTION_ENABLE_YAW)
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
637 {
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
638 angleYaw = compYaw * M_PI / 180.0;
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
639 }
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
640 else
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
641 {
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
642 angleYaw = 0.0;
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
643 }
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
644
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
645 curVec.x = 0;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
646 curVec.y = 0;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
647 curVec.z = 1.0;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
648 anglesToCoord(angleRoll,anglePitch,angleYaw, &curVec);
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
649
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
650 _a = CoordDot(curVec,n);
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
651 _b = CoordDot(refVec,n);
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
652
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
653 if(_b>=(-0.0001)&&_b<=0.0001) /* Check if view port is parallel (no matchpoint) */
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
654 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
655 retval = 3;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
656 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
657 else
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
658 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
659 r=_a/_b;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
660 if(r<0.00||r>1.40) /* are we looking into wrong direction? */
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
661 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
662 retval = 4;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
663 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
664 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
665 distance = retval * 1.0; /* just for debugging */
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
666 if(retval == 0)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
667 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
668 /* start calculating the matchpoint */
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
669 curVec = CoordMulF(curVec,r);
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
670 resultVec = CoordSub(refVec,curVec);
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
671
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
672 /* calculate the distance between reference and actual vector */
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
673 resultVec.x = resultVec.x * resultVec.x;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
674 resultVec.y = resultVec.y * resultVec.y;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
675 resultVec.z = resultVec.z * resultVec.z;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
676
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
677 if((resultVec.x == 0) && (resultVec.y == 0) && (resultVec.z == 0))
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
678 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
679 distance = 0.0;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
680 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
681 else
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
682 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
683 distance = sqrtf((resultVec.x + resultVec.y + resultVec.z));
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
684 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
685 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
686 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
687
627
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
688 movementDelta = GetDeltaHistory(0);
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
689
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
690 if(inFocus == 0) /* consider option to use smaller spot to detect focus state */
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
691 {
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
692 focusLimit = MOTION_FOCUS_LIMIT - (((pSettings->viewPortMode >> 5) & 0x03) / 10.0);
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
693 }
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
694 else
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
695 {
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
696 focusLimit = MOTION_FOCUS_LIMIT; /* use standard spot to detect diver interactions */
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
697 }
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
698
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
699 if((distance <= focusLimit) && (movementDelta.yaw != MOTION_DELTA_RAISE_FAST) && (movementDelta.yaw != MOTION_DELTA_FALL_FAST)) /* handle focus counter to avoid fast in/out focus changes */
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
700 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
701 if(focusCnt < 10)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
702 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
703 if((focusCnt == 9) && (inFocus == 0)) /* we will get into focus */
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
704 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
705 resetMotionDeltaHistory();
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
706 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
707 focusCnt++;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
708 }
574
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
709 if((focusCnt == 10) && (inFocus == 0))
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
710 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
711 inFocus = 1;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
712 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
713 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
714 else
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
715 {
627
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
716 if((movementDelta.yaw > MOTION_DELTA_JITTER ) && (focusCnt >= 5))
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
717 {
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
718 focusCnt--;
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
719 }
625
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
720 if(focusCnt >= 5) /* Reset focus faster then setting focus */
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
721 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
722 focusCnt--;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
723 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
724 else
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
725 {
574
01ee21dd311f Improved focus detection:
Ideenmodellierer
parents: 551
diff changeset
726 focusCnt = 0;
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
727 inFocus = 0;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
728 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
729 }
627
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
730 if ((r<1) && (retval == 0)) /* add direction information to distance */
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
731 {
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
732 distance *= -1.0;
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
733 }
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
734 return distance;
359
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
735 }
551
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
736 uint8_t viewInFocus(void)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
737 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
738 return inFocus;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
739 }
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
740 void resetFocusState(void)
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
741 {
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
742 inFocus = 0;
e3237f580ae9 Added viewport functionality:
Ideenmodellierer
parents: 385
diff changeset
743 }
611
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
744
642
c737cf5d9067 Do not show focus indicator in case motion detection is suspended:
Ideenmodellierer
parents: 627
diff changeset
745 uint8_t viewDetectionSuspended(void)
c737cf5d9067 Do not show focus indicator in case motion detection is suspended:
Ideenmodellierer
parents: 627
diff changeset
746 {
c737cf5d9067 Do not show focus indicator in case motion detection is suspended:
Ideenmodellierer
parents: 627
diff changeset
747 uint8_t retVal = 0;
c737cf5d9067 Do not show focus indicator in case motion detection is suspended:
Ideenmodellierer
parents: 627
diff changeset
748
c737cf5d9067 Do not show focus indicator in case motion detection is suspended:
Ideenmodellierer
parents: 627
diff changeset
749 if(suspendMotionDetectionSec)
c737cf5d9067 Do not show focus indicator in case motion detection is suspended:
Ideenmodellierer
parents: 627
diff changeset
750 {
c737cf5d9067 Do not show focus indicator in case motion detection is suspended:
Ideenmodellierer
parents: 627
diff changeset
751 retVal = 1;
c737cf5d9067 Do not show focus indicator in case motion detection is suspended:
Ideenmodellierer
parents: 627
diff changeset
752 }
c737cf5d9067 Do not show focus indicator in case motion detection is suspended:
Ideenmodellierer
parents: 627
diff changeset
753 return retVal;
c737cf5d9067 Do not show focus indicator in case motion detection is suspended:
Ideenmodellierer
parents: 627
diff changeset
754 }
c737cf5d9067 Do not show focus indicator in case motion detection is suspended:
Ideenmodellierer
parents: 627
diff changeset
755
611
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
756 void suspendMotionDetection(uint8_t seconds)
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
757 {
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
758 suspendMotionDetectionSec = seconds * 10; /* detection function is called every 100ms */
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
759 }
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
760
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
761 void HandleMotionDetection(void)
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
762 {
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
763 detectionState_t pitchstate = DETECT_NOTHING;
618
96af74455420 Development bugfix: focus state not remembered:
Ideenmodellierer
parents: 611
diff changeset
764 static uint8_t wasInFocus = 0;
625
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
765 float focusOffset = 0.0;
611
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
766
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
767 evaluateMotionDelta(stateUsed->lifeData.compass_roll, stateUsed->lifeData.compass_pitch, stateUsed->lifeData.compass_heading);
625
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
768 if(viewInFocus())
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
769 {
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
770 focusOffset = checkViewport(stateUsed->lifeData.compass_roll, stateUsed->lifeData.compass_pitch, stateUsed->lifeData.compass_heading, (MOTION_ENABLE_PITCH | MOTION_ENABLE_YAW));
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
771 }
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
772 else
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
773 {
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
774 focusOffset = checkViewport(stateUsed->lifeData.compass_roll, stateUsed->lifeData.compass_pitch, stateUsed->lifeData.compass_heading, MOTION_ENABLE_ALL);
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
775 }
611
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
776 if(viewInFocus())
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
777 {
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
778 wasInFocus = 1;
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
779 set_Backlight_Boost(settingsGetPointer()->viewPortMode & 0x03);
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
780
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
781 if(suspendMotionDetectionSec == 0) /* suspend detection while diver is manually operating the OSTC */
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
782 {
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
783 switch(settingsGetPointer()->MotionDetection)
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
784 {
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
785 case MOTION_DETECT_MOVE: pitchstate = detectPitch(stateRealGetPointer()->lifeData.compass_pitch);
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
786 break;
625
028d8f3a9410 Switch Sector / Scroll detection to vector implementation:
Ideenmodellierer
parents: 621
diff changeset
787 case MOTION_DETECT_SECTOR: pitchstate = detectSectorButtonEvent(focusOffset);
611
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
788 break;
627
189f945ae4ba Improve in / out of focus transitions:
Ideenmodellierer
parents: 625
diff changeset
789 case MOTION_DETECT_SCROLL: pitchstate = detectScrollButtonEvent(fabs(focusOffset));
611
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
790 break;
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
791 default:
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
792 pitchstate = DETECT_NOTHING;
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
793 break;
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
794 }
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
795 }
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
796
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
797 if(DETECT_NEG_PITCH == pitchstate)
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
798 {
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
799 StoreButtonAction((uint8_t)ACTION_PITCH_NEG);
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
800 }
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
801 if(DETECT_POS_PITCH == pitchstate)
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
802 {
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
803 StoreButtonAction((uint8_t)ACTION_PITCH_POS);
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
804 }
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
805 }
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
806 else
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
807 {
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
808 if(wasInFocus)
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
809 {
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
810 wasInFocus = 0;
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
811 if(suspendMotionDetectionSec == 0)
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
812 {
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
813 if(settingsGetPointer()->design == 7)
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
814 {
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
815 t7_set_customview_to_primary();
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
816 }
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
817 else
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
818 {
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
819 t3_set_customview_to_primary();
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
820 }
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
821 }
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
822 }
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
823 set_Backlight_Boost(0);
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
824 }
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
825 if(suspendMotionDetectionSec != 0)
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
826 {
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
827 suspendMotionDetectionSec--;
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
828 }
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
829 }
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
830
916998f90e39 Suspend MotionDetection events while diver is operationg the OSTC:
Ideenmodellierer
parents: 595
diff changeset
831