From 78c8104a58dc58e3e5304afa3aac796f77fc6477 Mon Sep 17 00:00:00 2001 From: Duke NUCem Date: Mon, 11 Oct 2021 20:06:27 +0200 Subject: [PATCH] Added sanity check to CO2 (must be more that 0 :D) --- fw/Core/Src/main.c | 20 +++++++++++++++++--- fw/iaq_wired_sensor Debug.launch | 2 +- tests/read_input_register_test.py | 2 +- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/fw/Core/Src/main.c b/fw/Core/Src/main.c index aaf8352..cb9ac02 100644 --- a/fw/Core/Src/main.c +++ b/fw/Core/Src/main.c @@ -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 */ diff --git a/fw/iaq_wired_sensor Debug.launch b/fw/iaq_wired_sensor Debug.launch index 647065f..e9df78e 100644 --- a/fw/iaq_wired_sensor Debug.launch +++ b/fw/iaq_wired_sensor Debug.launch @@ -68,6 +68,6 @@ - + diff --git a/tests/read_input_register_test.py b/tests/read_input_register_test.py index e1067c5..ac5a2c5 100755 --- a/tests/read_input_register_test.py +++ b/tests/read_input_register_test.py @@ -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