blink led to show more statuses, add internal error condition
This commit is contained in:
		@ -7,4 +7,6 @@ void status_led_init();
 | 
			
		||||
 | 
			
		||||
void status_led_state(TSState state, TSErrorKind error);
 | 
			
		||||
 | 
			
		||||
void set_led_internal_error();
 | 
			
		||||
 | 
			
		||||
#endif // INC_STATUS_LED_H
 | 
			
		||||
@ -520,6 +520,8 @@ void Error_Handler(void)
 | 
			
		||||
    ts_sm_set_relay_position(RELAY_NEG, 0);
 | 
			
		||||
    ts_sm_set_relay_position(RELAY_POS, 0);
 | 
			
		||||
    ts_sm_set_relay_position(RELAY_PRECHARGE, 0);
 | 
			
		||||
 | 
			
		||||
    set_led_internal_error();
 | 
			
		||||
  }
 | 
			
		||||
  /* USER CODE END Error_Handler_Debug */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -17,23 +17,53 @@ typedef enum {
 | 
			
		||||
    LED_2
 | 
			
		||||
} LedId;
 | 
			
		||||
 | 
			
		||||
static void set_led_color(LedId id, LedColor color) {
 | 
			
		||||
    GPIO_PinState red = color.red ? GPIO_PIN_SET : GPIO_PIN_RESET;
 | 
			
		||||
    GPIO_PinState green = color.green ? GPIO_PIN_SET : GPIO_PIN_RESET;
 | 
			
		||||
    GPIO_PinState blue = color.blue ? GPIO_PIN_SET : GPIO_PIN_RESET;
 | 
			
		||||
uint32_t count = 0;
 | 
			
		||||
bool main_led = false;
 | 
			
		||||
LedColor led_1 = (LedColor) {.red = 0, .green = 0, .blue = 0};
 | 
			
		||||
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) {
 | 
			
		||||
        case LED_1:
 | 
			
		||||
            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);
 | 
			
		||||
            led_1 = color;
 | 
			
		||||
            break;
 | 
			
		||||
        case LED_2:
 | 
			
		||||
            //HAL_GPIO_WritePin(STATUS_LED_GPIO_PORT, STATUS_LED_2_RED_PIN, red);
 | 
			
		||||
            //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);
 | 
			
		||||
            led_2 = color;
 | 
			
		||||
            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
 | 
			
		||||
  *
 | 
			
		||||
  * State -> Color mapping:
 | 
			
		||||
  * TS_INACTIVE       -> LED_1:   off, LED_2: off
 | 
			
		||||
  * TS_ACTIVE         -> LED_1:  blue, LED_2: off
 | 
			
		||||
  * TS_PRECHARGE      -> LED_1:  blue, LED_2: cyan
 | 
			
		||||
  * TS_DISCHARGE      -> LED_1:  blue, LED_2: magenta
 | 
			
		||||
  * TS_ERROR          -> LED_1:   red, LED_2: <see below>
 | 
			
		||||
  * TS_CHARGING_CHECK -> LED_1: green, LED_2: cyan
 | 
			
		||||
  * TS_CHARGING       -> LED_1: green, LED_2: off
 | 
			
		||||
  * TS_INACTIVE       -> LED_1:  green, LED_2: off
 | 
			
		||||
  * TS_ACTIVE         -> LED_1:   blue, LED_2: off
 | 
			
		||||
  * TS_PRECHARGE      -> LED_1:   blue, LED_2: cyan
 | 
			
		||||
  * TS_DISCHARGE      -> LED_1:   blue, LED_2: magenta
 | 
			
		||||
  * TS_ERROR          -> LED_1:    red, LED_2: <see below>
 | 
			
		||||
  * TS_CHARGING_CHECK -> LED_1: yellow, LED_2: cyan
 | 
			
		||||
  * TS_CHARGING       -> LED_1: yellow, LED_2: off
 | 
			
		||||
  *
 | 
			
		||||
  * Error -> LED_2 mapping:
 | 
			
		||||
  * 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) {
 | 
			
		||||
    switch (state) {
 | 
			
		||||
        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});
 | 
			
		||||
            break;
 | 
			
		||||
        case TS_ACTIVE:
 | 
			
		||||
@ -101,11 +131,11 @@ void status_led_state(TSState state, TSErrorKind error) {
 | 
			
		||||
            }
 | 
			
		||||
            break;
 | 
			
		||||
        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});
 | 
			
		||||
            break;
 | 
			
		||||
        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});
 | 
			
		||||
            break;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user