Added sanity check to CO2 (must be more that 0 :D)
This commit is contained in:
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user