Changed LED smooth transition to two intervals
This commit is contained in:
parent
0061723472
commit
3912a22467
@ -902,16 +902,28 @@ void CO2_to_color(uint16_t co2, uint16_t co2_limit_yellow, uint16_t co2_limit_re
|
|||||||
{
|
{
|
||||||
const uint16_t co2_limit_green = 400; /* fresh air, lowest possible value */
|
const uint16_t co2_limit_green = 400; /* fresh air, lowest possible value */
|
||||||
|
|
||||||
uint32_t co2_full_span;
|
uint32_t co2_interval_length;
|
||||||
|
uint32_t co2_lower_limit;
|
||||||
uint32_t intensity;
|
uint32_t intensity;
|
||||||
|
uint32_t intensity_offset;
|
||||||
|
|
||||||
if (co2 < co2_limit_green) {
|
if (co2 < co2_limit_green) {
|
||||||
rgbled_set_color(RGBLED_GREEN);
|
rgbled_set_color(RGBLED_GREEN);
|
||||||
} else if (co2 > co2_limit_red) {
|
} else if (co2 > co2_limit_red) {
|
||||||
rgbled_set_color(RGBLED_RED);
|
rgbled_set_color(RGBLED_RED);
|
||||||
} else {
|
} else {
|
||||||
co2_full_span = co2_limit_red - co2_limit_green;
|
if (co2 < co2_limit_yellow) {
|
||||||
intensity = (co2 - co2_limit_green) * 255 / co2_full_span;
|
/* first interval: from green to yellow (co2_alert_limit1) */
|
||||||
|
co2_interval_length = co2_limit_yellow - co2_limit_green;
|
||||||
|
co2_lower_limit = co2_limit_green;
|
||||||
|
intensity_offset = 0;
|
||||||
|
} else {
|
||||||
|
/* second interval: from yellow to red (co2_alert_limit2) */
|
||||||
|
co2_interval_length = co2_limit_red - co2_limit_yellow;
|
||||||
|
co2_lower_limit = co2_limit_yellow;
|
||||||
|
intensity_offset = 127;
|
||||||
|
}
|
||||||
|
intensity = (co2 - co2_lower_limit) * 128 / co2_interval_length + intensity_offset;
|
||||||
rgbled_set_color(intensity, 255 - intensity, 0);
|
rgbled_set_color(intensity, 255 - intensity, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user