From bf74c5c6788a06e0d1907150573d09a12316678f Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Thu, 30 Nov 2023 15:34:56 +0100 Subject: [PATCH] loop implemented --- src/main.rs | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 6c0fd6c..ef8e979 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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(); - 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 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; + } - cloudlog::upload(&settings.cloudlog.url, &radio_data_current); + if changes_detected { + cloudlog::upload(&settings.cloudlog.url, &radio_data_current); + changes_detected = false; + } + + thread::sleep(Duration::from_secs(1)); + } }