Skip to content

Conversation

@zidanekarim
Copy link

Implements logic for BTS (Brake, Throttle, Steer) authorization checks and visualizes the authorization status using a 7-segment display. It cycles through each component (BBC, Throttle, Steer) at 1kHz, displaying 0 if authorized and 1 if not.

Copy link
Member

@jacobkoziej jacobkoziej left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's BTS short for?

.envrc Outdated
Comment on lines 14 to 23
export SCONSFLAGS="${SCONSFLAGS:-} --directory=$(expand_path .)"

export SCONSFLAGS="${SCONSFLAGS:-} --directory=$(expand_path .)"

export SCONSFLAGS="${SCONSFLAGS:-} --directory=$(expand_path .)"

export SCONSFLAGS="${SCONSFLAGS:-} --directory=$(expand_path .)"

export SCONSFLAGS="${SCONSFLAGS:-} --directory=$(expand_path .)"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the point of doing this?

Comment on lines 13 to 25
SEG_A = 13,
SEG_B = 4,
SEG_C = 7,
SEG_D = 8,
SEG_E = 9,
SEG_F = 12,
SEG_G = 5,
SEG_DP = 11,
SEG_1 = 1,
SEG_2 = 2,
SEG_3 = 3,
SEG_4 = 6,
} SEVEN_SEG_PINS;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ESP-IDF defines macros for pin values, try to use those over numeric values instead, even if in this case they evaluate to the same thing. Since, C lacks namespaces, please prefix enums with some kind of common value like PIN_. Also, try to follow the convention for typedefs of name_t, in this case I'd call it seven_segment_pin_t, however, since this is only in the scope of sup.c, it is safe to just make this an anonymous enum. You also include the indices for the digit selection, but give them a name that's easy to interpret as a segment. It's also strange that you start indexing at 1, does the datasheet do the same? I'd also personally turn this into a lookup table for the digit index so that you could write something like PIN_DIGIT[N] and have a pragmatic way to select the digit you want.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought, all pins should be in this enum, or just be #defines. The lookup tables can be like your zero and one array.

Comment on lines 45 to 49
static enum {
bbc_state,
throttle_state,
steer_state
} current_state = bbc_state;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enum constants should be in SNAKE_CASE.

steer_state
} current_state = bbc_state;

static void init_pin(SEVEN_SEG_PINS pin)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the vision, but this is common use-case, so look into using gpio_config_t to achieve similar behavior.

Comment on lines 80 to 97
static void set_one()
{
for (int i = 0; i < 6; i++) {
gpio_set_level(zero[i], 1);
}
for (int i = 0; i < 2; i++) {
gpio_set_level(one[i], 0);
}
gpio_set_level(SEG_G, 1);
}

static void set_zero()
{
for (int i = 0; i < 6; i++) {
gpio_set_level(zero[i], 0); // active low
}
gpio_set_level(SEG_G, 1);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once, again, I see the vision, but you can make this a general function that accepts a bitfield as an argument, since the seven segments + decimal point can be represented as 8-bits. Instead make a function that maps each bit of a byte into something you can display. For special digit values you can define a constant (i.e write_segments(SEGMENTS_PATTERN_1)).

gpio_set_level(SEG_2, 0);
gpio_set_level(SEG_3, 1);
}
current_state = (current_state + 1) % 3;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No magic numbers! Add an additional member to your state enum called STATES_TOTAL. Since enums start counting at zero, the last element will conveniently have the same value as the number of states.

@zidanekarim zidanekarim requested a review from jacobkoziej April 25, 2025 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants