Added sanity check to CO2 (must be more that 0 :D)

This commit is contained in:
Duke NUCem 2021-10-11 20:06:27 +02:00
parent a87afdf6fa
commit 78c8104a58
3 changed files with 19 additions and 5 deletions

View File

@ -111,6 +111,7 @@ config_t sensor_config;
uint8_t sensor_config_pending_write = 0;
uint8_t baudrate_changed = 0;
uint8_t modbus_address_changed = 0;
uint8_t co2_valid = 0;
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
@ -179,7 +180,7 @@ int main(void)
/* Turn on MAGENTA LED to signal startup state */
LL_GPIO_ResetOutputPin(LED_R_GPIO_Port, LED_R_Pin);
LL_GPIO_SetOutputPin(LED_G_GPIO_Port, LED_G_Pin);
LL_GPIO_ResetOutputPin(LED_G_GPIO_Port, LED_G_Pin);
LL_GPIO_ResetOutputPin(LED_B_GPIO_Port, LED_B_Pin);
/* Enable I2C for sensors */
@ -297,6 +298,11 @@ int main(void)
scd4x_read_measurement(&CO2,
&T_SCD4x,
&RH_SCD4x);
if (CO2 > 0) {
co2_valid = 1;
} else {
co2_valid = 0;
}
}
/* Read SPS30 data (if connected) */
@ -312,6 +318,7 @@ int main(void)
}
/* TEST END */
if (sensor_config.led_on) {
if (co2_valid == 1) {
if (CO2 <= sensor_config.led_co2_alert_limit1) {
/* CO2 is OK -> GREEN */
LL_GPIO_SetOutputPin(LED_R_GPIO_Port, LED_R_Pin);
@ -331,10 +338,17 @@ int main(void)
LL_GPIO_SetOutputPin(LED_B_GPIO_Port, LED_B_Pin);
}
} else {
LL_GPIO_SetOutputPin(LED_R_GPIO_Port, LED_R_Pin);
LL_GPIO_ResetOutputPin(LED_R_GPIO_Port, LED_R_Pin);
LL_GPIO_SetOutputPin(LED_G_GPIO_Port, LED_G_Pin);
LL_GPIO_SetOutputPin(LED_B_GPIO_Port, LED_B_Pin);
LL_GPIO_ResetOutputPin(LED_B_GPIO_Port, LED_B_Pin);
}
} else {
LL_GPIO_SetOutputPin(LED_R_GPIO_Port, LED_R_Pin);
LL_GPIO_SetOutputPin(LED_G_GPIO_Port, LED_G_Pin);
LL_GPIO_SetOutputPin(LED_B_GPIO_Port, LED_B_Pin);
}
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */

View File

@ -68,6 +68,6 @@
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="4"/>
</listAttribute>
<stringAttribute key="org.eclipse.dsf.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#10;&lt;memoryBlockExpressionList context=&quot;reserved-for-future-use&quot;&gt;&#10; &lt;gdbmemoryBlockExpression address=&quot;134742016&quot; label=&quot;0x08080000&quot;/&gt;&#10; &lt;gdbmemoryBlockExpression address=&quot;134742020&quot; label=&quot;0x08080004&quot;/&gt;&#10;&lt;/memoryBlockExpressionList&gt;&#10;"/>
<stringAttribute key="org.eclipse.dsf.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&lt;memoryBlockExpressionList context=&quot;reserved-for-future-use&quot;&gt;&lt;gdbmemoryBlockExpression address=&quot;134742016&quot; label=&quot;0x08080000&quot;/&gt;&lt;gdbmemoryBlockExpression address=&quot;134742020&quot; label=&quot;0x08080004&quot;/&gt;&lt;gdbmemoryBlockExpression address=&quot;134742016&quot; label=&quot;0x08080000&quot;/&gt;&lt;/memoryBlockExpressionList&gt;"/>
<stringAttribute key="process_factory_id" value="org.eclipse.cdt.dsf.gdb.GdbProcessFactory"/>
</launchConfiguration>

View File

@ -5,7 +5,7 @@ import minimalmodbus
import serial
slave_address = 254
instrument = minimalmodbus.Instrument('/dev/ttyUSB0', slave_address, close_port_after_each_call=True) # port name, slave address (in decimal)
instrument = minimalmodbus.Instrument('/dev/rs485', slave_address, close_port_after_each_call=True) # port name, slave address (in decimal)
instrument.serial.baudrate = 19200
instrument.serial.bytesize = 8