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

Feature Request: Charging Indicators #18

Open
mehalter opened this issue Sep 27, 2020 · 2 comments
Open

Feature Request: Charging Indicators #18

mehalter opened this issue Sep 27, 2020 · 2 comments

Comments

@mehalter
Copy link
Contributor

It would be nice to have some sort of battery status keybinding that lights up across the top row with how charged the keyboard is and indicate whether the keyboard is currently charging or discharging. Using the top row is just an idea, this could be implemented in a number of different ways.

@BrianPugh
Copy link

I have implemented something similar here:

https://github.com/BrianPugh/makerdiary-m60-config

The important bits are (might need some imports depending on how you organize your code):

from time import sleep

charger_in = digitalio.DigitalInOut(microcontroller.pin.P0_03)  # NOTE: low/False=charging, high/True=not_charging
charger_in.pull = digitalio.Pull.UP
def battery_charge():
    return not charger_in.value

# code.py
def macro_handler_batt(dev, is_down):  # invoke this in your macro_handler
    if is_down:
        is_charging = battery_charge()
        level = int(round(battery_level() / 7.14))
        dev.backlight.off()
        for i in range(level):
            if i == 0 and is_charging:
                dev.backlight.pixel(i, 255, 0, 0)
            else:
                dev.backlight.pixel(i, 0, 255, 0)

            if i != level - 1:
                sleep(0.03)

            dev.backlight.update()
    else:
        dev.backlight.set_mode(dev.backlight.mode)

So whenever you press this macro it does the following:

  1. Turns off the backlight upon macro press.
  2. Sets "esc" to red if charging, green otherwise.
  3. Animates a bar along the top of your keyboard in green with the current charge level.
  4. Restores the backlight upon macro release.

@BrianPugh
Copy link

I also just committed more changes, like having the macro handlers be aware if shift or ctrl has been also pushed. I have it so that if I have shift pressed while pressing my battery macro, it will type the exact battery percentage.

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

No branches or pull requests

2 participants