-
Notifications
You must be signed in to change notification settings - Fork 1
Add BTS Authorization Logic and 7-Segment LED Status Display #216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from 35 commits
0ad25f8
e46b7f5
3d9610e
11d036c
239926a
692b962
467d9d3
8b2b78c
fdbf8be
a51ea58
cafd6d1
4dccda1
357e2c8
fbaf1f1
bdedc4e
1416ccf
ef1d459
63ffdc2
c815058
d50d7c7
eee1b82
6d9ef43
f445758
98f45dc
eabe265
d3e7f57
7bac742
35b6e48
8a87234
1d93a40
5997ded
adcbaa7
6bd3008
20ea781
537a436
23483cd
cda05e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| #include "sup.h" | ||
|
|
||
| #include "driver/gpio.h" | ||
| #include "firmware-base/state-machine.h" | ||
| #include <ember_taskglue.h> | ||
| #include <freertos/FreeRTOS.h> | ||
|
|
@@ -8,13 +9,131 @@ | |
| #include <opencan_templates.h> | ||
| #include <opencan_tx.h> | ||
|
|
||
| typedef enum { | ||
| 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; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On second thought, all pins should be in this |
||
|
|
||
| static void bts_authorization(); | ||
| static void init_led(); | ||
| static void sup_100Hz(); | ||
| static void init_pin(SEVEN_SEG_PINS pin); | ||
| static void set_one(); | ||
| static void set_zero(); | ||
|
|
||
|
|
||
| static bool bbc_authorized; | ||
| static bool throttle_authorized; | ||
| static bool steer_authorized; | ||
|
|
||
|
|
||
| static const SEVEN_SEG_PINS zero[] | ||
| = {SEG_A, SEG_B, SEG_C, SEG_D, SEG_E, SEG_F}; | ||
|
|
||
| static const SEVEN_SEG_PINS one[] = {SEG_B, SEG_C}; | ||
|
|
||
| static enum { | ||
| bbc_state, | ||
| throttle_state, | ||
| steer_state | ||
| } current_state = bbc_state; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| static void init_pin(SEVEN_SEG_PINS pin) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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_pad_select_gpio(pin); | ||
| gpio_set_direction(pin, GPIO_MODE_OUTPUT); | ||
| } | ||
|
|
||
| static void init_led() | ||
| { | ||
| init_pin(SEG_A); | ||
| init_pin(SEG_B); | ||
| init_pin(SEG_C); | ||
| init_pin(SEG_D); | ||
| init_pin(SEG_E); | ||
| init_pin(SEG_F); | ||
| init_pin(SEG_G); | ||
| init_pin(SEG_DP); | ||
| init_pin(SEG_1); | ||
| init_pin(SEG_2); | ||
| init_pin(SEG_3); | ||
| init_pin(SEG_4); | ||
|
|
||
| // set default state to 0 | ||
|
|
||
| set_zero(); | ||
| gpio_set_level(SEG_1, 1); | ||
| gpio_set_level(SEG_2, 1); | ||
| gpio_set_level(SEG_3, 1); | ||
| } | ||
|
|
||
| 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); | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
|
||
| static void bts_authorization() | ||
| { | ||
| if (current_state == bbc_state) { | ||
| if (bbc_authorized) { | ||
| // if bbc is authorized, show 0 | ||
| set_zero(); | ||
| } else { | ||
| // if not authorized, show 1 | ||
| set_one(); | ||
| } | ||
| gpio_set_level(SEG_1, 1); | ||
| gpio_set_level(SEG_2, 0); | ||
| gpio_set_level(SEG_3, 0); | ||
| } else if (current_state == throttle_state) { | ||
| if (throttle_authorized) { | ||
| set_zero(); | ||
| } else { | ||
| set_one(); | ||
| } | ||
| gpio_set_level(SEG_1, 0); | ||
| gpio_set_level(SEG_2, 1); | ||
| gpio_set_level(SEG_3, 0); | ||
| } else if (current_state == steer_state) { | ||
| if (steer_authorized) { | ||
| set_zero(); | ||
| } else { | ||
| set_one(); | ||
| } | ||
| gpio_set_level(SEG_1, 0); | ||
| gpio_set_level(SEG_2, 0); | ||
| gpio_set_level(SEG_3, 1); | ||
| } | ||
| current_state = (current_state + 1) % 3; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No magic numbers! Add an additional member to your state |
||
| } | ||
|
|
||
| ember_rate_funcs_S module_rf = { | ||
| .call_init = init_led, | ||
| .call_1kHz = bts_authorization, | ||
| .call_100Hz = sup_100Hz, | ||
| }; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
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?