Skip to content
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

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
Open

base bms cli #49

wants to merge 11 commits into from

Conversation

lonamle
Copy link

@lonamle lonamle commented Nov 25, 2022

Feature

prints various messages when user presses different keys

Implementation

receives input with sciReceive(), prints with UARTprintf(), if-statements use input to determine output

Testing

Test steps:

  1. launch debugger
  2. open serial terminal
  3. press keys (1, 2, 3)

Bugs (aka features)

the same message cannot be printed multiple times in a row, even if key is pressed again

@lonamle lonamle requested a review from rafguevara14 November 25, 2022 04:37
Copy link
Contributor

@rafguevara14 rafguevara14 left a 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'){
Copy link
Contributor

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");
Copy link
Contributor

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;
}


Comment on lines +19 to +34
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);
}
}
Copy link
Contributor

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:

  1. wait for a message
  2. dispatch/process message
  3. 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

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.

2 participants