-
Notifications
You must be signed in to change notification settings - Fork 22
Description
rpi_hardware_pwm/rpi_hardware_pwm/__init__.py
Lines 54 to 67 in eea3028
| self._duty_cycle = 0 | |
| self._hz = hz | |
| if not self.is_overlay_loaded(): | |
| raise HardwarePWMException( | |
| "Need to add 'dtoverlay=pwm-2chan' to /boot/config.txt and reboot" | |
| ) | |
| if not self.is_export_writable(): | |
| raise HardwarePWMException(f"Need write access to files in '{self.chippath}'") | |
| if not self.does_pwmX_exists(): | |
| self.create_pwmX() | |
| self.__init_frequency(self._hz) # set this first before DC | |
| self.__init_dc(self._duty_cycle) |
hi, here's something that i've found, not sure how of an edge case this counts but, if pwmX folder exists and duty_cycle also has a value(could happen if stop() wasn't called previously), then __init_frequency(...), __init_dc(...) sequence could fail for certain init hz. Because __init_frequency(...) runs first, it calculates a period nanoseconds using hz and writes to period, this could trigger one of the "Invalid argument" conditions, if the period is greater than that existing duty cycle.
i tested it, verified what i just described, and i think the order should be first __init_dc to 0, then __init_frequency, but the author specifically commented it should __init_dc first, so that throws me off... maybe something i don't see.
if you could confirm this is valid i can pr and fix it if needed.
thx.