Mercurial > public > ostc4
view Discovery/Src/demo.c @ 250:822416168585 bm-2
Buelmann: new implementation for ceiling
Since my first functional fix in the ceiling computation in
commit ceecabfddb57, I noticed that the computation used a
linear search, that became rather computational expensive after
that commit. The simple question is: why not a binary search?
So, this commit implements the binary search. But there is a long
story attached to this. Comparing ceiling results from hwOS and this
OSTC4 code were very different. Basically, the original OSTC4
algorithm computed the ceiling using the same GFlow to GFhigh
slope, in such a way, that the ceiling was in sync with the
presented deco stops, where the hwOS code presents a GFhigh
based ceiling.
This said, it is more logical when the OSTC4 and hwOS code give
similar results. This new recursive algorithm gives very similar
results for the ceiling compared to hwOS.
To be complete here, the Buelmann ceiling is the depth to which
you can ascend, so that the leading tissue reaches GFhigh. This
also explains why the deepest deco stop is normally deeper than
the ceiling (unless one dives with GF like 80/80).
The code implemented here is rather straightforward recursion.
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
author | Jan Mulder <jlmulder@xs4all.nl> |
---|---|
date | Thu, 11 Apr 2019 17:48:48 +0200 |
parents | 5f11787b4f42 |
children |
line wrap: on
line source
/** ****************************************************************************** * @copyright heinrichs weikamp gmbh * @file demo.c * @author heinrichs weikamp gmbh * @date 26-Nov-2015 * @version 0.1 * @since 26-Nov-2015 * @brief f�r die Messe und die Vitrine * @bug * @warning @verbatim ============================================================================== ============================================================================== @endverbatim ****************************************************************************** * @attention * * <h2><center>© COPYRIGHT(c) 2015 heinrichs weikamp</center></h2> * ****************************************************************************** */ #include "demo.h" #include "base.h" // for BUTTON_BACK, ... #include "data_exchange_main.h" // for time_elapsed_ms() #include "settings.h" #include "ostc.h" #ifndef DEMOMODE /* Exported functions --------------------------------------------------------*/ uint8_t demoGetCommand(void) { return 0; } uint8_t demoModeActive(void) { return 0; } void demoSendCommand(uint8_t action) { return; } #else /* Private variables with external access ------------------------------------*/ uint8_t demoModeActiveStatus = 1; uint32_t systickDemoMode; uint16_t demoModeActual = 0; #define BUTTON_BACK (BUTTON_BACK_PIN | 0x80) #define BUTTON_NEXT (BUTTON_NEXT_PIN | 0x80) #define BUTTON_ENTER (BUTTON_ENTER_PIN | 0x80) /* Private typedef -----------------------------------------------------------*/ #define MAXCOMMANDS 200 #ifdef SHOWCCRMODE const uint8_t commandlist[MAXCOMMANDS][3] = { /* Button, deci-seconds to wait */ // start for both {0, 40}, // start OC, activate CC {BUTTON_NEXT, 0}, {BUTTON_NEXT, 0}, {BUTTON_ENTER, 0}, {BUTTON_ENTER, 0}, {BUTTON_NEXT, 0}, {BUTTON_ENTER, 0}, // Change to CC {BUTTON_ENTER, 0}, // Leave Edit {BUTTON_BACK, 0}, // Cursor {BUTTON_NEXT, 0}, {BUTTON_NEXT, 0}, {BUTTON_NEXT, 0}, {BUTTON_NEXT, 0}, {BUTTON_BACK, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, // start CC @ 20, set cursor to Sim Menu {BUTTON_NEXT, 0}, {BUTTON_NEXT, 0}, {BUTTON_NEXT, 0}, {BUTTON_NEXT, 0}, {BUTTON_NEXT, 0}, {BUTTON_NEXT, 0}, {BUTTON_NEXT, 0}, {BUTTON_NEXT, 0}, {BUTTON_BACK, 50}, {0, 0}, // re-loop @ 30 {0, 3}, // Logbook {BUTTON_BACK, 0}, {BUTTON_ENTER, 20}, {BUTTON_NEXT, 20}, {BUTTON_BACK, 0}, {BUTTON_BACK, 0}, {BUTTON_BACK, 0}, // surface screen {0, 2}, // menu {BUTTON_NEXT, 0}, {BUTTON_NEXT, 0}, {BUTTON_NEXT, 0}, {BUTTON_NEXT, 0}, {BUTTON_NEXT, 0}, {BUTTON_NEXT, 0}, {BUTTON_NEXT, 0}, {BUTTON_NEXT, 0}, {BUTTON_NEXT, 0}, {BUTTON_ENTER, 30}, {BUTTON_ENTER, 0}, // simulator {0, 10}, {BUTTON_ENTER, 10}, {BUTTON_ENTER, 10}, {BUTTON_ENTER, 10}, {BUTTON_ENTER, 10}, {BUTTON_ENTER, 10}, {BUTTON_NEXT, 0}, {BUTTON_NEXT, 0}, {BUTTON_ENTER, 0}, {BUTTON_ENTER, 0}, // the end, repeat from start {255, 0} }; #else // OC Mode Demo const uint8_t commandlist[MAXCOMMANDS][2] = { /* Button, seconds to wait */ // start for both {0, 50}, // wait IS IMPORTANT // start CC, activate OC {BUTTON_NEXT, 0}, {BUTTON_NEXT, 0}, {BUTTON_NEXT, 0}, {BUTTON_NEXT, 0}, {BUTTON_ENTER, 0}, {BUTTON_ENTER, 0}, {BUTTON_ENTER, 0}, {BUTTON_ENTER, 0}, {BUTTON_BACK, 0}, // Leave Cursor Mode {BUTTON_NEXT, 0}, {BUTTON_NEXT, 0}, {BUTTON_NEXT, 0}, {BUTTON_NEXT, 0}, {BUTTON_NEXT, 0}, // OC {BUTTON_BACK, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, // start OC @ line 20 {BUTTON_NEXT, 0}, {BUTTON_NEXT, 0}, {BUTTON_NEXT, 0}, {BUTTON_NEXT, 0}, {BUTTON_NEXT, 0}, {BUTTON_NEXT, 0}, // OC -> SIM {BUTTON_BACK, 0}, // Exit Menu {0, 0}, {0, 0}, {0, 0}, // re-loop @ 30 {0, 10}, // Logbook {BUTTON_BACK, 4}, {BUTTON_NEXT, 0}, {BUTTON_NEXT, 10}, {BUTTON_ENTER, 20}, {BUTTON_NEXT, 20}, {BUTTON_NEXT, 20}, {BUTTON_BACK, 0}, {BUTTON_BACK, 5}, {BUTTON_BACK, 0}, // Exit Logbook Mode // surface screen {0, 10}, {BUTTON_ENTER, 10}, {BUTTON_ENTER, 10}, // menu // activate Configure Deco Gas {BUTTON_NEXT, 0}, // Start Menu {BUTTON_NEXT, 2}, // SIM -> OC {BUTTON_ENTER, 2}, {BUTTON_NEXT, 1}, {BUTTON_ENTER, 0}, {BUTTON_ENTER, 0}, // Mix 30 -> 90 {BUTTON_NEXT, 0}, {BUTTON_NEXT, 0}, {BUTTON_NEXT, 0}, {BUTTON_NEXT, 0}, {BUTTON_NEXT, 0}, {BUTTON_NEXT, 0}, {BUTTON_ENTER, 0}, // Mix 90 -> 99 {BUTTON_BACK, 0}, {BUTTON_ENTER, 0}, {BUTTON_ENTER, 0}, {BUTTON_ENTER, 5}, // First -> Deco {BUTTON_NEXT, 2}, {BUTTON_ENTER, 2}, {BUTTON_NEXT, 2}, {BUTTON_ENTER, 2}, {BUTTON_ENTER, 10}, {BUTTON_BACK, 0}, {BUTTON_BACK, 30}, /* // OC -> SIM {BUTTON_NEXT, 2}, {BUTTON_NEXT, 2}, {BUTTON_NEXT, 2}, {BUTTON_NEXT, 2}, {BUTTON_NEXT, 1}, {BUTTON_ENTER, 10}, */ // SYS2 Layout {BUTTON_NEXT, 2}, {BUTTON_NEXT, 2}, {BUTTON_NEXT, 2}, {BUTTON_NEXT, 2}, {BUTTON_ENTER, 2}, {BUTTON_NEXT, 2}, {BUTTON_NEXT, 2}, {BUTTON_ENTER, 2}, {BUTTON_NEXT, 2}, {BUTTON_ENTER, 2}, {BUTTON_BACK, 2}, {BUTTON_BACK, 10}, // SYS2 -> SIM {BUTTON_NEXT, 2}, {BUTTON_ENTER, 10}, // simulator {BUTTON_ENTER, 40}, // Start Simulator {BUTTON_ENTER, 10}, {BUTTON_ENTER, 10}, {BUTTON_ENTER, 10}, {BUTTON_ENTER, 10}, {BUTTON_ENTER, 10}, {BUTTON_ENTER, 10}, {BUTTON_ENTER, 90}, {BUTTON_NEXT, 5}, // Quit {BUTTON_NEXT, 5}, {BUTTON_ENTER, 5}, {BUTTON_ENTER, 50}, // surface screen {0, 10}, // Logbook {BUTTON_BACK, 20}, {BUTTON_ENTER, 20}, {BUTTON_NEXT, 20}, {BUTTON_NEXT, 20}, {BUTTON_BACK, 0}, {BUTTON_BACK, 5}, {BUTTON_BACK, 0}, // Exit Logbook Mode // surface screen {0, 10}, // activate Configure Deco Gas, go to Gas 2 {BUTTON_NEXT, 0}, // Start Menu {BUTTON_NEXT, 2}, // SIM -> OC {BUTTON_ENTER, 2}, {BUTTON_NEXT, 1}, {BUTTON_ENTER, 0}, {BUTTON_ENTER, 0}, // Mix Decogas 99 -> EAN30 First {BUTTON_BACK, 0}, {BUTTON_BACK, 0}, {BUTTON_BACK, 0}, {BUTTON_BACK, 0}, {BUTTON_BACK, 0}, {BUTTON_BACK, 0}, {BUTTON_ENTER, 0}, {BUTTON_NEXT, 0}, {BUTTON_ENTER, 0}, {BUTTON_ENTER, 0}, {BUTTON_ENTER, 2}, {BUTTON_NEXT, 2}, {BUTTON_ENTER, 5}, {BUTTON_ENTER, 5}, {BUTTON_ENTER, 10}, // Now EAN 30 First {BUTTON_BACK, 0}, // Exit Edit Mode {BUTTON_BACK, 30}, // Exit Cursor Mode /* // OC -> SIM {BUTTON_NEXT, 2}, {BUTTON_NEXT, 2}, {BUTTON_NEXT, 2}, {BUTTON_NEXT, 2}, {BUTTON_NEXT, 1}, {BUTTON_ENTER, 10}, */ // SYS2 Layout {BUTTON_NEXT, 2}, {BUTTON_NEXT, 2}, {BUTTON_NEXT, 2}, {BUTTON_NEXT, 2}, {BUTTON_ENTER, 2}, {BUTTON_NEXT, 2}, {BUTTON_NEXT, 2}, {BUTTON_ENTER, 2}, {BUTTON_NEXT, 2}, {BUTTON_ENTER, 2}, {BUTTON_BACK, 2}, {BUTTON_BACK, 10}, // SYS -> SIM {BUTTON_NEXT, 2}, {BUTTON_ENTER, 10}, // simulator {BUTTON_ENTER, 40}, // Start Simulator {BUTTON_ENTER, 5}, {BUTTON_ENTER, 10}, {BUTTON_ENTER, 10}, {BUTTON_ENTER, 10}, {BUTTON_ENTER, 10}, {BUTTON_ENTER, 10}, {BUTTON_ENTER, 90}, {BUTTON_NEXT, 5}, // Menu? {BUTTON_NEXT, 5}, // Quit? {BUTTON_ENTER, 10}, {BUTTON_ENTER, 50}, // the end, repeat from start {255, 0} }; #endif /* Exported functions --------------------------------------------------------*/ uint8_t demoModeActive(void) { return demoModeActiveStatus; } uint8_t demoGetCommand(void) { if(!demoModeActiveStatus) return 0; uint32_t milliSecondsSinceLast; uint32_t systick_now; systick_now = HAL_GetTick(); milliSecondsSinceLast = time_elapsed_ms(systickDemoMode, systick_now); #ifdef SHOWCCRMODE if((demoModeActual == 1) && (settingsGetPointer()->dive_mode == DIVEMODE_CCR)) demoModeActual = 20; #else if((demoModeActual == 1) && (settingsGetPointer()->dive_mode == DIVEMODE_OC)) demoModeActual = 20; #endif if(demoModeActual > MAXCOMMANDS - 2) demoModeActual = 30; uint32_t actualDelay = ((commandlist[demoModeActual][1]) * 100) + 15; if(milliSecondsSinceLast < actualDelay) return 0; systickDemoMode = systick_now; if(commandlist[demoModeActual][0] == 255) demoModeActual = 30; else demoModeActual++; return commandlist[demoModeActual][0]; } void demoSendCommand(uint8_t action) { demoModeActiveStatus = 0; } void demoConfigureSettings(void) { settingsGetPointer()->gas[1].oxygen_percentage = 21; settingsGetPointer()->gas[1].helium_percentage = 0; settingsGetPointer()->gas[1].depth_meter = 0; settingsGetPointer()->gas[1].note.ub.first = 0; settingsGetPointer()->gas[1].note.ub.active = 0; settingsGetPointer()->gas[1].note.ub.deco = 0; settingsGetPointer()->gas[1].note.ub.travel = 0; settingsGetPointer()->gas[2].oxygen_percentage = 30; settingsGetPointer()->gas[2].helium_percentage = 0; settingsGetPointer()->gas[2].depth_meter = 0; settingsGetPointer()->gas[2].note.ub.first = 1; settingsGetPointer()->gas[2].note.ub.active = 1; settingsGetPointer()->gas[2].note.ub.deco = 0; settingsGetPointer()->gas[2].note.ub.travel = 0; settingsGetPointer()->ButtonResponsiveness[0] = 90; settingsGetPointer()->ButtonResponsiveness[1] = 90; settingsGetPointer()->ButtonResponsiveness[2] = 90; settingsGetPointer()->ButtonResponsiveness[3] = 90; } /* Includes ------------------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ /* Private variables with external access ------------------------------------*/ /* Exported functions --------------------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ #endif // DEMO /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/