From 36bdf9dd16e19bb4a4349689d34e6995f4fafd73 Mon Sep 17 00:00:00 2001 From: Leonora Tindall Date: Tue, 31 Dec 2019 14:51:30 -0800 Subject: [PATCH] Move examples to examples/ --- CHANGELOG.md | 2 ++ examples/blinky.rs | 32 ++++++++++++++++++++++++++++++++ examples/lora_packet_rx.rs | 32 ++++++++++++++++++++++++++++++++ src/main.rs | 17 ----------------- 4 files changed, 66 insertions(+), 17 deletions(-) create mode 100644 examples/blinky.rs create mode 100644 examples/lora_packet_rx.rs delete mode 100644 src/main.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 25ac925..5c3a890 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/examples/blinky.rs b/examples/blinky.rs new file mode 100644 index 0000000..aedcc9d --- /dev/null +++ b/examples/blinky.rs @@ -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 "); + 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)); + } +} diff --git a/examples/lora_packet_rx.rs b/examples/lora_packet_rx.rs new file mode 100644 index 0000000..58736bb --- /dev/null +++ b/examples/lora_packet_rx.rs @@ -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 "); + 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(); + } +} diff --git a/src/main.rs b/src/main.rs deleted file mode 100644 index 0fdaa9c..0000000 --- a/src/main.rs +++ /dev/null @@ -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())); -}