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

Check for active_configuration before using it. #135

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions facedancer/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,11 @@ def get_endpoint(self, number: int, direction: USBDirection) -> USBEndpoint:
"""

# Search each of our interfaces for the relevant endpoint.
for interface in self.active_interfaces.values():
endpoint = interface.get_endpoint(number, direction)
if endpoint is not None:
return endpoint
if hasattr(self, 'active_interfaces'):
for interface in self.active_interfaces.values():
endpoint = interface.get_endpoint(number, direction)
if endpoint is not None:
return endpoint

# If none have one, return None.
return None
Expand All @@ -175,10 +176,11 @@ def handle_data_received(self, endpoint: USBEndpoint, data: bytes):
data : The raw bytes received on the relevant endpoint.
"""

for interface in self.active_interfaces.values():
if interface.has_endpoint(endpoint.number, direction=USBDirection.OUT):
interface.handle_data_received(endpoint, data)
return
if hasattr(self, 'active_interfaces'):
for interface in self.active_interfaces.values():
if interface.has_endpoint(endpoint.number, direction=USBDirection.OUT):
interface.handle_data_received(endpoint, data)
return

# If no interface owned the targeted endpoint, consider the data unexpected.
self.get_device().handle_unexpected_data_received(endpoint.number, data)
Expand All @@ -195,10 +197,11 @@ def handle_data_requested(self, endpoint: USBEndpoint):
endpoint : The endpoint on which the host requested data.
"""

for interface in self.active_interfaces.values():
if interface.has_endpoint(endpoint.number, direction=USBDirection.IN):
interface.handle_data_requested(endpoint)
return
if hasattr(self, 'active_interfaces'):
for interface in self.active_interfaces.values():
if interface.has_endpoint(endpoint.number, direction=USBDirection.IN):
interface.handle_data_requested(endpoint)
return

# If no one interface owned the targeted endpoint, consider the data unexpected.
self.get_device().handle_unexpected_data_requested(endpoint.number)
Expand All @@ -214,10 +217,11 @@ def handle_buffer_empty(self, endpoint: USBEndpoint):
This function is called only once per buffer.
"""

for interface in self.active_interfaces.values():
if interface.has_endpoint(endpoint.number, direction=USBDirection.IN):
interface.handle_buffer_empty(endpoint)
return
if hasattr(self, 'active_interfaces'):
for interface in self.active_interfaces.values():
if interface.has_endpoint(endpoint.number, direction=USBDirection.IN):
interface.handle_buffer_empty(endpoint)
return



Expand Down