changeset 562:ec76fa85009e

Added ADC sensor interface to O2 sensore menu structure: Based on the availability of an external ADC (Old / new HW) the interface to the O2 sensors may now be choosen between classic optical and the new analog. Depending on the selection HUB Battery or a button for sensor calibration will be shown.
author Ideenmodellierer
date Sun, 15 Nov 2020 19:58:14 +0100
parents e581425c7e3e
children d97f0e395058
files Discovery/Inc/tStructure.h Discovery/Inc/text_multilanguage.h Discovery/Src/tMenuEdit.c Discovery/Src/tMenuEditHardware.c Discovery/Src/text_multilanguage.c
diffstat 5 files changed, 146 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/Discovery/Inc/tStructure.h	Sun Nov 15 19:54:36 2020 +0100
+++ b/Discovery/Inc/tStructure.h	Sun Nov 15 19:58:14 2020 +0100
@@ -246,6 +246,8 @@
 #define StMHARD3_O2_Sensor2			_MB(2,7,3,2,0)
 #define StMHARD3_O2_Sensor3			_MB(2,7,3,3,0)
 #define StMHARD3_O2_Fallback		_MB(2,7,3,4,0)
+#define StMHARD3_O2_Calibrate		_MB(2,7,3,5,0)
+#define StMHARD3_O2_Source			_MB(2,7,3,6,0)
 
 #define StMHARD4_BrightnessEco	_MB(2,7,4,1,0)
 #define StMHARD4_BrightnessStd	_MB(2,7,4,2,0)
--- a/Discovery/Inc/text_multilanguage.h	Sun Nov 15 19:54:36 2020 +0100
+++ b/Discovery/Inc/text_multilanguage.h	Sun Nov 15 19:58:14 2020 +0100
@@ -268,6 +268,10 @@
 		TXT2BYTE_SetToMOD,
 		/* */
 		TXT2BYTE_HUDbattery,
+		TXT2BYTE_O2CalibAir,
+		TXT2BYTE_O2Interface,
+		TXT2BYTE_O2IFOptic,
+		TXT2BYTE_O2IFAnalog,
 		TXT2BYTE_LowerIsLess,
 		TXT2BYTE_DiveMenuQ,
 		TXT2BYTE_DiveQuitQ,
