Mercurial > public > ostc4
view Discovery/Src/demo.c @ 471:73da921869d9 fix-bat-2
bugfix: implement battery charge percentage in dive header
This commit is (much) less trivial than the related 919e5cb51c92.
First, rename the CCRmode attribute (corresponding to byte Ox59) of
the SLogbookHeaderOSTC3. This byte (according to the hwOS interface
document) does not contain any CCR related value, but it contains
"battery information". Already since 2017, this byte is used from
libdivecomputer to interface the charge percentage. So, its
renamed from CCRmode to batteryCharge, to reflect its true purpose.
Now, simply add a batteryCharge attribute to the SLogbookHeader
(and see below why that is possible, without breaking things).
The remaining changes are trivial to implement battery charge
percentage in dive header.
Caveat: do not get confused by the exact role of the individual
logbook header types. SLogbookHeaderOSTC3 is the formal type of
the logbook format that the OSTC4 produces. This format is
supposed to identical to the format, as is used in hwOS for the
series of small OSTCs. Only some values of attributes are different.
For example, the OSTC4 supports VPM, so byte 0x79 (deco model used
for this dive) also has a value for VPM. But the SLogbookHeader
type, despite its name and structure, is *not* a true logbook
header, as it includes attributes that are not available in the
SLogbookHeaderOSTC3 formal header type.
Signed-off-by: Jan Mulder <jan@jlmulder.nl>
author | Jan Mulder <jlmulder@xs4all.nl> |
---|---|
date | Wed, 22 Apr 2020 13:08:57 +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****/