Open mehalter opened 3 years ago
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:
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.
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.