Skip to content

Commit

Permalink
update dashboard validation (#251)
Browse files Browse the repository at this point in the history
* update dashboard validation

* Add conversion factor, fix private function

* lint

* update lint

---------

Co-authored-by: Mitchell Ostler <[email protected]>
  • Loading branch information
ay0fasan and mitchellostler authored Jan 3, 2024
1 parent 737ff7d commit 7289afd
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 170 deletions.
32 changes: 20 additions & 12 deletions libraries/ms-drivers/inc/seg_display.h
Original file line number Diff line number Diff line change
@@ -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);
130 changes: 87 additions & 43 deletions libraries/ms-drivers/src/seg_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/test_gen/src/test_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])):
Expand Down
108 changes: 40 additions & 68 deletions projects/centre_console/inc/cc_hw_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
}
2 changes: 1 addition & 1 deletion projects/centre_console/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ void pre_loop_init() {

void run_fast_cycle() {
get_button_press();
update_displays();
}

void run_medium_cycle() {
Expand All @@ -50,7 +51,6 @@ void run_medium_cycle() {
notify_get(&notif);
update_indicators(notif);
monitor_cruise_control();
update_displays();
fsm_run_cycle(drive);
wait_tasks(1);

Expand Down
Loading

0 comments on commit 7289afd

Please sign in to comment.