Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updade: Integrations navigator 0.3.1 - lib: PWM: Add set_pwm_channels_duty_cycle for Python and C #63

Merged
merged 1 commit into from Mar 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 28 additions & 1 deletion src/lib.rs
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