From e39512a84284d299daf667a8019cca1de3954cda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Jos=C3=A9=20Pereira?= Date: Fri, 20 Dec 2024 10:03:48 -0300 Subject: [PATCH] src: lib: Add build pattern for navigator and raspberry MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Patrick José Pereira --- src/lib.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index bf0d1d816..f6ec824e9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,6 +27,22 @@ use led::LedController; use pca9685::Pca9685Device; use rgb::RgbController; +// add docs ( difference btwen boards) +#[derive(Debug, Default, Clone, Copy)] +pub enum NavigatorVersion { + #[default] + V1, + V2, +} + +// add docs ( explicit difference btwen overlays) +#[derive(Debug, Default, Clone, Copy)] +pub enum PiVersion { + #[default] + Pi4, + Pi5, +} + /// Set of available options to select ADC's channel. #[derive(Debug, Clone, Copy)] pub enum AdcChannel { @@ -101,6 +117,8 @@ impl Navigator { pub fn create() -> NavigatorBuilder { NavigatorBuilder { + navigator: Default::default(), + pi: Default::default(), rgb_led_strip_size: 1, // There is only a single LED on the board } } @@ -372,15 +390,40 @@ impl Navigator { } pub struct NavigatorBuilder { + navigator: NavigatorVersion, + pi: PiVersion, rgb_led_strip_size: usize, } impl NavigatorBuilder { + pub fn with_navigator(mut self, navigator: NavigatorVersion) -> Self { + self.navigator = navigator; + self + } + + pub fn with_pi(mut self, pi: PiVersion) -> Self { + self.pi = pi; + self + } + pub fn with_rgb_led_strip_size(mut self, size: usize) -> Self { self.rgb_led_strip_size = size; self } + pub fn build(self) -> Navigator { + match self.pi { + PiVersion::Pi4 => match self.navigator { + NavigatorVersion::V1 => self.build_navigator_v1_pi4(), + NavigatorVersion::V2 => self.build_navigator_v2_pi4(), + }, + PiVersion::Pi5 => match self.navigator { + NavigatorVersion::V1 => self.build_navigator_v1_pi5(), + NavigatorVersion::V2 => self.build_navigator_v2_pi5(), + }, + } + } + pub fn build_navigator_v1_pi4(self) -> Navigator { let mut devices: Vec> = vec![ Box::new(