Added CO2 Level LED indication.
This commit is contained in:
parent
80a50d57cf
commit
5244fe768f
@ -49,8 +49,8 @@ config_read(&config);
|
||||
* Device configuration data can be accessed using config_t struct.
|
||||
*/
|
||||
#define CONFIG_DEFAULT_LED_ON 1
|
||||
#define CONFIG_DEFAULT_LED_ALERT1_LIMIT 1000
|
||||
#define CONFIG_DEFAULT_LED_ALERT2_LIMIT 2000
|
||||
#define CONFIG_DEFAULT_LED_ALERT1_LIMIT 1500
|
||||
#define CONFIG_DEFAULT_LED_ALERT2_LIMIT 3000
|
||||
|
||||
#define MODBUS_ADDR_LENGTH 2
|
||||
#define CONFIG_LED_ON_LENGTH 2
|
||||
|
@ -267,22 +267,15 @@ int main(void)
|
||||
MX_LPUART1_UART_Init();
|
||||
MX_TIM21_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
|
||||
/* 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_B_GPIO_Port, LED_B_Pin);
|
||||
|
||||
/* Enable I2C for sensors */
|
||||
LL_I2C_Enable(I2C1);
|
||||
|
||||
/* Enable UART for RS485 */
|
||||
LL_LPUART_Enable(LPUART1);
|
||||
|
||||
/* Start the timer for measurement triggering */
|
||||
LL_TIM_EnableCounter(TIM21);
|
||||
LL_TIM_EnableIT_UPDATE(TIM21);
|
||||
/*LL_TIM_GenerateEvent_UPDATE(TIM2);*/
|
||||
|
||||
/* I2C context init (for SHT4x and SCD4x) */
|
||||
i2c_context_t i2c_context;
|
||||
i2c_context.i2c = I2C1;
|
||||
i2c_init(&i2c_context);
|
||||
|
||||
/* Read config from EEPROM - if unsuccessful, set the default values*/
|
||||
int8_t config_read_status = config_read(&sensor_config);
|
||||
if (config_read_status != CONFIG_OK)
|
||||
@ -292,8 +285,22 @@ int main(void)
|
||||
sensor_config.led_co2_alert_limit2 = CONFIG_DEFAULT_LED_ALERT2_LIMIT;
|
||||
sensor_config.led_on = CONFIG_DEFAULT_LED_ON;
|
||||
}
|
||||
|
||||
/* Set the modbus address */
|
||||
modbus_slave_set_address(sensor_config.modbus_addr);
|
||||
|
||||
/* Enable UART for RS485 */
|
||||
LL_LPUART_Enable(LPUART1);
|
||||
|
||||
/* Start the timer for measurement triggering */
|
||||
LL_TIM_EnableCounter(TIM21);
|
||||
LL_TIM_EnableIT_UPDATE(TIM21);
|
||||
|
||||
/* I2C context init (for SHT4x and SCD4x) */
|
||||
i2c_context_t i2c_context;
|
||||
i2c_context.i2c = I2C1;
|
||||
i2c_init(&i2c_context);
|
||||
|
||||
scd4x_start_periodic_measurement();
|
||||
uint8_t scd4x_is_connected = 1;
|
||||
uint8_t sps30_is_connected = 0;
|
||||
@ -321,8 +328,6 @@ int main(void)
|
||||
/* SPS30 Init Time: max 30000 ms (datasheet pg. 2) */
|
||||
LL_mDelay(1000);
|
||||
|
||||
/* Turn on LED to signal ready state */
|
||||
LL_GPIO_ResetOutputPin(LED_B_GPIO_Port, LED_B_Pin);
|
||||
|
||||
/* Enter the main loop */
|
||||
while (1)
|
||||
@ -347,12 +352,32 @@ int main(void)
|
||||
{
|
||||
sps30_read_measured_values(sps30_measured_data, 10);
|
||||
}
|
||||
|
||||
/* Toggle LED for now */
|
||||
/* TODO: Remove LED Toggle */
|
||||
LL_GPIO_TogglePin(LED_B_GPIO_Port, LED_B_Pin);
|
||||
|
||||
/* TODO: Process data and light a desired color of LED */
|
||||
/* TODO: Add hystheresis */
|
||||
|
||||
if (CO2 <= sensor_config.led_co2_alert_limit1)
|
||||
{
|
||||
/* CO2 is OK -> BLUE */
|
||||
/* TODO: Decide if blue or green */
|
||||
LL_GPIO_SetOutputPin(LED_R_GPIO_Port, LED_R_Pin);
|
||||
LL_GPIO_SetOutputPin(LED_G_GPIO_Port, LED_G_Pin);
|
||||
LL_GPIO_ResetOutputPin(LED_B_GPIO_Port, LED_B_Pin);
|
||||
|
||||
} else if ((sensor_config.led_co2_alert_limit1 < CO2) && (CO2 <= sensor_config.led_co2_alert_limit2))
|
||||
{
|
||||
/* CO2 is NOT OK -> YELLOW */
|
||||
LL_GPIO_ResetOutputPin(LED_R_GPIO_Port, LED_R_Pin);
|
||||
LL_GPIO_ResetOutputPin(LED_G_GPIO_Port, LED_G_Pin);
|
||||
LL_GPIO_SetOutputPin(LED_B_GPIO_Port, LED_B_Pin);
|
||||
|
||||
} else if (sensor_config.led_co2_alert_limit2 < CO2)
|
||||
{
|
||||
/* CO2 is CRITICAL -> RED */
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
/* Reset the TIM21 Elapsed Period Flag */
|
||||
tim21_elapsed_period = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user