loop implemented

This commit is contained in:
Martin Brodbeck 2023-11-30 15:34:56 +01:00
parent 4df398a749
commit bf74c5c678

View file

@ -1,9 +1,11 @@
mod cloudlog;
mod settings;
mod flrig;
mod settings;
use std::{thread, time::Duration};
use settings::Settings;
use crate::cloudlog::RadioData;
use settings::Settings;
fn main() {
let settings = Settings::new().expect("Could not read settings.");
@ -16,11 +18,27 @@ fn main() {
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.mode = radio_data_new.mode;
radio_data_current.power = radio_data_new.power;
}
if changes_detected {
cloudlog::upload(&settings.cloudlog.url, &radio_data_current);
changes_detected = false;
}
thread::sleep(Duration::from_secs(1));
}
}