# HG changeset patch # User Ideenmodellierer # Date 1610655915 -3600 # Node ID 916998f90e390667c50c49a9f02f1e2a9f8b092f # Parent ae7f8333c900910d9815aeb1333f4321d8077f57 Suspend MotionDetection events while diver is operationg the OSTC: In the previous version in some situations the customer selection of the diver was immediatly overwritten by the detection function value (e.g. in sector mode). To prevent this behaviour a timeout for the detection has been added. Also in case the diver is operating a sub menu the handling of motion detection events will now be blocked. diff -r ae7f8333c900 -r 916998f90e39 Discovery/Inc/base.h --- a/Discovery/Inc/base.h Thu Jan 14 20:38:28 2021 +0100 +++ b/Discovery/Inc/base.h Thu Jan 14 21:25:15 2021 +0100 @@ -109,6 +109,7 @@ void set_returnFromComm(void); uint8_t font_update_required(void); void set_Backlight_Boost(uint8_t level); +void StoreButtonAction(uint8_t action); #endif /* BASE_H */ diff -r ae7f8333c900 -r 916998f90e39 Discovery/Inc/motion.h --- a/Discovery/Inc/motion.h Thu Jan 14 20:38:28 2021 +0100 +++ b/Discovery/Inc/motion.h Thu Jan 14 21:25:15 2021 +0100 @@ -73,6 +73,8 @@ } SDeltaHistory; void InitMotionDetection(void); +void suspendMotionDetection(uint8_t seconds); +void HandleMotionDetection(void); void resetMotionDeltaHistory(); void evaluateMotionDelta(float roll, float pitch, float yaw); void DefinePitchSectors(float centerAngle, uint8_t numOfSectors); diff -r ae7f8333c900 -r 916998f90e39 Discovery/Src/base.c --- a/Discovery/Src/base.c Thu Jan 14 20:38:28 2021 +0100 +++ b/Discovery/Src/base.c Thu Jan 14 21:25:15 2021 +0100 @@ -334,7 +334,7 @@ */ static uint8_t ButtonAction = ACTION_END; -static void StoreButtonAction(uint8_t action) +void StoreButtonAction(uint8_t action) { ButtonAction = action; } @@ -349,12 +349,9 @@ { uint32_t pLayerInvisible; uint16_t totalDiveCounterFound; - uint8_t wasInFocus = 0; SStateList status; -#ifdef ENABLE_MOTION_CONTROL - detectionState_t pitchstate; -#endif + set_globalState( StBoot0 ); LastButtonPressed = 0; @@ -510,51 +507,11 @@ #ifdef ENABLE_MOTION_CONTROL if((stateUsed->mode == MODE_DIVE) && (settingsGetPointer()->MotionDetection != MOTION_DETECT_OFF)) /* handle motion events in divemode only */ { - evaluateMotionDelta(stateUsed->lifeData.compass_roll, stateUsed->lifeData.compass_pitch, stateUsed->lifeData.compass_heading); - checkViewport(stateUsed->lifeData.compass_roll, stateUsed->lifeData.compass_pitch, stateUsed->lifeData.compass_heading); - - if(viewInFocus()) + if(get_globalState() != StD) { - wasInFocus = 1; - set_Backlight_Boost(settingsGetPointer()->viewPortMode & 0x03); - switch(settingsGetPointer()->MotionDetection) - { - case MOTION_DETECT_MOVE: pitchstate = detectPitch(stateRealGetPointer()->lifeData.compass_pitch); - break; - case MOTION_DETECT_SECTOR: pitchstate = detectSectorButtonEvent(stateRealGetPointer()->lifeData.compass_pitch); - break; - case MOTION_DETECT_SCROLL: pitchstate = detectScrollButtonEvent(stateRealGetPointer()->lifeData.compass_pitch); - break; - default: - pitchstate = DETECT_NOTHING; - break; - } - if(DETECT_NEG_PITCH == pitchstate) - { - StoreButtonAction((uint8_t)ACTION_PITCH_NEG); - } - if(DETECT_POS_PITCH == pitchstate) - { - StoreButtonAction((uint8_t)ACTION_PITCH_POS); - } - } - else - { - if(wasInFocus) - { - wasInFocus = 0; - if(settingsGetPointer()->design == 7) - { - t7_set_customview_to_primary(); - } - else - { - t3_set_customview_to_primary(); - } - } - - set_Backlight_Boost(0); - } + suspendMotionDetection(1); /* do not change custom views while divers is operating the computer */ + } + HandleMotionDetection(); } #endif @@ -751,6 +708,9 @@ { uint8_t action = ButtonAction; SStateList status; + SSettings* pSettings; + pSettings = settingsGetPointer(); + if(ButtonAction != ACTION_END) { @@ -778,9 +738,9 @@ { openInfo(StILOGLIST); } - else if ((status.page == PageDive) && (settingsGetPointer()->design < 7)) + else if ((status.page == PageDive) && (pSettings->design < 7)) { - if(settingsGetPointer()->design == 3) + if(pSettings->design == 3) { if(get_globalState() != StD) /* located in submenu? => return */ { @@ -788,31 +748,31 @@ } else /* return to t7 view */ { - settingsGetPointer()->design = 7; - if(settingsGetPointer()->MotionDetection == MOTION_DETECT_SECTOR) + pSettings->design = 7; + if(pSettings->MotionDetection == MOTION_DETECT_SECTOR) { - DefinePitchSectors(settingsGetPointer()->viewPitch,CUSTOMER_DEFINED_VIEWS); + DefinePitchSectors(pSettings->viewPitch,CUSTOMER_DEFINED_VIEWS); MapCVToSector(); } } } else { - settingsGetPointer()->design = 7; // auto switch to 9 if necessary + pSettings->design = 7; // auto switch to 9 if necessary } } else if ((status.page == PageDive) && (status.line != 0)) { - if (settingsGetPointer()->extraDisplay == EXTRADISPLAY_BIGFONT) + if (pSettings->extraDisplay == EXTRADISPLAY_BIGFONT) { - settingsGetPointer()->design = 3; - if(settingsGetPointer()->MotionDetection == MOTION_DETECT_SECTOR) + pSettings->design = 3; + if(pSettings->MotionDetection == MOTION_DETECT_SECTOR) { - DefinePitchSectors(settingsGetPointer()->viewPitch,CUSTOMER_DEFINED_VIEWS); + DefinePitchSectors(pSettings->viewPitch,CUSTOMER_DEFINED_VIEWS); MapCVToSector(); } } - else if (settingsGetPointer()->extraDisplay == EXTRADISPLAY_DECOGAME) - settingsGetPointer()->design = 4; + else if (pSettings->extraDisplay == EXTRADISPLAY_DECOGAME) + pSettings->design = 4; set_globalState(StD); } else @@ -824,6 +784,10 @@ if ((status.page == PageDive) && (status.line == 0)) { + if((action == ACTION_BUTTON_ENTER) && ((pSettings->MotionDetection == MOTION_DETECT_SECTOR) || (pSettings->MotionDetection == MOTION_DETECT_SCROLL))) + { + suspendMotionDetection(10); + } tHome_change_customview_button_pressed(action); } else if (status.page == PageSurface) diff -r ae7f8333c900 -r 916998f90e39 Discovery/Src/motion.c --- a/Discovery/Src/motion.c Thu Jan 14 20:38:28 2021 +0100 +++ b/Discovery/Src/motion.c Thu Jan 14 21:25:15 2021 +0100 @@ -50,6 +50,8 @@ static uint8_t inFocus = 0; static uint8_t sectorMap[SECTOR_MAX_CNT]; +static uint8_t suspendMotionDetectionSec = 0; + void resetMotionDeltaHistory() { motionDeltaHistoryIdx = 0; @@ -719,3 +721,73 @@ { inFocus = 0; } + +void suspendMotionDetection(uint8_t seconds) +{ + suspendMotionDetectionSec = seconds * 10; /* detection function is called every 100ms */ +} + +void HandleMotionDetection(void) +{ + detectionState_t pitchstate = DETECT_NOTHING; + uint8_t wasInFocus = 0; + + evaluateMotionDelta(stateUsed->lifeData.compass_roll, stateUsed->lifeData.compass_pitch, stateUsed->lifeData.compass_heading); + checkViewport(stateUsed->lifeData.compass_roll, stateUsed->lifeData.compass_pitch, stateUsed->lifeData.compass_heading); + + if(viewInFocus()) + { + wasInFocus = 1; + set_Backlight_Boost(settingsGetPointer()->viewPortMode & 0x03); + + if(suspendMotionDetectionSec == 0) /* suspend detection while diver is manually operating the OSTC */ + { + switch(settingsGetPointer()->MotionDetection) + { + case MOTION_DETECT_MOVE: pitchstate = detectPitch(stateRealGetPointer()->lifeData.compass_pitch); + break; + case MOTION_DETECT_SECTOR: pitchstate = detectSectorButtonEvent(stateRealGetPointer()->lifeData.compass_pitch); + break; + case MOTION_DETECT_SCROLL: pitchstate = detectScrollButtonEvent(stateRealGetPointer()->lifeData.compass_pitch); + break; + default: + pitchstate = DETECT_NOTHING; + break; + } + } + + if(DETECT_NEG_PITCH == pitchstate) + { + StoreButtonAction((uint8_t)ACTION_PITCH_NEG); + } + if(DETECT_POS_PITCH == pitchstate) + { + StoreButtonAction((uint8_t)ACTION_PITCH_POS); + } + } + else + { + if(wasInFocus) + { + wasInFocus = 0; + if(suspendMotionDetectionSec == 0) + { + if(settingsGetPointer()->design == 7) + { + t7_set_customview_to_primary(); + } + else + { + t3_set_customview_to_primary(); + } + } + } + set_Backlight_Boost(0); + } + if(suspendMotionDetectionSec != 0) + { + suspendMotionDetectionSec--; + } +} + +