Skip to content

Commit

Permalink
src: lib: PWM: Add set_pwm_channels_duty_cycle for Python and C
Browse files Browse the repository at this point in the history
  • Loading branch information
RaulTrombin committed Mar 4, 2024
1 parent 3c2f972 commit 2fbd092
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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
Expand All @@ -498,6 +510,20 @@ fn set_pwm_channels_value_py(channels: Vec<PwmChannel>, 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<PwmChannel>, 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) {
Expand Down Expand Up @@ -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
]
Expand Down

0 comments on commit 2fbd092

Please sign in to comment.