Move examples to examples/

This commit is contained in:
Leonora Tindall 2019-12-31 14:51:30 -08:00
parent acf059aa1a
commit 36bdf9dd16
Signed by: nora
GPG Key ID: 7A8B52EC67E09AAF
4 changed files with 66 additions and 17 deletions

View File

@ -13,12 +13,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `Rn2903::system_module_reset()`
- `Rn2903::mac_pause()` and `::mac_resume()`
- `BadResponse` and `CannotPause` error variants
- Examples directory with LED blinky and LoRa packet RX examples
### Changed
### Deprecated
### Removed
- `main.rs` (moved to an example)
### Fixed

32
examples/blinky.rs Normal file
View File

@ -0,0 +1,32 @@
use rn2903::Rn2903;
use std::env::args;
use std::process::exit;
use std::thread;
use std::time::Duration;
fn main() {
let args: Vec<_> = args().collect();
if args.len() <= 1 {
eprintln!("rn2903_blinky <serial port>");
eprintln!("\tReset the module and toggle pin 0b10 on and off.");
eprintln!("\tThis corresponds to the blue user LED on the LoStik.");
exit(1);
}
let mut txvr = Rn2903::new_at(&args[1]).expect("Could not open device. Error");
println!(
"Successfully connected. Version: {}",
txvr.system_version()
.expect("Could not read from device. Error:")
);
txvr.system_module_reset().unwrap();
txvr.transact(b"mac pause").unwrap();
loop {
txvr.transact(b"sys set pindig GPIO10 1").unwrap();
thread::sleep(Duration::from_millis(1000));
txvr.transact(b"sys set pindig GPIO10 0").unwrap();
thread::sleep(Duration::from_millis(1000));
}
}

View File

@ -0,0 +1,32 @@
use rn2903::Rn2903;
use std::env::args;
use std::process::exit;
use std::thread;
use std::time::Duration;
fn main() {
let args: Vec<_> = args().collect();
if args.len() <= 1 {
eprintln!("rn2903_lora_packet_rx <serial port>");
eprintln!("\tRecieve LoRa packets and print their corresponding hex values.");
exit(1);
}
let mut txvr = Rn2903::new_at(&args[1]).expect("Could not open device. Error");
println!(
"Successfully connected. Version: {}",
txvr.system_version()
.expect("Could not read from device. Error:")
);
txvr.mac_pause().unwrap();
txvr.transact(b"sys set pindig GPIO10 0").unwrap();
txvr.transact(b"radio rx 0").unwrap();
loop {
println!("{:?}", txvr.read_line().unwrap());
txvr.transact(b"sys set pindig GPIO10 1").unwrap();
thread::sleep(Duration::from_millis(100));
txvr.transact(b"sys set pindig GPIO10 0").unwrap();
txvr.transact(b"radio rx 0").unwrap();
}
}

View File

@ -1,17 +0,0 @@
use rn2903::{Rn2903, bytes_to_string};
use std::thread;
use std::time::Duration;
fn main() {
let mut txvr = Rn2903::new_at("/dev/ttyUSB0").expect("Could not open device. Error");
println!(
"Successfully connected. Version: {}",
txvr
.system_version()
.expect("Could not read from device. Error:")
);
dbg!(bytes_to_string(&txvr.transact(b"sys set pindig GPIO10 1").unwrap()));
thread::sleep(Duration::from_millis(200));
dbg!(bytes_to_string(&txvr.transact(b"sys set pindig GPIO10 0").unwrap()));
}