comparison Discovery/Src/motion.c @ 371:fca370f847f8 MotionDetection

Added parameter for number of sectors to be defined
author ideenmodellierer
date Mon, 19 Aug 2019 17:39:47 +0200
parents 77cdfbdaca8c
children 7b981f8bdd41
comparison
equal deleted inserted replaced
370:77cdfbdaca8c 371:fca370f847f8
9 #include <string.h> 9 #include <string.h>
10 #include <math.h> 10 #include <math.h>
11 #include "motion.h" 11 #include "motion.h"
12 #include "data_central.h" 12 #include "data_central.h"
13 #include "t7.h" 13 #include "t7.h"
14 #include "settings.h"
14 15
15 #define STABLE_STATE_COUNT 2 /* number of count to declare a state as stable (at the moment based on 100ms) */ 16 #define STABLE_STATE_COUNT 2 /* number of count to declare a state as stable (at the moment based on 100ms) */
16 #define STABLE_STATE_TIMEOUT 5 /* Detection shall be aborted if a movement state is stable for more than 500ms */ 17 #define STABLE_STATE_TIMEOUT 5 /* Detection shall be aborted if a movement state is stable for more than 500ms */
17 #define MOVE_DELTA_SPEED 4 /* Delta speed needed to identify a valid movement */ 18 #define MOVE_DELTA_SPEED 4 /* Delta speed needed to identify a valid movement */
18 #define PITCH_DELTA_COUNT 10 /* Delta count needed to identify a valid minima / maxima */ 19 #define PITCH_DELTA_COUNT 10 /* Delta count needed to identify a valid minima / maxima */
22 #define SECTOR_WINDOW 40.0 /* Pitch window which is used for custom view projection */ 23 #define SECTOR_WINDOW 40.0 /* Pitch window which is used for custom view projection */
23 #define SECTOR_HYSTERY 3 /* Additional offset to avoid fast changing displays */ 24 #define SECTOR_HYSTERY 3 /* Additional offset to avoid fast changing displays */
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
28 #define SECTOR_MAX 10 /* maximum number of sectors */
27 29
28 static detectionState_t detectionState = DETECT_NOTHING; 30 static detectionState_t detectionState = DETECT_NOTHING;
29 31
30 static uint8_t curSector; 32 static uint8_t curSector;
31 static uint8_t targetSector; 33 static uint8_t targetSector;
59 } 61 }
60 lastPitch = newPitch; 62 lastPitch = newPitch;
61 return sector; 63 return sector;
62 } 64 }
63 65
64 void DefinePitchSectors(float centerPitch) 66 void DefinePitchSectors(float centerPitch,uint8_t numOfSectors)
65 { 67 {
66 uint8_t index; 68 uint8_t index;
67 69
68 sectorCount = t7_GetEnabled_customviews(); 70 if(numOfSectors == CUSTOMER_DEFINED_VIEWS)
71 {
72 sectorCount = t7_GetEnabled_customviews();
73 if(sectorCount > 5)
74 {
75 sectorCount = 5; /* more views are hard to manually control */
76 }
77 }
78 else
79 {
80 sectorCount = numOfSectors;
81 }
69 sectorSize = SECTOR_WINDOW / sectorCount; 82 sectorSize = SECTOR_WINDOW / sectorCount;
70 83
71 PitchSector[0].upperlimit = centerPitch + (SECTOR_WINDOW / 2); 84 PitchSector[0].upperlimit = centerPitch + (SECTOR_WINDOW / 2);
72 PitchSector[0].lowerlimit = PitchSector[0].upperlimit - sectorSize - SECTOR_HYSTERY; 85 PitchSector[0].lowerlimit = PitchSector[0].upperlimit - sectorSize - SECTOR_HYSTERY;
73 86
89 { 102 {
90 targetSector = 0; 103 targetSector = 0;
91 curSector = 0; 104 curSector = 0;
92 sectorSize = 0; 105 sectorSize = 0;
93 sectorCount = 0; 106 sectorCount = 0;
94 DefinePitchSectors(0); 107
108 switch(settingsGetPointer()->MotionDetection)
109 {
110 case MOTION_DETECT_SECTOR: DefinePitchSectors(0,CUSTOMER_DEFINED_VIEWS);
111 break;
112 case MOTION_DETECT_MOVE: DefinePitchSectors(0,SECTOR_MAX);
113 break;
114 default:
115 break;
116 }
117
95 } 118 }
96 119
97 /* Map the current pitch value to a sector and create button event in case the sector is left */ 120 /* Map the current pitch value to a sector and create button event in case the sector is left */
98 detectionState_t detectSectorButtonEvent(float curPitch) 121 detectionState_t detectSectorButtonEvent(float curPitch)
99 { 122 {