comparison Discovery/Src/base.c @ 461:b3f684cea9c0

Merged in Ideenmodellierer/ostc4/minor_improvments (pull request #41) Minor improvments
author heinrichsweikamp <bitbucket@heinrichsweikamp.com>
date Mon, 30 Mar 2020 13:16:11 +0000
parents adc4ccbebbb5
children 19cff811616d
comparison
equal deleted inserted replaced
441:9a9e4908ce2e 461:b3f684cea9c0
197 */ 197 */
198 198
199 /* Includes ------------------------------------------------------------------*/ 199 /* Includes ------------------------------------------------------------------*/
200 #include "stdio.h" 200 #include "stdio.h"
201 #include <string.h> // for memcopy 201 #include <string.h> // for memcopy
202 #include "configuration.h"
202 203
203 #include "stm32f4xx_hal.h" 204 #include "stm32f4xx_hal.h"
204 #include "ostc.h" 205 #include "ostc.h"
205 #include "base.h" 206 #include "base.h"
206 #include "display.h" 207 #include "display.h"
325 ITM_Port8(0) = ch; 326 ITM_Port8(0) = ch;
326 } 327 }
327 return(ch); 328 return(ch);
328 } 329 }
329 */ 330 */
330 /* #define DEBUG_RUNTIME TRUE */
331 #ifdef DEBUG_RUNTIME
332 #define MEASURECNT 60 /* number of measuremets to be stored */
333 static uint32_t loopcnt[MEASURECNT];
334 #endif
335
336 static uint8_t ButtonAction = ACTION_END; 331 static uint8_t ButtonAction = ACTION_END;
337 332
338 static void StoreButtonAction(uint8_t action) 333 static void StoreButtonAction(uint8_t action)
339 { 334 {
340 ButtonAction = action; 335 ButtonAction = action;
348 // =============================================================================== 343 // ===============================================================================
349 int main(void) 344 int main(void)
350 { 345 {
351 uint32_t pLayerInvisible; 346 uint32_t pLayerInvisible;
352 uint16_t totalDiveCounterFound; 347 uint16_t totalDiveCounterFound;
353 #ifdef DEBUG_RUNTIME
354 RTC_TimeTypeDef Stime;
355 uint8_t measurementindex = 0;
356 uint8_t lastsecond = 0xFF;
357 #endif
358 348
359 SStateList status; 349 SStateList status;
360 detectionState_t pitchstate; 350 detectionState_t pitchstate;
361 set_globalState( StBoot0 ); 351 set_globalState( StBoot0 );
362 LastButtonPressed = 0; 352 LastButtonPressed = 0;
443 tCCR_init(); 433 tCCR_init();
444 434
445 GFX_logoAutoOff(); 435 GFX_logoAutoOff();
446 EXTILine_Buttons_Config(); 436 EXTILine_Buttons_Config();
447 437
438 #ifdef TRUST_LOG_CONSISTENCY
439 if(!ext_dive_log_consistent()) /* only repair log if an invalid entry was detected */
440 {
441 ext_flash_repair_dive_log();
442 }
443
444 #else /* always check and repair log */
448 ext_flash_repair_dive_log(); 445 ext_flash_repair_dive_log();
449 //ext_flash_repair_SPECIAL_dive_numbers_starting_count_with(1); 446 //ext_flash_repair_SPECIAL_dive_numbers_starting_count_with(1);
450 447 #endif
451 totalDiveCounterFound = logbook_lastDive_diveNumber(); 448 totalDiveCounterFound = logbook_lastDive_diveNumber();
452 if( settingsGetPointer()->totalDiveCounter < totalDiveCounterFound ) 449 if( settingsGetPointer()->totalDiveCounter < totalDiveCounterFound )
453 settingsGetPointer()->totalDiveCounter = totalDiveCounterFound; 450 settingsGetPointer()->totalDiveCounter = totalDiveCounterFound;
454 451
455 if( settingsGetPointer()->debugModeOnStart ) 452 if( settingsGetPointer()->debugModeOnStart )
525 StoreButtonAction((uint8_t)ACTION_PITCH_POS); 522 StoreButtonAction((uint8_t)ACTION_PITCH_POS);
526 } 523 }
527 } 524 }
528 525
529 526
530 // Enable this to make the simulator write a logbook entry
531 // #define SIM_WRITES_LOGBOOK 1
532
533 #ifdef SIM_WRITES_LOGBOOK 527 #ifdef SIM_WRITES_LOGBOOK
534 if(stateUsed == stateSimGetPointer()) 528 if(stateUsed == stateSimGetPointer())
535 logbook_InitAndWrite(stateUsed); 529 logbook_InitAndWrite(stateUsed);
536 #endif 530 #endif
537 if(stateUsed == stateRealGetPointer()) /* Handle log entries while in dive mode*/ 531 if(stateUsed == stateRealGetPointer()) /* Handle log entries while in dive mode*/
538 logbook_InitAndWrite(stateUsed); 532 logbook_InitAndWrite(stateUsed);
539 } 533 }
540
541 #ifdef DEBUG_RUNTIME
542 translateTime(stateUsed->lifeData.timeBinaryFormat, &Stime);
543 if(lastsecond == 0xFF)
544 {
545 measurementindex = 0;
546 loopcnt[measurementindex] = 0;
547 lastsecond = Stime.Seconds;
548 }
549 loopcnt[measurementindex]++;
550
551 if(lastsecond != Stime.Seconds)
552 {
553 measurementindex++;
554 if (measurementindex == MEASURECNT) measurementindex = 0;
555 loopcnt[measurementindex] = 0;
556 lastsecond = Stime.Seconds;
557 if(measurementindex +1 < MEASURECNT) loopcnt[measurementindex +1] = 0xffff; /* helps to identify the latest value */
558 }
559 #endif
560
561 } 534 }
562 } 535 }
563 536
564 537
565 538