diff Small_CPU/Src/externalInterface.c @ 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 95af969fe0ae
children bb37d4f3e50e
line wrap: on
line diff
--- 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)