Skip to content

Commit

Permalink
Allow user set timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
emeric-martineau committed Jan 14, 2024
1 parent 3726510 commit 9c3fdbb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ print!("First channel power: {}", jsy_my_194.channel1.power());

That's all!

## Changelog

### 1.0.1

- Rewrite module to be more easy to understand
- Add new public `read_with_timeout` method to allow user set his timeout

## License

The code is released under MIT License to allow every body to use it in all conditions. If you love open-source software and this crate, please give some money to [HaikuOS](https://haiku-os.org/) or [ReactOS](https://reactos.org).
11 changes: 9 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
//! | 15 | negative kwh2 | 55, 56, 57, 58 |
//! | 16 | crc | 59, 60 |
//!
use std::time::Duration;

use embedded_hal::blocking::delay::DelayMs;

pub mod error;
Expand Down Expand Up @@ -265,12 +267,17 @@ where
}
}

/// Read data.
// Read and wait 100ms
pub fn read(&mut self) -> Result<(), error::UartError> {
self.read_with_timeout(100)
}

/// Read data.
pub fn read_with_timeout(&mut self, timeout_ms: u32) -> Result<(), error::UartError> {
// send segment to JSY-MK-194
self.uart.write(&self.segment_write)?;

let is_read_data = self.uart.read(&mut self.segment_read, 100);
let is_read_data = self.uart.read(&mut self.segment_read, timeout_ms);

match is_read_data {
Ok(data_size) => {
Expand Down

0 comments on commit 9c3fdbb

Please sign in to comment.