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

Provide a way to set a priority with an LED colour change #1377

Open
tremby opened this issue Jan 22, 2024 · 0 comments
Open

Provide a way to set a priority with an LED colour change #1377

tremby opened this issue Jan 22, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@tremby
Copy link
Contributor

tremby commented Jan 22, 2024

Is your feature request related to a problem? Please describe.
I like having a particular LED mode on all the time, but I would like other plugins to be able to override the colours when they have something important to show.

In particular at the moment I'm running the "blazing trail" stalker (this is my favourite), but I'm experimenting with a new plugin which wants to keep a particular key lit while a temporary mode is active. In that plugin I set the colour of a particular key, but then stalker changes it to something else right after, or in the next cycle.

Describe the solution you'd like
It seems to me like it'd be useful for plugins to give a priority along with their request to set an LED's colour. A naive approach might be to remember the priority with which each LED's colour was set, and then when a new request comes in to set its colour, ignore it if the incoming priority is lower. When finished, a plugin can release control.

For example, an ambient colour scheme plugin like stalker could always use priority 0. Another plugin could set a status colour on a given key with a higher priority like 1. Then stalker's requests to change the colour of that same key right after would be ignored. Eventually the other plugin switches the LED back off, with priority 1, and gives an extra argument saying the recorded priority for the LED should end up at 0 rather than the 1, so other plugins can take back over.

Maybe some other plugin would use a higher priority number, because it deems its colours urgent.

Maybe there'd be some constants for common priority levels.

So, maybe something like this...

function setRgbAt(addr, colour, int priority = 0, int store_priority = -1) {
  // Do nothing if the LED was already set with a higher priority
  if (existingPriorityAt(addr) > priority)) return;

  // (Run whatever the current logic of setRgbAt is)

  // Remember the priority with which this colour was set.
  // Default to the priority which was passed, but if something (probably 0)
  // was passed for the 4th argument use that instead.
  setPriorityAt(addr, store_priority == -1 ? priority : store_priority);
}

Maybe there'd be a further function to release control without setting a colour at the same time, but I imagine in most cases they'd want to turn the LED off when done, so it may not be necessary.

Describe alternatives you've considered
What I'm doing right now is setting the colour again every single cycle. This is working, but it seems brittle. Surely if another plugin's afterEachCycle method runs after mine, it'll overrule the colour I'm setting. I'm not sure if this is a race condition or if it's to do with the order plugins are registered, or what.

@tremby tremby added the enhancement New feature or request label Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant