comparison 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
comparison
equal deleted inserted replaced
728:5143e927219f 729:d646a0f724a7
313 externalInterface_SwitchPower33(global.dataSendToSlave.data.externalInterface_Cmd && EXT_INTERFACE_33V_ON); 313 externalInterface_SwitchPower33(global.dataSendToSlave.data.externalInterface_Cmd && EXT_INTERFACE_33V_ON);
314 } 314 }
315 315
316 if(((global.dataSendToSlave.data.externalInterface_Cmd & EXT_INTERFACE_ADC_ON) != 0) != externalInterface_isEnabledADC()) 316 if(((global.dataSendToSlave.data.externalInterface_Cmd & EXT_INTERFACE_ADC_ON) != 0) != externalInterface_isEnabledADC())
317 { 317 {
318 externalInterface_SwitchADC(global.dataSendToSlave.data.externalInterface_Cmd && EXT_INTERFACE_ADC_ON); 318 externalInterface_SwitchADC(1-externalInterface_isEnabledADC());
319 } 319 }
320 320
321 if(((global.dataSendToSlave.data.externalInterface_Cmd >> 8) & 0x0F) != externalInterface_GetUARTProtocol()) 321 if(((global.dataSendToSlave.data.externalInterface_Cmd >> 8) & 0x0F) != externalInterface_GetUARTProtocol())
322 { 322 {
323 externalInterface_SwitchUART((global.dataSendToSlave.data.externalInterface_Cmd >> 8) & 0x0F); 323 externalInterface_SwitchUART((global.dataSendToSlave.data.externalInterface_Cmd >> 8) & 0x0F);
324 } 324 }
325 325
326 externalInface_SetSensorMap(global.dataSendToSlave.data.externalInterface_SensorMap);
326 if(global.dataSendToSlave.data.externalInterface_Cmd & 0x00FF) /* lowest nibble for commands */ 327 if(global.dataSendToSlave.data.externalInterface_Cmd & 0x00FF) /* lowest nibble for commands */
327 { 328 {
328 externalInterface_ExecuteCmd(global.dataSendToSlave.data.externalInterface_Cmd); 329 externalInterface_ExecuteCmd(global.dataSendToSlave.data.externalInterface_Cmd);
329 } 330 }
330 331
516 ticksdiff = time_elapsed_ms(Scheduler.tickstart,lasttick); 517 ticksdiff = time_elapsed_ms(Scheduler.tickstart,lasttick);
517 518
518 #ifdef ENABLE_CO2_SUPPORT 519 #ifdef ENABLE_CO2_SUPPORT
519 if(global.dataSendToSlave.data.externalInterface_Cmd & EXT_INTERFACE_UART_CO2) 520 if(global.dataSendToSlave.data.externalInterface_Cmd & EXT_INTERFACE_UART_CO2)
520 { 521 {
521 HandleUARTCO2Data(); 522 UART_HandleCO2Data();
522 } 523 }
523 #endif 524 #endif
524 #ifdef ENABLE_SENTINEL_MODE 525 #ifdef ENABLE_SENTINEL_MODE
525 if(global.dataSendToSlave.data.externalInterface_Cmd & EXT_INTERFACE_UART_SENTINEL) 526 if(global.dataSendToSlave.data.externalInterface_Cmd & EXT_INTERFACE_UART_SENTINEL)
526 { 527 {
527 HandleUARTSentinelData(); 528 UART_HandleSentinelData();
528 } 529 }
529 #endif 530 #endif
530 if(global.dataSendToSlave.data.externalInterface_Cmd & EXT_INTERFACE_UART_O2) 531 if(global.dataSendToSlave.data.externalInterface_Cmd & EXT_INTERFACE_UART_O2)
531 { 532 {
532 HandleUARTDigitalO2(); 533 UART_HandleDigitalO2();
533 } 534 }
534 535
535 if(ticksdiff >= Scheduler.counterSPIdata100msec * 100 + 10) 536 if(ticksdiff >= Scheduler.counterSPIdata100msec * 100 + 10)
536 { 537 {
537 if(SPI_Evaluate_RX_Data()!=0) /* did we receive something ? */ 538 if(SPI_Evaluate_RX_Data()!=0) /* did we receive something ? */
836 if(scheduleSetButtonResponsiveness()) 837 if(scheduleSetButtonResponsiveness())
837 setButtonsNow = 0; 838 setButtonsNow = 0;
838 } 839 }
839 840
840 #ifdef ENABLE_CO2_SUPPORT 841 #ifdef ENABLE_CO2_SUPPORT
841 if(global.dataSendToSlave.data.externalInterface_Cmd & EXT_INTERFACE_UART_CO2) 842 if(externalInterface_GetUARTProtocol() & (EXT_INTERFACE_UART_CO2 >> 8))
842 { 843 {
843 HandleUARTCO2Data(); 844 UART_HandleCO2Data();
844 } 845 }
845 #endif 846 #endif
846 #ifdef ENABLE_SENTINEL_MODE 847 #ifdef ENABLE_SENTINEL_MODE
847 if(global.dataSendToSlave.data.externalInterface_Cmd & EXT_INTERFACE_UART_SENTINEL) 848 if(global.dataSendToSlave.data.externalInterface_Cmd & EXT_INTERFACE_UART_SENTINEL)
848 { 849 {
849 HandleUARTSentinelData(); 850 UART_HandleSentinelData();
850 } 851 }
851 #endif 852 #endif
852 853
853 if(global.dataSendToSlave.data.externalInterface_Cmd & EXT_INTERFACE_UART_O2) 854 if(externalInterface_GetUARTProtocol() & (EXT_INTERFACE_UART_O2 >> 8))
854 { 855 {
855 HandleUARTDigitalO2(); 856 UART_HandleDigitalO2();
856 } 857 }
857 858
858 /* Evaluate received data at 10 ms, 110 ms, 210 ms,... duration ~<1ms */ 859 /* Evaluate received data at 10 ms, 110 ms, 210 ms,... duration ~<1ms */
859 if(ticksdiff >= Scheduler.counterSPIdata100msec * 100 + 10) 860 if(ticksdiff >= Scheduler.counterSPIdata100msec * 100 + 10)
860 { 861 {
999 { 1000 {
1000 init_battery_gas_gauge(); 1001 init_battery_gas_gauge();
1001 } 1002 }
1002 } 1003 }
1003 } 1004 }
1005 externalInterface_AutodetectSensor();
1004 } 1006 }
1005 1007
1006 if(ticksdiff >= 1000) 1008 if(ticksdiff >= 1000)
1007 { 1009 {
1008 //Set back tick counter 1010 //Set back tick counter
1732 { 1734 {
1733 value = getExternalInterfaceChannel(channel); 1735 value = getExternalInterfaceChannel(channel);
1734 global.dataSendToMaster.data[boolADCBuffer && DATA_BUFFER_ADC].extADC_voltage[channel] = value; 1736 global.dataSendToMaster.data[boolADCBuffer && DATA_BUFFER_ADC].extADC_voltage[channel] = value;
1735 } 1737 }
1736 global.dataSendToMaster.data[boolADCBuffer && DATA_BUFFER_ADC].externalInterface_SensorID = externalInterface_GetSensorData((uint8_t*)&global.dataSendToMaster.data[boolADCBuffer && DATA_BUFFER_ADC].sensor_data); 1738 global.dataSendToMaster.data[boolADCBuffer && DATA_BUFFER_ADC].externalInterface_SensorID = externalInterface_GetSensorData((uint8_t*)&global.dataSendToMaster.data[boolADCBuffer && DATA_BUFFER_ADC].sensor_data);
1739 memcpy(global.dataSendToMaster.data[boolADCBuffer && DATA_BUFFER_ADC].sensor_map,externalInterface_GetSensorMapPointer(),EXT_INTERFACE_SENSOR_CNT);
1737 global.dataSendToMaster.boolADCO2Data |= boolADCBuffer; 1740 global.dataSendToMaster.boolADCO2Data |= boolADCBuffer;
1738 } 1741 }
1739 1742
1740 void copyExtCO2data() 1743 void copyExtCO2data()
1741 { 1744 {