changeset 786:19ab6f3ed52a

Cleanup sensor data interface: In a very early implementation of the multiplexer the address of the mux was 0 followed by the sensors. As a resul the ID of the channels was shifted by one. To avoid confusion and because the mux address is meanwhile changed to the last address, it makes sense to return to the indexing where only the three visible sensor slots are used as reference (0,1,2).
author Ideenmodellierer
date Sun, 04 Jun 2023 21:54:24 +0200
parents 3c0b16473af4
children aeb72882f30a
files Discovery/Src/data_exchange_main.c Discovery/Src/tInfoSensor.c Discovery/Src/tMenuEdit.c Small_CPU/Inc/externalInterface.h Small_CPU/Src/externalInterface.c Small_CPU/Src/scheduler.c
diffstat 6 files changed, 43 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/Discovery/Src/data_exchange_main.c	Wed May 31 08:44:07 2023 +0200
+++ b/Discovery/Src/data_exchange_main.c	Sun Jun 04 21:54:24 2023 +0200
@@ -994,10 +994,10 @@
 	{
 
 		pStateReal->lifeData.extIf_sensor_Id = dataIn.data[(dataIn.boolADCO2Data && DATA_BUFFER_ADC)].externalInterface_SensorID;
-		if((pStateReal->lifeData.extIf_sensor_Id != 0) && (pStateReal->lifeData.extIf_sensor_Id <= 3))
+		if(pStateReal->lifeData.extIf_sensor_Id < 3)
 		{
 
-			memcpy(pStateReal->lifeData.extIf_sensor_data[pStateReal->lifeData.extIf_sensor_Id-1], dataIn.data[(dataIn.boolADCO2Data && DATA_BUFFER_ADC)].sensor_data, 32);
+			memcpy(pStateReal->lifeData.extIf_sensor_data[pStateReal->lifeData.extIf_sensor_Id], dataIn.data[(dataIn.boolADCO2Data && DATA_BUFFER_ADC)].sensor_data, 32);
 		}
 		memcpy(pStateReal->lifeData.extIf_sensor_map, dataIn.data[(dataIn.boolADCO2Data && DATA_BUFFER_ADC)].sensor_map, EXT_INTERFACE_SENSOR_CNT);
 
--- a/Discovery/Src/tInfoSensor.c	Wed May 31 08:44:07 2023 +0200
+++ b/Discovery/Src/tInfoSensor.c	Sun Jun 04 21:54:24 2023 +0200
@@ -52,17 +52,17 @@
     set_globalState(StISENINFO);
     switch (activeSensorId)
     {
-    	case 3: setBackMenu((uint32_t)openEdit_O2Sensors,0,3);
+    	case 2: setBackMenu((uint32_t)openEdit_O2Sensors,0,3);
     		break;
-    	case 2: setBackMenu((uint32_t)openEdit_O2Sensors,0,2);
+    	case 1: setBackMenu((uint32_t)openEdit_O2Sensors,0,2);
     	    		break;
     	default:
-    	case 1: setBackMenu((uint32_t)openEdit_O2Sensors,0,1);
+    	case 0: setBackMenu((uint32_t)openEdit_O2Sensors,0,1);
     	    		break;
     }
 
     sensorActive = 1;
-    if(pSettings->ppo2sensors_deactivated & (1 << (activeSensorId - 1)))
+    if(pSettings->ppo2sensors_deactivated & (1 << (activeSensorId)))
     {
     	sensorActive = 0;
     }
@@ -71,14 +71,14 @@
 
 uint8_t OnAction_Sensor(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
 {
-	if(settingsGetPointer()->ppo2sensors_deactivated & (1 << (activeSensorId - 1)))
+	if(settingsGetPointer()->ppo2sensors_deactivated & (1 << (activeSensorId)))
 	{
-		settingsGetPointer()->ppo2sensors_deactivated &= ~(1 << (activeSensorId - 1));
+		settingsGetPointer()->ppo2sensors_deactivated &= ~(1 << (activeSensorId));
 		tMenuEdit_set_on_off(editId, 1);
 	}
 	else
 	{
-		settingsGetPointer()->ppo2sensors_deactivated |= (1 << (activeSensorId - 1));
+		settingsGetPointer()->ppo2sensors_deactivated |= (1 << (activeSensorId));
 		tMenuEdit_set_on_off(editId, 0);
 	}
     return UPDATE_DIVESETTINGS;
@@ -155,11 +155,11 @@
 	text[2] = ' ';
 	text[3] = TXT_Information;
 	text[4] = ' ';
-	text[5] = '0' + activeSensorId;
+	text[5] = '1' + activeSensorId;
 	text[6] = 0;
 	tInfo_write_content_simple(  30, 340, ME_Y_LINE_BASE, &FontT48, text, CLUT_MenuPageHardware);
 
-    pDiveO2Data = (SSensorDataDiveO2*)&stateRealGetPointer()->lifeData.extIf_sensor_data[activeSensorId-1];
+    pDiveO2Data = (SSensorDataDiveO2*)&stateRealGetPointer()->lifeData.extIf_sensor_data[activeSensorId];
 
     strIndex = snprintf(text,32,"ID: ");
     if(pDiveO2Data->sensorId != 0)
@@ -201,9 +201,9 @@
     *textPointer++ = ' ';
     *textPointer++ = TXT_2BYTE;
     *textPointer++ = TXT2BYTE_O2IFDigital;
-    *textPointer++ = '0' + activeSensorId;
+    *textPointer++ = '1' + activeSensorId;
 
-    snprintf(textPointer, 20,": %01.2f, %01.1f mV",  pStateReal->lifeData.ppO2Sensor_bar[activeSensorId - 1], pStateReal->lifeData.sensorVoltage_mV[activeSensorId - 1]);
+    snprintf(textPointer, 20,": %01.2f, %01.1f mV",  pStateReal->lifeData.ppO2Sensor_bar[activeSensorId], pStateReal->lifeData.sensorVoltage_mV[activeSensorId]);
 
     tInfo_write_content_simple(  30, 340, ME_Y_LINE6, &FontT48, text, CLUT_Font020);
 
@@ -218,14 +218,14 @@
     		exitMenuEdit_to_BackMenu();
     			break;
 
-    	case ACTION_BUTTON_ENTER:    	if(settingsGetPointer()->ppo2sensors_deactivated & (1 << (activeSensorId - 1)))
+    	case ACTION_BUTTON_ENTER:    	if(settingsGetPointer()->ppo2sensors_deactivated & (1 << (activeSensorId)))
 										{
-    										settingsGetPointer()->ppo2sensors_deactivated &= ~(uint8_t)(1 << (activeSensorId - 1));
+    										settingsGetPointer()->ppo2sensors_deactivated &= ~(uint8_t)(1 << (activeSensorId));
 											sensorActive = 1;
 										}
 										else
 										{
-											settingsGetPointer()->ppo2sensors_deactivated |= (uint8_t)(1 << (activeSensorId - 1));
+											settingsGetPointer()->ppo2sensors_deactivated |= (uint8_t)(1 << (activeSensorId));
 											sensorActive = 0;
 										}
     		break;
--- a/Discovery/Src/tMenuEdit.c	Wed May 31 08:44:07 2023 +0200
+++ b/Discovery/Src/tMenuEdit.c	Sun Jun 04 21:54:24 2023 +0200
@@ -352,12 +352,12 @@
     exitMenuEdit(1);
 	switch(globState)
 	{
-	 	 case (StMHARD3_O2_Sensor3): openInfo_Sensor(3);
+	 	 case (StMHARD3_O2_Sensor3): openInfo_Sensor(2);
 			break;
-	 	 case (StMHARD3_O2_Sensor2): openInfo_Sensor(2);
+	 	 case (StMHARD3_O2_Sensor2): openInfo_Sensor(1);
 	 	 	 break;
 	 	 default:
-	 	 case (StMHARD3_O2_Sensor1): openInfo_Sensor(1);
+	 	 case (StMHARD3_O2_Sensor1): openInfo_Sensor(0);
 	 	 	 break;
 	}
 }
--- a/Small_CPU/Inc/externalInterface.h	Wed May 31 08:44:07 2023 +0200
+++ b/Small_CPU/Inc/externalInterface.h	Sun Jun 04 21:54:24 2023 +0200
@@ -87,7 +87,7 @@
 void externalInterface_SetCO2State(uint16_t state);
 uint16_t externalInterface_GetCO2State(void);
 uint8_t externalInterface_GetSensorData(uint8_t sensorId, uint8_t* pDataStruct);
-void externalInterface_SetSensorData(uint8_t dataId, uint8_t* pDataStruct);
+void externalInterface_SetSensorData(uint8_t sensorId, uint8_t* pDataStruct);
 void externalInface_SetSensorMap(uint8_t* pMap);
 uint8_t* externalInterface_GetSensorMapPointer(uint8_t finalMap);
 void externalInterface_AutodetectSensor(void);
--- a/Small_CPU/Src/externalInterface.c	Wed May 31 08:44:07 2023 +0200
+++ b/Small_CPU/Src/externalInterface.c	Sun Jun 04 21:54:24 2023 +0200
@@ -412,31 +412,36 @@
 uint8_t externalInterface_GetSensorData(uint8_t sensorId, uint8_t* pDataStruct)
 {
 	uint8_t localId = sensorId;
-	if(localId == 0)
+	if(localId == 0xFF)
 	{
 		localId = lastSensorDataId;
 	}
 
-	if((pDataStruct != NULL) && (localId > 0) && (localId <= MAX_ADC_CHANNEL))
+	if((pDataStruct != NULL) && (localId <= MAX_ADC_CHANNEL))
 	{
-		memcpy(pDataStruct, &sensorDataDiveO2[localId-1], sizeof(SSensorDataDiveO2));
+		memcpy(pDataStruct, &sensorDataDiveO2[localId], sizeof(SSensorDataDiveO2));
+	}
+	else
+	{
+		localId = 0xFF;
 	}
 	return localId;
 }
 
-void externalInterface_SetSensorData(uint8_t dataId, uint8_t* pDataStruct)
+void externalInterface_SetSensorData(uint8_t sensorId, uint8_t* pDataStruct)
 {
 	if(pDataStruct != NULL)
 	{
-		if((dataId != 0) && (dataId <= MAX_ADC_CHANNEL))
+		if((sensorId != 0xFF) && (sensorId < MAX_ADC_CHANNEL))
 		{
-			memcpy(&sensorDataDiveO2[dataId-1], pDataStruct, sizeof(SSensorDataDiveO2));
+			memcpy(&sensorDataDiveO2[sensorId], pDataStruct, sizeof(SSensorDataDiveO2));
+			lastSensorDataId = sensorId;
 		}
 		else
 		{
 			memset(&sensorDataDiveO2,0,sizeof(sensorDataDiveO2));
+			lastSensorDataId = 0xFF;
 		}
-		lastSensorDataId = dataId;
 	}
 }
 
@@ -642,7 +647,16 @@
 
 									externalAutoDetect = DETECTION_OFF;
 									externalInterface_SwitchUART(0);
-									UART_SetDigO2_Channel(0);
+
+
+									for(index = 0; index < MAX_ADC_CHANNEL; index++)
+									{
+										if(tmpSensorMap[index] == SENSOR_DIGO2) /* set Channel to first valid entry */
+										{
+											UART_SetDigO2_Channel(index);
+											break;
+										}
+									}
 									for(index = 0; index < MAX_ADC_CHANNEL; index++)
 									{
 										if(tmpSensorMap[index] != SENSOR_NONE)
--- a/Small_CPU/Src/scheduler.c	Wed May 31 08:44:07 2023 +0200
+++ b/Small_CPU/Src/scheduler.c	Sun Jun 04 21:54:24 2023 +0200
@@ -1735,7 +1735,7 @@
 		value = getExternalInterfaceChannel(channel);
 		global.dataSendToMaster.data[boolADCBuffer && DATA_BUFFER_ADC].extADC_voltage[channel] = value;
 	}
-	global.dataSendToMaster.data[boolADCBuffer && DATA_BUFFER_ADC].externalInterface_SensorID = externalInterface_GetSensorData(0, (uint8_t*)&global.dataSendToMaster.data[boolADCBuffer && DATA_BUFFER_ADC].sensor_data);
+	global.dataSendToMaster.data[boolADCBuffer && DATA_BUFFER_ADC].externalInterface_SensorID = externalInterface_GetSensorData(0xFF, (uint8_t*)&global.dataSendToMaster.data[boolADCBuffer && DATA_BUFFER_ADC].sensor_data);
 	memcpy(global.dataSendToMaster.data[boolADCBuffer && DATA_BUFFER_ADC].sensor_map,externalInterface_GetSensorMapPointer(1),EXT_INTERFACE_SENSOR_CNT);
 	global.dataSendToMaster.boolADCO2Data |= boolADCBuffer;
 }