Fix 'A PWM object already exists for this GPIO channel' exception #504

Merged
jacopotediosi merged 1 commits from fix-pwm_exception into master 2025-05-01 17:13:01 +01:00
jacopotediosi commented 2024-05-24 18:12:29 +01:00 (Migrated from github.com)

Previously, the configure_gpio method removed PWM entries from the pwm_instances list without first stopping the actual PWM signal on the corresponding GPIO pin. As a result, reconfiguring a pin that already had an active PWM object triggered the exception: A PWM object already exists for this GPIO channel.
This exception caused the plugin to crash, leading to broken GPIO functionality such as unresponsive buttons or failure to turn off the heater when the target temperature was reached.

This patch addresses the issue by explicitly stopping all active PWM instances associated with a given pin before removing them from the pwm_instances list.

It's important to note that we collect all matching instances first and remove them only after they’ve been stopped. This ensures proper handling of scenarios where multiple PWM instances are associated with the same GPIO pin.

Fix #335, fix #236.

Previously, the `configure_gpio` method removed PWM entries from the `pwm_instances` list without first stopping the actual PWM signal on the corresponding GPIO pin. As a result, reconfiguring a pin that already had an active PWM object triggered the exception: `A PWM object already exists for this GPIO channel`. This exception caused the plugin to crash, leading to broken GPIO functionality such as unresponsive buttons or failure to turn off the heater when the target temperature was reached. This patch addresses the issue by explicitly stopping all active PWM instances associated with a given pin before removing them from the pwm_instances list. It's important to note that we collect all matching instances first and remove them only after they’ve been stopped. This ensures proper handling of scenarios where multiple PWM instances are associated with the same GPIO pin. Fix #335, fix #236.
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Gandalf/OctoPrint-Enclosure#504