blink led to show more statuses, add internal error condition

This commit is contained in:
hamza 2024-05-20 21:36:42 +03:00
parent bfbecba2a6
commit 77078dfa41
3 changed files with 54 additions and 20 deletions

View File

@ -7,4 +7,6 @@ void status_led_init();
void status_led_state(TSState state, TSErrorKind error); void status_led_state(TSState state, TSErrorKind error);
void set_led_internal_error();
#endif // INC_STATUS_LED_H #endif // INC_STATUS_LED_H

View File

@ -520,6 +520,8 @@ void Error_Handler(void)
ts_sm_set_relay_position(RELAY_NEG, 0); ts_sm_set_relay_position(RELAY_NEG, 0);
ts_sm_set_relay_position(RELAY_POS, 0); ts_sm_set_relay_position(RELAY_POS, 0);
ts_sm_set_relay_position(RELAY_PRECHARGE, 0); ts_sm_set_relay_position(RELAY_PRECHARGE, 0);
set_led_internal_error();
} }
/* USER CODE END Error_Handler_Debug */ /* USER CODE END Error_Handler_Debug */
} }

View File

@ -17,23 +17,53 @@ typedef enum {
LED_2 LED_2
} LedId; } LedId;
static void set_led_color(LedId id, LedColor color) { uint32_t count = 0;
GPIO_PinState red = color.red ? GPIO_PIN_SET : GPIO_PIN_RESET; bool main_led = false;
GPIO_PinState green = color.green ? GPIO_PIN_SET : GPIO_PIN_RESET; LedColor led_1 = (LedColor) {.red = 0, .green = 0, .blue = 0};
GPIO_PinState blue = color.blue ? GPIO_PIN_SET : GPIO_PIN_RESET; LedColor led_2 = (LedColor) {.red = 0, .green = 0, .blue = 0};
#define ITER_COUNT 20
#define INTERN_ERROR_COUNT 7500
static void set_led_color_hw(LedColor color) {
GPIO_PinState red = color.red ? GPIO_PIN_RESET : GPIO_PIN_SET;
GPIO_PinState green = color.green ? GPIO_PIN_RESET : GPIO_PIN_SET;
GPIO_PinState blue = color.blue ? GPIO_PIN_RESET : GPIO_PIN_SET;
HAL_GPIO_WritePin(STATUS_LED_R_GPIO_Port, STATUS_LED_R_Pin, red);
HAL_GPIO_WritePin(STATUS_LED_G_GPIO_Port, STATUS_LED_G_Pin, green);
HAL_GPIO_WritePin(STATUS_LED_B_GPIO_Port, STATUS_LED_B_Pin, blue);
}
static void set_led_color(LedId id, LedColor color) {
switch (id) { switch (id) {
case LED_1: case LED_1:
HAL_GPIO_WritePin(STATUS_LED_R_GPIO_Port, STATUS_LED_R_Pin, red); led_1 = color;
HAL_GPIO_WritePin(STATUS_LED_G_GPIO_Port, STATUS_LED_G_Pin, green);
HAL_GPIO_WritePin(STATUS_LED_B_GPIO_Port, STATUS_LED_B_Pin, blue);
break; break;
case LED_2: case LED_2:
//HAL_GPIO_WritePin(STATUS_LED_GPIO_PORT, STATUS_LED_2_RED_PIN, red); led_2 = color;
//HAL_GPIO_WritePin(STATUS_LED_GPIO_PORT, STATUS_LED_2_GREEN_PIN, green);
//HAL_GPIO_WritePin(STATUS_LED_GPIO_PORT, STATUS_LED_2_BLUE_PIN, blue);
break; break;
} }
set_led_color_hw(main_led ? led_1 : led_2);
count++;
if (count > ITER_COUNT) {
count = 0;
main_led = !main_led;
}
}
void set_led_internal_error() {
led_1 = (LedColor) {.red = 1, .green = 0, .blue = 0};
led_2 = (LedColor) {.red = 0, .green = 0, .blue = 0};
set_led_color_hw(main_led ? led_1 : led_2);
count++;
if (count > INTERN_ERROR_COUNT) {
count = 0;
main_led = !main_led;
}
} }
/** /**
@ -42,13 +72,13 @@ static void set_led_color(LedId id, LedColor color) {
* @param state The state to set the LEDs to * @param state The state to set the LEDs to
* *
* State -> Color mapping: * State -> Color mapping:
* TS_INACTIVE -> LED_1: off, LED_2: off * TS_INACTIVE -> LED_1: green, LED_2: off
* TS_ACTIVE -> LED_1: blue, LED_2: off * TS_ACTIVE -> LED_1: blue, LED_2: off
* TS_PRECHARGE -> LED_1: blue, LED_2: cyan * TS_PRECHARGE -> LED_1: blue, LED_2: cyan
* TS_DISCHARGE -> LED_1: blue, LED_2: magenta * TS_DISCHARGE -> LED_1: blue, LED_2: magenta
* TS_ERROR -> LED_1: red, LED_2: <see below> * TS_ERROR -> LED_1: red, LED_2: <see below>
* TS_CHARGING_CHECK -> LED_1: green, LED_2: cyan * TS_CHARGING_CHECK -> LED_1: yellow, LED_2: cyan
* TS_CHARGING -> LED_1: green, LED_2: off * TS_CHARGING -> LED_1: yellow, LED_2: off
* *
* Error -> LED_2 mapping: * Error -> LED_2 mapping:
* TS_ERRORKIND_NONE -> off * TS_ERRORKIND_NONE -> off
@ -62,7 +92,7 @@ static void set_led_color(LedId id, LedColor color) {
void status_led_state(TSState state, TSErrorKind error) { void status_led_state(TSState state, TSErrorKind error) {
switch (state) { switch (state) {
case TS_INACTIVE: case TS_INACTIVE:
set_led_color(LED_1, (LedColor) {.red = 0, .green = 0, .blue = 0}); set_led_color(LED_1, (LedColor) {.red = 0, .green = 1, .blue = 0});
set_led_color(LED_2, (LedColor) {.red = 0, .green = 0, .blue = 0}); set_led_color(LED_2, (LedColor) {.red = 0, .green = 0, .blue = 0});
break; break;
case TS_ACTIVE: case TS_ACTIVE:
@ -101,11 +131,11 @@ void status_led_state(TSState state, TSErrorKind error) {
} }
break; break;
case TS_CHARGING_CHECK: case TS_CHARGING_CHECK:
set_led_color(LED_1, (LedColor) {.red = 0, .green = 1, .blue = 0}); set_led_color(LED_1, (LedColor) {.red = 1, .green = 1, .blue = 0});
set_led_color(LED_2, (LedColor) {.red = 0, .green = 1, .blue = 1}); set_led_color(LED_2, (LedColor) {.red = 0, .green = 1, .blue = 1});
break; break;
case TS_CHARGING: case TS_CHARGING:
set_led_color(LED_1, (LedColor) {.red = 0, .green = 1, .blue = 0}); set_led_color(LED_1, (LedColor) {.red = 1, .green = 1, .blue = 0});
set_led_color(LED_2, (LedColor) {.red = 0, .green = 0, .blue = 0}); set_led_color(LED_2, (LedColor) {.red = 0, .green = 0, .blue = 0});
break; break;
} }