Mercurial > public > ostc4
annotate Small_CPU/Src/externalInterface.c @ 741:6a35e2e97bfb
Added button lock after wakeup in surface mode:
During setup of diveequipment the OSTC4 is sometimes operated unintended (e.g. while equipping the jaket). To avoid this it is now possible to activate a button lock in the button lock sensitivity menu. The OSTC4 will then wakeup as usuall but if the diver wants to oerate the menus he has to press the buttons in a certain order. The button to be pressed is indicated by a blue bar. The button lock is deactivated in dive mode.
author | Ideenmodellierer |
---|---|
date | Thu, 02 Feb 2023 17:35:54 +0100 |
parents | 30717de00f3a |
children | e23fe82cbf8c |
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>© 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 | 31 #include "uart.h" |
32 #include "data_exchange.h" | |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
33 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
34 extern SGlobal global; |
662 | 35 extern UART_HandleTypeDef huart1; |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
36 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
37 #define ADC_ANSWER_LENGTH (5u) /* 3424 will provide addr + 4 data bytes */ |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
38 #define ADC_TIMEOUT (10u) /* conversion stuck for unknown reason => restart */ |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
39 #define ADC_REF_VOLTAGE_MV (2048.0f) /* reference voltage of MPC3424*/ |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
40 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
41 #define ADC_START_CONVERSION (0x80) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
42 #define ADC_GAIN_4 (0x02) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
43 #define ADC_GAIN_4_VALUE (4.0f) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
44 #define ADC_GAIN_8 (0x03) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
45 #define ADC_GAIN_8_VALUE (8.0f) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
46 #define ADC_RESOLUTION_16BIT (0x08) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
47 #define ADC_RESOLUTION_16BIT_VALUE (16u) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
48 #define ADC_RESOLUTION_18BIT (0x0C) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
49 #define ADC_RESOLUTION_18BIT_VALUE (18u) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
50 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
51 #define ANSWER_CONFBYTE_INDEX (4u) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
52 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
53 static uint8_t activeChannel = 0; /* channel which is in request */ |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
54 static uint8_t recBuf[ADC_ANSWER_LENGTH]; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
55 static uint8_t timeoutCnt = 0; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
56 static uint8_t externalInterfacePresent = 0; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
57 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
58 float externalChannel_mV[MAX_ADC_CHANNEL]; |
662 | 59 static uint8_t externalV33_On = 0; |
691 | 60 static uint8_t externalADC_On = 0; |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
61 static uint8_t externalUART_Protocol = 0; |
662 | 62 static uint16_t externalCO2Value; |
63 static uint16_t externalCO2SignalStrength; | |
64 static uint16_t externalCO2Status = 0; | |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
65 |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
66 static uint8_t sensorDataId = 0; |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
67 static SSensorDataDiveO2 sensorDataDiveO2; |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
68 static externalInterfaceAutoDetect_t externalAutoDetect = DETECTION_OFF; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
69 static externalInterfaceSensorType SensorMap[EXT_INTERFACE_SENSOR_CNT] ={ SENSOR_ANALOG, SENSOR_ANALOG, SENSOR_ANALOG, SENSOR_NONE, SENSOR_NONE}; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
70 static externalInterfaceSensorType tmpSensorMap[EXT_INTERFACE_SENSOR_CNT]; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
71 static externalInterfaceSensorType MasterSensorMap[EXT_INTERFACE_SENSOR_CNT]; |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
72 |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
73 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
74 void externalInterface_Init(void) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
75 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
76 activeChannel = 0; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
77 timeoutCnt = 0; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
78 externalInterfacePresent = 0; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
79 if(externalInterface_StartConversion(activeChannel) == HAL_OK) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
80 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
81 externalInterfacePresent = 1; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
82 global.deviceDataSendToMaster.hw_Info.extADC = 1; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
83 } |
559 | 84 global.deviceDataSendToMaster.hw_Info.checkADC = 1; |
662 | 85 |
738
30717de00f3a
Added data init function for external interface:
Ideenmodellierer
parents:
731
diff
changeset
|
86 externalInterface_InitDatastruct(); |
30717de00f3a
Added data init function for external interface:
Ideenmodellierer
parents:
731
diff
changeset
|
87 } |
30717de00f3a
Added data init function for external interface:
Ideenmodellierer
parents:
731
diff
changeset
|
88 |
30717de00f3a
Added data init function for external interface:
Ideenmodellierer
parents:
731
diff
changeset
|
89 void externalInterface_InitDatastruct(void) |
30717de00f3a
Added data init function for external interface:
Ideenmodellierer
parents:
731
diff
changeset
|
90 { |
30717de00f3a
Added data init function for external interface:
Ideenmodellierer
parents:
731
diff
changeset
|
91 uint8_t index = 0; |
30717de00f3a
Added data init function for external interface:
Ideenmodellierer
parents:
731
diff
changeset
|
92 /* init data values */ |
662 | 93 externalV33_On = 0; |
94 externalCO2Value = 0; | |
95 externalCO2SignalStrength = 0; | |
96 externalCO2Status = 0; | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
97 externalAutoDetect = DETECTION_OFF; |
738
30717de00f3a
Added data init function for external interface:
Ideenmodellierer
parents:
731
diff
changeset
|
98 |
30717de00f3a
Added data init function for external interface:
Ideenmodellierer
parents:
731
diff
changeset
|
99 for(index = 0; index < MAX_ADC_CHANNEL; index++) |
30717de00f3a
Added data init function for external interface:
Ideenmodellierer
parents:
731
diff
changeset
|
100 { |
30717de00f3a
Added data init function for external interface:
Ideenmodellierer
parents:
731
diff
changeset
|
101 externalChannel_mV[index] = 0.0; |
30717de00f3a
Added data init function for external interface:
Ideenmodellierer
parents:
731
diff
changeset
|
102 } |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
103 } |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
104 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
105 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
106 uint8_t externalInterface_StartConversion(uint8_t channel) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
107 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
108 uint8_t retval = 0; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
109 uint8_t confByte = 0; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
110 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
111 if(channel < MAX_ADC_CHANNEL) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
112 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
113 confByte = ADC_START_CONVERSION | ADC_RESOLUTION_16BIT | ADC_GAIN_8; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
114 confByte |= channel << 5; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
115 retval = I2C_Master_Transmit(DEVICE_EXTERNAL_ADC, &confByte, 1); |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
116 } |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
117 return retval; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
118 } |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
119 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
120 /* Check if conversion is done and trigger measurement of next channel */ |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
121 uint8_t externalInterface_ReadAndSwitch() |
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 retval = EXTERNAL_ADC_NO_DATA; |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
124 uint8_t nextChannel; |
731 | 125 uint8_t* psensorMap = externalInterface_GetSensorMapPointer(0); |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
126 |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
127 if(externalADC_On) |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
128 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
129 if(I2C_Master_Receive(DEVICE_EXTERNAL_ADC, recBuf, ADC_ANSWER_LENGTH) == HAL_OK) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
130 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
131 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
|
132 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
133 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
|
134 nextChannel = activeChannel + 1; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
135 if(nextChannel == MAX_ADC_CHANNEL) |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
136 { |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
137 nextChannel = 0; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
138 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
139 |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
140 while((psensorMap[nextChannel] != SENSOR_ANALOG) && (nextChannel != activeChannel)) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
141 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
142 if(nextChannel == MAX_ADC_CHANNEL) |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
143 { |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
144 nextChannel = 0; |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
145 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
146 else |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
147 { |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
148 nextChannel++; |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
149 } |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
150 } |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
151 |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
152 activeChannel = nextChannel; |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
153 externalInterface_StartConversion(activeChannel); |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
154 timeoutCnt = 0; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
155 } |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
156 else |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
157 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
158 if(timeoutCnt++ >= ADC_TIMEOUT) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
159 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
160 externalInterface_StartConversion(activeChannel); |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
161 timeoutCnt = 0; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
162 } |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
163 } |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
164 } |
581
011d8f9f5ddb
Added ex Interface measurement restart in case of i2c disturbance:
Ideenmodellierer
parents:
559
diff
changeset
|
165 else /* take also i2c bus disturb into account */ |
011d8f9f5ddb
Added ex Interface measurement restart in case of i2c disturbance:
Ideenmodellierer
parents:
559
diff
changeset
|
166 { |
011d8f9f5ddb
Added ex Interface measurement restart in case of i2c disturbance:
Ideenmodellierer
parents:
559
diff
changeset
|
167 if(timeoutCnt++ >= ADC_TIMEOUT) |
011d8f9f5ddb
Added ex Interface measurement restart in case of i2c disturbance:
Ideenmodellierer
parents:
559
diff
changeset
|
168 { |
011d8f9f5ddb
Added ex Interface measurement restart in case of i2c disturbance:
Ideenmodellierer
parents:
559
diff
changeset
|
169 externalInterface_StartConversion(activeChannel); |
011d8f9f5ddb
Added ex Interface measurement restart in case of i2c disturbance:
Ideenmodellierer
parents:
559
diff
changeset
|
170 timeoutCnt = 0; |
011d8f9f5ddb
Added ex Interface measurement restart in case of i2c disturbance:
Ideenmodellierer
parents:
559
diff
changeset
|
171 } |
011d8f9f5ddb
Added ex Interface measurement restart in case of i2c disturbance:
Ideenmodellierer
parents:
559
diff
changeset
|
172 } |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
173 } |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
174 return retval; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
175 } |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
176 float externalInterface_CalculateADCValue(uint8_t channel) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
177 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
178 int32_t rawvalue = 0; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
179 float retValue = 0.0; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
180 if(channel < MAX_ADC_CHANNEL) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
181 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
182 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
183 rawvalue = ((recBuf[0] << 16) | (recBuf[1] << 8) | (recBuf[2])); |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
184 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
185 switch(recBuf[3] & 0x0C) /* confbyte => Resolution bits*/ |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
186 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
187 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
|
188 if(rawvalue & (0x1 << (ADC_RESOLUTION_16BIT_VALUE-1))) /* MSB set => negative number */ |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
189 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
190 rawvalue |= 0xFFFF0000; /* set MSB for int32 */ |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
191 } |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
192 else |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
193 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
194 rawvalue &= 0x0000FFFF; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
195 } |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
196 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
|
197 break; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
198 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
|
199 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
200 rawvalue |= 0xFFFE0000; /* set MSB for int32 */ |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
201 } |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
202 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
|
203 break; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
204 default: rawvalue = 0; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
205 break; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
206 } |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
207 externalChannel_mV[channel] = externalChannel_mV[channel] * rawvalue / ADC_GAIN_8_VALUE; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
208 retValue = externalChannel_mV[channel]; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
209 } |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
210 return retValue; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
211 } |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
212 float getExternalInterfaceChannel(uint8_t channel) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
213 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
214 float retval = 0; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
215 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
216 if(channel < MAX_ADC_CHANNEL) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
217 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
218 retval = externalChannel_mV[channel]; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
219 } |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
220 return retval; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
221 } |
662 | 222 |
691 | 223 uint8_t setExternalInterfaceChannel(uint8_t channel, float value) |
224 { | |
225 uint8_t retval = 0; | |
226 | |
227 if(channel < MAX_ADC_CHANNEL) | |
228 { | |
229 externalChannel_mV[channel] = value; | |
230 retval = 1; | |
231 } | |
232 return retval; | |
233 } | |
234 | |
662 | 235 void externalInterface_InitPower33(void) |
236 { | |
237 GPIO_InitTypeDef GPIO_InitStructure; | |
238 | |
239 GPIO_InitStructure.Pin = GPIO_PIN_7; | |
240 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | |
241 GPIO_InitStructure.Pull = GPIO_PULLUP; | |
242 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
243 HAL_GPIO_Init(GPIOC, &GPIO_InitStructure); | |
244 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_SET); | |
245 } | |
246 | |
247 | |
248 uint8_t externalInterface_isEnabledPower33() | |
249 { | |
250 return externalV33_On; | |
251 } | |
691 | 252 |
253 uint8_t externalInterface_isEnabledADC() | |
254 { | |
255 return externalADC_On; | |
256 } | |
257 | |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
258 uint8_t externalInterface_GetUARTProtocol() |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
259 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
260 return externalUART_Protocol; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
261 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
262 |
662 | 263 void externalInterface_SwitchPower33(uint8_t state) |
264 { | |
265 if(state != externalV33_On) | |
266 { | |
267 if(state) | |
268 { | |
269 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_RESET); | |
270 externalV33_On = 1; | |
271 } | |
272 else | |
273 { | |
731 | 274 if(externalAutoDetect == DETECTION_OFF) |
275 { | |
276 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_SET); | |
277 externalV33_On = 0; | |
278 externalInterface_SetCO2Value(0); | |
279 externalInterface_SetCO2SignalStrength(0); | |
280 } | |
662 | 281 } |
282 } | |
283 } | |
691 | 284 void externalInterface_SwitchADC(uint8_t state) |
285 { | |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
286 uint8_t loop = 0; |
691 | 287 if((state) && (externalInterfacePresent)) |
288 { | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
289 if(externalADC_On == 0) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
290 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
291 activeChannel = 0; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
292 externalInterface_StartConversion(activeChannel); |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
293 externalADC_On = 1; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
294 } |
691 | 295 } |
296 else | |
297 { | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
298 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
|
299 { |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
300 externalADC_On = 0; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
301 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
|
302 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
303 externalChannel_mV[loop] = 0; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
304 } |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
305 } |
691 | 306 } |
307 } | |
662 | 308 |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
309 void externalInterface_SwitchUART(uint8_t protocol) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
310 { |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
311 switch(protocol) |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
312 { |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
313 case 0: |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
314 case (EXT_INTERFACE_UART_CO2 >> 8): |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
315 case (EXT_INTERFACE_UART_O2 >> 8): |
731 | 316 if((externalAutoDetect <= DETECTION_START) || ((protocol == EXT_INTERFACE_UART_CO2 >> 8) && (externalAutoDetect == DETECTION_CO2)) |
317 || ((protocol == EXT_INTERFACE_UART_O2 >> 8) && (externalAutoDetect == DETECTION_DIGO2))) | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
318 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
319 sensorDataId = 0; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
320 externalUART_Protocol = protocol; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
321 MX_USART1_UART_DeInit(); |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
322 if( protocol != 0) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
323 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
324 MX_USART1_UART_Init(); |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
325 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
326 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
327 break; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
328 default: |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
329 break; |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
330 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
331 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
332 |
662 | 333 void externalInterface_SetCO2Value(uint16_t CO2_ppm) |
334 { | |
335 externalCO2Value = CO2_ppm; | |
336 } | |
337 | |
338 void externalInterface_SetCO2SignalStrength(uint16_t LED_qa) | |
339 { | |
340 externalCO2SignalStrength = LED_qa; | |
341 } | |
342 | |
343 uint16_t externalInterface_GetCO2Value(void) | |
344 { | |
345 return externalCO2Value; | |
346 } | |
347 | |
348 uint16_t externalInterface_GetCO2SignalStrength(void) | |
349 { | |
350 return externalCO2SignalStrength; | |
351 } | |
352 | |
353 | |
354 void externalInterface_SetCO2State(uint16_t state) | |
355 { | |
356 externalCO2Status = state; | |
357 } | |
358 | |
359 uint16_t externalInterface_GetCO2State(void) | |
360 { | |
361 return externalCO2Status; | |
362 } | |
363 | |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
364 |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
365 uint8_t externalInterface_GetSensorData(uint8_t* pDataStruct) |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
366 { |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
367 |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
368 if((pDataStruct != NULL) && sensorDataId != 0) |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
369 { |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
370 memcpy(pDataStruct, &sensorDataDiveO2, sizeof(sensorDataDiveO2)); |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
371 } |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
372 return sensorDataId; |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
373 } |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
374 |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
375 void externalInterface_SetSensorData(uint8_t dataId, uint8_t* pDataStruct) |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
376 { |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
377 if(pDataStruct != NULL) |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
378 { |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
379 if(dataId != 0) |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
380 { |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
381 memcpy(&sensorDataDiveO2, pDataStruct, sizeof(sensorDataDiveO2)); |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
382 } |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
383 else |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
384 { |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
385 memset(&sensorDataDiveO2,0,sizeof(sensorDataDiveO2)); |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
386 } |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
387 sensorDataId = dataId; |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
388 } |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
389 } |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
390 |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
391 void externalInface_SetSensorMap(uint8_t* pMap) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
392 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
393 if(pMap != NULL) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
394 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
395 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
|
396 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
397 |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
398 } |
731 | 399 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
|
400 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
401 uint8_t* pret; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
402 |
731 | 403 if((externalAutoDetect != DETECTION_OFF) && (!finalMap)) |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
404 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
405 pret = tmpSensorMap; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
406 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
407 else |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
408 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
409 pret = SensorMap; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
410 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
411 return pret; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
412 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
413 |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
414 void externalInterface_AutodetectSensor() |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
415 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
416 static uint8_t sensorIndex = 0; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
417 uint8_t index = 0; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
418 |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
419 if(externalAutoDetect != DETECTION_OFF) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
420 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
421 switch(externalAutoDetect) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
422 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
423 case DETECTION_INIT: sensorIndex = 0; |
731 | 424 tmpSensorMap[0] = SENSOR_OPTIC; |
425 tmpSensorMap[1] = SENSOR_OPTIC; | |
426 tmpSensorMap[2] = SENSOR_OPTIC; | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
427 tmpSensorMap[3] = SENSOR_NONE; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
428 tmpSensorMap[4] = SENSOR_NONE; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
429 |
731 | 430 if(externalInterfacePresent) |
431 { | |
432 externalInterface_SwitchPower33(0); | |
433 externalInterface_SwitchUART(0); | |
434 for(index = 0; index < MAX_ADC_CHANNEL; index++) | |
435 { | |
436 externalChannel_mV[index] = 0; | |
437 } | |
438 externalAutoDetect = DETECTION_START; | |
439 } | |
440 else | |
441 { | |
442 externalAutoDetect = DETECTION_DONE; /* without external interface O2 values may only be received via optical port => return default sensor map */ | |
443 } | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
444 break; |
731 | 445 case DETECTION_START: tmpSensorMap[0] = SENSOR_ANALOG; |
446 tmpSensorMap[1] = SENSOR_ANALOG; | |
447 tmpSensorMap[2] = SENSOR_ANALOG; | |
448 externalInterface_SwitchPower33(1); | |
449 externalInterface_SwitchADC(1); | |
450 externalAutoDetect = DETECTION_ANALOG1; | |
451 break; | |
452 case DETECTION_ANALOG1: externalAutoDetect = DETECTION_ANALOG2; /* do a second loop to make sure all adc channels could be processed */ | |
453 break; | |
454 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
|
455 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
456 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
|
457 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
458 tmpSensorMap[sensorIndex++] = SENSOR_ANALOG; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
459 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
460 else |
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 tmpSensorMap[sensorIndex++] = SENSOR_NONE; |
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 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
465 externalAutoDetect = DETECTION_DIGO2; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
466 externalInterface_SwitchUART(EXT_INTERFACE_UART_O2 >> 8); |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
467 break; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
468 case DETECTION_DIGO2: if(UART_isDigO2Connected()) |
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 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
|
471 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
472 if(tmpSensorMap[index] == SENSOR_NONE) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
473 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
474 break; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
475 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
476 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
477 if(index == 3) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
478 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
479 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
|
480 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
481 else |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
482 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
483 tmpSensorMap[index] = SENSOR_DIGO2; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
484 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
485 |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
486 UART_setTargetChannel(index); |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
487 /* tmpSensorMap[sensorIndex++] = SENSOR_DIGO2; */ |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
488 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
489 externalAutoDetect = DETECTION_CO2; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
490 externalInterface_SwitchUART(EXT_INTERFACE_UART_CO2 >> 8); |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
491 break; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
492 case DETECTION_CO2: if(UART_isCO2Connected()) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
493 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
494 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
|
495 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
496 if(tmpSensorMap[index] == SENSOR_NONE) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
497 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
498 break; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
499 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
500 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
501 if(index == 3) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
502 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
503 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
|
504 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
505 else |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
506 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
507 tmpSensorMap[index] = SENSOR_CO2; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
508 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
509 |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
510 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
511 externalAutoDetect = DETECTION_DONE; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
512 break; |
731 | 513 case DETECTION_DONE: for(index = 0; index < EXT_INTERFACE_SENSOR_CNT; index++) |
514 { | |
515 if(tmpSensorMap[index] != SENSOR_NONE) | |
516 { | |
517 break; | |
518 } | |
519 } | |
520 | |
521 if(index != EXT_INTERFACE_SENSOR_CNT) /* return default sensor map if no sensor at all has been detected */ | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
522 { |
731 | 523 while(sensorIndex < EXT_INTERFACE_SENSOR_CNT) |
524 { | |
525 tmpSensorMap[sensorIndex++] = SENSOR_NONE; | |
526 } | |
527 } | |
528 else | |
529 { | |
530 tmpSensorMap[0] = SENSOR_OPTIC; | |
531 tmpSensorMap[1] = SENSOR_OPTIC; | |
532 tmpSensorMap[2] = SENSOR_OPTIC; | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
533 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
534 memcpy(SensorMap, tmpSensorMap, sizeof(tmpSensorMap)); |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
535 externalAutoDetect = DETECTION_OFF; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
536 break; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
537 default: |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
538 break; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
539 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
540 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
541 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
542 |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
543 |
662 | 544 void externalInterface_ExecuteCmd(uint16_t Cmd) |
545 { | |
546 char cmdString[10]; | |
547 uint8_t cmdLength = 0; | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
548 uint8_t index; |
662 | 549 |
550 switch(Cmd & 0x00FF) /* lower byte is reserved for commands */ | |
551 { | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
552 case EXT_INTERFACE_AUTODETECT: externalAutoDetect = DETECTION_INIT; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
553 break; |
662 | 554 case EXT_INTERFACE_CO2_CALIB: cmdLength = snprintf(cmdString, 10, "G\r\n"); |
555 break; | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
556 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
|
557 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
558 memcpy(SensorMap, MasterSensorMap, 5); |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
559 for(index = 0; index < 3; index++) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
560 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
561 if(SensorMap[index] == SENSOR_DIGO2) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
562 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
563 break; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
564 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
565 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
566 UART_setTargetChannel(index); /* if no slot for digO2 is found then the function will be called with an invalid parameter causing the overwrite function to fail */ |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
567 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
568 break; |
662 | 569 default: |
570 break; | |
571 } | |
572 if(cmdLength != 0) | |
573 { | |
574 HAL_UART_Transmit(&huart1,(uint8_t*)cmdString,cmdLength,10); | |
575 } | |
576 return; | |
577 } | |
578 |