Mercurial > public > ostc4
changeset 1071:b4a79464caf7 Icon_Integration
Dynamic menu creation for CV views:
Because of the increasing features of the OSTC the maintenance of the the menus becomes difficult. Some are not available because of HW version or connected sensors. To keep the "legacy" menus stable the functionality of the cv options page has been increased. Based on enabled cv views and connected sensors the page will be filled dynamically. The page items allow quick acces to the view related options. For the first implementation the views: compass, timer, sensor O2 and sensor CO2 are supported.
| author | Ideenmodellierer |
|---|---|
| date | Thu, 19 Feb 2026 13:28:37 +0100 |
| parents | 4499227a2db8 |
| children | 8b97003dbb60 |
| files | Discovery/Inc/tMenu.h Discovery/Inc/tMenuCvOption.h Discovery/Inc/tMenuCvOptionText.h Discovery/Inc/tMenuEditCvOption.h Discovery/Src/tMenu.c Discovery/Src/tMenuCvOption.c Discovery/Src/tMenuCvOptionText.c Discovery/Src/tMenuEditCvOption.c |
| diffstat | 8 files changed, 354 insertions(+), 55 deletions(-) [+] |
line wrap: on
line diff
--- a/Discovery/Inc/tMenu.h Thu Feb 19 13:17:25 2026 +0100 +++ b/Discovery/Inc/tMenu.h Thu Feb 19 13:28:37 2026 +0100 @@ -55,6 +55,7 @@ /* Exported constants --------------------------------------------------------*/ #define MAX_PAGE_TEXTSIZE 65 * 6 +#define MAXLINES 6 /* Exported variables --------------------------------------------------------*/
--- a/Discovery/Inc/tMenuCvOption.h Thu Feb 19 13:17:25 2026 +0100 +++ b/Discovery/Inc/tMenuCvOption.h Thu Feb 19 13:28:37 2026 +0100 @@ -35,8 +35,8 @@ /** @addtogroup Template * @{ */ +/* Exported variables --------------------------------------------------------*/ -/* Exported variables --------------------------------------------------------*/ /* Exported functions --------------------------------------------------------*/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Discovery/Inc/tMenuCvOptionText.h Thu Feb 19 13:28:37 2026 +0100 @@ -0,0 +1,64 @@ +/////////////////////////////////////////////////////////////////////////////// +/// -*- coding: UTF-8 -*- +/// +/// \file Discovery/Inc/tMenuCvOption.h +/// \brief Header file text line provider functions +/// \author heinrichs weikamp gmbh +/// \date 03-Feb-2026 +/// +/// $Id$ +/////////////////////////////////////////////////////////////////////////////// +/// \par Copyright (c) 2014-2026 Heinrichs Weikamp gmbh +/// +/// This program is free software: you can redistribute it and/or modify +/// it under the terms of the GNU General Public License as published by +/// the Free Software Foundation, either version 3 of the License, or +/// (at your option) any later version. +/// +/// This program is distributed in the hope that it will be useful, +/// but WITHOUT ANY WARRANTY; without even the implied warranty of +/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +/// GNU General Public License for more details. +/// +/// You should have received a copy of the GNU General Public License +/// along with this program. If not, see <http://www.gnu.org/licenses/>. +////////////////////////////////////////////////////////////////////////////// + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef TMENU_CVOPTIONTEXT_H +#define TMENU_CVOPTIONTEXT_H + +/* Includes ------------------------------------------------------------------*/ +/** @addtogroup Template + * @{ + */ +#include <stdint.h> + +enum CVOPTIONS /* the order defines the priority as well */ +{ + CVOPT_Compass = 0, + CVOPT_O2_Sensor, + CVOPT_CO2_Sensor, + CVOPT_Pressure_Sensor, + CVOPT_Timer, + CVOPT_END +}; + +typedef uint8_t (*refreshFunc_t)(char *); + +/* Exported variables --------------------------------------------------------*/ + + + +/* Exported functions --------------------------------------------------------*/ + +uint8_t tMCvOptText_BuildDynamicContentList(); +refreshFunc_t* tMCvOptText_GetTable(); +uint8_t tMCvOptText_GetTableItemCnt(); + +uint8_t tMCvOptText_refreshCompass(char* pText); +uint8_t tMCvOptText_refreshTimer(char* pText); +uint8_t tMCvOptText_refreshO2(char* pText); +uint8_t tMCvOptText_refreshCO2(char* pText); + +#endif /* TMENU_CVOPTIONTEXT_H */
--- a/Discovery/Inc/tMenuEditCvOption.h Thu Feb 19 13:17:25 2026 +0100 +++ b/Discovery/Inc/tMenuEditCvOption.h Thu Feb 19 13:28:37 2026 +0100 @@ -35,6 +35,10 @@ #include "settings.h" #include "data_central.h" + +typedef void (*openFunc_t)(void); +void tMCvOption_SetOpenFnct(uint8_t cvOptId, uint8_t index); + void openEdit_CvOption(uint8_t line); void refresh_CompassEdit(void); uint32_t tMCvOption_refresh(uint8_t line, char *text, uint16_t *tab, char *subtext);
--- a/Discovery/Src/tMenu.c Thu Feb 19 13:17:25 2026 +0100 +++ b/Discovery/Src/tMenu.c Thu Feb 19 13:28:37 2026 +0100 @@ -42,6 +42,7 @@ #include "tMenuEditSystem.h" #include "tMenuEditXtra.h" #include "tMenuEditCustom.h" +#include "tMenuCvOptionText.h" #include "tMenuEditCvOption.h" #include "tMenuGas.h" #include "tMenuHardware.h" @@ -64,7 +65,6 @@ #define TAB_BAR_SPACING 5 #define SLOW_UPDATE_CNT 10 /* Some content shall not be update in short intervals => add prescalar */ -#define MAXLINES 6 typedef struct { @@ -656,6 +656,7 @@ id = tMCustom_refresh(0, text, &tabPosition, subtext); tM_build_page(id, text, tabPosition, subtext); + tMCvOptText_BuildDynamicContentList(); id = tMCvOption_refresh(0, text, &tabPosition, subtext); tM_build_page(id, text, tabPosition, subtext); } @@ -690,12 +691,20 @@ update_content_with_new_frame(page, text, tabPosition, subtext); } break; - case StMCG: if((actual_menu_content != MENU_SURFACE) && (slowUpdate == 0)) + case StMCG: +#ifndef ENABLE_ADVANCED_GAS + if((actual_menu_content != MENU_SURFACE) && (slowUpdate == 0)) +#else + if(slowUpdate == 0) +#endif { tMCG_refresh(0, text, &tabPosition, subtext); update_content_with_new_frame(page, text, tabPosition, subtext); } break; + case StMOption: tMCvOption_refresh(0, text, &tabPosition, subtext); + update_content_with_new_frame(page, text, tabPosition, subtext); + break; default: break; }
--- a/Discovery/Src/tMenuCvOption.c Thu Feb 19 13:17:25 2026 +0100 +++ b/Discovery/Src/tMenuCvOption.c Thu Feb 19 13:28:37 2026 +0100 @@ -29,6 +29,7 @@ /* Includes ------------------------------------------------------------------*/ #include "tMenu.h" #include "tMenuCvOption.h" +#include "tMenuCvOptionText.h" #include "tHome.h" // for enum CUSTOMVIEWS and init_t7_compass() #include "t7.h" @@ -36,54 +37,31 @@ /* Exported functions --------------------------------------------------------*/ + uint32_t tMCvOption_refresh(uint8_t line, char *text, uint16_t *tab, char *subtext) { - SSettings *data; uint8_t textPointer; - - data = settingsGetPointer(); + refreshFunc_t* pRefreshTable; + uint8_t activeLines; + uint8_t index = 0; textPointer = 0; - *tab = 300; + *tab = 450; *subtext = 0; resetLineMask(StMOption); - if((line == 0) || (line == 1)) - { - text[textPointer++] = TXT_2BYTE; - text[textPointer++] = TXT2BYTE_Compass; - text[textPointer++] = '\t'; + activeLines = tMCvOptText_GetTableItemCnt(); + pRefreshTable = tMCvOptText_GetTable(); - if(settingsGetPointer()->compassBearing != 0) - { - textPointer += snprintf(&text[textPointer], 20, "(%03u`)", settingsGetPointer()->compassBearing % 360); - } - text[textPointer] = 0; - } - nextline(text,&textPointer); - if (line == 0 || line == 2) - { - if(t7_customview_disabled(CVIEW_Timer)) - { - text[textPointer++] = '\031'; /* change text color */ - textPointer += snprintf(&text[textPointer], 21, "%c%c\t%u:%02u \016\016[m:ss]\017", TXT_2BYTE, TXT2BYTE_Timer, data->timerDurationS / 60, data->timerDurationS % 60); - text[textPointer++] = '\020'; /* restore text color */ - } - else - { - textPointer += snprintf(&text[textPointer], 21, "%c%c\t%u:%02u \016\016[m:ss]\017", TXT_2BYTE, TXT2BYTE_Timer, data->timerDurationS / 60, data->timerDurationS % 60); - } - } - nextline(text,&textPointer); - -#ifdef ENABLE_PULSE_SENSOR_BT - if (line == 0 || line == 3) - { - textPointer += snprintf(&text[textPointer], 21, "%c%c", TXT_2BYTE, TXT2BYTE_Pulse); - } - nextline(text,&textPointer); - -#endif + for(index = 1; index <= activeLines; index++) + { + if((line == 0) || (index == line)) + { + textPointer += pRefreshTable[index - 1](&text[textPointer]); + } + nextline(text,&textPointer); + } + text[textPointer] = 0; return StMOption; }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Discovery/Src/tMenuCvOptionText.c Thu Feb 19 13:28:37 2026 +0100 @@ -0,0 +1,231 @@ +/////////////////////////////////////////////////////////////////////////////// +/// -*- coding: UTF-8 -*- +/// +/// \file Discovery/Src/tMenuCvOptionText.c +/// \brief File providing functions for generation of text lines +/// \author heinrichs weikamp gmbh +/// \date 03-Feb-2026 +/// +/// \details +/// +/// $Id$ +/////////////////////////////////////////////////////////////////////////////// +/// \par Copyright (c) 2014-2025 Heinrichs Weikamp gmbh +/// +/// This program is free software: you can redistribute it and/or modify +/// it under the terms of the GNU General Public License as published by +/// the Free Software Foundation, either version 3 of the License, or +/// (at your option) any later version. +/// +/// This program is distributed in the hope that it will be useful, +/// but WITHOUT ANY WARRANTY; without even the implied warranty of +/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +/// GNU General Public License for more details. +/// +/// You should have received a copy of the GNU General Public License +/// along with this program. If not, see <http://www.gnu.org/licenses/>. +////////////////////////////////////////////////////////////////////////////// + +/* Includes ------------------------------------------------------------------*/ +#include "tMenuCvOptionText.h" +#include "tMenuEditCvOption.h" +#include "tMenu.h" +#include "tHome.h" // for enum CUSTOMVIEWS and init_t7_compass() +#include "t3.h" +#include "t7.h" + +/* Private function prototypes -----------------------------------------------*/ + +/* Exported functions --------------------------------------------------------*/ + + +static refreshFunc_t refreshFctPointerTable[MAXLINES]; /* function pointer for refresh */ +static uint8_t activeLines = 0; /* number of active lines */ + +refreshFunc_t* tMCvOptText_GetTable() +{ + return refreshFctPointerTable; +} +uint8_t tMCvOptText_GetTableItemCnt() +{ + return activeLines; +} + +uint8_t tMCvOptText_refreshCompass(char* pText) +{ + uint8_t textPointer = 0; + pText[textPointer++] = TXT_2BYTE; + pText[textPointer++] = TXT2BYTE_Compass; + pText[textPointer++] = '\t'; + + if(settingsGetPointer()->compassBearing != 0) + { + textPointer += snprintf(&pText[textPointer], 20, "(%03u`)", settingsGetPointer()->compassBearing % 360); + } + pText[textPointer] = 0; + return strlen(pText); +} + +uint8_t tMCvOptText_refreshTimer(char* pText) +{ + SSettings *settings = settingsGetPointer(); + snprintf(pText, 21, "%c%c\t%u:%02u \016\016[m:ss]\017", TXT_2BYTE, TXT2BYTE_Timer, settings->timerDurationS / 60, settings->timerDurationS % 60); + return strlen(pText); +} + +uint8_t tMCvOptText_refreshO2(char* pText) +{ + char sensorStatusColor[3]; + uint8_t textPointer = 0; + SSettings *pSettings = settingsGetPointer(); + + + pText[textPointer++] = TXT_2BYTE; + pText[textPointer++] = TXT2BYTE_Sensor; + + textPointer += snprintf(&pText[textPointer],20,"O2 %c%c",TXT_2BYTE,TXT2BYTE_Sensor); + + if((stateUsed->lifeData.ppO2Sensor_bar[0] != 0) || (stateUsed->lifeData.ppO2Sensor_bar[1] != 0) || (stateUsed->lifeData.ppO2Sensor_bar[2] != 0)) + { + pText[textPointer++] = '\t'; + sensorStatusColor[0] = '\020'; + sensorStatusColor[1] = '\020'; + sensorStatusColor[2] = '\020'; + + /* Warning */ + if(stateUsed->warnings.sensorOutOfBounds) sensorStatusColor[0] = '\024'; + if(stateUsed->warnings.sensorOutOfBounds) sensorStatusColor[1] = '\024'; + if(stateUsed->warnings.sensorOutOfBounds) sensorStatusColor[2] = '\024'; + /* Grey out */ + if(stateUsed->diveSettings.ppo2sensors_deactivated & 1) sensorStatusColor[0] = '\031'; + if(stateUsed->diveSettings.ppo2sensors_deactivated & 2) sensorStatusColor[1] = '\031'; + if(stateUsed->diveSettings.ppo2sensors_deactivated & 4) sensorStatusColor[2] = '\031'; + + if((pSettings->ext_sensor_map[0] == SENSOR_ANALOG) || (pSettings->ext_sensor_map[0] == SENSOR_DIGO2M) || (pSettings->ext_sensor_map[0] == SENSOR_SENTINELM)) + { + textPointer += snprintf(&pText[textPointer],20,"%c%01.1f \020\007",sensorStatusColor[0], stateUsed->lifeData.ppO2Sensor_bar[0]); + } + if((pSettings->ext_sensor_map[1] == SENSOR_ANALOG) || (pSettings->ext_sensor_map[1] == SENSOR_DIGO2M) || (pSettings->ext_sensor_map[1] == SENSOR_SENTINELM)) + { + textPointer += snprintf(&pText[textPointer],20,"%c%01.1f \020\007",sensorStatusColor[1], stateUsed->lifeData.ppO2Sensor_bar[1]); + } + if((pSettings->ext_sensor_map[2] == SENSOR_ANALOG) || (pSettings->ext_sensor_map[2] == SENSOR_DIGO2M) || (pSettings->ext_sensor_map[2] == SENSOR_SENTINELM)) + { + textPointer += snprintf(&pText[textPointer],20,"%c%01.1f",sensorStatusColor[2], stateUsed->lifeData.ppO2Sensor_bar[2]); + } + } + pText[textPointer++] = '\020'; + pText[textPointer] = 0; + return strlen(pText); +} + +uint8_t tMCvOptText_refreshCO2(char* pText) +{ + char sensorStatusColor; + uint8_t textPointer = 0; + SSettings *pSettings = settingsGetPointer(); + + + pText[textPointer++] = TXT_2BYTE; + pText[textPointer++] = TXT2BYTE_Sensor; + + textPointer += snprintf(&pText[textPointer],20,"CO2 %c%c",TXT_2BYTE,TXT2BYTE_Sensor); + + + pText[textPointer++] = '\t'; + sensorStatusColor = '\020'; + + /* Warning */ + if(stateUsed->warnings.co2High) sensorStatusColor = '\024'; + /* Grey out */ + if(pSettings->co2_sensor_active == 0) sensorStatusColor = '\031'; + + textPointer += snprintf(&pText[textPointer],20,"%c%ld \020\007",sensorStatusColor, stateUsed->lifeData.CO2_data.CO2_ppm); + + pText[textPointer++] = '\020'; + pText[textPointer] = 0; + return strlen(pText); +} + + +uint8_t tMCvOptText_BuildDynamicContentList() +{ + uint8_t cvOptIndex = 0; + uint8_t CvOptAvailable = 0; + uint8_t index = 0; + uint8_t SensorActive[SENSOR_END]; + SSettings *settings = settingsGetPointer(); + + memset(SensorActive, 0, sizeof(SensorActive)); + + + for (index = 0; index < EXT_INTERFACE_SENSOR_CNT; index++) + { + switch(settings->ext_sensor_map[index]) + { + case SENSOR_ANALOG: SensorActive[SENSOR_ANALOG] = 1; + break; + case SENSOR_SENTINEL: + case SENSOR_DIGO2M: SensorActive[SENSOR_DIGO2] = 1; + break; + case SENSOR_CO2: SensorActive[SENSOR_CO2] = 1; + break; +#if defined ENABLE_GNSS_INTERNAL || defined ENABLE_GNSS_EXTERN + case SENSOR_GNSS: SensorActive[SENSOR_GNSS] = 1; + break; +#endif + default: + break; + } + } + + do + { + CvOptAvailable = 0; + switch(cvOptIndex) + { + case CVOPT_Compass: if((!t3_customview_disabled(CVIEW_T3_Compass)) || (!t3_customview_disabled(CVIEW_T3_Navigation)) || (!t7_customview_disabled(CVIEW_Compass))) + { + refreshFctPointerTable[activeLines] = tMCvOptText_refreshCompass; + CvOptAvailable = 1; + } + break; + case CVOPT_Timer: if(!t7_customview_disabled(CVIEW_Timer)) + { + refreshFctPointerTable[activeLines] = tMCvOptText_refreshTimer; + CvOptAvailable = 1; + } + break; + case CVOPT_O2_Sensor: if((SensorActive[SENSOR_ANALOG]) || (SensorActive[SENSOR_DIGO2])) + { + refreshFctPointerTable[activeLines] = tMCvOptText_refreshO2; + CvOptAvailable = 1; + } + break; + case CVOPT_CO2_Sensor: if(SensorActive[SENSOR_CO2]) + { + refreshFctPointerTable[activeLines] = tMCvOptText_refreshCO2; + CvOptAvailable = 1; + } + break; + default: + break; + } + if(CvOptAvailable) + { + tMCvOption_SetOpenFnct(cvOptIndex,activeLines); + activeLines++; + } + cvOptIndex++; + } while((activeLines < MAXLINES) && (cvOptIndex != CVOPT_END)); + + for(index = activeLines; index < MAXLINES; index++) /* delete pointers not in use */ + { + tMCvOption_SetOpenFnct(CVOPT_END, index); + } + + return activeLines; +} + + +/* Private functions ---------------------------------------------------------*/
--- a/Discovery/Src/tMenuEditCvOption.c Thu Feb 19 13:17:25 2026 +0100 +++ b/Discovery/Src/tMenuEditCvOption.c Thu Feb 19 13:28:37 2026 +0100 @@ -28,6 +28,7 @@ /* Includes ------------------------------------------------------------------*/ #include "tMenuEditCvOption.h" +#include "tMenuCvOptionText.h" #include "tMenuEdit.h" #include "gfx_fonts.h" @@ -37,6 +38,9 @@ #include "cv_heartbeat.h" + +static openFunc_t openFctPointerTable[MAXLINES]; /* function pointer for refresh */ + /* Private function prototypes -----------------------------------------------*/ static void openEdit_Timer(void); void openEdit_Compass(void); @@ -51,22 +55,30 @@ /* Exported functions --------------------------------------------------------*/ + +void tMCvOption_SetOpenFnct(uint8_t cvOptId, uint8_t index) +{ + if(index < MAXLINES) + { + switch(cvOptId) + { + case CVOPT_Compass: openFctPointerTable[index] = openEdit_Compass; + break; + case CVOPT_Timer: openFctPointerTable[index] = openEdit_Timer; + break; + case CVOPT_END: openFctPointerTable[index] = NULL; + break; + default: break; + } + } +} + + void openEdit_CvOption(uint8_t line) { - set_globalState_Menu_Line(line); - - switch(line) + if(openFctPointerTable[line - 1] != NULL) { - case 1: - default: resetMenuEdit(CLUT_MenuPageHardware); - openEdit_Compass(); - break; - case 2: openEdit_Timer(); - break; -#ifdef ENABLE_PULSE_SENSOR_BT - case 3: openEdit_Heartbeat(); -#endif - break; + openFctPointerTable[line - 1](); } }
