Mercurial > public > ostc4
comparison Small_CPU/Src/scheduler.c @ 346:73325a78c907 FlightMode_Improvment
Added function to support manuel exit of dive mode
In some special cases the diver might want to exit the divemode manually. To avoid immediate return to dive mode the limit for starting next dive is increased for 30 minutes
author | ideenmodellierer |
---|---|
date | Thu, 03 Oct 2019 21:30:16 +0200 |
parents | b6a59e93cc91 |
children | 9d82411d0afa |
comparison
equal
deleted
inserted
replaced
345:4093ac18b25c | 346:73325a78c907 |
---|---|
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(); |
534 if(ticksdiff >= Scheduler.tick_execute1second) | 549 if(ticksdiff >= Scheduler.tick_execute1second) |
535 { | 550 { |
536 Scheduler.tick_execute1second = 0xFFFFFFFF; /* execute once only in the second cycle */ | 551 Scheduler.tick_execute1second = 0xFFFFFFFF; /* execute once only in the second cycle */ |
537 if(global.dataSendToSlave.diveModeInfo != DIVEMODE_Apnea) | 552 if(global.dataSendToSlave.diveModeInfo != DIVEMODE_Apnea) |
538 { | 553 { |
554 if(ManualExitDiveCounter) | |
555 { | |
556 ManualExitDiveCounter--; | |
557 } | |
539 scheduleUpdateLifeData(0); // includes tissues | 558 scheduleUpdateLifeData(0); // includes tissues |
540 global.lifeData.dive_time_seconds++; // there is dive_time_seconds_without_surface_time too | 559 global.lifeData.dive_time_seconds++; // there is dive_time_seconds_without_surface_time too |
541 global.lifeData.ppO2 = decom_calc_ppO2(global.lifeData.pressure_ambient_bar, &global.lifeData.actualGas); | 560 global.lifeData.ppO2 = decom_calc_ppO2(global.lifeData.pressure_ambient_bar, &global.lifeData.actualGas); |
542 decom_oxygen_calculate_cns(&global.lifeData.cns,global.lifeData.ppO2); | 561 decom_oxygen_calculate_cns(&global.lifeData.cns,global.lifeData.ppO2); |
543 decom_oxygen_calculate_otu(&global.lifeData.otu,global.lifeData.ppO2); | 562 decom_oxygen_calculate_otu(&global.lifeData.otu,global.lifeData.ppO2); |
554 { | 573 { |
555 global.mode = MODE_SURFACE; | 574 global.mode = MODE_SURFACE; |
556 global.demo_mode = 0; | 575 global.demo_mode = 0; |
557 } | 576 } |
558 } | 577 } |
559 | 578 |
560 if(is_ambient_pressure_close_to_surface(&global.lifeData)) | 579 if(is_ambient_pressure_close_to_surface(&global.lifeData)) |
561 { | 580 { |
562 global.lifeData.counterSecondsShallowDepth++; | 581 global.lifeData.counterSecondsShallowDepth++; |
563 if((global.lifeData.counterSecondsShallowDepth >= global.settings.timeoutDiveReachedZeroDepth) || ((global.lifeData.dive_time_seconds < 60) && (global.demo_mode == 0)) || (global.dataSendToSlave.setEndDive)) | 582 if((global.lifeData.counterSecondsShallowDepth >= global.settings.timeoutDiveReachedZeroDepth) || ((global.lifeData.dive_time_seconds < 60) && (global.demo_mode == 0)) |
583 || (ManualExitDiveCounter)) | |
564 { | 584 { |
565 global.seconds_since_last_dive = 1; // start counter | 585 global.seconds_since_last_dive = 1; // start counter |
566 schedule_update_timer_helper(0); // zum starten :-) | 586 schedule_update_timer_helper(0); // zum starten :-) |
567 global.dataSendToMaster.mode = MODE_ENDDIVE; | 587 global.dataSendToMaster.mode = MODE_ENDDIVE; |
568 global.deviceDataSendToMaster.mode = MODE_ENDDIVE; | 588 global.deviceDataSendToMaster.mode = MODE_ENDDIVE; |
598 global.lifeData.counterSecondsShallowDepth++; | 618 global.lifeData.counterSecondsShallowDepth++; |
599 if(global.lifeData.counterSecondsShallowDepth > 3) // time for main cpu to copy to apnea_last_dive_time_seconds | 619 if(global.lifeData.counterSecondsShallowDepth > 3) // time for main cpu to copy to apnea_last_dive_time_seconds |
600 { | 620 { |
601 global.lifeData.dive_time_seconds = 0; // this apnea dive ends here | 621 global.lifeData.dive_time_seconds = 0; // this apnea dive ends here |
602 } | 622 } |
603 if((global.lifeData.counterSecondsShallowDepth >= global.settings.timeoutDiveReachedZeroDepth) || (global.dataSendToSlave.setEndDive)) | 623 if((global.lifeData.counterSecondsShallowDepth >= global.settings.timeoutDiveReachedZeroDepth) || (ManualExitDiveCounter)) |
604 { | 624 { |
605 global.dataSendToMaster.mode = MODE_ENDDIVE; | 625 global.dataSendToMaster.mode = MODE_ENDDIVE; |
606 global.deviceDataSendToMaster.mode = MODE_ENDDIVE; | 626 global.deviceDataSendToMaster.mode = MODE_ENDDIVE; |
607 } | 627 } |
608 } | 628 } |
1379 global.dataSendToMaster.data[boolPressureData].pressure_mbar = get_pressure_mbar(); | 1399 global.dataSendToMaster.data[boolPressureData].pressure_mbar = get_pressure_mbar(); |
1380 global.dataSendToMaster.data[boolPressureData].surface_mbar = get_surface_mbar(); | 1400 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; | 1401 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(); | 1402 global.dataSendToMaster.data[boolPressureData].pressure_uTick = HAL_GetTick(); |
1383 global.dataSendToMaster.boolPressureData = boolPressureData; | 1403 global.dataSendToMaster.boolPressureData = boolPressureData; |
1404 global.dataSendToMaster.data[boolPressureData].SPARE1 = is_surface_pressure_stable(); | |
1384 } | 1405 } |
1385 | 1406 |
1386 | 1407 |
1387 //Supports threadsave copying!!! | 1408 //Supports threadsave copying!!! |
1388 void copyCnsAndOtuData(void) | 1409 void copyCnsAndOtuData(void) |
1585 } | 1606 } |
1586 | 1607 |
1587 /* same as in data_central.c */ | 1608 /* same as in data_central.c */ |
1588 _Bool is_ambient_pressure_close_to_surface(SLifeData *lifeData) | 1609 _Bool is_ambient_pressure_close_to_surface(SLifeData *lifeData) |
1589 { | 1610 { |
1590 if(lifeData->pressure_ambient_bar == INVALID_PREASURE_VALUE) /* as long as no valid data is available expect we are close to surface */ | 1611 _Bool retval = true; |
1591 { | 1612 |
1592 return true; | 1613 if(lifeData->pressure_ambient_bar != INVALID_PREASURE_VALUE) /* as long as no valid data is available expect we are close to surface */ |
1593 } | 1614 { |
1594 if (lifeData->pressure_ambient_bar > START_DIVE_IMMEDIATLY_BAR) | 1615 /* 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; | 1616 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 | 1617 { |
1597 return true; | 1618 retval = false; |
1598 else | 1619 } |
1599 return false; | 1620 else if(is_surface_pressure_stable()) /* this is the expected start condition */ |
1621 { | |
1622 if((lifeData->pressure_ambient_bar >= (lifeData->pressure_surface_bar + 0.1f)) | |
1623 && (ManualExitDiveCounter == 0)) /* only if diver did not request to exit dive mode */ | |
1624 { | |
1625 retval = false; | |
1626 } | |
1627 } | |
1628 } | |
1629 return retval; | |
1600 } | 1630 } |
1601 | 1631 |
1602 | 1632 |
1603 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ | 1633 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ |
1604 | 1634 |