Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Commit

Permalink
fix(examples): sleeps in accessories and typo in basic
Browse files Browse the repository at this point in the history
  • Loading branch information
Gavin-Niederman committed Dec 22, 2023
1 parent 5dd3021 commit f51fbdd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions pros/examples/accessories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![no_main]

use core::time::Duration;
use pros::prelude::*;
use pros::{prelude::*, task::delay};

#[derive(Debug, Default)]
struct ExampleRobot;
Expand All @@ -12,7 +12,7 @@ impl AsyncRobot for ExampleRobot {
let handle = pros::async_runtime::spawn(async {
for _ in 0..5 {
println!("Hello from async!");
sleep(Duration::from_millis(1000));
sleep(Duration::from_millis(1000)).await;
}
});

Expand All @@ -38,7 +38,9 @@ impl AsyncRobot for ExampleRobot {

// Sleep the task as to not steal processing time from the OS.
// This should always be done in any loop, including loops in the main task.
sleep(Duration::from_millis(20));
// Because this is a real FreeRTOS task this is not the sleep function used elsewhere in this example.
// This sleep function will block the entire task, including the async executor! (There isn't one running here, but there is in the main task.)
delay(Duration::from_millis(20));
});

loop {
Expand All @@ -50,7 +52,7 @@ impl AsyncRobot for ExampleRobot {
println!("Vision objs {}", vision.nth_largest_object(0)?.middle_x);

// Once again, sleep.
sleep(Duration::from_millis(20));
sleep(Duration::from_millis(20)).await;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pros/examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub struct Robot;
#[async_trait]
impl AsyncRobot for Robot {
async fn opcontrol(&mut self) -> pros::Result {
println!("basic exasmple");
println!("basic example");

Ok(())
}
Expand Down

0 comments on commit f51fbdd

Please sign in to comment.