-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: David Beechey <[email protected]>
- Loading branch information
1 parent
1414840
commit 36b1999
Showing
5 changed files
with
123 additions
and
88 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
#![no_std] | ||
|
||
pub mod preprocessing; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod keyence; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,97 @@ | ||
use heapless::Vec; | ||
|
||
#[derive(PartialEq, Debug)] | ||
pub enum SensorChecks { | ||
Acceptable, | ||
Unnaceptable, | ||
} | ||
|
||
/// Checks if the two Keyence sensors are in agreement. | ||
/// If the sensors disagree for two consecutive readings, the check fails. | ||
pub struct KeyenceAgrees { | ||
previous_keyence_agreement: bool, | ||
} | ||
|
||
impl Default for KeyenceAgrees { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} | ||
|
||
impl KeyenceAgrees { | ||
pub fn new() -> Self { | ||
KeyenceAgrees { | ||
previous_keyence_agreement: true, | ||
} | ||
} | ||
|
||
pub fn check_keyence_agrees(&mut self, keyence_data: Vec<bool, 2>) -> SensorChecks { | ||
if keyence_data[0] != keyence_data[1] && !self.previous_keyence_agreement { | ||
return SensorChecks::Unnaceptable; | ||
} else { | ||
self.previous_keyence_agreement = keyence_data[0] == keyence_data[1]; | ||
} | ||
|
||
SensorChecks::Acceptable | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_acceptable_success() { | ||
let keyence_data: Vec<bool, 2> = Vec::from_slice(&[true, true]).unwrap(); | ||
let mut keyence_agrees = KeyenceAgrees::new(); | ||
let desired_outcome = SensorChecks::Acceptable; | ||
let result = keyence_agrees.check_keyence_agrees(keyence_data); | ||
assert_eq!(result, desired_outcome); | ||
} | ||
|
||
#[test] | ||
fn test_acceptable_false_success() { | ||
let keyence_data: Vec<bool, 2> = Vec::from_slice(&[true, false]).unwrap(); | ||
let mut keyence_agrees = KeyenceAgrees::new(); | ||
let desired_outcome = SensorChecks::Acceptable; | ||
let result = keyence_agrees.check_keyence_agrees(keyence_data); | ||
assert_eq!(result, desired_outcome); | ||
} | ||
|
||
#[test] | ||
fn test_acceptable_second_false_success() { | ||
let first_keyence_data: Vec<bool, 2> = Vec::from_slice(&[true, true]).unwrap(); | ||
let second_keyence_data: Vec<bool, 2> = Vec::from_slice(&[true, false]).unwrap(); | ||
let mut keyence_agrees = KeyenceAgrees::new(); | ||
let desired_outcome = SensorChecks::Acceptable; | ||
let initial_try = keyence_agrees.check_keyence_agrees(first_keyence_data); | ||
let result = keyence_agrees.check_keyence_agrees(second_keyence_data); | ||
assert_eq!(initial_try, desired_outcome); | ||
assert_eq!(result, desired_outcome); | ||
} | ||
|
||
#[test] | ||
fn test_acceptable_prev_false_success() { | ||
let first_keyence_data: Vec<bool, 2> = Vec::from_slice(&[true, false]).unwrap(); | ||
let second_keyence_data: Vec<bool, 2> = Vec::from_slice(&[true, true]).unwrap(); | ||
let mut keyence_agrees = KeyenceAgrees::new(); | ||
let desired_outcome = SensorChecks::Acceptable; | ||
let initial_try = keyence_agrees.check_keyence_agrees(first_keyence_data); | ||
let result = keyence_agrees.check_keyence_agrees(second_keyence_data); | ||
assert_eq!(initial_try, desired_outcome); | ||
assert_eq!(result, desired_outcome); | ||
} | ||
|
||
#[test] | ||
fn test_unnacceptable_prev_false_success() { | ||
let first_keyence_data: Vec<bool, 2> = Vec::from_slice(&[true, false]).unwrap(); | ||
let second_keyence_data: Vec<bool, 2> = Vec::from_slice(&[true, false]).unwrap(); | ||
let mut keyence_agrees = KeyenceAgrees::new(); | ||
let first_outcome = SensorChecks::Acceptable; | ||
let second_outcome = SensorChecks::Unnaceptable; | ||
let initial_try = keyence_agrees.check_keyence_agrees(first_keyence_data); | ||
let result = keyence_agrees.check_keyence_agrees(second_keyence_data); | ||
assert_eq!(initial_try, first_outcome); | ||
assert_eq!(result, second_outcome); | ||
} | ||
} |