From 608862d4a8e9fa6d37ae21f1dae7546c43c09413 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Jos=C3=A9=20Pereira?= Date: Mon, 29 Jul 2024 12:36:01 -0300 Subject: [PATCH] lib: Add generic rgb strip size MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Patrick José Pereira --- src/lib.rs | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index a0be81519..cf31f71c6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,6 +3,34 @@ use cpy_binder::{cpy_enum, cpy_fn, cpy_fn_c, cpy_fn_py, cpy_module, cpy_struct}; use lazy_static::lazy_static; use std::sync::Mutex; +struct NavigatorBuilderManager { + rgb_led_strip_size: usize, +} + +lazy_static! { + static ref NAVIGATORBUILDER: Mutex = + Mutex::new(NavigatorBuilderManager { + rgb_led_strip_size: 1, + }); +} + +macro_rules! with_navigator_builder { + () => { + NAVIGATORBUILDER.lock().unwrap() + }; +} + +#[cpy_fn] +#[comment_c = "Sets the size of the navigator led strip (1 is the default), should be called before `init`."] +#[comment_py = "Sets the size of the navigator led strip (1 is the default), should be called before `init`.\n + Examples:\n + >>> import bluerobotics_navigator as navigator\n + >>> navigator.set_rgb_led_strip_size(1)\n + >>> navigator.init()"] +fn set_rgb_led_strip_size(size: usize) { + with_navigator_builder!().rgb_led_strip_size = size; +} + struct NavigatorManager { navigator: navigator_rs::Navigator, } @@ -15,7 +43,9 @@ impl NavigatorManager { fn get_instance() -> &'static Mutex> { if NAVIGATOR.lock().unwrap().is_none() { *NAVIGATOR.lock().unwrap() = Some(NavigatorManager { - navigator: navigator_rs::Navigator::new(), + navigator: navigator_rs::Navigator::create() + .with_rgb_led_strip_size(with_navigator_builder!().rgb_led_strip_size) + .build(), }); } &NAVIGATOR