File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -189,6 +189,19 @@ impl Pwm {
189
189
Ok ( ( ) )
190
190
}
191
191
192
+ /// Get the currently configured duty_cycle as percentage of period
193
+ pub fn get_duty_cycle ( & self ) -> Result < f32 > {
194
+ Ok ( ( self . get_duty_cycle_ns ( ) ? as f32 ) / ( self . get_period_ns ( ) ? as f32 ) )
195
+ }
196
+
197
+ /// The active time of the PWM signal
198
+ ///
199
+ /// Value is as percentage of period.
200
+ pub fn set_duty_cycle ( & self , duty_cycle : f32 ) -> Result < ( ) > {
201
+ self . set_duty_cycle_ns ( ( self . get_period_ns ( ) ? as f32 * duty_cycle) . round ( ) as u32 ) ?;
202
+ Ok ( ( ) )
203
+ }
204
+
192
205
/// Get the currently configured period in nanoseconds
193
206
pub fn get_period_ns ( & self ) -> Result < u32 > {
194
207
pwm_file_parse :: < u32 > ( & self . chip , self . number , "period" )
You can’t perform that action at this time.
0 commit comments