annotate Discovery/Src/motion.c @ 376:a90100959871 MotionDetection

Added string for Empty/ Debug custom view selection
author ideenmodellierer
date Mon, 16 Sep 2019 20:21:06 +0200
parents 7b981f8bdd41
children 834e087505ec
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"
371
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
15 #include "settings.h"
359
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
16
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
17 #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
18 #define STABLE_STATE_TIMEOUT 5 /* Detection shall be aborted if a movement state is stable for more than 500ms */
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
19 #define MOVE_DELTA_SPEED 4 /* Delta speed needed to identify a valid movement */
370
77cdfbdaca8c Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents: 363
diff changeset
20 #define PITCH_DELTA_COUNT 10 /* Delta count needed to identify a valid minima / maxima */
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 #define PITCH_DELTA_END 10 /* Delta allowed between start and end position */
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
22
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
23
373
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
24 #define SECTOR_WINDOW 80.0 /* Pitch window which is used for custom view projection */
370
77cdfbdaca8c Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents: 363
diff changeset
25 #define SECTOR_HYSTERY 3 /* Additional offset to avoid fast changing displays */
77cdfbdaca8c Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents: 363
diff changeset
26 #define SECTOR_BORDER 400.0 /* Define a value which is out of limit to avoid not wanted key events */
77cdfbdaca8c Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents: 363
diff changeset
27 #define SECTOR_FILTER 10 /* Define speed for calculated angle to follow real value */
77cdfbdaca8c Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents: 363
diff changeset
28
373
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
29 #define SECTOR_MAX 20 /* maximum number of sectors */
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
30 #define SECTOR_SCROLL 6 /* number of sectors used for scroll detection */
359
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
31
373
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
32 detectionState_t detectionState = DETECT_NOTHING;
362
7b8c87a39c0e Parameter update
Ideenmodellierer
parents: 359
diff changeset
33
373
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
34 uint8_t curSector;
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
35 static uint8_t targetSector;
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
36 static uint8_t sectorSize;
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
37 static uint8_t sectorCount;
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
38
373
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
39 SSector PitchSector[SECTOR_MAX]; /* max number of enabled custom views */
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
40
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
41
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
42 uint8_t GetSectorForPitch(float pitch)
77cdfbdaca8c Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents: 363
diff changeset
43 {
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
44 static float lastPitch = 1000;
77cdfbdaca8c Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents: 363
diff changeset
45 float newPitch;
77cdfbdaca8c Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents: 363
diff changeset
46 uint8_t index;
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
47 uint8_t sector = 0;
77cdfbdaca8c Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents: 363
diff changeset
48
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
49 if(lastPitch == 1000) /* init at first call */
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 {
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
51 lastPitch = pitch;
77cdfbdaca8c Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents: 363
diff changeset
52 }
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
53
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
54 newPitch = lastPitch + (pitch / SECTOR_FILTER);
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
55
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
56 for(index = 1; index < sectorCount; index++)
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
57 {
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
58 if((pitch < PitchSector[index].upperlimit) && (pitch > PitchSector[index].lowerlimit ))
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
59 {
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
60 sector = index;
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
61 break;
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
62 }
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
63 }
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
64 lastPitch = newPitch;
77cdfbdaca8c Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents: 363
diff changeset
65 return sector;
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
66 }
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
67
371
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
68 void DefinePitchSectors(float centerPitch,uint8_t numOfSectors)
370
77cdfbdaca8c Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents: 363
diff changeset
69 {
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
70 uint8_t index;
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
71
371
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
72 if(numOfSectors == CUSTOMER_DEFINED_VIEWS)
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
73 {
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
74 sectorCount = t7_GetEnabled_customviews();
373
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
75 if(sectorCount > 7)
371
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
76 {
373
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
77 sectorCount = 7; /* more views are hard to manually control */
371
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
78 }
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
79 }
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
80 else
373
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
81 if(numOfSectors != CUSTOMER_KEEP_LAST_SECTORS)
371
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
82 {
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
83 sectorCount = numOfSectors;
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
84 }
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
85 sectorSize = SECTOR_WINDOW / sectorCount;
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
86
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
87 PitchSector[0].upperlimit = centerPitch + (SECTOR_WINDOW / 2);
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
88 PitchSector[0].lowerlimit = PitchSector[0].upperlimit - sectorSize - SECTOR_HYSTERY;
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
89
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
90 for(index = 1; index < sectorCount; index++)
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
91 {
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
92 PitchSector[index].upperlimit = PitchSector[0].upperlimit - index * sectorSize + SECTOR_HYSTERY;
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
93 PitchSector[index].lowerlimit = PitchSector[0].upperlimit - (index + 1) * sectorSize - SECTOR_HYSTERY;
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
94 }
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
95
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
96 PitchSector[0].upperlimit = SECTOR_BORDER;
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
97 PitchSector[index - 1].lowerlimit = SECTOR_BORDER * -1.0;
77cdfbdaca8c Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents: 363
diff changeset
98
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
99 /* get the current sector */
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
100 curSector = GetSectorForPitch(stateRealGetPointer()->lifeData.compass_pitch);
77cdfbdaca8c Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents: 363
diff changeset
101 targetSector = curSector;
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
102 }
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
103
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
104 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
105 {
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
106 targetSector = 0;
77cdfbdaca8c Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents: 363
diff changeset
107 curSector = 0;
77cdfbdaca8c Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents: 363
diff changeset
108 sectorSize = 0;
77cdfbdaca8c Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents: 363
diff changeset
109 sectorCount = 0;
371
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
110
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
111 switch(settingsGetPointer()->MotionDetection)
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
112 {
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
113 case MOTION_DETECT_SECTOR: DefinePitchSectors(0,CUSTOMER_DEFINED_VIEWS);
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
114 break;
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
115 case MOTION_DETECT_MOVE: DefinePitchSectors(0,SECTOR_MAX);
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
116 break;
373
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
117 case MOTION_DETECT_SCROLL: DefinePitchSectors(0,SECTOR_SCROLL);
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
118 break;
371
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
119 default:
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
120 break;
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
121 }
fca370f847f8 Added parameter for number of sectors to be defined
ideenmodellierer
parents: 370
diff changeset
122
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
123 }
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
124
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
125 /* Map the current pitch value to a sector and create button event in case the sector is left */
77cdfbdaca8c Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents: 363
diff changeset
126 detectionState_t detectSectorButtonEvent(float curPitch)
77cdfbdaca8c Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents: 363
diff changeset
127 {
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
128 static uint8_t lastTargetSector = 0;
77cdfbdaca8c Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents: 363
diff changeset
129 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
130 uint8_t PitchEvent = DETECT_NOTHING;
77cdfbdaca8c Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents: 363
diff changeset
131
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
132 /* only change sector if reading is stable */
77cdfbdaca8c Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents: 363
diff changeset
133 newTargetSector = GetSectorForPitch(stateRealGetPointer()->lifeData.compass_pitch);
77cdfbdaca8c Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents: 363
diff changeset
134 if(lastTargetSector == newTargetSector)
77cdfbdaca8c Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents: 363
diff changeset
135 {
77cdfbdaca8c Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents: 363
diff changeset
136 targetSector = 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
137 }
77cdfbdaca8c Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents: 363
diff changeset
138 lastTargetSector = newTargetSector;
77cdfbdaca8c Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents: 363
diff changeset
139 if(targetSector != curSector)
77cdfbdaca8c Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents: 363
diff changeset
140 {
77cdfbdaca8c Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents: 363
diff changeset
141 if(targetSector > curSector)
77cdfbdaca8c Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents: 363
diff changeset
142 {
77cdfbdaca8c Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents: 363
diff changeset
143 curSector++;
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
144 PitchEvent = DETECT_POS_PITCH;
77cdfbdaca8c Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents: 363
diff changeset
145 }
77cdfbdaca8c Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents: 363
diff changeset
146 else
77cdfbdaca8c Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents: 363
diff changeset
147 {
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
148 curSector--;
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 PitchEvent = DETECT_NEG_PITCH;
77cdfbdaca8c Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents: 363
diff changeset
150 }
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 return PitchEvent;
77cdfbdaca8c Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents: 363
diff changeset
153 }
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
373
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
155 /* Check if pitch is not in center position and trigger a button action if needed */
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
156 detectionState_t detectScrollButtonEvent(float curPitch)
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
157 {
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
158 static uint8_t delayscroll = 0; /* slow dow 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
159
373
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
160 uint8_t PitchEvent = DETECT_NOTHING;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
161 uint8_t newSector;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
162
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
163 if(delayscroll == 0)
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
164 {
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
165 newSector = GetSectorForPitch(stateRealGetPointer()->lifeData.compass_pitch);
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
166 /* for scroll detection the motion windoe is split into 6 sectors => set event accoring to the sector number*/
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
167 switch(newSector)
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
168 {
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
169 case 0:
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
170 case 1: PitchEvent = DETECT_POS_PITCH;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
171 break;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
172 case 4:
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
173 case 5: PitchEvent = DETECT_NEG_PITCH;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
174 break;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
175 default:
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
176 break;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
177 }
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
178 if(PitchEvent != DETECT_NOTHING)
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
179 {
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
180 delayscroll = 5;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
181 }
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
182 }
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
183 else
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
184 {
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
185 delayscroll--;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
186 }
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
187 return PitchEvent;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
188 }
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
189
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
190
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
191 uint8_t sectorhist[20];
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
192 uint8_t sectorindex = 0;
370
77cdfbdaca8c Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents: 363
diff changeset
193 /* 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
194 /* 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
195 detectionState_t detectPitch(float currentPitch)
359
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
196 {
373
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
197 static uint8_t lastSector = 0;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
198 static uint8_t startSector = 0;
359
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
199 static uint8_t stableCnt = 0;
370
77cdfbdaca8c Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents: 363
diff changeset
200
77cdfbdaca8c Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents: 363
diff changeset
201 if((detectionState == DETECT_NEG_PITCH) || (detectionState == DETECT_POS_PITCH)) /* discard last detection */
359
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
202 {
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
203 detectionState = DETECT_NOTHING;
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
204 }
363
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
205
373
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
206 curSector = GetSectorForPitch(stateRealGetPointer()->lifeData.compass_pitch);
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
207
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
208 sectorhist[sectorindex++] = curSector;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
209 if(sectorindex == 20) sectorindex=0;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
210
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
211 /* feed value into state machine */
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
212 switch (detectionState)
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
213 {
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
214 case DETECT_NOTHING: if(curSector == lastSector) /* detect a stable condition before evaluating for the next move */
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
215 {
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
216 stableCnt++;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
217 }
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
218 else
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
219 {
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
220 stableCnt=0;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
221 }
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
222
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
223 if(stableCnt > STABLE_STATE_COUNT)
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
224 {
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
225 detectionState = DETECT_START;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
226 stableCnt = 0;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
227 startSector = lastSector;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
228 }
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
229 break;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
230 case DETECT_START: if(curSector != lastSector)
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
231 {
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
232 if(abs(curSector - startSector) > 1)
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
233 {
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
234 if(curSector > lastSector)
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
235 {
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
236 detectionState = DETECT_POS_MOVE;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
237 }
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
238 else
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
239 {
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
240 detectionState = DETECT_NEG_MOVE;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
241 }
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
242 stableCnt = 0;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
243 startSector = lastSector;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
244 }
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
245 else
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
246 {
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
247 stableCnt++; /* reset start sector in case of slow movement */
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
248 }
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
249 // startPitch = lastPitch;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
250 }
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
251 break;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
252 case DETECT_NEG_MOVE:
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
253 case DETECT_POS_MOVE: if(curSector != lastSector) /* still moving? */
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
254 {
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
255 stableCnt++;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
256 }
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
257 else
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
258 {
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
259 // if(stableCnt >= 1) /* debounce movement */
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
260 {
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
261 if(abs(startSector - curSector) > 2)
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
262 {
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
263 detectionState++;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
264 stableCnt = 0;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
265 }
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
266 else
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
267 {
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
268 // detectionState = DETECT_NOTHING;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
269 stableCnt++; /* maybe on the boundary of a sector => handle as stable */
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
270 }
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
271 }
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
272 #if 0
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
273 else
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
274 {
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
275 // detectionState = DETECT_NOTHING;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
276 stableCnt++; /* maybe on the boundary of a sector => handle as stable */
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
277 }
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
278 #endif
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
279 }
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
280 break;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
281 case DETECT_MINIMA:
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
282 case DETECT_MAXIMA: /* stay at maximum for short time to add a pattern for user interaction */
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
283 if(curSector == lastSector)
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
284 {
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
285 stableCnt++;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
286 }
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
287 else
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
288 {
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
289 if(stableCnt > 0) /* restart movement after a short break? */
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
290 {
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
291 detectionState++;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
292 stableCnt = 0;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
293 }
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
294 else
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
295 {
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
296 // detectionState = DETECT_NOTHING;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
297 stableCnt++; /* maybe on the boundary of a sector => handle as stable */
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
298 }
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
299 }
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
300 break;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
301 case DETECT_RISEBACK:
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
302 case DETECT_FALLBACK: if(curSector == lastSector) /* check if we are back at start position at end of movement */
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
303 {
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
304 if(abs(startSector - curSector) <= 1) //(curSector == startSector)
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
305 {
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
306 detectionState++;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
307 stableCnt = 0;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
308 }
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
309 else
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 // detectionState = DETECT_NOTHING;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
312 stableCnt++; /* maybe on the boundary of a sector => handle as stable */
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
313 }
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
314 }
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
315 else
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
316 {
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
317 stableCnt++;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
318 }
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
319 break;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
320 default:
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
321 detectionState = DETECT_NOTHING;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
322 break;
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 }
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
325 lastSector = curSector;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
326 if(stableCnt > STABLE_STATE_TIMEOUT)
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 detectionState = DETECT_NOTHING;
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
329 stableCnt = 0;
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
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
332 #if 0
363
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
333 curSpeed = currentPitch - lastPitch;
359
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
334
363
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
335 /* feed value into state machine */
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
336 switch (detectionState)
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
337 {
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
338 case DETECT_NOTHING: if(fabsf(curSpeed) < MOVE_DELTA_SPEED) /* detect a stable condition before evaluating for the next move */
359
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
339 {
363
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
340 stableCnt++;
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
341 }
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
342 else
77cdfbdaca8c Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents: 363
diff changeset
343 {
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
344 stableCnt=0;
77cdfbdaca8c Changed function names from shake to pitch and improved detection function: Shake might be confusing for people reading the code because pitch values are ased for calculation => changed name to pitch to be more transparent
ideenmodellierer
parents: 363
diff changeset
345 }
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
346
363
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
347 if(stableCnt > STABLE_STATE_COUNT)
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
348 {
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
349 detectionState = DETECT_START;
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
350 stableCnt = 0;
359
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
351 }
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
352 break;
363
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
353 case DETECT_START: if(fabsf(curSpeed) > MOVE_DELTA_SPEED)
359
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
354 {
363
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
355 if(curSpeed > 0)
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
356 {
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
357 detectionState = DETECT_POS_MOVE;
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
358 }
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
359 else
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
360 {
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
361 detectionState = DETECT_NEG_MOVE;
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
362 }
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
363 stableCnt = 0;
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
364 startPitch = lastPitch;
359
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
365 }
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
366 break;
363
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
367 case DETECT_NEG_MOVE:
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
368 case DETECT_POS_MOVE: if(fabsf(curSpeed) > MOVE_DELTA_SPEED )
359
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
369 {
363
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
370 stableCnt++;
359
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
371 }
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
372 else
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
373 {
363
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
374 if(stableCnt >= STABLE_STATE_COUNT) /* debounce movement */
359
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
375 {
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
376 if(fabsf(startPitch - currentPitch) > PITCH_DELTA_COUNT)
363
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
377 {
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
378 detectionState++;
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
379 }
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
380 else
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
381 {
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
382 detectionState = DETECT_NOTHING;
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
383 }
359
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
384 }
363
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
385 else
359
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
386 {
363
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
387 detectionState = DETECT_NOTHING;
359
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
388 }
363
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
389 stableCnt = 0;
359
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
390 }
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
391 break;
363
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
392 case DETECT_MINIMA:
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
393 case DETECT_MAXIMA: /* stay at maximum for short time to add a pattern for user interaction */
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
394 if(fabsf(curSpeed) < MOVE_DELTA_SPEED )
359
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
395 {
363
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
396 stableCnt++;
359
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
397 }
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
398 else
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
399 {
363
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
400 if(stableCnt > 0)
359
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
401 {
363
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
402 detectionState++;
359
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
403 }
363
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
404 else
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
405 {
359
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
406 detectionState = DETECT_NOTHING;
363
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
407 }
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
408 stableCnt = 0;
359
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
409 }
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
410 break;
363
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
411 case DETECT_RISEBACK:
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
412 case DETECT_FALLBACK: if(fabsf(curSpeed) < MOVE_DELTA_SPEED)
359
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
413 {
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
414 if(fabsf(startPitch - currentPitch) < PITCH_DELTA_END)
363
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
415 {
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
416 detectionState++;
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
417 }
359
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
418 }
363
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
419 stableCnt++;
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
420 break;
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
421 default:
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
422 detectionState = DETECT_NOTHING;
359
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
423 break;
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
424
363
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
425 }
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
426 if(stableCnt > STABLE_STATE_TIMEOUT)
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
427 {
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
428 detectionState = DETECT_NOTHING;
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
429 stableCnt = 0;
bdf978d2a5d4 Reworked detection function
ideenmodellierer
parents: 362
diff changeset
430 }
359
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
431
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
432 lastPitch = currentPitch;
373
7b981f8bdd41 Add scroll event by pitch angle detection:
ideenmodellierer
parents: 371
diff changeset
433 #endif
359
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
434 return detectionState;
4258ea9b67fa Added new files for motion detection (shaking) detection
ideenmodellierer
parents:
diff changeset
435 }