Skip to content

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

Merged
merged 6 commits into from
Mar 12, 2020

Conversation

jamesbeyond
Copy link
Contributor

wait() and wait_ms() been deprecated, so in the example repo. replace those function call with either ThisThread::sleep_for where sleep can happen and wait_us() where we don't want sleep

Copy link
Member

@fkjagodzinski fkjagodzinski left a 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);
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link

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

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.

Copy link

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

Choose a reason for hiding this comment

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

And here

Copy link

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

Choose a reason for hiding this comment

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

And here :)

Copy link
Member

@fkjagodzinski fkjagodzinski left a 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. 👍

@jamesbeyond
Copy link
Contributor Author

ARMmbed/mbed-os#12572

Copy link

@evedon evedon left a 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);
Copy link

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

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

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)

@evedon
Copy link

evedon commented Mar 11, 2020

Short copyrights need to be added as well.

@jamesbeyond
Copy link
Contributor Author

Could you also run AStyle - some files don't follow the formatting guidelines.

all of the comments been addressed

@jamesbeyond
Copy link
Contributor Author

Short copyrights need to be added as well.

I'll add the copyright to all the files missing in a separate PR, possibly adding a CI to check the license as well

@jamesbeyond
Copy link
Contributor Author

@evedon, could you review again

@jamesbeyond jamesbeyond merged commit d5c93cd into ARMmbed:master Mar 12, 2020
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.

4 participants