loop implemented
This commit is contained in:
parent
4df398a749
commit
bf74c5c678
1 changed files with 25 additions and 7 deletions
24
src/main.rs
24
src/main.rs
|
@ -1,9 +1,11 @@
|
||||||
mod cloudlog;
|
mod cloudlog;
|
||||||
mod settings;
|
|
||||||
mod flrig;
|
mod flrig;
|
||||||
|
mod settings;
|
||||||
|
|
||||||
|
use std::{thread, time::Duration};
|
||||||
|
|
||||||
use settings::Settings;
|
|
||||||
use crate::cloudlog::RadioData;
|
use crate::cloudlog::RadioData;
|
||||||
|
use settings::Settings;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let settings = Settings::new().expect("Could not read settings.");
|
let settings = Settings::new().expect("Could not read settings.");
|
||||||
|
@ -16,11 +18,27 @@ fn main() {
|
||||||
power: String::from("5"),
|
power: String::from("5"),
|
||||||
};
|
};
|
||||||
|
|
||||||
let radio_data_new = flrig::get_radio_data(&settings.flrig.host, &settings.flrig.port).unwrap();
|
let mut changes_detected = false;
|
||||||
|
|
||||||
|
loop {
|
||||||
|
let radio_data_new =
|
||||||
|
flrig::get_radio_data(&settings.flrig.host, &settings.flrig.port).unwrap();
|
||||||
|
|
||||||
|
if radio_data_current.frequency != radio_data_new.frequency
|
||||||
|
|| radio_data_current.mode != radio_data_new.mode
|
||||||
|
|| radio_data_current.power != radio_data_new.power
|
||||||
|
{
|
||||||
|
changes_detected = true;
|
||||||
radio_data_current.frequency = radio_data_new.frequency;
|
radio_data_current.frequency = radio_data_new.frequency;
|
||||||
radio_data_current.mode = radio_data_new.mode;
|
radio_data_current.mode = radio_data_new.mode;
|
||||||
radio_data_current.power = radio_data_new.power;
|
radio_data_current.power = radio_data_new.power;
|
||||||
|
}
|
||||||
|
|
||||||
|
if changes_detected {
|
||||||
cloudlog::upload(&settings.cloudlog.url, &radio_data_current);
|
cloudlog::upload(&settings.cloudlog.url, &radio_data_current);
|
||||||
|
changes_detected = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
thread::sleep(Duration::from_secs(1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue