diff --git a/fw/Core/Inc/rgbled.h b/fw/Core/Inc/rgbled.h index 9580f20..ed1c1a9 100644 --- a/fw/Core/Inc/rgbled.h +++ b/fw/Core/Inc/rgbled.h @@ -19,9 +19,25 @@ #define RGBLED_ERROR -1 // generic error #define RGBLED_WRONG_CHANNEL -2 // channel number not in {1,2,3,4} +/* + * Defaults used for LL timer (PWM) initialization + */ + #define RGBLED_PRESCALER 0 #define RGBLED_PERIOD 255 +/* + * Shorthands for colors + */ + +#define RGBLED_RED 255,0,0 +#define RGBLED_GREEN 0,255,0 +#define RGBLED_BLUE 0,0,255 +#define RGBLED_WHITE 255,255,255 +#define RGBLED_YELLOW 255,255,0 +#define RGBLED_OFF 0,0,0 +#define RGBLED_MAGENTA 255,0,255 + /* * Type definitions */ diff --git a/fw/Core/Src/main.c b/fw/Core/Src/main.c index 5b8964e..29c72cd 100644 --- a/fw/Core/Src/main.c +++ b/fw/Core/Src/main.c @@ -225,7 +225,7 @@ int main(void) rgbled_context.channel.B = 1; rgbled_init(&rgbled_context); - rgbled_set_color(50, 50, 0); + rgbled_set_color(RGBLED_WHITE); LL_mDelay(2000); @@ -343,33 +343,25 @@ int main(void) 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); -// LL_GPIO_ResetOutputPin(LED_G_GPIO_Port, LED_G_Pin); -// LL_GPIO_SetOutputPin(LED_B_GPIO_Port, LED_B_Pin); + rgbled_set_color(RGBLED_GREEN); } 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); + /* CO2 is NOT OK -> YELLOW */ + rgbled_set_color(RGBLED_YELLOW); + } 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); + rgbled_set_color(RGBLED_RED); } } else { - -// 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); + /* CO2 invalid */ + rgbled_set_color(RGBLED_MAGENTA); } } 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); + /* LED disabled by user */ + rgbled_set_color(RGBLED_OFF); } /* USER CODE END WHILE */ diff --git a/fw/Core/Src/rgbled.c b/fw/Core/Src/rgbled.c index 917202d..cc929a6 100644 --- a/fw/Core/Src/rgbled.c +++ b/fw/Core/Src/rgbled.c @@ -57,5 +57,5 @@ int8_t rgbled_set_color(uint8_t R, uint8_t G, uint8_t B) int8_t rgbled_off(void) { - + rgbled_set_color(RGBLED_OFF); }