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

IdleLEDs: Implement a .suspend() and a .resume() method #1289

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

algernon
Copy link
Contributor

Sometimes we want to control LEDs outside of IdleLEDs, like through HostPowerManagement, and in these cases, we would like IdleLEDs to have an up-to-date idea about what's going on. That is, if the host enters sleep, IdleLEDs should be aware of that, and enter idle state. Once the host wakes up, either via the keyboard or otherwise, IdleLEDs should resume its tasks.

With the new .suspend() and .resume() method, this becomes possible.

This addresses a big part of #1287.

@algernon algernon added the bug Something isn't working label Oct 19, 2022
@algernon algernon requested review from obra and tlyu October 19, 2022 17:29
@algernon algernon self-assigned this Oct 19, 2022
Sometimes we want to control LEDs outside of `IdleLEDs`, like through
`HostPowerManagement`, and in these cases, we would like `IdleLEDs` to have an
up-to-date idea about what's going on. That is, if the host enters sleep,
`IdleLEDs` should be aware of that, and enter idle state. Once the host wakes
up, either via the keyboard or otherwise, `IdleLEDs` should resume its tasks.

With the new `.suspend()` and `.resume()` method, this becomes possible.

This addresses a big part of #1287.

Signed-off-by: Gergely Nagy <algernon@keyboard.io>
@algernon
Copy link
Contributor Author

Posting this as a draft for now, because I haven't actually tested that this works as it should in all scenarios. I'd appreciate some help there, not sure when I'll have the cycles to test it myself.

Copy link
Collaborator

@tlyu tlyu left a comment

Choose a reason for hiding this comment

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

You might also want to update the Model 100 sketches, and any others where HostPowerManagement and IdleLEDs are both enabled, so they take advantage of this.

@@ -44,26 +44,38 @@ void IdleLEDs::setIdleTimeoutSeconds(uint32_t new_limit) {
idle_time_limit = new_limit * 1000;
}

void IdleLEDs::resume() {
// Enabling LEDs is fairly expensive, so we only do it if we have to.
Copy link
Collaborator

Choose a reason for hiding this comment

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

In what way is it expensive to enable them? I guess running an animated effect is expensive, but there's a similar comment around disabling, so I'm not sure what this comment is referring to.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It refers to LEDControl.enable() and .disable() doing this:

  refreshAll(); // set_all_leds_to(CRGB(0, 0, 0)); in case of disable()
  Runtime.device().syncLeds();

The .syncLeds() part is the most expensive, but we don't want to refreshAll() on every "resume" either, only when we change states.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah. It might make sense to push that logic down into LEDControl, then. Maybe that should be a separate PR.

@algernon
Copy link
Contributor Author

You might also want to update the Model 100 sketches, and any others where HostPowerManagement and IdleLEDs are both enabled, so they take advantage of this.

The problem with that is that the Model01/Model100 sketches are copies of chyrsalis-firmware-bundle's, and I'd rather not have them diverge too much.

@tlyu
Copy link
Collaborator

tlyu commented Oct 19, 2022

The problem with that is that the Model01/Model100 sketches are copies of chyrsalis-firmware-bundle's, and I'd rather not have them diverge too much.

I think it's worth doing, to make the resume behavior a little less surprising. (both in Chrysalis-Firmware-Bundle and the examples)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

3 participants