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

Expose the time of the last change to the LED state #17222

Merged
merged 1 commit into from
Jul 2, 2022

Conversation

joukewitteveen
Copy link
Contributor

@joukewitteveen joukewitteveen commented May 28, 2022

This PR is in part a question: would the proposed change make sense? It extends #11552 and #11595.

Description

This introduces two new functions that mimic

uint32_t last_input_activity_time(void);    // Timestamp of the last matrix or encoder activity
uint32_t last_input_activity_elapsed(void); // Number of milliseconds since the last matrix or encoder activity

from keyboard.h.

Keyboard activity can come from inside (key and/or encoder activity), or from outside. Outside activity happens in the form of USB 'set' reports that can change the LED state.

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Keyboard (addition or update)
  • Keymap/layout/userspace (addition or update)
  • Documentation

Issues Fixed or Closed by This PR

  • Some keyboards use a screen to show the LED state. If such keyboards have a need to implement custom screen timeout logic (e.g. when they show an animation that breaks the normal timeout logic), it would be real easy if they could just do:
    if (timer_elapsed32(MAX(last_input_activity_time(), last_led_activity_time())) > CUSTOM_TIMEOUT) screen_off();

I found user code by @bcat and @snowe2010 that wold benefit from this.

Checklist

  • My code follows the code style of this project: C, Python
  • I have read the PR Checklist document and have made the appropriate changes.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

@github-actions github-actions bot added the core label May 28, 2022
@joukewitteveen
Copy link
Contributor Author

joukewitteveen commented May 28, 2022

We could even consider adding

#if defined(OLED_ENABLE) && OLED_TIMEOUT > 0
    oled_on();
#endif

below led_set() at the bottom of let_task. This is not strictly needed since if the oled task acts on the led state change, the changed oled content will also trigger oled_on(). The main difference will be when the led change is not rendered on the screen: those screens currently stay off but would turn on with the code suggested above.

@bcat
Copy link
Contributor

bcat commented May 28, 2022

I like the idea for consistency, but what's the advantage over the "leds != prev_leds" check I use now (

if (redraw || leds.raw != prev_leds.raw) {
)?

Not intended as a criticism, I'm just curious if checking the last-modified time is roughly equivalent or if my sleepy weekend brain is missing something. :)

@bcat
Copy link
Contributor

bcat commented May 28, 2022

Oh, I guess maybe one difference is that right now, if the host changes LED state (e.g., it's not as a side effect of a key press), then with my current OLED code, the OLED won't wake up, whereas looking at the timer, it would.

I'm honestly not sure which behavior I'd prefer, but having the choice would be nice.

@joukewitteveen
Copy link
Contributor Author

Oh, I guess maybe one difference is that right now, if the host changes LED state (e.g., it's not as a side effect of a key press), then with my current OLED code, the OLED won't wake up, whereas looking at the timer, it would.

I'm honestly not sure which behavior I'd prefer, but having the choice would be nice.

That is indeed the difference, so the interesting line would be this one:

if (last_input_activity_elapsed() < TIMEOUT_MILLIS) {

Note that if you change the screen based on a LED state change, than the screen change will trigger oled_on(). However, if you have a custom timeout logic, than that would typically turn the screen back off immediately after. The result is that the host-initiated led state change caused the screen to flash briefly.

@bcat
Copy link
Contributor

bcat commented May 28, 2022

I see the point, that is an odd edge case. Yeah, it'd be nice to have a more complete "did anything change" API. Thanks for explaining!

@drashna drashna requested a review from a team May 29, 2022 21:38
@tzarc tzarc merged commit 0112938 into qmk:develop Jul 2, 2022
nolanseaton pushed a commit to nolanseaton/qmk_firmware that referenced this pull request Jan 23, 2023
yokada-code added a commit to yokada-code/qmk_firmware that referenced this pull request Aug 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants