Skip to content

Commit d5f9fd8

Browse files
committed
Review fixes
1 parent a5360f5 commit d5f9fd8

4 files changed

Lines changed: 7 additions & 4 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This crate aims to be as flexible as possible to support various HALs and use-ca
1111
## Examples
1212

1313
For more examples consider looking into the [examples](https://github.com/maxwase/button-driver/tree/master/examples) folder.
14-
You can easily flash/rub them using `cargo run` command! Use `trunk serve` to run the wasm example.
14+
You can easily flash/run them using `cargo run` command! Use `trunk serve` to run the wasm example.
1515

1616
For **ESP32C3** with std:
1717

examples/wasm/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/wasm/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! A WebAssembly example demonstrating button driver usage in the browser.
2-
//! This example uses the built-in [instant::wasm::Instant] type which wraps `js_sys::Date::now()`.
2+
//! This example uses the built-in [button_driver::instant::wasm::Instant] type which wraps `js_sys::Date::now()`.
33
//!
44
//! To run this example:
55
//! 1. Install trunk: `cargo install trunk`

src/instant.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,11 @@ pub mod wasm {
5151
type Output = Duration;
5252

5353
fn sub(self, rhs: Self) -> Self::Output {
54+
// Instant should be monotonic, so self.0 >= rhs.0
5455
let delta_ms = self.0 - rhs.0;
55-
Duration::from_millis(delta_ms as u64)
56+
let millis = delta_ms.trunc() as u64;
57+
let micros = (delta_ms.fract() * 1000.0) as u64;
58+
Duration::from_millis(millis) + Duration::from_micros(micros)
5659
}
5760
}
5861

0 commit comments

Comments
 (0)