-
Notifications
You must be signed in to change notification settings - Fork 26
update examplea replace deprecated wait and wait_ms api #59
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
Conversation
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.
Everything, apart from that one changed value, looks OK.
@@ -9,7 +9,7 @@ int main() { | |||
while(1) { | |||
if(BUTTON_PRESS == button){ | |||
led = !led; | |||
wait(1); | |||
wait_us(1000000); |
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.
Why is that a busy wait? The example is called busy-wait because we don't use semaphore etc, but we shouldn't push users towards busy loops.
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.
I convert it to the wait_us()
because the whole example page is talking about busy wait. if we change it to sleep, I think we need to chnage som contents to docs page as well:
https://os.mbed.com/docs/mbed-os/v5.14/tutorials/application-flow-control.html
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.
I agree with Bartek that we should limit usage of wait_us
so we will have to rewrite the application flow control tutorial. I will add a task to work on this next sprint.
For this PR, I propose that we use wait_us
only in the first example (Tutorials_UsingAPIs/Flow-Control-Busy-Wait/main.cpp ) and that we emphasize that busy-wait is to be avoided. All other examples should use ThisThread::sleep_for
.
Here we should use ThisThread::sleep_for(1000)
and rename the example Flow-Control-Active-Polling-Button.
@@ -6,9 +6,9 @@ int main() { | |||
while(1) { | |||
myled = 1; | |||
// printf("LED On\r\n"); | |||
wait(0.2); | |||
wait_us(200000); |
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.
Same here, no need to busy wait.
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.
As per previous comment, I propose that this is the only example that uses wait_us
. Let's emphasize further by adding a comment
wait_us(200000); // Busy wait
When updating the tutorial, we should add a forth option : "sleep" option.
@@ -12,6 +12,6 @@ int main() { | |||
button.rise(&toggle); // call toggle function on the rising edge | |||
while(1) { // wait around, interrupts will interrupt this! | |||
heartbeat = !heartbeat; | |||
wait(0.25); | |||
wait_us(250000); |
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.
And here
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.
Let's use ThisThread::sleep_for(250)
@@ -15,6 +15,6 @@ int main() { | |||
// spin in a main loop. flipper will interrupt it to call flip | |||
while(1) { | |||
led1 = !led1; | |||
wait(0.2); | |||
wait_us(200000); |
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.
And here :)
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.
No more comments from me. 👍
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.
Could you also run AStyle - some files don't follow the formatting guidelines.
@@ -9,7 +9,7 @@ int main() { | |||
while(1) { | |||
if(BUTTON_PRESS == button){ | |||
led = !led; | |||
wait(1); | |||
wait_us(1000000); |
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.
I agree with Bartek that we should limit usage of wait_us
so we will have to rewrite the application flow control tutorial. I will add a task to work on this next sprint.
For this PR, I propose that we use wait_us
only in the first example (Tutorials_UsingAPIs/Flow-Control-Busy-Wait/main.cpp ) and that we emphasize that busy-wait is to be avoided. All other examples should use ThisThread::sleep_for
.
Here we should use ThisThread::sleep_for(1000)
and rename the example Flow-Control-Active-Polling-Button.
@@ -6,9 +6,9 @@ int main() { | |||
while(1) { | |||
myled = 1; | |||
// printf("LED On\r\n"); | |||
wait(0.2); | |||
wait_us(200000); |
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.
As per previous comment, I propose that this is the only example that uses wait_us
. Let's emphasize further by adding a comment
wait_us(200000); // Busy wait
When updating the tutorial, we should add a forth option : "sleep" option.
@@ -12,6 +12,6 @@ int main() { | |||
button.rise(&toggle); // call toggle function on the rising edge | |||
while(1) { // wait around, interrupts will interrupt this! | |||
heartbeat = !heartbeat; | |||
wait(0.25); | |||
wait_us(250000); |
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.
Let's use ThisThread::sleep_for(250)
Short copyrights need to be added as well. |
Co-Authored-By: Filip Jagodziński <[email protected]>
all of the comments been addressed |
I'll add the copyright to all the files missing in a separate PR, possibly adding a CI to check the license as well |
@evedon, could you review again |
wait()
andwait_ms()
been deprecated, so in the example repo. replace those function call with eitherThisThread::sleep_for
where sleep can happen andwait_us()
where we don't want sleep