diff options
author | tom barrett <spalf0@gmail.com> | 2018-06-05 02:21:04 -0500 |
---|---|---|
committer | tom barrett <spalf0@gmail.com> | 2018-06-05 02:21:04 -0500 |
commit | f6c9fbea8f535febaf51dc08c353e985aa73988d (patch) | |
tree | 7168eeb42589b8e425b895a423fdcd4c83c64ae6 /src/modules | |
parent | d2b75c42c1c494c2796188a5d600dddb913f5a5d (diff) |
frail implementation of mining
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/mining.rs | 36 |
1 files changed, 34 insertions, 2 deletions
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<SystemTime>, + 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; + } + } } |