diff Small_CPU/Src/scheduler.c @ 729:d646a0f724a7

Added auto detection functionality for sensors connected to the external interface: O2 sensors may be connected to the analog input as well as to the UART. The GUI visualization provides three slots for ppo2 display. Beside detection of sensor kind the task of the function is to place the available sensor in this three slots. CO2 has its own communication slot outside the ppo2 channel. The result of the automatic detection is communicated via the sensor map.
author Ideenmodellierer
date Sat, 14 Jan 2023 20:46:17 +0100
parents 621265ec3d23
children 2a801cfe23ab
line wrap: on
line diff
--- a/Small_CPU/Src/scheduler.c	Sat Jan 14 20:41:36 2023 +0100
+++ b/Small_CPU/Src/scheduler.c	Sat Jan 14 20:46:17 2023 +0100
@@ -315,7 +315,7 @@
 
 	if(((global.dataSendToSlave.data.externalInterface_Cmd & EXT_INTERFACE_ADC_ON) != 0) != externalInterface_isEnabledADC())
 	{
-		externalInterface_SwitchADC(global.dataSendToSlave.data.externalInterface_Cmd && EXT_INTERFACE_ADC_ON);
+		externalInterface_SwitchADC(1-externalInterface_isEnabledADC());
 	}
 
 	if(((global.dataSendToSlave.data.externalInterface_Cmd >> 8) & 0x0F) != externalInterface_GetUARTProtocol())
@@ -323,6 +323,7 @@
 		externalInterface_SwitchUART((global.dataSendToSlave.data.externalInterface_Cmd >> 8) & 0x0F);
 	}
 
+	externalInface_SetSensorMap(global.dataSendToSlave.data.externalInterface_SensorMap);
 	if(global.dataSendToSlave.data.externalInterface_Cmd & 0x00FF)	/* lowest nibble for commands */
 	{
 		externalInterface_ExecuteCmd(global.dataSendToSlave.data.externalInterface_Cmd);
@@ -518,18 +519,18 @@
 #ifdef ENABLE_CO2_SUPPORT
 		if(global.dataSendToSlave.data.externalInterface_Cmd & EXT_INTERFACE_UART_CO2)
 		{
-			HandleUARTCO2Data();
+			UART_HandleCO2Data();
 		}
 #endif
 #ifdef ENABLE_SENTINEL_MODE
 		if(global.dataSendToSlave.data.externalInterface_Cmd & EXT_INTERFACE_UART_SENTINEL)
 		{
-			HandleUARTSentinelData();
+			UART_HandleSentinelData();
 		}
 #endif
 		if(global.dataSendToSlave.data.externalInterface_Cmd & EXT_INTERFACE_UART_O2)
 		{
-			HandleUARTDigitalO2();
+			UART_HandleDigitalO2();
 		}
 
 		if(ticksdiff >= Scheduler.counterSPIdata100msec * 100 + 10)
@@ -838,21 +839,21 @@
 		}
 
 #ifdef ENABLE_CO2_SUPPORT
-		if(global.dataSendToSlave.data.externalInterface_Cmd & EXT_INTERFACE_UART_CO2)
+		if(externalInterface_GetUARTProtocol() & (EXT_INTERFACE_UART_CO2 >> 8))
 		{
-			HandleUARTCO2Data();
+			UART_HandleCO2Data();
 		}
 #endif
 #ifdef ENABLE_SENTINEL_MODE
 		if(global.dataSendToSlave.data.externalInterface_Cmd & EXT_INTERFACE_UART_SENTINEL)
 		{
-			HandleUARTSentinelData();
+			UART_HandleSentinelData();
 		}
 #endif
 
-		if(global.dataSendToSlave.data.externalInterface_Cmd & EXT_INTERFACE_UART_O2)
+		if(externalInterface_GetUARTProtocol() & (EXT_INTERFACE_UART_O2 >> 8))
 		{
-			HandleUARTDigitalO2();
+			UART_HandleDigitalO2();
 		}
 
 		/* Evaluate received data at 10 ms, 110 ms, 210 ms,... duration ~<1ms */
@@ -1001,6 +1002,7 @@
 					}
 				}
 			}
+			externalInterface_AutodetectSensor();
 		}
 
 		if(ticksdiff >= 1000)
@@ -1734,6 +1736,7 @@
 		global.dataSendToMaster.data[boolADCBuffer && DATA_BUFFER_ADC].extADC_voltage[channel] = value;
 	}
 	global.dataSendToMaster.data[boolADCBuffer && DATA_BUFFER_ADC].externalInterface_SensorID = externalInterface_GetSensorData((uint8_t*)&global.dataSendToMaster.data[boolADCBuffer && DATA_BUFFER_ADC].sensor_data);
+	memcpy(global.dataSendToMaster.data[boolADCBuffer && DATA_BUFFER_ADC].sensor_map,externalInterface_GetSensorMapPointer(),EXT_INTERFACE_SENSOR_CNT);
 	global.dataSendToMaster.boolADCO2Data |= boolADCBuffer;
 }