comparison Discovery/Src/base.c @ 387:0dbb74be972f

Merged in Ideenmodellierer/ostc4/MotionDetection (pull request #34) MotionDetection
author heinrichsweikamp <bitbucket@heinrichsweikamp.com>
date Sun, 24 Nov 2019 15:46:58 +0000
parents 427ae9f8e28e
children eb7696e0510f
comparison
equal deleted inserted replaced
358:c6a084d1433f 387:0dbb74be972f
227 #include "decom.h" 227 #include "decom.h"
228 #include "timer.h" 228 #include "timer.h"
229 #include "logbook_miniLive.h" 229 #include "logbook_miniLive.h"
230 #include "test_vpm.h" 230 #include "test_vpm.h"
231 #include "tDebug.h" 231 #include "tDebug.h"
232 #include "motion.h"
232 233
233 #ifdef DEMOMODE 234 #ifdef DEMOMODE
234 #include "demo.h" 235 #include "demo.h"
235 static void TIM_DEMO_init(void); 236 static void TIM_DEMO_init(void);
236 #endif 237 #endif
238
237 239
238 //#include "lodepng.h" 240 //#include "lodepng.h"
239 //#include <stdlib.h> // for malloc and free 241 //#include <stdlib.h> // for malloc and free
240 242
241 /** @addtogroup OSTC 4 243 /** @addtogroup OSTC 4
323 /* #define DEBUG_RUNTIME TRUE */ 325 /* #define DEBUG_RUNTIME TRUE */
324 #ifdef DEBUG_RUNTIME 326 #ifdef DEBUG_RUNTIME
325 #define MEASURECNT 60 /* number of measuremets to be stored */ 327 #define MEASURECNT 60 /* number of measuremets to be stored */
326 static uint32_t loopcnt[MEASURECNT]; 328 static uint32_t loopcnt[MEASURECNT];
327 #endif 329 #endif
330
331 static uint8_t ButtonAction = ACTION_END;
332
333 static void StoreButtonAction(uint8_t action)
334 {
335 ButtonAction = action;
336 }
337
328 // =============================================================================== 338 // ===============================================================================
329 // main 339 // main
330 /// @brief This function makes initializations and has the nonIRQ endless loop 340 /// @brief This function makes initializations and has the nonIRQ endless loop
331 /// for bluetooth and deco calculations 341 /// for bluetooth and deco calculations
332 /// 342 ///
339 RTC_TimeTypeDef Stime; 349 RTC_TimeTypeDef Stime;
340 uint8_t measurementindex = 0; 350 uint8_t measurementindex = 0;
341 uint8_t lastsecond = 0xFF; 351 uint8_t lastsecond = 0xFF;
342 #endif 352 #endif
343 353
354 detectionState_t pitchstate;
344 set_globalState( StBoot0 ); 355 set_globalState( StBoot0 );
345 LastButtonPressed = 0; 356 LastButtonPressed = 0;
346 357
347 HAL_Init(); 358 HAL_Init();
348 HAL_NVIC_SetPriorityGrouping( NVIC_PRIORITYGROUP_2 ); 359 HAL_NVIC_SetPriorityGrouping( NVIC_PRIORITYGROUP_2 );
444 settingsGetPointer()->debugModeOnStart = 0; 455 settingsGetPointer()->debugModeOnStart = 0;
445 ext_flash_write_settings(); 456 ext_flash_write_settings();
446 setDebugMode(); 457 setDebugMode();
447 openInfo( StIDEBUG ); 458 openInfo( StIDEBUG );
448 } 459 }
460 InitMotionDetection();
449 461
450 TIM_init(); /* start cylic 100ms task */ 462 TIM_init(); /* start cylic 100ms task */
451 463
452 /* @brief main LOOP 464 /* @brief main LOOP
453 * 465 *
474 if(DoDisplayRefresh) 486 if(DoDisplayRefresh)
475 { 487 {
476 DoDisplayRefresh = 0; 488 DoDisplayRefresh = 0;
477 RefreshDisplay(); 489 RefreshDisplay();
478 490
491 if(stateUsed->mode == MODE_DIVE) /* handle motion events in divemode only */
492 {
493 switch(settingsGetPointer()->MotionDetection)
494 {
495 case MOTION_DETECT_MOVE: pitchstate = detectPitch(stateRealGetPointer()->lifeData.compass_pitch);
496 break;
497 case MOTION_DETECT_SECTOR: pitchstate = detectSectorButtonEvent(stateRealGetPointer()->lifeData.compass_pitch);
498 break;
499 case MOTION_DETECT_SCROLL: pitchstate = detectScrollButtonEvent(stateRealGetPointer()->lifeData.compass_pitch);
500 break;
501 default:
502 pitchstate = DETECT_NOTHING;
503 break;
504 }
505 if(DETECT_NEG_PITCH == pitchstate)
506 {
507 StoreButtonAction((uint8_t)ACTION_PITCH_NEG);
508 }
509 if(DETECT_POS_PITCH == pitchstate)
510 {
511 StoreButtonAction((uint8_t)ACTION_PITCH_POS);
512 }
513 }
514
515
479 // Enable this to make the simulator write a logbook entry 516 // Enable this to make the simulator write a logbook entry
480 // #define SIM_WRITES_LOGBOOK 1 517 // #define SIM_WRITES_LOGBOOK 1
481 518
482 #ifdef SIM_WRITES_LOGBOOK 519 #ifdef SIM_WRITES_LOGBOOK
483 if(stateUsed == stateSimGetPointer()) 520 if(stateUsed == stateSimGetPointer())
507 } 544 }
508 #endif 545 #endif
509 546
510 } 547 }
511 } 548 }
549
550
551
512 552
513 // =============================================================================== 553 // ===============================================================================
514 // timer IRQ 554 // timer IRQ
515 /// @brief this is called periodically 555 /// @brief this is called periodically
516 /// 556 ///
817 if(get_globalState() == StStop) 857 if(get_globalState() == StStop)
818 tHome_sleepmode_fun(); 858 tHome_sleepmode_fun();
819 break; 859 break;
820 } 860 }
821 } 861 }
822 static uint8_t ButtonAction = ACTION_END; 862
823
824 static void StoreButtonAction(uint8_t action)
825 {
826 ButtonAction = action;
827 }
828 863
829 static void TriggerButtonAction() 864 static void TriggerButtonAction()
830 { 865 {
831 uint8_t action = ButtonAction; 866 uint8_t action = ButtonAction;
832 SStateList status; 867 SStateList status;
858 else if ((status.page == PageDive) 893 else if ((status.page == PageDive)
859 && (settingsGetPointer()->design < 7)) { 894 && (settingsGetPointer()->design < 7)) {
860 settingsGetPointer()->design = 7; // auto switch to 9 if necessary 895 settingsGetPointer()->design = 7; // auto switch to 9 if necessary
861 } else if ((status.page == PageDive) && (status.line != 0)) { 896 } else if ((status.page == PageDive) && (status.line != 0)) {
862 if (settingsGetPointer()->extraDisplay == EXTRADISPLAY_BIGFONT) 897 if (settingsGetPointer()->extraDisplay == EXTRADISPLAY_BIGFONT)
898 {
863 settingsGetPointer()->design = 3; 899 settingsGetPointer()->design = 3;
900 if(settingsGetPointer()->MotionDetection == MOTION_DETECT_SECTOR)
901 {
902 DefinePitchSectors(stateRealGetPointer()->lifeData.compass_pitch,CUSTOMER_DEFINED_VIEWS);
903 }
904 }
864 else if (settingsGetPointer()->extraDisplay 905 else if (settingsGetPointer()->extraDisplay
865 == EXTRADISPLAY_DECOGAME) 906 == EXTRADISPLAY_DECOGAME)
866 settingsGetPointer()->design = 4; 907 settingsGetPointer()->design = 4;
867 908
868 set_globalState(StD); 909 set_globalState(StD);
869 } else 910 } else
870 tHome_change_field_button_pressed(); 911 tHome_change_field_button_pressed();
871 } else if (action == ACTION_BUTTON_ENTER) { 912 } else if ((action == ACTION_BUTTON_ENTER) || (action == ACTION_PITCH_NEG) || (action == ACTION_PITCH_POS))
872 if ((status.page == PageDive) && (status.line == 0)) 913 {
873 tHome_change_customview_button_pressed(); 914
874 else if (status.page == PageSurface) 915 if ((status.page == PageDive) && (status.line == 0))
875 tHome_change_customview_button_pressed(); 916 {
876 else 917 tHome_change_customview_button_pressed(action);
877 tHomeDiveMenuControl(action); 918 if((settingsGetPointer()->MotionDetection != MOTION_DETECT_OFF) && (action == ACTION_BUTTON_ENTER)) /* Button pressed while motion detection is active => calibrate to current pitch value */
878 } 919 {
920 DefinePitchSectors(stateRealGetPointer()->lifeData.compass_pitch,CUSTOMER_KEEP_LAST_SECTORS);
921 }
922 }
923 else if (status.page == PageSurface)
924 tHome_change_customview_button_pressed(action);
925 else
926 tHomeDiveMenuControl(action);
927 }
879 break; 928 break;
880 929
881 case BaseMenu: 930 case BaseMenu:
882 if (status.line == 0) 931 if (status.line == 0)
883 sendActionToMenu(action); 932 sendActionToMenu(action);