Skip to content

Commit

Permalink
temperature-display_no-rtic working with LoRa.
Browse files Browse the repository at this point in the history
  • Loading branch information
pdgilbert committed Oct 13, 2024
1 parent 577cfab commit 895fa64
Show file tree
Hide file tree
Showing 3 changed files with 245 additions and 100 deletions.
88 changes: 51 additions & 37 deletions examples/projects/lora_show_ping.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
//! To Do:
//! - get working when dispaly is not present
//! - delay between first 8 and second 8 display
//!
//! Transmit a simple message with LoRa using crate radio_sx127x (on SPI).
//! Display on ssd if it is detected on I2C2.
//! Status: WIP, adapted from lora_spi_send. Intend to incorporate into sensor projects.
Expand Down Expand Up @@ -100,6 +105,8 @@ use rust_integration_testing_of_examples::setup::{Peripherals, LED, MONOCLOCK, I

use rust_integration_testing_of_examples::lora::{CONFIG_PA, CONFIG_RADIO, CONFIG_LORA, CONFIG_CH, FREQUENCY, MODE};
//use rust_integration_testing_of_examples::lora::{CONFIG_RADIO};
use rust_integration_testing_of_examples::setup::{Spi, SPI1, Pin, Output, halDelay, TIM5, };
use rust_integration_testing_of_examples::lora::Base;


// ///////////////////// constants and types
Expand Down Expand Up @@ -139,6 +146,44 @@ type DisplayType = Ssd1306<I2CInterface<I2c2Type>, DisplaySize, BufferedGraphic

// //////////////////////////////////////////////////////////////////////

type LoraType = Sx127x<Base<Spi<SPI1>, Pin<'A', 4, Output>, Pin<'B', 4>, Pin<'B', 5>, Pin<'A', 0, Output>, halDelay<TIM5, 1000000>>>;

fn send(
lora: &mut LoraType,
message: &[u8],
disp: &mut Option<DisplayType>,
) -> () {

match lora.start_transmit(message) {
Ok(_b) => {//show_message("start_transmit ok", disp);
//hprintln!("lora.start ok").unwrap()
}
Err(_e) => {show_message("start_transmit error", disp);
//hprintln!("Error in lora.start_transmit()").unwrap()
}
};
//hprintln!("... done").unwrap();

lora.delay_ms(10); // treated as seconds. Without some delay next returns bad. (interrupt may also be an option)

match lora.check_transmit() {
Ok(b) => {if b {show_message("TX good", disp);
//hprintln!("TX good").unwrap();
}
else {show_message("TX bad", disp);
//hprintln!("TX bad").unwrap()
}
}
Err(_e) => {show_message("check_transmit Fail", disp);
//hprintln!("check_transmit() Error. Should return True or False.").unwrap()
}
};
//hprintln!("check_transmit done").unwrap();
()
}

// //////////////////////////////////////////////////////////////////////

#[entry]
fn main() -> ! {
let dp =Peripherals::take().unwrap();
Expand All @@ -158,18 +203,12 @@ fn main() -> ! {
//hprintln!("match z.init() ...").unwrap();

// stalls here if there is no display but works when display is present
// let mut disp: Option<DisplayType> = match z.init() {
// Ok(_d) => {Some(z.into_buffered_graphics_mode())}
// Err(_e) => {None}
// };

let mut zz = z.init();
// hprintln!("z.init() done ...").unwrap();
let mut disp: Option<DisplayType> = match zz {
Ok(d) => {Some(z.into_buffered_graphics_mode())}
let mut disp: Option<DisplayType> = match z.init() {
Ok(_d) => {Some(z.into_buffered_graphics_mode())}
Err(_e) => {None}
};


//hprintln!("disp set ...").unwrap();

show_message("lora_show_ping", &mut disp);
Expand Down Expand Up @@ -198,8 +237,7 @@ fn main() -> ! {

//delay is now available in lora BUT treats arg as seconds not ms!!
lora.delay_ms(1); // this is being treated as seconds



// print out configuration (for debugging)
// hprintln!("frequency {:?}", lora.get_frequency());

Expand All @@ -219,7 +257,7 @@ fn main() -> ! {
// hprintln!("tx_power {:?}", lora.get_tx_power()).unwrap();


///////////////////// transmit
///////////////////// transmit loop

let message = b"Hello, LoRa!";

Expand All @@ -231,31 +269,7 @@ fn main() -> ! {
loop {

//hprintln!("start_transmit ...").unwrap();
match lora.start_transmit(message) {
Ok(_b) => {//show_message("start_transmit ok", &mut disp);
//hprintln!("lora.start ok").unwrap()
}
Err(_e) => {show_message("start_transmit error", &mut disp);
//hprintln!("Error in lora.start_transmit()").unwrap()
}
};
//hprintln!("... done").unwrap();

lora.delay_ms(10); // treated as seconds. Without some delay next returns bad. (interrupt may also be an option)

match lora.check_transmit() {
Ok(b) => {if b {show_message("TX good", &mut disp);
//hprintln!("TX good").unwrap();
}
else {show_message("TX bad", &mut disp);
//hprintln!("TX bad").unwrap()
}
}
Err(_e) => {show_message("check_transmit Fail", &mut disp);
//hprintln!("check_transmit() Error. Should return True or False.").unwrap()
}
};
//hprintln!("check_transmit done").unwrap();
send(&mut lora, message, &mut disp);

lora.delay_ms(READ_INTERVAL); // treated as seconds
//hprintln!("re-loop").unwrap();
Expand Down
Loading

0 comments on commit 895fa64

Please sign in to comment.