-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathsimple_emitter_ack.rs
44 lines (41 loc) · 1.32 KB
/
simple_emitter_ack.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
extern crate nrf24l01;
use std::thread::sleep;
use std::time::Duration;
use nrf24l01::{OperatingMode, PALevel, TXConfig, NRF24L01};
fn main() {
let config = TXConfig {
channel: 108,
pa_level: PALevel::Low,
pipe0_address: *b"abcde",
max_retries: 3,
retry_delay: 2,
..Default::default()
};
let mut device = NRF24L01::new(25, 0).unwrap();
let message = b"sendtest";
device.configure(&OperatingMode::TX(config)).unwrap();
device.flush_output().unwrap();
loop {
device.push(0, message).unwrap();
match device.send() {
Ok(retries) => {
println!("Message sent, {} retries needed", retries);
if device.data_available().unwrap() {
device
.read_all(|packet| {
println!("Received back {:?} bytes", packet.len());
println!("ACK Payload {:?}", packet)
})
.unwrap();
} else {
println!("Blank ACK")
}
}
Err(err) => {
println!("Destination unreachable: {:?}", err);
device.flush_output().unwrap()
}
};
sleep(Duration::from_millis(5000));
}
}