Skip to content

Color LED tab#793

Open
ArisMorgens wants to merge 13 commits into
cflib2from
Aris/cflib2/ColorLEDTab
Open

Color LED tab#793
ArisMorgens wants to merge 13 commits into
cflib2from
Aris/cflib2/ColorLEDTab

Conversation

@ArisMorgens
Copy link
Copy Markdown
Member

No description provided.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enables the Color LED tab in the UI and migrates its Crazyflie interactions to the newer async cflib2-style APIs (async params + log streaming), aligning it with the newer connection model used by other tabs like ParamTab.

Changes:

  • Enabled ColorLEDTab in the tab loader (available list + import).
  • Reworked Color LED deck detection, param writes, and thermal throttling monitoring to use async cflib2 calls and create_task() scheduling.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
src/cfclient/ui/tabs/__init__.py Uncomments/imports ColorLEDTab and adds it to the available tab list so it can be loaded.
src/cfclient/ui/tabs/ColorLEDTab.py Migrates to async cflib2 param/log APIs, adds async connection setup, and implements thermal log stream reading via background tasks.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread src/cfclient/ui/tabs/ColorLEDTab.py Outdated
Comment thread src/cfclient/ui/tabs/ColorLEDTab.py Outdated
Comment thread src/cfclient/ui/tabs/ColorLEDTab.py Outdated
Comment thread src/cfclient/ui/tabs/ColorLEDTab.py Outdated
Comment thread src/cfclient/ui/tabs/ColorLEDTab.py
@ArisMorgens ArisMorgens changed the title Added a cflib2-based Color LED tab Color LED tab Mar 12, 2026
@gemenerik gemenerik requested a review from Copilot March 23, 2026 13:52
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/cfclient/ui/tabs/ColorLEDTab.py Outdated
Comment thread src/cfclient/ui/tabs/ColorLEDTab.py Outdated
Comment thread src/cfclient/ui/tabs/ColorLEDTab.py
@gemenerik
Copy link
Copy Markdown
Member

image

Custom colors are not grayed out when disconnected. (They may not have been in the old client, but anyways)

@ArisMorgens
Copy link
Copy Markdown
Member Author

Nice catch! This issue exists in the old client as well. It is fixed for the new client in 0ae1059.

@ArisMorgens ArisMorgens force-pushed the Aris/cflib2/ColorLEDTab branch 2 times, most recently from 7940a4e to 5b502d1 Compare March 25, 2026 12:53
Copy link
Copy Markdown
Member

@gemenerik gemenerik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Several places replace specific exception types with bare except Exception. The risk here is that it hides; programming mistakes, unexpected runtime issues, new exception types from cflib2. They would all be silently logged as a debug message while the code moves on. It's better to catch only the exceptions you actually expect.

Comment thread src/cfclient/ui/tabs/ColorLEDTab.py Outdated
self._cf, present_decks
)
for position, stream in streams.items():
create_task(self._run_thermal_stream(position, stream))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thermal stream tasks created here aren't stored, so they can't be canceled on disconnect. Currently they only terminate because the Disconnected exception is caught by the general except Exception handler, but catching exceptions is meant to catch things going wrong, not to handle a normal disconnect. The disconnect path should use explicit cancellation of the task. Store the task references and cancel them in disconnected(), like with how _connected_task is handled.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added proper handling of the thermal_stream_tasks upon disconnection in 506a7f9.

Comment thread src/cfclient/ui/tabs/ColorLEDTab.py Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not this pr but this feels fragile

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 3530d38.
Instead of retrieving a button's color by reading its stylesheet, we now store the color directly on the button using Qt's setProperty(). This happens both on preset buttons once during connection, and on custom buttons when they're created.

@ArisMorgens
Copy link
Copy Markdown
Member Author

Several places replace specific exception types with bare except Exception. The risk here is that it hides; programming mistakes, unexpected runtime issues, new exception types from cflib2. They would all be silently logged as a debug message while the code moves on. It's better to catch only the exceptions you actually expect.

I replaced the broad except Exceptions with specific ones from cflib2.error in e3833c2. I tried to match the exception with the relevant errors from each call (e.g. detect_decks() calls cf.param().get(), so I used ParamError). @gemenerik Is this the appropriate approach of catching the expected exceptions?

@ArisMorgens ArisMorgens force-pushed the Aris/cflib2/ColorLEDTab branch from 3530d38 to 1ef9f60 Compare May 5, 2026 12:24
Comment thread src/cfclient/ui/tabs/ColorLEDTab.py Outdated
self._process_thermal_data(log_data.data)
except asyncio.CancelledError:
raise
except Exception as e:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last trailing except Exception

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops. Fixed in 7443322.

Comment thread src/cfclient/ui/tabs/ColorLEDTab.py Outdated
]
for btn in color_buttons:
style = btn.styleSheet()
hex_color = style.split("background-color:")[-1].split(";")[0].strip()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still has this potentially fragile parsing. Again not this PR but maybe nice to fix.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In 6994368 I replaced the chained split() with a regex that explicitly targets the QPushButton{} block, so the parsing should be more robust now. What do you think @gemenerik?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants