Skip to content

Commit 131cca2

Browse files
committed
Rise/Fall fix for #11
1 parent d835e03 commit 131cca2

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

library/cap1xxx.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -579,8 +579,20 @@ def set_led_ramp_alert(self, value):
579579
self._change_bit(R_LED_CONFIG, 6, value)
580580

581581
def set_led_direct_ramp_rate(self, rise_rate=0, fall_rate=0):
582-
'''Set the rise/fall rate in ms, max 2000'''
583-
rate = 0b00000000 + (rise_rate << 4) + fall_rate
582+
'''Set the rise/fall rate in ms, max 2000.
583+
584+
Rounds input to the nearest valid value.
585+
586+
Valid values are 0, 250, 500, 750, 1000, 1250, 1500, 2000
587+
588+
'''
589+
rise_rate = int(round(rise_rate / 250.0))
590+
fall_rate = int(round(fall_rate / 250.0))
591+
592+
rise_rate = min(7, rise_rate)
593+
fall_rate = min(7, fall_rate)
594+
595+
rate = (rise_rate << 4) | fall_rate
584596
self._write_byte(R_LED_DIRECT_RAMP, rate)
585597

586598
def set_led_direct_duty(self, duty_min, duty_max):

0 commit comments

Comments
 (0)