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);
|
||||
/* USER CODE BEGIN PFP */
|
||||
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 */
|
||||
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
@ -306,7 +307,6 @@ int main(void)
|
||||
|
||||
new_baud = LL_USART_GetBaudRate(USART2, SYSTICK_FREQ_HZ, LL_USART_OVERSAMPLING_16);
|
||||
}
|
||||
|
||||
/* It is time for measurement */
|
||||
if (tim21_elapsed_period == 1)
|
||||
{
|
||||
@ -339,8 +339,9 @@ int main(void)
|
||||
tim21_elapsed_period = 0;
|
||||
}
|
||||
/* TEST END */
|
||||
if (sensor_config.led_on) {
|
||||
if (sensor_config.led_on == 1) {
|
||||
if (co2_valid == 1) {
|
||||
if (sensor_config.led_smooth == 0) {
|
||||
if (CO2 <= sensor_config.led_co2_alert_limit1) {
|
||||
/* CO2 is OK -> GREEN */
|
||||
rgbled_set_color(RGBLED_GREEN);
|
||||
@ -354,6 +355,10 @@ int main(void)
|
||||
/* CO2 is CRITICAL -> RED */
|
||||
rgbled_set_color(RGBLED_RED);
|
||||
}
|
||||
} else {
|
||||
/* */
|
||||
CO2_to_color(CO2, sensor_config.led_co2_alert_limit1, sensor_config.led_co2_alert_limit2);
|
||||
}
|
||||
} else {
|
||||
/* CO2 invalid */
|
||||
rgbled_set_color(RGBLED_MAGENTA);
|
||||
@ -892,6 +897,24 @@ int8_t modbus_transmit_function(uint8_t *buffer, uint16_t data_len)
|
||||
USART2_TX_Buffer(buffer, data_len);
|
||||
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 */
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user