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_channel_duty_cycle #64

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
23 changes: 23 additions & 0 deletions src/lib.rs
Expand Up @@ -426,6 +426,28 @@ fn set_pwm_channel_value(channel: PwmChannel, value: u16) {
with_navigator!().set_pwm_channel_value(channel.into(), value)
}

#[cpy_fn]
#[comment_c = "Sets the duty cycle (the proportion of ON time) for the selected PWM channel."]
#[comment_py = "Sets the duty cycle (the proportion of ON time) for the selected PWM channel.\n
Similar to :py:func:`set_pwm_channel_value`, this function calculate the OFF counter
value to match desired PWM channel's duty_cyle.\n
Notes:\n
A duty cycle of 1.0 or 0.0 acts like a relay.\n
Details of counters on IC, check :py:func:`set_pwm_channel_value`.
Args:\n
channel (:py:class:`PwmChannel`): The channel to be selected for PWM.\n
duty_cycle (f32) : Duty cycle count value (0.0 : 1.0).\n
Examples:\n
>>> import bluerobotics_navigator as navigator\n
>>> from bluerobotics_navigator import PwmChannel\n
>>> navigator.init()\n
>>> navigator.set_pwm_freq_hz(1000)\n
>>> navigator.set_pwm_channel_duty_cycle(PwmChannel.Ch1, 0.5)\n
>>> navigator.set_pwm_enable(True)"]
fn set_pwm_channel_duty_cycle(channel: PwmChannel, duty_cycle: f32) {
with_navigator!().set_pwm_channel_duty_cycle(channel.into(), duty_cycle)
}

#[cpy_fn_c]
#[comment = "Sets the duty cycle for a list of multiple PWM channels."]
fn set_pwm_channels_value_c(channels: *const PwmChannel, value: u16, length: usize) {
Expand Down Expand Up @@ -510,6 +532,7 @@ cpy_module!(
set_pwm_freq_prescale,
set_pwm_freq_hz,
set_pwm_channel_value,
set_pwm_channel_duty_cycle,
set_pwm_channels_value,
set_pwm_channels_values
]
Expand Down