-
Notifications
You must be signed in to change notification settings - Fork 1
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 bms cli #49
base: develop
Are you sure you want to change the base?
base bms cli #49
Conversation
# Conflicts: # BMS Workspace-git/bms-1227-fw/main.c
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.
looks good! just a few comments about code readability
sciReceive(PC_UART, 1, &msg); | ||
if(msg==previous){ | ||
// do nothing | ||
} else if(msg=='1'){ |
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.
when creating actual commands let's use proper macros. This makes it easier to read and change and uses no program memory because the values are placed at compile time
#define DO_SMT_CMD '1'
if (msg == DO_SMT_CMD)
...
} else if(msg=='2'){ | ||
UARTprintf("Message 2 received\r\n"); | ||
} else if(msg=='3'){ | ||
UARTprintf("Message 3 received\r\n"); |
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.
Now that the code is written it's easier to see that a switch statement fits more nicely with this logic.
switch(param)
{
case param:
// do the thing
break;
}
while(1){ | ||
uint8 msg; | ||
sciReceive(PC_UART, 1, &msg); | ||
if(msg==previous){ | ||
// do nothing | ||
} else if(msg=='1'){ | ||
UARTprintf("Message 1 received\r\n"); | ||
} else if(msg=='2'){ | ||
UARTprintf("Message 2 received\r\n"); | ||
} else if(msg=='3'){ | ||
UARTprintf("Message 3 received\r\n"); | ||
} | ||
previous = msg; | ||
vTaskDelay(1000); | ||
} | ||
} |
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.
it's easy to see now that there are 3 logical parts:
- wait for a message
- dispatch/process message
- update variables
// wait for user input
uint8 msg;
sciReceive();
// process input
if ()
{
}
// update previous
previous = msg;
vTaskDelay(1000);
spacing (along with comments) can make this clearer
Feature
prints various messages when user presses different keys
Implementation
receives input with
sciReceive()
, prints withUARTprintf()
, if-statements use input to determine outputTesting
Test steps:
Bugs (aka features)
the same message cannot be printed multiple times in a row, even if key is pressed again