--- a/Discovery/Src/tMenuEdit.c	Sun Nov 15 19:54:36 2020 +0100
+++ b/Discovery/Src/tMenuEdit.c	Sun Nov 15 19:58:14 2020 +0100
@@ -205,7 +205,8 @@
 
 	 switch(globState)
 	 {
-	 	 case (StMHARD3_O2_Sensor1 & MaskFieldDigit): refreshFct = refresh_O2Sensors;
+	 	 case (StMHARD3_O2_Sensor1 & MaskFieldDigit):
+	 	 case (StMHARD3_O2_Source):						 refreshFct = refresh_O2Sensors;
 	 	 	 break;
 	 	 case (StMHARD2_Compass_SetCourse & MaskFieldDigit): refreshFct = refresh_CompassEdit;
 	 	 	 break;
--- a/Discovery/Src/tMenuEditHardware.c	Sun Nov 15 19:54:36 2020 +0100
+++ b/Discovery/Src/tMenuEditHardware.c	Sun Nov 15 19:58:14 2020 +0100
@@ -38,6 +38,7 @@
 #include "tInfo.h"
 #include "tInfoLog.h"
 #include "tComm.h"
+#include "data_exchange_main.h"
 
 extern void tM_build_pages(void);
 
@@ -60,12 +61,18 @@
 uint8_t OnAction_Sensor2		(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
 uint8_t OnAction_Sensor3		(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
 uint8_t OnAction_O2_Fallback	(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
+uint8_t OnAction_O2_Calibrate   (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
+uint8_t OnAction_O2_Source		(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
 uint8_t OnAction_Button			(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
 uint8_t OnAction_ButtonBalance	(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
 // nicht notwending uint8_t OnAction_Bluetooth				(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
 
 /* Exported functions --------------------------------------------------------*/
 
+
+#define O2_CALIB_FRACTION_AIR	(0.209F)
+
+
 void openEdit_Hardware(uint8_t line)
 {
     set_globalState_Menu_Line(line);
@@ -267,9 +274,11 @@
 
 void refresh_O2Sensors(void)
 {
-    char text[16];
+    char text[32];
     uint16_t y_line;
 
+    const SDiveState *pStateReal = stateRealGetPointer();
+
     text[0] = '\001';
     text[1] = TXT_o2Sensors;
     text[2] = 0;
@@ -287,22 +296,49 @@
     text[3] = '3';
     write_label_var(  96, 340, ME_Y_LINE3, &FontT48, text);
 
-    text[0] = TXT_2BYTE;
-    text[1] = TXT2BYTE_HUDbattery;
-    text[2] = 0;
-    write_label_var(  30, 340, ME_Y_LINE4, &FontT48, text);
-//	write_label_var(  30, 340, ME_Y_LINE4, &FontT48, "HUD Battery");
+    if(settingsGetPointer()->ppo2sensors_source == O2_SENSOR_SOURCE_OPTIC)
+    {
+		text[0] = TXT_2BYTE;
+		text[1] = TXT2BYTE_HUDbattery;
+		text[2] = 0;
+		write_label_var(  30, 340, ME_Y_LINE4, &FontT48, text);
+
 
-    for(int i=0;i<3;i++)
+		snprintf(text, 20,"%01.3fV", get_HUD_battery_voltage_V());
+		write_label_var(  400, 800, ME_Y_LINE4, &FontT48, text);
+    }
+    else
     {
-        snprintf(text, 20,"%01.2f, %01.1fmV",get_ppO2Sensor_bar(i),get_sensorVoltage_mV(i));
-        y_line = ME_Y_LINE1 + (i * ME_Y_LINE_STEP);
-        write_label_var(  400, 800, y_line, &FontT48, text);
+    	text[0] = TXT_2BYTE;
+    	text[1] = TXT2BYTE_O2CalibAir;
+    	text[2] = 0;
+    	write_label_var(  30, 340, ME_Y_LINE4, &FontT48, text);
     }
 
-    snprintf(text, 20,"%01.3fV", get_HUD_battery_voltage_V());
-    write_label_var(  400, 800, ME_Y_LINE4, &FontT48, text);
+	for(int i=0;i<3;i++)
+	{
+		snprintf(text, 20,"%01.2f, %01.1fmV",  pStateReal->lifeData.ppO2Sensor_bar[i], pStateReal->lifeData.sensorVoltage_mV[i]);
+		y_line = ME_Y_LINE1 + (i * ME_Y_LINE_STEP);
+		write_label_var(  400, 800, y_line, &FontT48, text);
+	}
 
+    if(DataEX_external_ADC_Present())
+    {
+		text[0] = TXT_2BYTE;
+		text[1] = TXT2BYTE_O2Interface;
+		text[2] = 0;
+		write_label_var(  30, 340, ME_Y_LINE6, &FontT48, text);
+		text[0] = TXT_2BYTE;
+		switch(settingsGetPointer()->ppo2sensors_source)
+		{
+			default:
+			case O2_SENSOR_SOURCE_OPTIC: text[1] = TXT2BYTE_O2IFOptic;
+				break;
+			case O2_SENSOR_SOURCE_ANALOG: text[1] = TXT2BYTE_O2IFAnalog;
+		}
+		text[2] = 0;
+		write_label_var(  400, 800, ME_Y_LINE6, &FontT48, text);
+    }
     tMenuEdit_refresh_field(StMHARD3_O2_Sensor1);
     tMenuEdit_refresh_field(StMHARD3_O2_Sensor2);
     tMenuEdit_refresh_field(StMHARD3_O2_Sensor3);
@@ -331,14 +367,33 @@
     write_field_on_off(StMHARD3_O2_Sensor2,	 30, 95, ME_Y_LINE2,  &FontT48, "", sensorActive[1]);
     write_field_on_off(StMHARD3_O2_Sensor3,	 30, 95, ME_Y_LINE3,  &FontT48, "", sensorActive[2]);
 
+    if(settingsGetPointer()->ppo2sensors_source == O2_SENSOR_SOURCE_ANALOG)
+    {
+    	write_field_button(StMHARD3_O2_Calibrate,	 30, 800, ME_Y_LINE4,  &FontT48, "");
+    }
+
     text[0] = TXT_Fallback;
     text[1] = 1;
+
     write_field_on_off(StMHARD3_O2_Fallback,	 30, 500, ME_Y_LINE5,  &FontT48, text, settingsGetPointer()->fallbackToFixedSetpoint);
 
+    if(DataEX_external_ADC_Present())
+    {
+    	write_field_button(StMHARD3_O2_Source,	 30, 800, ME_Y_LINE6,  &FontT48, "");
+    }
+
     setEvent(StMHARD3_O2_Sensor1, (uint32_t)OnAction_Sensor1);
     setEvent(StMHARD3_O2_Sensor2, (uint32_t)OnAction_Sensor2);
     setEvent(StMHARD3_O2_Sensor3, (uint32_t)OnAction_Sensor3);
+    if(settingsGetPointer()->ppo2sensors_source == O2_SENSOR_SOURCE_ANALOG)
+    {
+    	setEvent(StMHARD3_O2_Calibrate, (uint32_t)OnAction_O2_Calibrate);
+    }
     setEvent(StMHARD3_O2_Fallback, (uint32_t)OnAction_O2_Fallback);
+    if(DataEX_external_ADC_Present())
+    {
+    	setEvent(StMHARD3_O2_Source, (uint32_t)OnAction_O2_Source);
+    }
 
     write_buttonTextline(TXT2BYTE_ButtonBack,TXT2BYTE_ButtonEnter,TXT2BYTE_ButtonNext);
 }
@@ -408,7 +463,50 @@
     tMenuEdit_set_on_off(editId, fallback);
     return UPDATE_DIVESETTINGS;
 }
+uint8_t OnAction_O2_Calibrate (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
+{
+	uint8_t loop;
+	const SDiveState *pStateReal = stateRealGetPointer();
+	SSettings* pSettings = settingsGetPointer();
 
+	for(loop=0;loop<3;loop++)
+	{
+		if((pSettings->ppo2sensors_deactivated & (0x1 << loop)) == 0)
+		{
+			if(pStateReal->lifeData.sensorVoltage_mV[loop] > 0.0001)		/* sensor connected ?*/
+			{
+				pSettings->ppo2sensors_calibCoeff[loop] = O2_CALIB_FRACTION_AIR / pStateReal->lifeData.sensorVoltage_mV[loop];
+			}
+			else
+			{
+				pSettings->ppo2sensors_calibCoeff[loop] = 0.0;
+				settingsGetPointer()->ppo2sensors_deactivated |= 0x1 << loop;
+				tMenuEdit_set_on_off(editId, 0);
+			}
+		}
+	}
+
+	return UPDATE_DIVESETTINGS;
+}
+uint8_t OnAction_O2_Source	(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
+{
+    uint8_t source = settingsGetPointer()->ppo2sensors_source;
+
+    if(source == O2_SENSOR_SOURCE_OPTIC)
+    {
+    	source = O2_SENSOR_SOURCE_ANALOG;
+    }
+    else
+    {
+    	source = O2_SENSOR_SOURCE_OPTIC;
+    }
+
+    settingsGetPointer()->ppo2sensors_source = source;
+
+    resetMenuEdit(CLUT_MenuPageHardware); 	/* rebuild menu structure (Hide HUD <=> Show Calibrate) */
+    openEdit_O2Sensors();
+    return UPDATE_DIVESETTINGS;
+}
 
 void openEdit_Brightness(void)
 {
--- a/Discovery/Src/text_multilanguage.c	Sun Nov 15 19:54:36 2020 +0100
+++ b/Discovery/Src/text_multilanguage.c	Sun Nov 15 19:58:14 2020 +0100
@@ -1235,6 +1235,30 @@
 static uint8_t text_IT_HUDBattery[] = "Batteria HUD";
 static uint8_t text_ES_HUDBattery[] = "Carga del HUD";
 
+static uint8_t text_EN_O2CalibAir[] = "Calibrate Air";
+static uint8_t text_DE_O2CalibAir[] = "Kalibrierung Luft";
+static uint8_t text_FR_O2CalibAir[] = "";
+static uint8_t text_IT_O2CalibAir[] = "";
+static uint8_t text_ES_O2CalibAir[] = "";
+
+static uint8_t text_EN_O2Interface[] = "O2 Interface";
+static uint8_t text_DE_O2Interface[] = "O2 Interface";
+static uint8_t text_FR_O2Interface[] = "";
+static uint8_t text_IT_O2Interface[] = "";
+static uint8_t text_ES_O2Interface[] = "";
+
+static uint8_t text_EN_O2IFOptic[] = "optical";
+static uint8_t text_DE_O2IFOptic[] = "optisch";
+static uint8_t text_FR_O2IFOptic[] = "";
+static uint8_t text_IT_O2IFOptic[] = "";
+static uint8_t text_ES_O2IFOptic[] = "";
+
+static uint8_t text_EN_O2IFAnalog[] = "analog";
+static uint8_t text_DE_O2IFAnalog[] = "analog";
+static uint8_t text_FR_O2IFAnalog[] = "";
+static uint8_t text_IT_O2IFAnalog[] = "";
+static uint8_t text_ES_O2IFAnalog[] = "";
+
 // Menu SYS1 sub (buttons)
 static uint8_t text_EN_LowerIsLess[] = "Lower is less sensitive";
 static uint8_t text_DE_LowerIsLess[] = "Niedriger ist schwergängiger";
@@ -1820,6 +1844,10 @@
     {(uint8_t)TXT2BYTE_CornerStandard,  {text_EN_CornerStandard, text_DE_CornerStandard, text_FR_CornerStandard, text_IT_CornerStandard, text_ES_CornerStandard}},
     {(uint8_t)TXT2BYTE_SetToMOD,		{text_EN_SetToMOD, text_DE_SetToMOD, text_FR_SetToMOD, text_IT_SetToMOD, text_ES_SetToMOD}},
     {(uint8_t)TXT2BYTE_HUDbattery,		{text_EN_HUDBattery, text_DE_HUDBattery, text_FR_HUDBattery, text_IT_HUDBattery, text_ES_HUDBattery}},
+	{(uint8_t)TXT2BYTE_O2CalibAir,		{text_EN_O2CalibAir, text_DE_O2CalibAir, text_FR_O2CalibAir, text_IT_O2CalibAir, text_ES_O2CalibAir}},
+	{(uint8_t)TXT2BYTE_O2Interface,		{text_EN_O2Interface, text_DE_O2Interface, text_FR_O2Interface, text_IT_O2Interface, text_ES_O2Interface}},
+	{(uint8_t)TXT2BYTE_O2IFOptic,		{text_EN_O2IFOptic, text_DE_O2IFOptic, text_FR_O2IFOptic, text_IT_O2IFOptic, text_ES_O2IFOptic}},
+	{(uint8_t)TXT2BYTE_O2IFAnalog,		{text_EN_O2IFAnalog, text_DE_O2IFAnalog, text_FR_O2IFAnalog, text_IT_O2IFAnalog, text_ES_O2IFAnalog}},
     {(uint8_t)TXT2BYTE_LowerIsLess,		{text_EN_LowerIsLess, text_DE_LowerIsLess, text_FR_LowerIsLess, text_IT_LowerIsLess, text_ES_LowerIsLess}},
     {(uint8_t)TXT2BYTE_DiveMenuQ,		{text_EN_DiveMenuQ, text_DE_DiveMenuQ, text_FR_DiveMenuQ, text_IT_DiveMenuQ, text_ES_DiveMenuQ}},
     {(uint8_t)TXT2BYTE_DiveQuitQ,		{text_EN_DiveQuitQ, text_DE_DiveQuitQ, text_FR_DiveQuitQ, text_IT_DiveQuitQ, text_ES_DiveQuitQ}},