From 8481b8f1ab7bf8229219797eb609085e357ba700 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Jos=C3=A9=20Pereira?= Date: Mon, 29 Jul 2024 12:39:39 -0300 Subject: [PATCH] lib: Add support to RGBW neopixel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Patrick José Pereira --- src/lib.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 569b25304..9d156965d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -255,6 +255,28 @@ fn set_led_all(state: bool) { with_navigator!().set_led_all(state) } +#[cpy_fn_c] +#[comment = "Set the color brightnesses of a connected RGBW NeoPixel LED array."] +fn set_neopixel_rgbw_c(rgbw_array: *const [u8; 4], length: usize) { + let array = unsafe { + assert!(!rgbw_array.is_null()); + std::slice::from_raw_parts(rgbw_array, length) + }; + with_navigator!().set_neopixel_rgbw(array); +} + +#[cpy_fn_py] +#[comment = "Set the color brightnesses of a connected RGBW NeoPixel LED array.\n + Args:\n + state ([[uint8, uint8, uint8, uint8], ...]): A 2D array containing RGBW values for each LED.\n + Set the Red, Green, Blue and White components independently, with values from 0-255.\n + Examples:\n + >>> import bluerobotics_navigator as navigator\n + >>> navigator.set_neopixel_rgbw([[100,0,0,100]])"] +fn set_neopixel_rgbw_py(rgbw_array: Vec<[u8; 4]>) { + with_navigator!().set_neopixel_rgbw(&rgbw_array) +} + #[cpy_fn_c] #[comment = "Set the color brightnesses of a connected NeoPixel LED array."] fn set_neopixel_c(rgb_array: *const [u8; 3], length: usize) {