Linear change of LED color according to CO2 level
This commit is contained in:
parent
c2a67d173d
commit
bb274d367a
@ -124,6 +124,7 @@ static void MX_TIM2_Init(void);
|
|||||||
static void MX_TIM22_Init(void);
|
static void MX_TIM22_Init(void);
|
||||||
/* USER CODE BEGIN PFP */
|
/* USER CODE BEGIN PFP */
|
||||||
void USART2_TX_Buffer(uint8_t* buffer_tx, uint16_t buffer_tx_len);
|
void USART2_TX_Buffer(uint8_t* buffer_tx, uint16_t buffer_tx_len);
|
||||||
|
void CO2_to_color(uint16_t co2, uint16_t co2_limit_yellow, uint16_t co2_limit_red);
|
||||||
/* USER CODE END PFP */
|
/* USER CODE END PFP */
|
||||||
|
|
||||||
/* Private user code ---------------------------------------------------------*/
|
/* Private user code ---------------------------------------------------------*/
|
||||||
@ -306,7 +307,6 @@ int main(void)
|
|||||||
|
|
||||||
new_baud = LL_USART_GetBaudRate(USART2, SYSTICK_FREQ_HZ, LL_USART_OVERSAMPLING_16);
|
new_baud = LL_USART_GetBaudRate(USART2, SYSTICK_FREQ_HZ, LL_USART_OVERSAMPLING_16);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* It is time for measurement */
|
/* It is time for measurement */
|
||||||
if (tim21_elapsed_period == 1)
|
if (tim21_elapsed_period == 1)
|
||||||
{
|
{
|
||||||
@ -339,20 +339,25 @@ int main(void)
|
|||||||
tim21_elapsed_period = 0;
|
tim21_elapsed_period = 0;
|
||||||
}
|
}
|
||||||
/* TEST END */
|
/* TEST END */
|
||||||
if (sensor_config.led_on) {
|
if (sensor_config.led_on == 1) {
|
||||||
if (co2_valid == 1) {
|
if (co2_valid == 1) {
|
||||||
if (CO2 <= sensor_config.led_co2_alert_limit1) {
|
if (sensor_config.led_smooth == 0) {
|
||||||
/* CO2 is OK -> GREEN */
|
if (CO2 <= sensor_config.led_co2_alert_limit1) {
|
||||||
rgbled_set_color(RGBLED_GREEN);
|
/* CO2 is OK -> GREEN */
|
||||||
|
rgbled_set_color(RGBLED_GREEN);
|
||||||
|
|
||||||
} else if ((sensor_config.led_co2_alert_limit1 < CO2) && (CO2 <= sensor_config.led_co2_alert_limit2)) {
|
} else if ((sensor_config.led_co2_alert_limit1 < CO2) && (CO2 <= sensor_config.led_co2_alert_limit2)) {
|
||||||
/* CO2 is NOT OK -> YELLOW */
|
/* CO2 is NOT OK -> YELLOW */
|
||||||
rgbled_set_color(RGBLED_YELLOW);
|
rgbled_set_color(RGBLED_YELLOW);
|
||||||
|
|
||||||
|
|
||||||
} else if (sensor_config.led_co2_alert_limit2 < CO2) {
|
} else if (sensor_config.led_co2_alert_limit2 < CO2) {
|
||||||
/* CO2 is CRITICAL -> RED */
|
/* CO2 is CRITICAL -> RED */
|
||||||
rgbled_set_color(RGBLED_RED);
|
rgbled_set_color(RGBLED_RED);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* */
|
||||||
|
CO2_to_color(CO2, sensor_config.led_co2_alert_limit1, sensor_config.led_co2_alert_limit2);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* CO2 invalid */
|
/* CO2 invalid */
|
||||||
@ -892,6 +897,24 @@ int8_t modbus_transmit_function(uint8_t *buffer, uint16_t data_len)
|
|||||||
USART2_TX_Buffer(buffer, data_len);
|
USART2_TX_Buffer(buffer, data_len);
|
||||||
return MODBUS_OK;
|
return MODBUS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CO2_to_color(uint16_t co2, uint16_t co2_limit_yellow, uint16_t co2_limit_red)
|
||||||
|
{
|
||||||
|
const uint16_t co2_limit_green = 400; /* fresh air, lowest possible value */
|
||||||
|
|
||||||
|
uint32_t co2_full_span;
|
||||||
|
uint32_t intensity;
|
||||||
|
|
||||||
|
if (co2 < co2_limit_green) {
|
||||||
|
rgbled_set_color(RGBLED_GREEN);
|
||||||
|
} else if (co2 > co2_limit_red) {
|
||||||
|
rgbled_set_color(RGBLED_RED);
|
||||||
|
} else {
|
||||||
|
co2_full_span = co2_limit_red - co2_limit_green;
|
||||||
|
intensity = (co2 - co2_limit_green) * 255 / co2_full_span;
|
||||||
|
rgbled_set_color(intensity, 255 - intensity, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
/* USER CODE END 4 */
|
/* USER CODE END 4 */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user