comparison Discovery/Src/motion.c @ 592:f52bc70e380f

MotionCtrl - Sectorview Map sectors directly to custom views: In previous version detection of sector changes lead to a button event which triggered the change of the shown custom view. As result the views shown were depending on the angle which is present while entering focus state. The new implementation maps the primary view to the center sector and assigns the other enabled views around the center => views will always appear at the same angle value.
author Ideenmodellierer
date Sun, 03 Jan 2021 14:43:16 +0100
parents 4dfdf230d8ba
children fd0b60dee6f3
comparison
equal deleted inserted replaced
591:0172431fbad9 592:f52bc70e380f
12 #include "motion.h" 12 #include "motion.h"
13 #include "data_central.h" 13 #include "data_central.h"
14 #include "t7.h" 14 #include "t7.h"
15 #include "t3.h" 15 #include "t3.h"
16 #include "settings.h" 16 #include "settings.h"
17 #include "base.h"
17 18
18 #define STABLE_STATE_COUNT 2 /* number of count to declare a state as stable (at the moment based on 100ms) */ 19 #define STABLE_STATE_COUNT 2 /* number of count to declare a state as stable (at the moment based on 100ms) */
19 #define STABLE_STATE_TIMEOUT 5 /* Detection shall be aborted if a movement state is stable for more than 500ms */ 20 #define STABLE_STATE_TIMEOUT 5 /* Detection shall be aborted if a movement state is stable for more than 500ms */
20 21
21 #define SECTOR_WINDOW 30.0 /* Pitch window which is used for custom view projection */ 22 #define SECTOR_WINDOW 30.0 /* Pitch window which is used for custom view projection */
24 #define SECTOR_BORDER 400.0 /* Define a value which is out of limit to avoid not wanted key events */ 25 #define SECTOR_BORDER 400.0 /* Define a value which is out of limit to avoid not wanted key events */
25 #define SECTOR_FILTER 10 /* Define speed for calculated angle to follow real value */ 26 #define SECTOR_FILTER 10 /* Define speed for calculated angle to follow real value */
26 27
27 #define SECTOR_MAX 24 /* maximum number of sectors */ 28 #define SECTOR_MAX 24 /* maximum number of sectors */
28 #define SECTOR_SCROLL 7 /* number of sectors used for scroll detection */ 29 #define SECTOR_SCROLL 7 /* number of sectors used for scroll detection */
30 #define SECTOR_MAX_CNT 5 /* max number of views used for sector control */
29 31
30 #define MOTION_DELTA_STABLE 0 32 #define MOTION_DELTA_STABLE 0
31 #define MOTION_DELTA_JITTER 1 33 #define MOTION_DELTA_JITTER 1
32 #define MOTION_DELTA_RAISE 2 34 #define MOTION_DELTA_RAISE 2
33 #define MOTION_DELTA_FALL 3 35 #define MOTION_DELTA_FALL 3
44 static uint8_t motionDeltaHistory[3][MOTION_DELTA_HISTORY_SIZE]; /* Change history of roll, pitch and yaw */ 46 static uint8_t motionDeltaHistory[3][MOTION_DELTA_HISTORY_SIZE]; /* Change history of roll, pitch and yaw */
45 static uint8_t motionDeltaHistoryIdx; /* Current index of history data */ 47 static uint8_t motionDeltaHistoryIdx; /* Current index of history data */
46 48
47 static uint8_t focusCnt = 0; 49 static uint8_t focusCnt = 0;
48 static uint8_t inFocus = 0; 50 static uint8_t inFocus = 0;
51 static uint8_t sectorMap[SECTOR_MAX_CNT];
49 52
50 void resetMotionDeltaHistory() 53 void resetMotionDeltaHistory()
51 { 54 {
52 motionDeltaHistoryIdx = 0; 55 motionDeltaHistoryIdx = 0;
53 memset(motionDeltaHistory, 0, sizeof(motionDeltaHistory)); 56 memset(motionDeltaHistory, 0, sizeof(motionDeltaHistory));
170 } 173 }
171 else 174 else
172 { 175 {
173 sectorDetection.count = t7_GetEnabled_customviews(); 176 sectorDetection.count = t7_GetEnabled_customviews();
174 } 177 }
175 if(sectorDetection.count > 5) 178 if(sectorDetection.count > SECTOR_MAX_CNT)
176 { 179 {
177 sectorDetection.count = 5; /* more views are hard to manually control */ 180 sectorDetection.count = SECTOR_MAX_CNT; /* more views are hard to manually control */
178 } 181 }
179 } 182 }
180 else 183 else
181 if(numOfSectors != CUSTOMER_KEEP_LAST_SECTORS) 184 if(numOfSectors != CUSTOMER_KEEP_LAST_SECTORS)
182 { 185 {
205 /* do a small adjustment to center pitch to make sure the actual pitch is in the center of the current sector */ 208 /* do a small adjustment to center pitch to make sure the actual pitch is in the center of the current sector */
206 sectorDetection.center = (sectorDetection.upperborder) - ((sectorDetection.size + 2 *SECTOR_HYSTERY) / 2.0) - (centerPitch + sectorDetection.offset); 209 sectorDetection.center = (sectorDetection.upperborder) - ((sectorDetection.size + 2 *SECTOR_HYSTERY) / 2.0) - (centerPitch + sectorDetection.offset);
207 210
208 } 211 }
209 212
213
214 uint8_t GetCVForSector(uint8_t selSector)
215 {
216 if(selSector < sectorDetection.count)
217 {
218 return sectorMap[selSector];
219 }
220 else
221 {
222 return 0;
223 }
224 }
225 void MapCVToSector()
226 {
227 uint8_t centerView = 0;
228
229 memset(sectorMap, 0, sizeof(sectorMap));
230
231 switch(sectorDetection.count)
232 {
233 case 1: centerView = 0; break;
234 case 2: centerView = 0; break;
235 case 3: centerView = 1; break;
236 case 4: centerView = 1; break;
237 case 5: centerView = 2; break;
238 default: centerView = sectorDetection.count / 2 - 1;
239 break;
240 }
241 if(settingsGetPointer()->design == 3) /* Big font view ? */
242 {
243 sectorMap[centerView] = settingsGetPointer()->tX_customViewPrimaryBF;
244 }
245 else
246 {
247 sectorMap[centerView] = settingsGetPointer()->tX_customViewPrimary;
248 }
249
250 centerView++;
251 while(sectorMap[centerView] == 0)
252 {
253 if(settingsGetPointer()->design == 3) /* Big font view ? */
254 {
255 sectorMap[centerView] = t3_change_customview(ACTION_BUTTON_ENTER);
256 }
257 else
258 {
259 sectorMap[centerView] = t7_change_customview(ACTION_BUTTON_ENTER);
260 }
261 centerView++;
262 if(centerView == sectorDetection.count)
263 {
264 centerView = 0;
265 }
266 }
267
268 }
269
210 void InitMotionDetection(void) 270 void InitMotionDetection(void)
211 { 271 {
212 sectorDetection.target = 0; 272 sectorDetection.target = 0;
213 sectorDetection.current = 0; 273 sectorDetection.current = 0;
214 sectorDetection.size = 0; 274 sectorDetection.size = 0;
215 sectorDetection.count = 0; 275 sectorDetection.count = 0;
216 276
217 switch(settingsGetPointer()->MotionDetection) 277 switch(settingsGetPointer()->MotionDetection)
218 { 278 {
219 case MOTION_DETECT_SECTOR: DefinePitchSectors(settingsGetPointer()->viewPitch,CUSTOMER_DEFINED_VIEWS); 279 case MOTION_DETECT_SECTOR: DefinePitchSectors(settingsGetPointer()->viewPitch,CUSTOMER_DEFINED_VIEWS);
280 MapCVToSector();
220 break; 281 break;
221 case MOTION_DETECT_MOVE: DefinePitchSectors(settingsGetPointer()->viewPitch,SECTOR_MAX); 282 case MOTION_DETECT_MOVE: DefinePitchSectors(settingsGetPointer()->viewPitch,SECTOR_MAX);
222 break; 283 break;
223 case MOTION_DETECT_SCROLL: DefinePitchSectors(settingsGetPointer()->viewPitch,SECTOR_SCROLL); 284 case MOTION_DETECT_SCROLL: DefinePitchSectors(settingsGetPointer()->viewPitch,SECTOR_SCROLL);
224 break; 285 break;
230 } 291 }
231 292
232 /* Map the current pitch value to a sector and create button event in case the sector is left */ 293 /* Map the current pitch value to a sector and create button event in case the sector is left */
233 detectionState_t detectSectorButtonEvent(float curPitch) 294 detectionState_t detectSectorButtonEvent(float curPitch)
234 { 295 {
235 static uint8_t lastTargetSector = 0;
236 uint8_t newTargetSector; 296 uint8_t newTargetSector;
237 uint8_t PitchEvent = DETECT_NOTHING; 297
238
239 /* only change sector if reading is stable */
240 newTargetSector = GetSectorForPitch(stateRealGetPointer()->lifeData.compass_pitch); 298 newTargetSector = GetSectorForPitch(stateRealGetPointer()->lifeData.compass_pitch);
241 if(lastTargetSector == newTargetSector) 299
242 { 300 if(settingsGetPointer()->design == 3) /* Big font view ? */
243 sectorDetection.target = newTargetSector; 301 {
244 } 302 t3_select_customview(GetCVForSector(newTargetSector));
245 lastTargetSector = newTargetSector; 303 }
246 if(sectorDetection.target != sectorDetection.current) 304 else
247 { 305 {
248 if(sectorDetection.target > sectorDetection.current) 306 t7_select_customview(GetCVForSector(newTargetSector));
249 { 307 }
250 sectorDetection.current++; 308
251 PitchEvent = DETECT_POS_PITCH; 309 return DETECT_NOTHING;
252 }
253 else
254 {
255 sectorDetection.current--;
256 PitchEvent = DETECT_NEG_PITCH;
257 }
258 }
259 return PitchEvent;
260 } 310 }
261 311
262 /* Check if pitch is not in center position and trigger a button action if needed */ 312 /* Check if pitch is not in center position and trigger a button action if needed */
263 detectionState_t detectScrollButtonEvent(float curPitch) 313 detectionState_t detectScrollButtonEvent(float curPitch)
264 { 314 {