diff --git a/src/lib.rs b/src/lib.rs index bc3686c50..02fd286ec 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -473,7 +473,7 @@ fn set_pwm_channel_duty_cycle(channel: PwmChannel, duty_cycle: f32) { } #[cpy_fn_c] -#[comment = "Sets the duty cycle for a list of multiple PWM channels."] +#[comment = "Sets the duty cycle (based on OFF counter from 0 to 4096) for a list of multiple PWM channels."] fn set_pwm_channels_value_c(channels: *const PwmChannel, value: u16, length: usize) { let array_channels = unsafe { assert!(!channels.is_null()); @@ -484,6 +484,18 @@ fn set_pwm_channels_value_c(channels: *const PwmChannel, value: u16, length: usi } } +#[cpy_fn_c] +#[comment = "Sets the duty cycle (from 0.0 to 1.0) for a list of multiple PWM channels."] +fn set_pwm_channels_duty_cycle_c(channels: *const PwmChannel, duty_cycle: f32, length: usize) { + let array_channels = unsafe { + assert!(!channels.is_null()); + std::slice::from_raw_parts(channels, length) + }; + for channel in array_channels.iter().take(length) { + with_navigator!().set_pwm_channel_duty_cycle(channel.clone().into(), duty_cycle); + } +} + #[cpy_fn_py] #[comment = "Like :py:func:`set_pwm_channel_value`. This function sets the duty cycle for a list of multiple PWM channels.\n Args:\n @@ -498,6 +510,20 @@ fn set_pwm_channels_value_py(channels: Vec, value: u16) { } } +#[cpy_fn_py] +#[comment = "Like :py:func:`set_pwm_channel_duty_cycle`. This function sets the duty cycle for a list of multiple PWM channels.\n + Args:\n + channels ([:py:class:`PwmChannel`]): A list of PWM channels to configure.\n + duty_cycle (f32) : Duty cycle count value (0.0 : 1.0).\n + Examples:\n + You can use this method like :py:func:`set_pwm_channel_duty_cycle`.\n + >>> navigator.set_pwm_channels_value([PwmChannel.Ch1, PwmChannel.Ch16], 0.5)"] +fn set_pwm_channels_duty_cycle_py(channels: Vec, duty_cycle: f32) { + for channel in channels { + with_navigator!().set_pwm_channel_duty_cycle(channel.into(), duty_cycle); + } +} + #[cpy_fn_c] #[comment = "Sets the duty cycle (from 0 to 4096) for a list of multiple channels with multiple values."] fn set_pwm_channels_values_c(channels: *const PwmChannel, values: *const u16, length: usize) { @@ -601,6 +627,7 @@ cpy_module!( set_pwm_channel_value, set_pwm_channel_duty_cycle, set_pwm_channels_value, + set_pwm_channels_duty_cycle, set_pwm_channels_values, set_pwm_channels_duty_cycle_values ]