From f6c9fbea8f535febaf51dc08c353e985aa73988d Mon Sep 17 00:00:00 2001 From: tom barrett Date: Tue, 5 Jun 2018 02:21:04 -0500 Subject: frail implementation of mining --- src/modules/mining.rs | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'src/modules') diff --git a/src/modules/mining.rs b/src/modules/mining.rs index e22918f..7f11f05 100644 --- a/src/modules/mining.rs +++ b/src/modules/mining.rs @@ -6,6 +6,7 @@ pub struct Mining { pub status : bool, time : u64, start : Option, + pub ready : bool, } @@ -14,10 +15,41 @@ impl Mining { Mining { range : 10.0, status : false, - time : 1, + time : 5, start : None, + ready : false, } } - pub fn toggle(&self) {} + pub fn toggle(&mut self) { + self.status = !self.status; + self.start = match self.status { + true => Some(SystemTime::now()), + false => None, + }; + } + + pub fn off(&mut self) { + self.status = false; + } + + pub fn take(&mut self) { + self.ready = false; + } + + pub fn process(&mut self) { + match self.start.clone() { + Some(timer) => { + if timer.elapsed().unwrap().as_secs() > self.time { + self.start = Some(SystemTime::now()); + self.ready = true; + } + } + _ => (), + } + if !self.status { + self.start = None; + self.ready = false; + } + } } -- cgit v1.2.3