annotate Small_CPU/Src/externalInterface.c @ 787:aeb72882f30a

Dev Bugfx Empty buffer indication and stability improvments: The mux prototype used ASCII coding for channel selection while the current realization used real number (0...4) for addressing the mux. The UART read function uses the '0' to indicate an empty buffer element. The mux now loops back '0' used by channel selection causing the read function to process the data. As result data interrups are visible at the display. To avoid this another character has been defined indicate empty buffer locations. Beside this the functionality has been improved with regard to access speed and better recovery in case of transition failure.
author Ideenmodellierer
date Sun, 04 Jun 2023 21:59:26 +0200
parents 19ab6f3ed52a
children bb37d4f3e50e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
554
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
1 /**
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
2 ******************************************************************************
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
3 * @file externalInterface.c
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
4 * @author heinrichs weikamp gmbh
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
5 * @version V0.0.1
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
6 * @date 07-Nov-2020
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
7 * @brief Interface functionality to proceed external analog signal via i2c connection
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
8 *
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
9 @verbatim
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
10 ==============================================================================
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
11 ##### stm32f4xx_hal_i2c.c modification #####
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
12 ==============================================================================
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
13 The LTC2942 requires an repeated start condition without stop condition
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
14 for data reception.
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
15
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
16 @endverbatim
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
17 ******************************************************************************
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
18 * @attention
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
19 *
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
20 * <h2><center>&copy; COPYRIGHT(c) 2014 heinrichs weikamp</center></h2>
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
21 *
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
22 ******************************************************************************
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
23 */
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
24 /* Includes ------------------------------------------------------------------*/
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
25
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
26 #include <math.h>
714
045ff7800501 Added customizable data area for specific sensor data:
Ideenmodellierer
parents: 704
diff changeset
27 #include <string.h>
554
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
28 #include "i2c.h"
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
29 #include "externalInterface.h"
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
30 #include "scheduler.h"
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
31 #include "uart.h"
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
32 #include "data_exchange.h"
747
df0d43da1614 Added pressure compensation to CO2 detection:
Ideenmodellierer
parents: 746
diff changeset
33 #include "pressure.h"
554
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
34
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
35 extern SGlobal global;
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
36 extern UART_HandleTypeDef huart1;
554
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
37
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
38 #define ADC_ANSWER_LENGTH (5u) /* 3424 will provide addr + 4 data bytes */
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
39 #define ADC_TIMEOUT (10u) /* conversion stuck for unknown reason => restart */
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
40 #define ADC_REF_VOLTAGE_MV (2048.0f) /* reference voltage of MPC3424*/
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
41
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
42 #define ADC_START_CONVERSION (0x80)
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
43 #define ADC_GAIN_4 (0x02)
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
44 #define ADC_GAIN_4_VALUE (4.0f)
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
45 #define ADC_GAIN_8 (0x03)
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
46 #define ADC_GAIN_8_VALUE (8.0f)
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
47 #define ADC_RESOLUTION_16BIT (0x08)
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
48 #define ADC_RESOLUTION_16BIT_VALUE (16u)
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
49 #define ADC_RESOLUTION_18BIT (0x0C)
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
50 #define ADC_RESOLUTION_18BIT_VALUE (18u)
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
51
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
52 #define ANSWER_CONFBYTE_INDEX (4u)
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
53
747
df0d43da1614 Added pressure compensation to CO2 detection:
Ideenmodellierer
parents: 746
diff changeset
54 #define LOOKUP_CO2_CORR_TABLE_SCALE (1000u)
df0d43da1614 Added pressure compensation to CO2 detection:
Ideenmodellierer
parents: 746
diff changeset
55 #define LOOKUP_CO2_CORR_TABLE_MAX (30000u)
df0d43da1614 Added pressure compensation to CO2 detection:
Ideenmodellierer
parents: 746
diff changeset
56
554
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
57 static uint8_t activeChannel = 0; /* channel which is in request */
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
58 static uint8_t recBuf[ADC_ANSWER_LENGTH];
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
59 static uint8_t timeoutCnt = 0;
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
60 static uint8_t externalInterfacePresent = 0;
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
61
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
62 float externalChannel_mV[MAX_ADC_CHANNEL];
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
63 static uint8_t externalV33_On = 0;
691
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
64 static uint8_t externalADC_On = 0;
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 691
diff changeset
65 static uint8_t externalUART_Protocol = 0;
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
66 static uint16_t externalCO2Value;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
67 static uint16_t externalCO2SignalStrength;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
68 static uint16_t externalCO2Status = 0;
554
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
69
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
70 static uint8_t lastSensorDataId = 0;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
71 static SSensorDataDiveO2 sensorDataDiveO2[MAX_ADC_CHANNEL];
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
72 static externalInterfaceAutoDetect_t externalAutoDetect = DETECTION_OFF;
747
df0d43da1614 Added pressure compensation to CO2 detection:
Ideenmodellierer
parents: 746
diff changeset
73 static externalInterfaceSensorType SensorMap[EXT_INTERFACE_SENSOR_CNT] ={ SENSOR_OPTIC, SENSOR_OPTIC, SENSOR_OPTIC, SENSOR_NONE, SENSOR_NONE};
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
74 static externalInterfaceSensorType tmpSensorMap[EXT_INTERFACE_SENSOR_CNT];
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
75 static externalInterfaceSensorType MasterSensorMap[EXT_INTERFACE_SENSOR_CNT];
714
045ff7800501 Added customizable data area for specific sensor data:
Ideenmodellierer
parents: 704
diff changeset
76
747
df0d43da1614 Added pressure compensation to CO2 detection:
Ideenmodellierer
parents: 746
diff changeset
77 static float LookupCO2PressureCorrection[LOOKUP_CO2_CORR_TABLE_MAX / LOOKUP_CO2_CORR_TABLE_SCALE]; /* lookup table for pressure compensation values */
df0d43da1614 Added pressure compensation to CO2 detection:
Ideenmodellierer
parents: 746
diff changeset
78
554
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
79
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
80 void externalInterface_Init(void)
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
81 {
747
df0d43da1614 Added pressure compensation to CO2 detection:
Ideenmodellierer
parents: 746
diff changeset
82 uint16_t index;
df0d43da1614 Added pressure compensation to CO2 detection:
Ideenmodellierer
parents: 746
diff changeset
83 uint16_t coeff;
554
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
84 activeChannel = 0;
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
85 timeoutCnt = 0;
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
86 externalInterfacePresent = 0;
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
87 if(externalInterface_StartConversion(activeChannel) == HAL_OK)
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
88 {
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
89 externalInterfacePresent = 1;
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
90 global.deviceDataSendToMaster.hw_Info.extADC = 1;
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
91 }
559
84a4e1200726 Check if HW evaluation was performed:
Ideenmodellierer
parents: 554
diff changeset
92 global.deviceDataSendToMaster.hw_Info.checkADC = 1;
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
93
747
df0d43da1614 Added pressure compensation to CO2 detection:
Ideenmodellierer
parents: 746
diff changeset
94 /* Create a lookup table based on GSS application note AN001: PRESSURE COMPENSATION OF A CO2 SENSOR */
df0d43da1614 Added pressure compensation to CO2 detection:
Ideenmodellierer
parents: 746
diff changeset
95 /* The main purpose of the sensor in the dive application is to be a warning indicator */
753
4a28402e4aca Updated outdated comment
Ideenmodellierer
parents: 747
diff changeset
96 /* => no exact values necessary => a lookup table with 1000ppm scaling should be sufficient */
747
df0d43da1614 Added pressure compensation to CO2 detection:
Ideenmodellierer
parents: 746
diff changeset
97 LookupCO2PressureCorrection [0] = -0.0014;
df0d43da1614 Added pressure compensation to CO2 detection:
Ideenmodellierer
parents: 746
diff changeset
98 for(index = 1; index < (LOOKUP_CO2_CORR_TABLE_MAX / LOOKUP_CO2_CORR_TABLE_SCALE); index++)
df0d43da1614 Added pressure compensation to CO2 detection:
Ideenmodellierer
parents: 746
diff changeset
99 {
df0d43da1614 Added pressure compensation to CO2 detection:
Ideenmodellierer
parents: 746
diff changeset
100 coeff = index * LOOKUP_CO2_CORR_TABLE_SCALE;
df0d43da1614 Added pressure compensation to CO2 detection:
Ideenmodellierer
parents: 746
diff changeset
101 LookupCO2PressureCorrection[index] = 2.811*pow(10,-38)*pow(coeff,6)- 9.817*pow(10,-32)*pow(coeff,5)+1.304*pow(10,-25)*pow(coeff,4)-8.216*pow(10,-20)*pow(coeff,3)+2.311*pow(10,-14)*pow(coeff,2) - 2.195*pow(10,-9)*coeff - 1.471*pow(10,-3);
df0d43da1614 Added pressure compensation to CO2 detection:
Ideenmodellierer
parents: 746
diff changeset
102 }
738
30717de00f3a Added data init function for external interface:
Ideenmodellierer
parents: 731
diff changeset
103 externalInterface_InitDatastruct();
30717de00f3a Added data init function for external interface:
Ideenmodellierer
parents: 731
diff changeset
104 }
30717de00f3a Added data init function for external interface:
Ideenmodellierer
parents: 731
diff changeset
105
30717de00f3a Added data init function for external interface:
Ideenmodellierer
parents: 731
diff changeset
106 void externalInterface_InitDatastruct(void)
30717de00f3a Added data init function for external interface:
Ideenmodellierer
parents: 731
diff changeset
107 {
30717de00f3a Added data init function for external interface:
Ideenmodellierer
parents: 731
diff changeset
108 uint8_t index = 0;
30717de00f3a Added data init function for external interface:
Ideenmodellierer
parents: 731
diff changeset
109 /* init data values */
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
110 externalV33_On = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
111 externalCO2Value = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
112 externalCO2SignalStrength = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
113 externalCO2Status = 0;
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
114 externalAutoDetect = DETECTION_OFF;
738
30717de00f3a Added data init function for external interface:
Ideenmodellierer
parents: 731
diff changeset
115
30717de00f3a Added data init function for external interface:
Ideenmodellierer
parents: 731
diff changeset
116 for(index = 0; index < MAX_ADC_CHANNEL; index++)
30717de00f3a Added data init function for external interface:
Ideenmodellierer
parents: 731
diff changeset
117 {
30717de00f3a Added data init function for external interface:
Ideenmodellierer
parents: 731
diff changeset
118 externalChannel_mV[index] = 0.0;
30717de00f3a Added data init function for external interface:
Ideenmodellierer
parents: 731
diff changeset
119 }
554
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
120 }
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
121
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
122
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
123 uint8_t externalInterface_StartConversion(uint8_t channel)
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
124 {
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
125 uint8_t retval = 0;
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
126 uint8_t confByte = 0;
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
127
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
128 if(channel < MAX_ADC_CHANNEL)
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
129 {
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
130 confByte = ADC_START_CONVERSION | ADC_RESOLUTION_16BIT | ADC_GAIN_8;
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
131 confByte |= channel << 5;
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
132 retval = I2C_Master_Transmit(DEVICE_EXTERNAL_ADC, &confByte, 1);
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
133 }
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
134 return retval;
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
135 }
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
136
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
137 /* Check if conversion is done and trigger measurement of next channel */
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
138 uint8_t externalInterface_ReadAndSwitch()
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
139 {
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
140 uint8_t retval = EXTERNAL_ADC_NO_DATA;
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
141 uint8_t nextChannel;
731
2a801cfe23ab Improvment sensor Autodetection:
Ideenmodellierer
parents: 729
diff changeset
142 uint8_t* psensorMap = externalInterface_GetSensorMapPointer(0);
554
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
143
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
144 if(externalADC_On)
554
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
145 {
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
146 if(I2C_Master_Receive(DEVICE_EXTERNAL_ADC, recBuf, ADC_ANSWER_LENGTH) == HAL_OK)
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
147 {
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
148 if((recBuf[ANSWER_CONFBYTE_INDEX] & ADC_START_CONVERSION) == 0) /* !ready set => received data contains new value */
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
149 {
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
150 retval = activeChannel; /* return channel number providing new data */
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
151 nextChannel = activeChannel + 1;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
152 if(nextChannel == MAX_ADC_CHANNEL)
554
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
153 {
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
154 nextChannel = 0;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
155 }
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
156
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
157 while((psensorMap[nextChannel] != SENSOR_ANALOG) && (nextChannel != activeChannel))
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
158 {
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
159 if(nextChannel == MAX_ADC_CHANNEL)
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 691
diff changeset
160 {
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
161 nextChannel = 0;
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 691
diff changeset
162 }
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 691
diff changeset
163 else
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 691
diff changeset
164 {
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
165 nextChannel++;
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 691
diff changeset
166 }
554
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
167 }
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
168
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
169 activeChannel = nextChannel;
554
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
170 externalInterface_StartConversion(activeChannel);
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
171 timeoutCnt = 0;
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
172 }
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
173 else
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
174 {
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
175 if(timeoutCnt++ >= ADC_TIMEOUT)
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
176 {
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
177 externalInterface_StartConversion(activeChannel);
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
178 timeoutCnt = 0;
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
179 }
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
180 }
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
181 }
581
011d8f9f5ddb Added ex Interface measurement restart in case of i2c disturbance:
Ideenmodellierer
parents: 559
diff changeset
182 else /* take also i2c bus disturb into account */
011d8f9f5ddb Added ex Interface measurement restart in case of i2c disturbance:
Ideenmodellierer
parents: 559
diff changeset
183 {
011d8f9f5ddb Added ex Interface measurement restart in case of i2c disturbance:
Ideenmodellierer
parents: 559
diff changeset
184 if(timeoutCnt++ >= ADC_TIMEOUT)
011d8f9f5ddb Added ex Interface measurement restart in case of i2c disturbance:
Ideenmodellierer
parents: 559
diff changeset
185 {
011d8f9f5ddb Added ex Interface measurement restart in case of i2c disturbance:
Ideenmodellierer
parents: 559
diff changeset
186 externalInterface_StartConversion(activeChannel);
011d8f9f5ddb Added ex Interface measurement restart in case of i2c disturbance:
Ideenmodellierer
parents: 559
diff changeset
187 timeoutCnt = 0;
011d8f9f5ddb Added ex Interface measurement restart in case of i2c disturbance:
Ideenmodellierer
parents: 559
diff changeset
188 }
011d8f9f5ddb Added ex Interface measurement restart in case of i2c disturbance:
Ideenmodellierer
parents: 559
diff changeset
189 }
554
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
190 }
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
191 return retval;
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
192 }
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
193 float externalInterface_CalculateADCValue(uint8_t channel)
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
194 {
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
195 int32_t rawvalue = 0;
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
196 float retValue = 0.0;
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
197 if(channel < MAX_ADC_CHANNEL)
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
198 {
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
199
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
200 rawvalue = ((recBuf[0] << 16) | (recBuf[1] << 8) | (recBuf[2]));
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
201
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
202 switch(recBuf[3] & 0x0C) /* confbyte => Resolution bits*/
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
203 {
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
204 case ADC_RESOLUTION_16BIT: rawvalue = rawvalue >> 8; /* only 2 databytes received shift out confbyte*/
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
205 if(rawvalue & (0x1 << (ADC_RESOLUTION_16BIT_VALUE-1))) /* MSB set => negative number */
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
206 {
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
207 rawvalue |= 0xFFFF0000; /* set MSB for int32 */
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
208 }
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
209 else
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
210 {
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
211 rawvalue &= 0x0000FFFF;
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
212 }
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
213 externalChannel_mV[channel] = ADC_REF_VOLTAGE_MV * 2.0 / (float) pow(2,ADC_RESOLUTION_16BIT_VALUE); /* calculate bit resolution */
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
214 break;
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
215 case ADC_RESOLUTION_18BIT: if(rawvalue & (0x1 << (ADC_RESOLUTION_18BIT_VALUE-1))) /* MSB set => negative number */
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
216 {
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
217 rawvalue |= 0xFFFE0000; /* set MSB for int32 */
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
218 }
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
219 externalChannel_mV[channel] = ADC_REF_VOLTAGE_MV * 2.0 / (float) pow(2,ADC_RESOLUTION_18BIT_VALUE); /* calculate bit resolution */
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
220 break;
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
221 default: rawvalue = 0;
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
222 break;
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
223 }
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
224 externalChannel_mV[channel] = externalChannel_mV[channel] * rawvalue / ADC_GAIN_8_VALUE;
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
225 retValue = externalChannel_mV[channel];
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
226 }
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
227 return retValue;
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
228 }
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
229 float getExternalInterfaceChannel(uint8_t channel)
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
230 {
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
231 float retval = 0;
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
232
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
233 if(channel < MAX_ADC_CHANNEL)
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
234 {
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
235 retval = externalChannel_mV[channel];
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
236 }
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
237 return retval;
3328189786e7 Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff changeset
238 }
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
239
691
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
240 uint8_t setExternalInterfaceChannel(uint8_t channel, float value)
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
241 {
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
242 uint8_t retval = 0;
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
243
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
244 if(channel < MAX_ADC_CHANNEL)
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
245 {
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
246 externalChannel_mV[channel] = value;
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
247 retval = 1;
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
248 }
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
249 return retval;
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
250 }
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
251
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
252 void externalInterface_InitPower33(void)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
253 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
254 GPIO_InitTypeDef GPIO_InitStructure;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
255
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
256 GPIO_InitStructure.Pin = GPIO_PIN_7;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
257 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
258 GPIO_InitStructure.Pull = GPIO_PULLUP;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
259 GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
260 HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
261 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_SET);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
262 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
263
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
264
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
265 uint8_t externalInterface_isEnabledPower33()
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
266 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
267 return externalV33_On;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
268 }
691
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
269
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
270 uint8_t externalInterface_isEnabledADC()
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
271 {
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
272 return externalADC_On;
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
273 }
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
274
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 691
diff changeset
275 uint8_t externalInterface_GetUARTProtocol()
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 691
diff changeset
276 {
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 691
diff changeset
277 return externalUART_Protocol;
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 691
diff changeset
278 }
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 691
diff changeset
279
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
280 void externalInterface_SwitchPower33(uint8_t state)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
281 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
282 if(state != externalV33_On)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
283 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
284 if(state)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
285 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
286 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_RESET);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
287 externalV33_On = 1;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
288 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
289 else
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
290 {
731
2a801cfe23ab Improvment sensor Autodetection:
Ideenmodellierer
parents: 729
diff changeset
291 if(externalAutoDetect == DETECTION_OFF)
2a801cfe23ab Improvment sensor Autodetection:
Ideenmodellierer
parents: 729
diff changeset
292 {
2a801cfe23ab Improvment sensor Autodetection:
Ideenmodellierer
parents: 729
diff changeset
293 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_SET);
2a801cfe23ab Improvment sensor Autodetection:
Ideenmodellierer
parents: 729
diff changeset
294 externalV33_On = 0;
2a801cfe23ab Improvment sensor Autodetection:
Ideenmodellierer
parents: 729
diff changeset
295 externalInterface_SetCO2Value(0);
2a801cfe23ab Improvment sensor Autodetection:
Ideenmodellierer
parents: 729
diff changeset
296 externalInterface_SetCO2SignalStrength(0);
2a801cfe23ab Improvment sensor Autodetection:
Ideenmodellierer
parents: 729
diff changeset
297 }
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
298 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
299 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
300 }
691
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
301 void externalInterface_SwitchADC(uint8_t state)
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
302 {
714
045ff7800501 Added customizable data area for specific sensor data:
Ideenmodellierer
parents: 704
diff changeset
303 uint8_t loop = 0;
691
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
304 if((state) && (externalInterfacePresent))
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
305 {
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
306 if(externalADC_On == 0)
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
307 {
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
308 activeChannel = 0;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
309 externalInterface_StartConversion(activeChannel);
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
310 externalADC_On = 1;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
311 }
691
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
312 }
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
313 else
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
314 {
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
315 if(externalAutoDetect == DETECTION_OFF) /* block deactivation requests if auto detection is active */
714
045ff7800501 Added customizable data area for specific sensor data:
Ideenmodellierer
parents: 704
diff changeset
316 {
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
317 externalADC_On = 0;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
318 for(loop = 0; loop < MAX_ADC_CHANNEL; loop++)
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
319 {
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
320 externalChannel_mV[loop] = 0;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
321 }
714
045ff7800501 Added customizable data area for specific sensor data:
Ideenmodellierer
parents: 704
diff changeset
322 }
691
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
323 }
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
324 }
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
325
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 691
diff changeset
326 void externalInterface_SwitchUART(uint8_t protocol)
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 691
diff changeset
327 {
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
328 switch(protocol)
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 691
diff changeset
329 {
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
330 case 0:
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
331 case (EXT_INTERFACE_UART_CO2 >> 8):
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
332 case (EXT_INTERFACE_UART_O2 >> 8):
742
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 738
diff changeset
333 case (EXT_INTERFACE_UART_SENTINEL >> 8):
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
334 if((externalAutoDetect <= DETECTION_START)
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
335 || ((protocol == EXT_INTERFACE_UART_O2 >> 8) && (externalAutoDetect == DETECTION_DIGO2_0))
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
336 || ((protocol == EXT_INTERFACE_UART_O2 >> 8) && (externalAutoDetect == DETECTION_DIGO2_1))
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
337 || ((protocol == EXT_INTERFACE_UART_O2 >> 8) && (externalAutoDetect == DETECTION_DIGO2_2))
781
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
338 || ((protocol == EXT_INTERFACE_UART_O2 >> 8) && (externalAutoDetect == DETECTION_DIGO2_3))
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
339 || ((protocol == EXT_INTERFACE_UART_O2 >> 8) && (externalAutoDetect == DETECTION_UARTMUX))
746
7e84ae1513b6 Code cleanup sensors under development:
Ideenmodellierer
parents: 742
diff changeset
340 #ifdef ENABLE_CO2_SUPPORT
7e84ae1513b6 Code cleanup sensors under development:
Ideenmodellierer
parents: 742
diff changeset
341 || ((protocol == EXT_INTERFACE_UART_CO2 >> 8) && (externalAutoDetect == DETECTION_CO2))
7e84ae1513b6 Code cleanup sensors under development:
Ideenmodellierer
parents: 742
diff changeset
342 #endif
7e84ae1513b6 Code cleanup sensors under development:
Ideenmodellierer
parents: 742
diff changeset
343 #ifdef ENABLE_SENTINEL_MODE
7e84ae1513b6 Code cleanup sensors under development:
Ideenmodellierer
parents: 742
diff changeset
344 || ((protocol == EXT_INTERFACE_UART_SENTINEL >> 8) && (externalAutoDetect == DETECTION_SENTINEL))
7e84ae1513b6 Code cleanup sensors under development:
Ideenmodellierer
parents: 742
diff changeset
345 #endif
7e84ae1513b6 Code cleanup sensors under development:
Ideenmodellierer
parents: 742
diff changeset
346 )
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
347 {
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
348 lastSensorDataId = 0;
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
349 externalUART_Protocol = protocol;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
350 MX_USART1_UART_DeInit();
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
351 if( protocol != 0)
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
352 {
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
353 MX_USART1_UART_Init();
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
354 }
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
355 }
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
356 break;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
357 default:
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
358 break;
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 691
diff changeset
359 }
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 691
diff changeset
360 }
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 691
diff changeset
361
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
362 void externalInterface_SetCO2Value(uint16_t CO2_ppm)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
363 {
747
df0d43da1614 Added pressure compensation to CO2 detection:
Ideenmodellierer
parents: 746
diff changeset
364 float local_ppm = CO2_ppm * 10.0; /* scalfactor */
df0d43da1614 Added pressure compensation to CO2 detection:
Ideenmodellierer
parents: 746
diff changeset
365
df0d43da1614 Added pressure compensation to CO2 detection:
Ideenmodellierer
parents: 746
diff changeset
366 #ifndef ENABLE_EXTERNAL_PRESSURE
df0d43da1614 Added pressure compensation to CO2 detection:
Ideenmodellierer
parents: 746
diff changeset
367 float local_corr = 0.0;
df0d43da1614 Added pressure compensation to CO2 detection:
Ideenmodellierer
parents: 746
diff changeset
368
df0d43da1614 Added pressure compensation to CO2 detection:
Ideenmodellierer
parents: 746
diff changeset
369 if (local_ppm >= LOOKUP_CO2_CORR_TABLE_MAX)
df0d43da1614 Added pressure compensation to CO2 detection:
Ideenmodellierer
parents: 746
diff changeset
370 {
df0d43da1614 Added pressure compensation to CO2 detection:
Ideenmodellierer
parents: 746
diff changeset
371 local_corr = -0.0014;
df0d43da1614 Added pressure compensation to CO2 detection:
Ideenmodellierer
parents: 746
diff changeset
372 }
df0d43da1614 Added pressure compensation to CO2 detection:
Ideenmodellierer
parents: 746
diff changeset
373 else
df0d43da1614 Added pressure compensation to CO2 detection:
Ideenmodellierer
parents: 746
diff changeset
374 {
df0d43da1614 Added pressure compensation to CO2 detection:
Ideenmodellierer
parents: 746
diff changeset
375 local_corr = LookupCO2PressureCorrection[((uint16_t) (local_ppm / LOOKUP_CO2_CORR_TABLE_SCALE))];
df0d43da1614 Added pressure compensation to CO2 detection:
Ideenmodellierer
parents: 746
diff changeset
376 }
df0d43da1614 Added pressure compensation to CO2 detection:
Ideenmodellierer
parents: 746
diff changeset
377 local_ppm = local_ppm / (1.0 + (local_corr * (get_surface_mbar() - get_pressure_mbar())));
df0d43da1614 Added pressure compensation to CO2 detection:
Ideenmodellierer
parents: 746
diff changeset
378 #else
df0d43da1614 Added pressure compensation to CO2 detection:
Ideenmodellierer
parents: 746
diff changeset
379 /* The external pressure value is passed via ADC channel2 and calibration is done at firmware => just forward sensor data */
df0d43da1614 Added pressure compensation to CO2 detection:
Ideenmodellierer
parents: 746
diff changeset
380 /* compensation is done at firmware side. This is for testing only. Take care the the same algorithm is taken as used for the lookup table */
df0d43da1614 Added pressure compensation to CO2 detection:
Ideenmodellierer
parents: 746
diff changeset
381 #endif
df0d43da1614 Added pressure compensation to CO2 detection:
Ideenmodellierer
parents: 746
diff changeset
382 externalCO2Value = local_ppm / 10.0;
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
383 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
384
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
385 void externalInterface_SetCO2SignalStrength(uint16_t LED_qa)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
386 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
387 externalCO2SignalStrength = LED_qa;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
388 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
389
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
390 uint16_t externalInterface_GetCO2Value(void)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
391 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
392 return externalCO2Value;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
393 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
394
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
395 uint16_t externalInterface_GetCO2SignalStrength(void)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
396 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
397 return externalCO2SignalStrength;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
398 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
399
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
400
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
401 void externalInterface_SetCO2State(uint16_t state)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
402 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
403 externalCO2Status = state;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
404 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
405
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
406 uint16_t externalInterface_GetCO2State(void)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
407 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
408 return externalCO2Status;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
409 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
410
714
045ff7800501 Added customizable data area for specific sensor data:
Ideenmodellierer
parents: 704
diff changeset
411
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
412 uint8_t externalInterface_GetSensorData(uint8_t sensorId, uint8_t* pDataStruct)
714
045ff7800501 Added customizable data area for specific sensor data:
Ideenmodellierer
parents: 704
diff changeset
413 {
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
414 uint8_t localId = sensorId;
786
19ab6f3ed52a Cleanup sensor data interface:
Ideenmodellierer
parents: 784
diff changeset
415 if(localId == 0xFF)
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
416 {
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
417 localId = lastSensorDataId;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
418 }
714
045ff7800501 Added customizable data area for specific sensor data:
Ideenmodellierer
parents: 704
diff changeset
419
786
19ab6f3ed52a Cleanup sensor data interface:
Ideenmodellierer
parents: 784
diff changeset
420 if((pDataStruct != NULL) && (localId <= MAX_ADC_CHANNEL))
714
045ff7800501 Added customizable data area for specific sensor data:
Ideenmodellierer
parents: 704
diff changeset
421 {
786
19ab6f3ed52a Cleanup sensor data interface:
Ideenmodellierer
parents: 784
diff changeset
422 memcpy(pDataStruct, &sensorDataDiveO2[localId], sizeof(SSensorDataDiveO2));
19ab6f3ed52a Cleanup sensor data interface:
Ideenmodellierer
parents: 784
diff changeset
423 }
19ab6f3ed52a Cleanup sensor data interface:
Ideenmodellierer
parents: 784
diff changeset
424 else
19ab6f3ed52a Cleanup sensor data interface:
Ideenmodellierer
parents: 784
diff changeset
425 {
19ab6f3ed52a Cleanup sensor data interface:
Ideenmodellierer
parents: 784
diff changeset
426 localId = 0xFF;
714
045ff7800501 Added customizable data area for specific sensor data:
Ideenmodellierer
parents: 704
diff changeset
427 }
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
428 return localId;
714
045ff7800501 Added customizable data area for specific sensor data:
Ideenmodellierer
parents: 704
diff changeset
429 }
045ff7800501 Added customizable data area for specific sensor data:
Ideenmodellierer
parents: 704
diff changeset
430
786
19ab6f3ed52a Cleanup sensor data interface:
Ideenmodellierer
parents: 784
diff changeset
431 void externalInterface_SetSensorData(uint8_t sensorId, uint8_t* pDataStruct)
714
045ff7800501 Added customizable data area for specific sensor data:
Ideenmodellierer
parents: 704
diff changeset
432 {
045ff7800501 Added customizable data area for specific sensor data:
Ideenmodellierer
parents: 704
diff changeset
433 if(pDataStruct != NULL)
045ff7800501 Added customizable data area for specific sensor data:
Ideenmodellierer
parents: 704
diff changeset
434 {
786
19ab6f3ed52a Cleanup sensor data interface:
Ideenmodellierer
parents: 784
diff changeset
435 if((sensorId != 0xFF) && (sensorId < MAX_ADC_CHANNEL))
714
045ff7800501 Added customizable data area for specific sensor data:
Ideenmodellierer
parents: 704
diff changeset
436 {
786
19ab6f3ed52a Cleanup sensor data interface:
Ideenmodellierer
parents: 784
diff changeset
437 memcpy(&sensorDataDiveO2[sensorId], pDataStruct, sizeof(SSensorDataDiveO2));
19ab6f3ed52a Cleanup sensor data interface:
Ideenmodellierer
parents: 784
diff changeset
438 lastSensorDataId = sensorId;
714
045ff7800501 Added customizable data area for specific sensor data:
Ideenmodellierer
parents: 704
diff changeset
439 }
045ff7800501 Added customizable data area for specific sensor data:
Ideenmodellierer
parents: 704
diff changeset
440 else
045ff7800501 Added customizable data area for specific sensor data:
Ideenmodellierer
parents: 704
diff changeset
441 {
045ff7800501 Added customizable data area for specific sensor data:
Ideenmodellierer
parents: 704
diff changeset
442 memset(&sensorDataDiveO2,0,sizeof(sensorDataDiveO2));
786
19ab6f3ed52a Cleanup sensor data interface:
Ideenmodellierer
parents: 784
diff changeset
443 lastSensorDataId = 0xFF;
714
045ff7800501 Added customizable data area for specific sensor data:
Ideenmodellierer
parents: 704
diff changeset
444 }
045ff7800501 Added customizable data area for specific sensor data:
Ideenmodellierer
parents: 704
diff changeset
445 }
045ff7800501 Added customizable data area for specific sensor data:
Ideenmodellierer
parents: 704
diff changeset
446 }
045ff7800501 Added customizable data area for specific sensor data:
Ideenmodellierer
parents: 704
diff changeset
447
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
448 void externalInface_SetSensorMap(uint8_t* pMap)
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
449 {
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
450 if(pMap != NULL)
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
451 {
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
452 memcpy(MasterSensorMap, pMap, 5); /* the map is not directly copied. Copy is done via cmd request */
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
453 }
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
454
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
455 }
731
2a801cfe23ab Improvment sensor Autodetection:
Ideenmodellierer
parents: 729
diff changeset
456 uint8_t* externalInterface_GetSensorMapPointer(uint8_t finalMap)
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
457 {
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
458 uint8_t* pret;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
459
731
2a801cfe23ab Improvment sensor Autodetection:
Ideenmodellierer
parents: 729
diff changeset
460 if((externalAutoDetect != DETECTION_OFF) && (!finalMap))
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
461 {
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
462 pret = tmpSensorMap;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
463 }
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
464 else
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
465 {
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
466 pret = SensorMap;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
467 }
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
468 return pret;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
469 }
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
470
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
471 void externalInterface_AutodetectSensor()
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
472 {
781
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
473 static uint8_t tmpMuxMapping[MAX_MUX_CHANNEL];
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
474 static uint8_t sensorIndex = 0;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
475 static uint8_t uartMuxChannel = 0;
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
476 uint8_t index = 0;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
477
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
478 if(externalAutoDetect != DETECTION_OFF)
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
479 {
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
480 switch(externalAutoDetect)
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
481 {
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
482 case DETECTION_INIT: sensorIndex = 0;
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
483 uartMuxChannel = 0;
731
2a801cfe23ab Improvment sensor Autodetection:
Ideenmodellierer
parents: 729
diff changeset
484 tmpSensorMap[0] = SENSOR_OPTIC;
2a801cfe23ab Improvment sensor Autodetection:
Ideenmodellierer
parents: 729
diff changeset
485 tmpSensorMap[1] = SENSOR_OPTIC;
2a801cfe23ab Improvment sensor Autodetection:
Ideenmodellierer
parents: 729
diff changeset
486 tmpSensorMap[2] = SENSOR_OPTIC;
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
487 tmpSensorMap[3] = SENSOR_NONE;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
488 tmpSensorMap[4] = SENSOR_NONE;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
489
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
490 for(index = 0; index < MAX_ADC_CHANNEL; index++)
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
491 {
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
492 UART_MapDigO2_Channel(index,index); /* request all addresses */
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
493 tmpMuxMapping[index] = 0xff;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
494 }
784
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
495 UART_MapDigO2_Channel(2,3);
781
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
496
731
2a801cfe23ab Improvment sensor Autodetection:
Ideenmodellierer
parents: 729
diff changeset
497 if(externalInterfacePresent)
2a801cfe23ab Improvment sensor Autodetection:
Ideenmodellierer
parents: 729
diff changeset
498 {
2a801cfe23ab Improvment sensor Autodetection:
Ideenmodellierer
parents: 729
diff changeset
499 externalInterface_SwitchPower33(0);
2a801cfe23ab Improvment sensor Autodetection:
Ideenmodellierer
parents: 729
diff changeset
500 externalInterface_SwitchUART(0);
2a801cfe23ab Improvment sensor Autodetection:
Ideenmodellierer
parents: 729
diff changeset
501 for(index = 0; index < MAX_ADC_CHANNEL; index++)
2a801cfe23ab Improvment sensor Autodetection:
Ideenmodellierer
parents: 729
diff changeset
502 {
2a801cfe23ab Improvment sensor Autodetection:
Ideenmodellierer
parents: 729
diff changeset
503 externalChannel_mV[index] = 0;
2a801cfe23ab Improvment sensor Autodetection:
Ideenmodellierer
parents: 729
diff changeset
504 }
2a801cfe23ab Improvment sensor Autodetection:
Ideenmodellierer
parents: 729
diff changeset
505 externalAutoDetect = DETECTION_START;
2a801cfe23ab Improvment sensor Autodetection:
Ideenmodellierer
parents: 729
diff changeset
506 }
2a801cfe23ab Improvment sensor Autodetection:
Ideenmodellierer
parents: 729
diff changeset
507 else
2a801cfe23ab Improvment sensor Autodetection:
Ideenmodellierer
parents: 729
diff changeset
508 {
2a801cfe23ab Improvment sensor Autodetection:
Ideenmodellierer
parents: 729
diff changeset
509 externalAutoDetect = DETECTION_DONE; /* without external interface O2 values may only be received via optical port => return default sensor map */
2a801cfe23ab Improvment sensor Autodetection:
Ideenmodellierer
parents: 729
diff changeset
510 }
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
511 break;
731
2a801cfe23ab Improvment sensor Autodetection:
Ideenmodellierer
parents: 729
diff changeset
512 case DETECTION_START: tmpSensorMap[0] = SENSOR_ANALOG;
2a801cfe23ab Improvment sensor Autodetection:
Ideenmodellierer
parents: 729
diff changeset
513 tmpSensorMap[1] = SENSOR_ANALOG;
2a801cfe23ab Improvment sensor Autodetection:
Ideenmodellierer
parents: 729
diff changeset
514 tmpSensorMap[2] = SENSOR_ANALOG;
2a801cfe23ab Improvment sensor Autodetection:
Ideenmodellierer
parents: 729
diff changeset
515 externalInterface_SwitchPower33(1);
2a801cfe23ab Improvment sensor Autodetection:
Ideenmodellierer
parents: 729
diff changeset
516 externalInterface_SwitchADC(1);
2a801cfe23ab Improvment sensor Autodetection:
Ideenmodellierer
parents: 729
diff changeset
517 externalAutoDetect = DETECTION_ANALOG1;
2a801cfe23ab Improvment sensor Autodetection:
Ideenmodellierer
parents: 729
diff changeset
518 break;
2a801cfe23ab Improvment sensor Autodetection:
Ideenmodellierer
parents: 729
diff changeset
519 case DETECTION_ANALOG1: externalAutoDetect = DETECTION_ANALOG2; /* do a second loop to make sure all adc channels could be processed */
2a801cfe23ab Improvment sensor Autodetection:
Ideenmodellierer
parents: 729
diff changeset
520 break;
2a801cfe23ab Improvment sensor Autodetection:
Ideenmodellierer
parents: 729
diff changeset
521 case DETECTION_ANALOG2: for(index = 0; index < MAX_ADC_CHANNEL; index++)
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
522 {
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
523 if(externalChannel_mV[index] > MIN_ADC_VOLTAGE_MV)
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
524 {
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
525 tmpSensorMap[sensorIndex++] = SENSOR_ANALOG;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
526 }
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
527 else
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
528 {
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
529 tmpSensorMap[sensorIndex++] = SENSOR_NONE;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
530 }
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
531 }
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
532 externalAutoDetect = DETECTION_UARTMUX;
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
533 externalInterface_SwitchUART(EXT_INTERFACE_UART_O2 >> 8);
781
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
534 UART_SetDigO2_Channel(MAX_MUX_CHANNEL);
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
535 break;
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
536 case DETECTION_UARTMUX: if(UART_isDigO2Connected())
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
537 {
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
538 uartMuxChannel = 1;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
539 }
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
540 externalAutoDetect = DETECTION_DIGO2_0;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
541 externalInterface_SwitchUART(EXT_INTERFACE_UART_O2 >> 8);
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
542 UART_SetDigO2_Channel(0);
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
543
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
544 break;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
545 case DETECTION_DIGO2_0:
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
546 case DETECTION_DIGO2_1:
781
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
547 case DETECTION_DIGO2_2:
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
548 case DETECTION_DIGO2_3:
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
549 if(UART_isDigO2Connected())
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
550 {
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
551 for(index = 0; index < 3; index++) /* lookup a channel which may be used by digO2 */
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
552 {
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
553 if(tmpSensorMap[index] == SENSOR_NONE)
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
554 {
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
555 break;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
556 }
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
557 }
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
558 if(index == 3)
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
559 {
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
560 tmpSensorMap[2] = SENSOR_DIGO2; /* digital sensor overwrites ADC */
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
561 }
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
562 else
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
563 {
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
564 tmpSensorMap[index] = SENSOR_DIGO2;
781
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
565 tmpMuxMapping[externalAutoDetect - DETECTION_DIGO2_0] = index;
784
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
566 if(externalAutoDetect == DETECTION_DIGO2_2 ) /* special handling needed because channel is used twice during mux detection */
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
567 {
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
568 UART_MapDigO2_Channel(0xff, externalAutoDetect - DETECTION_DIGO2_0);
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
569 }
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
570 }
781
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
571 }
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
572 else
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
573 {
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
574 UART_MapDigO2_Channel(0xff, externalAutoDetect - DETECTION_DIGO2_0);
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
575 }
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
576 if(uartMuxChannel)
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
577 {
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
578 externalInterface_SwitchUART(EXT_INTERFACE_UART_O2 >> 8);
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
579 UART_SetDigO2_Channel(uartMuxChannel);
784
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
580 if(uartMuxChannel < MAX_ADC_CHANNEL - 1)
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
581 {
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
582 uartMuxChannel++;
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
583 }
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
584 }
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
585 else
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
586 {
781
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
587 externalAutoDetect = DETECTION_DIGO2_3; /* skip detection of other serial sensors */
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
588 }
742
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 738
diff changeset
589 externalAutoDetect++;
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 738
diff changeset
590 #ifdef ENABLE_CO2_SUPPORT
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
591 if(externalAutoDetect == DETECTION_CO2)
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
592 {
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
593 externalInterface_SwitchUART(EXT_INTERFACE_UART_CO2 >> 8);
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
594 }
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
595 break;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
596 case DETECTION_CO2: if(UART_isCO2Connected())
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
597 {
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
598 for(index = 0; index < 3; index++) /* lookup a channel which may be used by CO2*/
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
599 {
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
600 if(tmpSensorMap[index] == SENSOR_NONE)
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
601 {
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
602 break;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
603 }
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
604 }
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
605 if(index == 3)
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
606 {
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
607 tmpSensorMap[sensorIndex++] = SENSOR_CO2; /* place Co2 sensor behind O2 sensors (not visible) */
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
608 }
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
609 else
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
610 {
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
611 tmpSensorMap[index] = SENSOR_CO2;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
612 }
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
613
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
614 }
742
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 738
diff changeset
615 externalAutoDetect++;
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 738
diff changeset
616 #endif
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 738
diff changeset
617 #ifdef ENABLE_SENTINEL_MODE
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
618 if(externalAutoDetect == DETECTION_SENTINEL)
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
619 {
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
620 externalInterface_SwitchUART(EXT_INTERFACE_UART_SENTINEL >> 8);
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
621 UART_StartDMA_Receiption();
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
622 }
742
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 738
diff changeset
623 break;
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 738
diff changeset
624
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 738
diff changeset
625 case DETECTION_SENTINEL:
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 738
diff changeset
626 case DETECTION_SENTINEL2:
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 738
diff changeset
627 if(UART_isSentinelConnected())
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 738
diff changeset
628 {
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 738
diff changeset
629 for(index = 0; index < 3; index++) /* Sentinel is occupiing all sensor slots */
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 738
diff changeset
630 {
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 738
diff changeset
631 tmpSensorMap[index] = SENSOR_SENTINEL;
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 738
diff changeset
632 }
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 738
diff changeset
633 sensorIndex = 3;
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 738
diff changeset
634 }
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 738
diff changeset
635 externalAutoDetect++;
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 738
diff changeset
636 #endif
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
637 break;
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
638 case DETECTION_DONE: if(uartMuxChannel)
731
2a801cfe23ab Improvment sensor Autodetection:
Ideenmodellierer
parents: 729
diff changeset
639 {
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
640 tmpSensorMap[EXT_INTERFACE_SENSOR_CNT-1] = SENSOR_MUX;
731
2a801cfe23ab Improvment sensor Autodetection:
Ideenmodellierer
parents: 729
diff changeset
641 }
784
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
642
781
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
643 for(index = 0; index < MAX_MUX_CHANNEL; index++)
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
644 {
784
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
645 UART_MapDigO2_Channel(tmpMuxMapping[index], index);
731
2a801cfe23ab Improvment sensor Autodetection:
Ideenmodellierer
parents: 729
diff changeset
646 }
784
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
647
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
648 externalAutoDetect = DETECTION_OFF;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
649 externalInterface_SwitchUART(0);
786
19ab6f3ed52a Cleanup sensor data interface:
Ideenmodellierer
parents: 784
diff changeset
650
19ab6f3ed52a Cleanup sensor data interface:
Ideenmodellierer
parents: 784
diff changeset
651
19ab6f3ed52a Cleanup sensor data interface:
Ideenmodellierer
parents: 784
diff changeset
652 for(index = 0; index < MAX_ADC_CHANNEL; index++)
19ab6f3ed52a Cleanup sensor data interface:
Ideenmodellierer
parents: 784
diff changeset
653 {
19ab6f3ed52a Cleanup sensor data interface:
Ideenmodellierer
parents: 784
diff changeset
654 if(tmpSensorMap[index] == SENSOR_DIGO2) /* set Channel to first valid entry */
19ab6f3ed52a Cleanup sensor data interface:
Ideenmodellierer
parents: 784
diff changeset
655 {
19ab6f3ed52a Cleanup sensor data interface:
Ideenmodellierer
parents: 784
diff changeset
656 UART_SetDigO2_Channel(index);
19ab6f3ed52a Cleanup sensor data interface:
Ideenmodellierer
parents: 784
diff changeset
657 break;
19ab6f3ed52a Cleanup sensor data interface:
Ideenmodellierer
parents: 784
diff changeset
658 }
19ab6f3ed52a Cleanup sensor data interface:
Ideenmodellierer
parents: 784
diff changeset
659 }
784
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
660 for(index = 0; index < MAX_ADC_CHANNEL; index++)
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
661 {
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
662 if(tmpSensorMap[index] != SENSOR_NONE)
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
663 {
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
664 break;
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
665 }
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
666 }
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
667
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
668 if(index == MAX_ADC_CHANNEL) /* return default sensor map if no sensor at all has been detected */
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
669 {
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
670 tmpSensorMap[0] = SENSOR_OPTIC;
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
671 tmpSensorMap[1] = SENSOR_OPTIC;
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
672 tmpSensorMap[2] = SENSOR_OPTIC;
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
673 }
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
674 memcpy(SensorMap, tmpSensorMap, sizeof(tmpSensorMap));
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 753
diff changeset
675
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
676 break;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
677 default:
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
678 break;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
679 }
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
680 }
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
681 }
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
682
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
683
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
684 void externalInterface_ExecuteCmd(uint16_t Cmd)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
685 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
686 char cmdString[10];
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
687 uint8_t cmdLength = 0;
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
688 uint8_t index;
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
689
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
690 switch(Cmd & 0x00FF) /* lower byte is reserved for commands */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
691 {
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
692 case EXT_INTERFACE_AUTODETECT: externalAutoDetect = DETECTION_INIT;
742
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 738
diff changeset
693 for(index = 0; index < 3; index++)
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 738
diff changeset
694 {
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 738
diff changeset
695 SensorMap[index] = SENSOR_SEARCH;
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 738
diff changeset
696 }
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
697 break;
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
698 case EXT_INTERFACE_CO2_CALIB: cmdLength = snprintf(cmdString, 10, "G\r\n");
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
699 break;
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
700 case EXT_INTERFACE_COPY_SENSORMAP: if(externalAutoDetect == DETECTION_OFF)
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
701 {
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
702 memcpy(SensorMap, MasterSensorMap, 5);
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
703 for(index = 0; index < 3; index++)
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
704 {
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
705 if(SensorMap[index] == SENSOR_DIGO2)
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
706 {
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
707 break;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
708 }
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
709 }
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
710 }
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 714
diff changeset
711 break;
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
712 default:
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
713 break;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
714 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
715 if(cmdLength != 0)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
716 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
717 HAL_UART_Transmit(&huart1,(uint8_t*)cmdString,cmdLength,10);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
718 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
719 return;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
720 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 581
diff changeset
721