diff --git a/libraries/ms-drivers/inc/seg_display.h b/libraries/ms-drivers/inc/seg_display.h index 08c359396..7cedae945 100644 --- a/libraries/ms-drivers/inc/seg_display.h +++ b/libraries/ms-drivers/inc/seg_display.h @@ -1,26 +1,34 @@ #pragma once #include "gpio.h" -// Functions interact with 7 segment display -// Initializes all the gpios necessary for 7 segment display operation and sets both integers and -// floats to the display +// Functions interact with three 7 segment displays +// Initializes all the gpios necessary for three 7 segment displays operation and sets both integers +// and floats to the displays typedef struct SegDisplay { - const GpioAddress A; - const GpioAddress B; - const GpioAddress C; - const GpioAddress D; - const GpioAddress DP; + const GpioAddress A1; + const GpioAddress B1; + const GpioAddress C1; const GpioAddress D1; + const GpioAddress A2; + const GpioAddress B2; + const GpioAddress C2; const GpioAddress D2; + const GpioAddress A3; + const GpioAddress B3; + const GpioAddress C3; const GpioAddress D3; + const GpioAddress DP; + const GpioAddress Digit1; + const GpioAddress Digit2; + const GpioAddress Digit3; } SegDisplay; // Initializes input and display GPIOs -StatusCode seg_display_init(SegDisplay *display); +StatusCode seg_displays_init(SegDisplay *display); // Sets an integer value onto the display with a max value of 999 -StatusCode seg_display_set_int(SegDisplay *display, uint16_t val); +StatusCode seg_displays_set_int(SegDisplay *display, uint16_t val1, uint16_t val2, uint16_t val3); -// Sets a single digit decimal value onto the display with a max value of 99.9 -StatusCode seg_display_set_float(SegDisplay *display, float val); +// Sets a decimal value onto the display for val1, and integer value for val2 and val3 +StatusCode seg_displays_set_float(SegDisplay *display, float val1, uint16_t val2, uint16_t val3); diff --git a/libraries/ms-drivers/src/seg_display.c b/libraries/ms-drivers/src/seg_display.c index 2fc8eca33..9ed099629 100644 --- a/libraries/ms-drivers/src/seg_display.c +++ b/libraries/ms-drivers/src/seg_display.c @@ -5,87 +5,131 @@ #define MAX_DISPLAY_VALUE 999 #define DELAY_BETWEEN_DIGITS_MS 3 -void set_seg_display(SegDisplay *display, uint16_t val); -void seg_display_reset(SegDisplay *display); -void set_digit(SegDisplay *display, GpioAddress *digit, uint16_t val); - -StatusCode seg_display_init(SegDisplay *display) { - gpio_init_pin(&display->A, GPIO_OUTPUT_PUSH_PULL, GPIO_STATE_LOW); - gpio_init_pin(&display->B, GPIO_OUTPUT_PUSH_PULL, GPIO_STATE_LOW); - gpio_init_pin(&display->C, GPIO_OUTPUT_PUSH_PULL, GPIO_STATE_LOW); - gpio_init_pin(&display->D, GPIO_OUTPUT_PUSH_PULL, GPIO_STATE_HIGH); +void seg_displays_reset(SegDisplay *display); +void set_digit(SegDisplay *display, GpioAddress *digit, uint16_t val1, uint16_t val2, + uint16_t val3); + +StatusCode seg_displays_init(SegDisplay *display) { + gpio_init_pin(&display->A1, GPIO_OUTPUT_PUSH_PULL, GPIO_STATE_LOW); + gpio_init_pin(&display->B1, GPIO_OUTPUT_PUSH_PULL, GPIO_STATE_LOW); + gpio_init_pin(&display->C1, GPIO_OUTPUT_PUSH_PULL, GPIO_STATE_LOW); + gpio_init_pin(&display->D1, GPIO_OUTPUT_PUSH_PULL, GPIO_STATE_HIGH); + gpio_init_pin(&display->A2, GPIO_OUTPUT_PUSH_PULL, GPIO_STATE_LOW); + gpio_init_pin(&display->B2, GPIO_OUTPUT_PUSH_PULL, GPIO_STATE_LOW); + gpio_init_pin(&display->C2, GPIO_OUTPUT_PUSH_PULL, GPIO_STATE_LOW); + gpio_init_pin(&display->D2, GPIO_OUTPUT_PUSH_PULL, GPIO_STATE_HIGH); + gpio_init_pin(&display->A3, GPIO_OUTPUT_PUSH_PULL, GPIO_STATE_LOW); + gpio_init_pin(&display->B3, GPIO_OUTPUT_PUSH_PULL, GPIO_STATE_LOW); + gpio_init_pin(&display->C3, GPIO_OUTPUT_PUSH_PULL, GPIO_STATE_LOW); + gpio_init_pin(&display->D3, GPIO_OUTPUT_PUSH_PULL, GPIO_STATE_HIGH); gpio_init_pin(&display->DP, GPIO_OUTPUT_PUSH_PULL, GPIO_STATE_LOW); - gpio_init_pin(&display->D1, GPIO_OUTPUT_PUSH_PULL, GPIO_STATE_LOW); - gpio_init_pin(&display->D2, GPIO_OUTPUT_PUSH_PULL, GPIO_STATE_LOW); - gpio_init_pin(&display->D3, GPIO_OUTPUT_PUSH_PULL, GPIO_STATE_LOW); + gpio_init_pin(&display->Digit1, GPIO_OUTPUT_PUSH_PULL, GPIO_STATE_LOW); + gpio_init_pin(&display->Digit2, GPIO_OUTPUT_PUSH_PULL, GPIO_STATE_LOW); + gpio_init_pin(&display->Digit3, GPIO_OUTPUT_PUSH_PULL, GPIO_STATE_LOW); return STATUS_CODE_OK; } -void seg_display_reset(SegDisplay *display) { - gpio_set_state(&display->A, GPIO_STATE_LOW); - gpio_set_state(&display->B, GPIO_STATE_LOW); - gpio_set_state(&display->C, GPIO_STATE_LOW); - gpio_set_state(&display->D, GPIO_STATE_LOW); +void seg_displays_reset(SegDisplay *display) { + gpio_set_state(&display->A1, GPIO_STATE_LOW); + gpio_set_state(&display->B1, GPIO_STATE_LOW); + gpio_set_state(&display->C1, GPIO_STATE_LOW); + gpio_set_state(&display->D1, GPIO_STATE_LOW); + gpio_set_state(&display->A2, GPIO_STATE_LOW); + gpio_set_state(&display->B2, GPIO_STATE_LOW); + gpio_set_state(&display->C2, GPIO_STATE_LOW); + gpio_set_state(&display->D2, GPIO_STATE_LOW); + gpio_set_state(&display->A3, GPIO_STATE_LOW); + gpio_set_state(&display->B3, GPIO_STATE_LOW); + gpio_set_state(&display->C3, GPIO_STATE_LOW); + gpio_set_state(&display->D3, GPIO_STATE_LOW); gpio_set_state(&display->DP, GPIO_STATE_HIGH); - gpio_set_state(&display->D1, GPIO_STATE_HIGH); - gpio_set_state(&display->D2, GPIO_STATE_HIGH); - gpio_set_state(&display->D3, GPIO_STATE_HIGH); + gpio_set_state(&display->Digit1, GPIO_STATE_HIGH); + gpio_set_state(&display->Digit2, GPIO_STATE_HIGH); + gpio_set_state(&display->Digit3, GPIO_STATE_HIGH); } -void set_seg_display(SegDisplay *display, uint16_t val) { // Sets ABCD according to value +static void prv_set_seg_displays(SegDisplay *display, uint16_t val1, uint16_t val2, + uint16_t val3) { // Sets ABCD according to value GpioState state; - state = ((val & 8) != 0) ? GPIO_STATE_HIGH : GPIO_STATE_LOW; - gpio_set_state(&display->D, state); + state = ((val1 & 8) != 0) ? GPIO_STATE_HIGH : GPIO_STATE_LOW; + gpio_set_state(&display->D1, state); - state = ((val & 4) != 0) ? GPIO_STATE_HIGH : GPIO_STATE_LOW; - gpio_set_state(&display->C, state); + state = ((val1 & 4) != 0) ? GPIO_STATE_HIGH : GPIO_STATE_LOW; + gpio_set_state(&display->C1, state); - state = ((val & 2) != 0) ? GPIO_STATE_HIGH : GPIO_STATE_LOW; - gpio_set_state(&display->B, state); + state = ((val1 & 2) != 0) ? GPIO_STATE_HIGH : GPIO_STATE_LOW; + gpio_set_state(&display->B1, state); - state = ((val & 1) != 0) ? GPIO_STATE_HIGH : GPIO_STATE_LOW; - gpio_set_state(&display->A, state); + state = ((val1 & 1) != 0) ? GPIO_STATE_HIGH : GPIO_STATE_LOW; + gpio_set_state(&display->A1, state); + + state = ((val2 & 8) != 0) ? GPIO_STATE_HIGH : GPIO_STATE_LOW; + gpio_set_state(&display->D2, state); + + state = ((val2 & 4) != 0) ? GPIO_STATE_HIGH : GPIO_STATE_LOW; + gpio_set_state(&display->C2, state); + + state = ((val2 & 2) != 0) ? GPIO_STATE_HIGH : GPIO_STATE_LOW; + gpio_set_state(&display->B2, state); + + state = ((val2 & 1) != 0) ? GPIO_STATE_HIGH : GPIO_STATE_LOW; + gpio_set_state(&display->A2, state); + + state = ((val3 & 8) != 0) ? GPIO_STATE_HIGH : GPIO_STATE_LOW; + gpio_set_state(&display->D3, state); + + state = ((val3 & 4) != 0) ? GPIO_STATE_HIGH : GPIO_STATE_LOW; + gpio_set_state(&display->C3, state); + + state = ((val3 & 2) != 0) ? GPIO_STATE_HIGH : GPIO_STATE_LOW; + gpio_set_state(&display->B3, state); + + state = ((val3 & 1) != 0) ? GPIO_STATE_HIGH : GPIO_STATE_LOW; + gpio_set_state(&display->A3, state); } -void set_digit(SegDisplay *display, GpioAddress *digit, uint16_t val) { // Sets D1 D2 D3 +void set_digit(SegDisplay *display, GpioAddress *digit, uint16_t val1, uint16_t val2, + uint16_t val3) { // Sets D1 D2 D3 gpio_set_state(digit, GPIO_STATE_LOW); - set_seg_display(display, val); + prv_set_seg_displays(display, val1, val2, val3); delay_ms(DELAY_BETWEEN_DIGITS_MS); gpio_set_state(digit, GPIO_STATE_HIGH); } -StatusCode seg_display_set_int(SegDisplay *display, uint16_t val) { +StatusCode seg_displays_set_int(SegDisplay *display, uint16_t val1, uint16_t val2, uint16_t val3) { // Check for max value - if (val > MAX_DISPLAY_VALUE) { + if ((val1 > MAX_DISPLAY_VALUE) || (val2 > MAX_DISPLAY_VALUE) || (val3 > MAX_DISPLAY_VALUE)) { return STATUS_CODE_OUT_OF_RANGE; } else { - seg_display_reset(display); + seg_displays_reset(display); - set_digit(display, &display->D1, (val / 100)); - set_digit(display, &display->D2, ((val / 10) % 10)); - set_digit(display, &display->D3, (val % 10)); + set_digit(display, &display->Digit1, (val1 / 100), (val2 / 100), (val3 / 100)); + set_digit(display, &display->Digit2, ((val1 / 10) % 10), ((val2 / 10) % 10), + ((val3 / 10) % 10)); + set_digit(display, &display->Digit3, (val1 % 10), (val2 % 10), (val3 % 10)); return STATUS_CODE_OK; } } -StatusCode seg_display_set_float(SegDisplay *display, float val) { - uint16_t val_int = val * 10; +StatusCode seg_displays_set_float(SegDisplay *display, float val1, uint16_t val2, uint16_t val3) { + uint16_t val_int = val1 * 10; if (val_int > MAX_DISPLAY_VALUE) { return STATUS_CODE_OUT_OF_RANGE; } else { - seg_display_reset(display); + seg_displays_reset(display); - set_digit(display, &display->D1, (val_int / 100)); + set_digit(display, &display->Digit1, (val_int / 100), (val2 / 100), (val3 / 100)); gpio_set_state(&display->DP, GPIO_STATE_LOW); // Enable decimal point - set_digit(display, &display->D2, ((val_int / 10) % 10)); + set_digit(display, &display->Digit2, ((val_int / 10) % 10), ((val2 / 10) % 10), + ((val3 / 10) % 10)); gpio_set_state(&display->DP, GPIO_STATE_HIGH); - set_digit(display, &display->D3, (val_int % 10)); + set_digit(display, &display->Digit3, (val_int % 10), (val2 % 10), (val3 % 10)); return STATUS_CODE_OK; } diff --git a/libraries/test_gen/src/test_generator.py b/libraries/test_gen/src/test_generator.py index 50b04c958..5ce24aa67 100644 --- a/libraries/test_gen/src/test_generator.py +++ b/libraries/test_gen/src/test_generator.py @@ -29,7 +29,7 @@ def get_function_line_spacing(function_words): spacing -= 1 if bracket_location == -1: - raise Exception("No bracket in provided line!") + raise ValueError("No bracket in provided line!") # Count the number of letters leading up to the bracket for i in range(len(function_words[bracket_location])): diff --git a/projects/centre_console/inc/cc_hw_defs.h b/projects/centre_console/inc/cc_hw_defs.h index ced6341f5..529e5b29b 100644 --- a/projects/centre_console/inc/cc_hw_defs.h +++ b/projects/centre_console/inc/cc_hw_defs.h @@ -16,104 +16,76 @@ #define RIGHT_LED_ADDR \ { .i2c_address = CC_IO_EXP_ADDR, .pin = PCA9555_PIN_IO1_6 } #define CRUISE_LED_ADDR \ - { .i2c_address = CC_IO_EXP_ADDR, .pin = PCA9555_PIN_IO0_4 } + { .i2c_address = CC_IO_EXP_ADDR, .pin = PCA9555_PIN_IO1_4 } #define REGEN_LED_ADDR \ { .i2c_address = CC_IO_EXP_ADDR, .pin = PCA9555_PIN_IO0_5 } - -// Button Inputs and backlit LEDS -#define CC_BTN_POWER \ - { .port = NUM_GPIO_PORTS - 1, .pin = GPIO_PINS_PER_PORT - 1 } -#define CC_BTN_STATE_DRIVE \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } -#define CC_BTN_STATE_NEUTRAL \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } -#define CC_BTN_STATE_REVERSE \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } -#define CC_BTN_DRL_LIGHTS \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } -#define CC_BTN_REGEN_BRAKE \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } - -// LEDs for backlights on buttons -#define CC_LED_POWER \ - { .i2c_address = CC_IO_EXP_ADDR, .pin = PCA9555_PIN_IO0_4 } -#define CC_LED_STATE_DRIVE \ - { .i2c_address = CC_IO_EXP_ADDR, .pin = PCA9555_PIN_IO0_4 } -#define CC_LED_STATE_NEUTRAL \ - { .i2c_address = CC_IO_EXP_ADDR, .pin = PCA9555_PIN_IO0_4 } -#define CC_LED_STATE_REVERSE \ - { .i2c_address = CC_IO_EXP_ADDR, .pin = PCA9555_PIN_IO0_4 } -#define CC_LED_STATE_REVERSE \ - { .i2c_address = CC_IO_EXP_ADDR, .pin = PCA9555_PIN_IO0_4 } -#define CC_LED_REGEN_BRAKE \ - { .i2c_address = CC_IO_EXP_ADDR, .pin = PCA9555_PIN_IO0_4 } +#define LIGHTS_LED_ADDR \ + { .i2c_address = CC_IO_EXP_ADDR, .pin = PCA9555_PIN_IO1_5 } +#define POWER_LED_ADDR \ + { .i2c_address = CC_IO_EXP_ADDR, .pin = PCA9555_PIN_IO0_2 } +#define BPS_LED_ADDR \ + { .i2c_address = CC_IO_EXP_ADDR, .pin = PCA9555_PIN_IO0_2 } // Seven Segment display GPIO Addresses // Cruise Control #define CC_DISP1 \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } + { .port = GPIO_PORT_B, .pin = 11 } #define CC_DISP2 \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } + { .port = GPIO_PORT_B, .pin = 1 } #define CC_DISP3 \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } + { .port = GPIO_PORT_B, .pin = 2 } #define CC_DISP4 \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } + { .port = GPIO_PORT_B, .pin = 10 } #define CC_DISP5 \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } + { .port = GPIO_PORT_A, .pin = 9 } #define CC_DISP6 \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } + { .port = GPIO_PORT_B, .pin = 14 } #define CC_DISP7 \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } + { .port = GPIO_PORT_B, .pin = 15 } #define CC_DISP8 \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } -#define CC_DISPLAY \ - { \ - .A = CC_DISP1, .B = CC_DISP2, .C = CC_DISP3, .D = CC_DISP4, .DP = CC_DISP5, .D1 = CC_DISP6, \ - .D2 = CC_DISP7, .D3 = CC_DISP8 \ - } + { .port = GPIO_PORT_A, .pin = 8 } -// Speed +// Speedometer #define SPD_DISP1 \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } + { .port = GPIO_PORT_A, .pin = 3 } #define SPD_DISP2 \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } + { .port = GPIO_PORT_A, .pin = 0 } #define SPD_DISP3 \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } + { .port = GPIO_PORT_A, .pin = 1 } #define SPD_DISP4 \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } + { .port = GPIO_PORT_A, .pin = 2 } #define SPD_DISP5 \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } + { .port = GPIO_PORT_A, .pin = 9 } #define SPD_DISP6 \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } + { .port = GPIO_PORT_B, .pin = 14 } #define SPD_DISP7 \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } + { .port = GPIO_PORT_B, .pin = 15 } #define SPD_DISP8 \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } -#define SPD_DISPLAY \ - { \ - .A = CC_DISP1, .B = CC_DISP2, .C = CC_DISP3, .D = CC_DISP4, .DP = CC_DISP5, .D1 = CC_DISP6, \ - .D2 = CC_DISP7, .D3 = CC_DISP8 \ - } + { .port = GPIO_PORT_A, .pin = 8 } // Battery #define BATT_DISP1 \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } + { .port = GPIO_PORT_A, .pin = 7 } #define BATT_DISP2 \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } + { .port = GPIO_PORT_A, .pin = 4 } #define BATT_DISP3 \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } + { .port = GPIO_PORT_A, .pin = 5 } #define BATT_DISP4 \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } + { .port = GPIO_PORT_A, .pin = 6 } #define BATT_DISP5 \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } + { .port = GPIO_PORT_A, .pin = 9 } #define BATT_DISP6 \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } + { .port = GPIO_PORT_B, .pin = 14 } #define BATT_DISP7 \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } + { .port = GPIO_PORT_B, .pin = 15 } #define BATT_DISP8 \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } -#define BATT_DISPLAY \ - { \ - .A = BATT_DISP1, .B = BATT_DISP2, .C = BATT_DISP3, .D = BATT_DISP4, .DP = BATT_DISP5, \ - .D1 = BATT_DISP6, .D2 = BATT_DISP7, .D3 = BATT_DISP8 \ + { .port = GPIO_PORT_A, .pin = 8 } + +// All displays +#define ALL_DISPLAYS \ + { \ + .A1 = SPD_DISP1, .B1 = SPD_DISP2, .C1 = SPD_DISP3, .D1 = SPD_DISP4, .A2 = BATT_DISP1, \ + .B2 = BATT_DISP2, .C2 = BATT_DISP3, .D2 = BATT_DISP4, .A3 = CC_DISP1, .B3 = CC_DISP2, \ + .C3 = CC_DISP3, .D3 = CC_DISP4, .DP = BATT_DISP5, .Digit1 = BATT_DISP6, .Digit2 = BATT_DISP7, \ + .Digit3 = BATT_DISP8 \ } diff --git a/projects/centre_console/src/main.c b/projects/centre_console/src/main.c index 1662e1ac3..19112fdc7 100644 --- a/projects/centre_console/src/main.c +++ b/projects/centre_console/src/main.c @@ -40,6 +40,7 @@ void pre_loop_init() { void run_fast_cycle() { get_button_press(); + update_displays(); } void run_medium_cycle() { @@ -50,7 +51,6 @@ void run_medium_cycle() { notify_get(¬if); update_indicators(notif); monitor_cruise_control(); - update_displays(); fsm_run_cycle(drive); wait_tasks(1); diff --git a/projects/centre_console/src/update_dashboard.c b/projects/centre_console/src/update_dashboard.c index 33174d8f6..e1e974b49 100644 --- a/projects/centre_console/src/update_dashboard.c +++ b/projects/centre_console/src/update_dashboard.c @@ -7,23 +7,15 @@ #include "pca9555_gpio_expander.h" #include "seg_display.h" -// Multiplication factor to convert CAN motor velocity (cm/s) into drive output velocity (mm/s) -#define CONVERT_VELOCITY 5 +// Multiplication factor to convert CAN drive output velocity (cm/s) to kph +#define CONVERT_VELOCITY_TO_KPH 0.036 -// Multiplication factor to convert CAN drive output velocity to kph -#define CONVERT_VELOCITY_TO_KPH 0.0036 - -// Multiplication Factor to convert CAN Velocity in 100 * m/s to kph -#define CONVERT_VELOCITY_TO_SPEED 0.018 - -static SegDisplay cc_display = CC_DISPLAY; -static SegDisplay speed_display = SPD_DISPLAY; -SegDisplay batt_perc_display = BATT_DISPLAY; +SegDisplay all_displays = ALL_DISPLAYS; // Centre Console State Variables -static uint8_t s_drive_state; static bool s_cc_enabled; static bool s_regen_braking; +static bool s_hazard_state; static uint32_t s_target_velocity; static uint32_t s_last_power_state = EE_POWER_OFF_STATE; static uint8_t s_last_lights_state = EE_STEERING_LIGHTS_OFF_STATE; @@ -35,33 +27,36 @@ typedef enum DriveLeds { LEFT_LED, RIGHT_LED, CRUISE_LED, + LIGHTS_LED, NUM_DRIVE_LED, } DriveLeds; static Pca9555GpioAddress s_output_leds[NUM_DRIVE_LED] = { - [POWER_LED] = CC_LED_POWER, [HAZARD_LED] = HAZARD_LED_ADDR, [LEFT_LED] = LEFT_LED_ADDR, - [RIGHT_LED] = RIGHT_LED_ADDR, [CRUISE_LED] = CRUISE_LED_ADDR, [REGEN_LED] = REGEN_LED_ADDR + [POWER_LED] = POWER_LED_ADDR, [HAZARD_LED] = HAZARD_LED_ADDR, [LEFT_LED] = LEFT_LED_ADDR, + [RIGHT_LED] = RIGHT_LED_ADDR, [CRUISE_LED] = CRUISE_LED_ADDR, [REGEN_LED] = REGEN_LED_ADDR, + [LIGHTS_LED] = LIGHTS_LED_ADDR, }; void update_indicators(uint32_t notif) { // Update hazard light if (notify_check_event(¬if, HAZARD_BUTTON_EVENT)) { - if (s_regen_braking) { - s_regen_braking = false; - pca9555_gpio_set_state(&s_output_leds[HAZARD_LED], PCA9555_GPIO_STATE_LOW); - } else { - s_regen_braking = false; + if (!s_hazard_state) { + s_hazard_state = true; pca9555_gpio_set_state(&s_output_leds[HAZARD_LED], PCA9555_GPIO_STATE_HIGH); } + } else { + if (s_hazard_state) { + s_hazard_state = false; + pca9555_gpio_set_state(&s_output_leds[HAZARD_LED], PCA9555_GPIO_STATE_LOW); + } } - // Update regen light if (notify_check_event(¬if, REGEN_BUTTON_EVENT)) { if (s_regen_braking) { s_regen_braking = false; pca9555_gpio_set_state(&s_output_leds[REGEN_LED], PCA9555_GPIO_STATE_LOW); } else { - s_regen_braking = false; + s_regen_braking = true; pca9555_gpio_set_state(&s_output_leds[REGEN_LED], PCA9555_GPIO_STATE_HIGH); } } @@ -72,7 +67,7 @@ void update_indicators(uint32_t notif) { get_power_info_power_state() == EE_POWER_DRIVE_STATE) { pca9555_gpio_set_state(&s_output_leds[POWER_LED], PCA9555_GPIO_STATE_HIGH); } else { - pca9555_gpio_set_state(&s_output_leds[POWER_LED], PCA9555_GPIO_STATE_HIGH); + pca9555_gpio_set_state(&s_output_leds[POWER_LED], PCA9555_GPIO_STATE_LOW); } s_last_power_state = get_power_info_power_state(); } @@ -93,6 +88,7 @@ void update_indicators(uint32_t notif) { default: break; } + s_last_lights_state = get_steering_info_input_lights(); } } @@ -104,55 +100,47 @@ void monitor_cruise_control() { if (get_drive_state() != DRIVE || get_pedal_output_brake_output()) { new_cc_state = false; } else { - if (cc_info & EE_STEERING_CC_TOGGLE_MASK) { + if (get_received_steering_info() && (cc_info & EE_STEERING_CC_TOGGLE_MASK)) { new_cc_state = !s_cc_enabled; } } // If a state change has occurred update values and indicator LED if (new_cc_state != s_cc_enabled) { - if (s_cc_enabled) { + if (new_cc_state) { // Store recent speed from MCI as initial cruise control speed - unsigned int convert_velocity = CONVERT_VELOCITY; - float converted_val = - (get_motor_velocity_velocity_l() + get_motor_velocity_velocity_r()) * CONVERT_VELOCITY; - s_target_velocity = (unsigned int)converted_val; + float avg_speed = (get_motor_velocity_velocity_l() + get_motor_velocity_velocity_r()) / 2; + float speed_kph = avg_speed * CONVERT_VELOCITY_TO_KPH; + s_target_velocity = (unsigned int)speed_kph; pca9555_gpio_set_state(&s_output_leds[CRUISE_LED], PCA9555_GPIO_STATE_HIGH); } else { s_target_velocity = 0; pca9555_gpio_set_state(&s_output_leds[CRUISE_LED], PCA9555_GPIO_STATE_LOW); } + s_cc_enabled = new_cc_state; } // Allow for updates to cruise control value if it is enabled if (s_cc_enabled) { - if (cc_info & EE_STEERING_CC_INCREASE_MASK) { - s_target_velocity = - ((s_target_velocity * CONVERT_VELOCITY_TO_KPH) + 1) / CONVERT_VELOCITY_TO_KPH; + if (get_received_steering_info() && (cc_info & EE_STEERING_CC_INCREASE_MASK)) { + s_target_velocity++; } - if (cc_info & EE_STEERING_CC_DECREASE_MASK) { - s_target_velocity = - ((s_target_velocity * CONVERT_VELOCITY_TO_KPH) - 1) / CONVERT_VELOCITY_TO_KPH; + if (get_received_steering_info() && (cc_info & EE_STEERING_CC_DECREASE_MASK)) { + s_target_velocity--; } } } void update_displays(void) { - seg_display_init(&cc_display); - seg_display_init(&speed_display); - seg_display_init(&batt_perc_display); - // Read data from CAN structs and update displays with those values - float speed_kph = - (get_motor_velocity_velocity_l() + get_motor_velocity_velocity_r()) * CONVERT_VELOCITY; + float avg_speed = (get_motor_velocity_velocity_l() + get_motor_velocity_velocity_r()) / 2; + float speed_kph = avg_speed * CONVERT_VELOCITY_TO_KPH; uint16_t batt_perc_val = get_battery_status_batt_perc(); - seg_display_set_int(&cc_display, s_target_velocity); if (speed_kph >= 100) { - seg_display_set_int(&speed_display, (int)speed_kph); + seg_displays_set_int(&all_displays, (int)speed_kph, batt_perc_val, s_target_velocity); } else { - seg_display_set_float(&speed_display, speed_kph); + seg_displays_set_float(&all_displays, speed_kph, batt_perc_val, s_target_velocity); } - seg_display_set_int(&batt_perc_display, batt_perc_val); } void update_drive_output(uint32_t notif) { @@ -165,10 +153,10 @@ void update_drive_output(uint32_t notif) { } else { set_cc_power_control_power_event(EE_CC_PWR_CTL_EVENT_NONE); } - set_drive_output_drive_state(s_drive_state); set_drive_output_cruise_control(s_cc_enabled); set_drive_output_target_velocity(s_target_velocity); set_drive_output_regen_braking(s_regen_braking); + set_cc_power_control_hazard_enabled(s_hazard_state); } StatusCode dashboard_init(void) { @@ -179,5 +167,7 @@ StatusCode dashboard_init(void) { for (int i = 0; i < NUM_DRIVE_LED; i++) { status_ok_or_return(pca9555_gpio_init_pin(&s_output_leds[i], &settings)); } + seg_displays_init(&all_displays); + pca9555_gpio_set_state(&s_output_leds[REGEN_LED], PCA9555_GPIO_STATE_HIGH); return STATUS_CODE_OK; }