comparison Small_CPU/Src/scheduler.c @ 350:607099140a41

Merged in Ideenmodellierer/ostc4/FlightMode_Improvment (pull request #32) FlightMode Improvment
author heinrichsweikamp <bitbucket@heinrichsweikamp.com>
date Sun, 06 Oct 2019 11:58:36 +0000
parents 9d82411d0afa
children cb3870f79e9d
comparison
equal deleted inserted replaced
340:0756013e43b3 350:607099140a41
55 SDevice DeviceDataFlash; 55 SDevice DeviceDataFlash;
56 uint8_t deviceDataFlashValid = 0; 56 uint8_t deviceDataFlashValid = 0;
57 uint8_t deviceDataSubSeconds = 0; 57 uint8_t deviceDataSubSeconds = 0;
58 58
59 /* Private variables ---------------------------------------------------------*/ 59 /* Private variables ---------------------------------------------------------*/
60 static uint16_t ManualExitDiveCounter = 0; /* The computer will exit dive mode in shallow area immediately. Increase depth to restart dive while counter is active */
61
60 /* can be lost while in sleep */ 62 /* can be lost while in sleep */
61 uint8_t clearDecoNow = 0; 63 uint8_t clearDecoNow = 0;
62 uint8_t setButtonsNow = 0; 64 uint8_t setButtonsNow = 0;
63 65
64 /* has to be in SRAM2 */ 66 /* has to be in SRAM2 */
260 global.dataSendToMaster.confirmRequest.ub.batterygauge = 1; 262 global.dataSendToMaster.confirmRequest.ub.batterygauge = 1;
261 battery_gas_gauge_set(global.dataSendToSlave.data.newBatteryGaugePercentageFloat); 263 battery_gas_gauge_set(global.dataSendToSlave.data.newBatteryGaugePercentageFloat);
262 } 264 }
263 } 265 }
264 266
267 if(global.dataSendToSlave.setEndDive)
268 {
269 ManualExitDiveCounter = 30 * 60; /* This will cause the computer to leave dive mode if in shallow area and increase the depth to enter dive mode for the next 30 minutes */
270 }
271
265 if((global.mode == MODE_SURFACE) && (global.dataSendToSlave.mode == MODE_SHUTDOWN)) 272 if((global.mode == MODE_SURFACE) && (global.dataSendToSlave.mode == MODE_SHUTDOWN))
266 { 273 {
267 global.mode = MODE_SHUTDOWN; 274 global.mode = MODE_SHUTDOWN;
268 } 275 }
269 276
458 Scheduler.tick_execute1second = SCHEDULER_TICK_EXE1SEC; 465 Scheduler.tick_execute1second = SCHEDULER_TICK_EXE1SEC;
459 466
460 global.deviceData.diveCycles.value_int32++; 467 global.deviceData.diveCycles.value_int32++;
461 scheduleSetDate(&global.deviceData.diveCycles); 468 scheduleSetDate(&global.deviceData.diveCycles);
462 global.lifeData.counterSecondsShallowDepth = 0; 469 global.lifeData.counterSecondsShallowDepth = 0;
470
471 /* Get the last stable value in case of an unstable surface history condition */
472 if(!is_surface_pressure_stable())
473 {
474 set_last_surface_pressure_stable();
475 }
476 global.lifeData.pressure_surface_bar = get_surface_mbar() / 1000.0f;
477 ManualExitDiveCounter = 0; /* reset early exit request */
463 478
464 Scheduler.tickstart = HAL_GetTick(); 479 Scheduler.tickstart = HAL_GetTick();
465 while(global.mode == MODE_DIVE) 480 while(global.mode == MODE_DIVE)
466 { 481 {
467 lasttick = HAL_GetTick(); 482 lasttick = HAL_GetTick();
554 { 569 {
555 global.mode = MODE_SURFACE; 570 global.mode = MODE_SURFACE;
556 global.demo_mode = 0; 571 global.demo_mode = 0;
557 } 572 }
558 } 573 }
559 574
560 if(is_ambient_pressure_close_to_surface(&global.lifeData)) 575 if(is_ambient_pressure_close_to_surface(&global.lifeData))
561 { 576 {
562 global.lifeData.counterSecondsShallowDepth++; 577 global.lifeData.counterSecondsShallowDepth++;
563 if((global.lifeData.counterSecondsShallowDepth >= global.settings.timeoutDiveReachedZeroDepth) || ((global.lifeData.dive_time_seconds < 60) && (global.demo_mode == 0)) || (global.dataSendToSlave.setEndDive)) 578 if((global.lifeData.counterSecondsShallowDepth >= global.settings.timeoutDiveReachedZeroDepth) || ((global.lifeData.dive_time_seconds < 60) && (global.demo_mode == 0))
579 || (ManualExitDiveCounter))
564 { 580 {
565 global.seconds_since_last_dive = 1; // start counter 581 global.seconds_since_last_dive = 1; // start counter
566 schedule_update_timer_helper(0); // zum starten :-) 582 schedule_update_timer_helper(0); // zum starten :-)
567 global.dataSendToMaster.mode = MODE_ENDDIVE; 583 global.dataSendToMaster.mode = MODE_ENDDIVE;
568 global.deviceDataSendToMaster.mode = MODE_ENDDIVE; 584 global.deviceDataSendToMaster.mode = MODE_ENDDIVE;
598 global.lifeData.counterSecondsShallowDepth++; 614 global.lifeData.counterSecondsShallowDepth++;
599 if(global.lifeData.counterSecondsShallowDepth > 3) // time for main cpu to copy to apnea_last_dive_time_seconds 615 if(global.lifeData.counterSecondsShallowDepth > 3) // time for main cpu to copy to apnea_last_dive_time_seconds
600 { 616 {
601 global.lifeData.dive_time_seconds = 0; // this apnea dive ends here 617 global.lifeData.dive_time_seconds = 0; // this apnea dive ends here
602 } 618 }
603 if((global.lifeData.counterSecondsShallowDepth >= global.settings.timeoutDiveReachedZeroDepth) || (global.dataSendToSlave.setEndDive)) 619 if((global.lifeData.counterSecondsShallowDepth >= global.settings.timeoutDiveReachedZeroDepth) || (ManualExitDiveCounter))
604 { 620 {
605 global.dataSendToMaster.mode = MODE_ENDDIVE; 621 global.dataSendToMaster.mode = MODE_ENDDIVE;
606 global.deviceDataSendToMaster.mode = MODE_ENDDIVE; 622 global.deviceDataSendToMaster.mode = MODE_ENDDIVE;
607 } 623 }
608 } 624 }
810 global.no_fly_time_minutes = 0; 826 global.no_fly_time_minutes = 0;
811 global.accidentFlag = 0; 827 global.accidentFlag = 0;
812 global.accidentRemainingSeconds = 0; 828 global.accidentRemainingSeconds = 0;
813 vpm_init(&global.vpm, global.conservatism, global.repetitive_dive, global.seconds_since_last_dive); 829 vpm_init(&global.vpm, global.conservatism, global.repetitive_dive, global.seconds_since_last_dive);
814 clearDecoNow = 0; 830 clearDecoNow = 0;
831 }
832
833 if(ManualExitDiveCounter)
834 {
835 ManualExitDiveCounter--;
815 } 836 }
816 837
817 if(global.seconds_since_last_dive) 838 if(global.seconds_since_last_dive)
818 { 839 {
819 schedule_update_timer_helper(-1); 840 schedule_update_timer_helper(-1);
1379 global.dataSendToMaster.data[boolPressureData].pressure_mbar = get_pressure_mbar(); 1400 global.dataSendToMaster.data[boolPressureData].pressure_mbar = get_pressure_mbar();
1380 global.dataSendToMaster.data[boolPressureData].surface_mbar = get_surface_mbar(); 1401 global.dataSendToMaster.data[boolPressureData].surface_mbar = get_surface_mbar();
1381 global.dataSendToMaster.data[boolPressureData].ascent_rate_meter_per_min = global.lifeData.ascent_rate_meter_per_min; 1402 global.dataSendToMaster.data[boolPressureData].ascent_rate_meter_per_min = global.lifeData.ascent_rate_meter_per_min;
1382 global.dataSendToMaster.data[boolPressureData].pressure_uTick = HAL_GetTick(); 1403 global.dataSendToMaster.data[boolPressureData].pressure_uTick = HAL_GetTick();
1383 global.dataSendToMaster.boolPressureData = boolPressureData; 1404 global.dataSendToMaster.boolPressureData = boolPressureData;
1405 global.dataSendToMaster.data[boolPressureData].SPARE1 = is_surface_pressure_stable();
1384 } 1406 }
1385 1407
1386 1408
1387 //Supports threadsave copying!!! 1409 //Supports threadsave copying!!!
1388 void copyCnsAndOtuData(void) 1410 void copyCnsAndOtuData(void)
1585 } 1607 }
1586 1608
1587 /* same as in data_central.c */ 1609 /* same as in data_central.c */
1588 _Bool is_ambient_pressure_close_to_surface(SLifeData *lifeData) 1610 _Bool is_ambient_pressure_close_to_surface(SLifeData *lifeData)
1589 { 1611 {
1590 if(lifeData->pressure_ambient_bar == INVALID_PREASURE_VALUE) /* as long as no valid data is available expect we are close to surface */ 1612 _Bool retval = true;
1591 { 1613
1592 return true; 1614 if(lifeData->pressure_ambient_bar != INVALID_PREASURE_VALUE) /* as long as no valid data is available expect we are close to surface */
1593 } 1615 {
1594 if (lifeData->pressure_ambient_bar > START_DIVE_IMMEDIATLY_BAR) 1616 /* this will e.g. apply in case of a significant pressure change during last 30 minutes => use increased offset for surface detection */
1595 return false; 1617 if (lifeData->pressure_ambient_bar > START_DIVE_IMMEDIATLY_BAR)
1596 else if(lifeData->pressure_ambient_bar < (lifeData->pressure_surface_bar + 0.1f)) // hw 161121 now 1 mter, before 0.04f 1618 {
1597 return true; 1619 retval = false;
1598 else 1620 }
1599 return false; 1621 else if(is_surface_pressure_stable()) /* this is the expected start condition */
1622 {
1623 if((lifeData->pressure_ambient_bar >= (lifeData->pressure_surface_bar + 0.1f))
1624 && (ManualExitDiveCounter == 0)) /* only if diver did not request to exit dive mode */
1625 {
1626 retval = false;
1627 }
1628 }
1629 }
1630 return retval;
1600 } 1631 }
1601 1632
1602 1633
1603 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ 1634 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/
1604 1635