Update various internal key handling stuff to be CircuitPython-compatible
This commit is contained in:
parent
d379acfc97
commit
a23acc6131
@ -4,6 +4,7 @@ from collections import namedtuple
|
|||||||
from micropython import const
|
from micropython import const
|
||||||
|
|
||||||
from kmk.common.keycodes import Keycodes
|
from kmk.common.keycodes import Keycodes
|
||||||
|
from kmk.common.util import reset_bootloader
|
||||||
|
|
||||||
KEY_UP_EVENT = const(1)
|
KEY_UP_EVENT = const(1)
|
||||||
KEY_DOWN_EVENT = const(2)
|
KEY_DOWN_EVENT = const(2)
|
||||||
@ -117,11 +118,7 @@ def matrix_changed(new_pressed):
|
|||||||
dispatch(hid_report_event())
|
dispatch(hid_report_event())
|
||||||
|
|
||||||
if Keycodes.KMK.KC_RESET in state.keys_pressed:
|
if Keycodes.KMK.KC_RESET in state.keys_pressed:
|
||||||
try:
|
reset_bootloader()
|
||||||
import machine
|
|
||||||
machine.bootloader()
|
|
||||||
except ImportError:
|
|
||||||
logger.warning('Tried to reset to bootloader, but not supported on this chip?')
|
|
||||||
|
|
||||||
if state.pending_keys:
|
if state.pending_keys:
|
||||||
for key in state.pending_keys:
|
for key in state.pending_keys:
|
||||||
|
@ -1,13 +1,33 @@
|
|||||||
|
import math
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import utime
|
import utime as time
|
||||||
|
USE_UTIME = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
import time
|
||||||
|
USE_UTIME = False
|
||||||
|
|
||||||
|
|
||||||
|
def sleep_ms(ms):
|
||||||
|
'''
|
||||||
|
Tries to sleep for a number of milliseconds in a cross-implementation
|
||||||
|
way. Will raise an ImportError if time is not available on the platform.
|
||||||
|
'''
|
||||||
|
if USE_UTIME:
|
||||||
|
return time.sleep_ms(ms)
|
||||||
|
else:
|
||||||
|
return time.sleep(ms / 1000)
|
||||||
|
|
||||||
|
|
||||||
def ticks_ms():
|
def ticks_ms():
|
||||||
return utime.ticks_ms()
|
if USE_UTIME:
|
||||||
|
return time.ticks_ms()
|
||||||
|
else:
|
||||||
|
return math.floor(time.monotonic() * 1000)
|
||||||
|
|
||||||
|
|
||||||
def ticks_diff(new, old):
|
def ticks_diff(new, old):
|
||||||
return utime.ticks_diff(new, old)
|
if USE_UTIME:
|
||||||
|
return time.ticks_diff(new, old)
|
||||||
|
else:
|
||||||
|
return new - old
|
||||||
|
@ -3,7 +3,7 @@ import string
|
|||||||
from kmk.common.event_defs import (hid_report_event, keycode_down_event,
|
from kmk.common.event_defs import (hid_report_event, keycode_down_event,
|
||||||
keycode_up_event)
|
keycode_up_event)
|
||||||
from kmk.common.keycodes import Keycodes, Macro, RawKeycodes, char_lookup
|
from kmk.common.keycodes import Keycodes, Macro, RawKeycodes, char_lookup
|
||||||
from kmk.common.util import sleep_ms
|
from kmk.common.kmktime import sleep_ms
|
||||||
|
|
||||||
|
|
||||||
def simple_key_sequence(seq):
|
def simple_key_sequence(seq):
|
||||||
|
@ -29,16 +29,3 @@ def reset_bootloader():
|
|||||||
import microcontroller
|
import microcontroller
|
||||||
microcontroller.on_next_reset(microcontroller.RunMode.BOOTLOADER)
|
microcontroller.on_next_reset(microcontroller.RunMode.BOOTLOADER)
|
||||||
microcontroller.reset()
|
microcontroller.reset()
|
||||||
|
|
||||||
|
|
||||||
def sleep_ms(ms):
|
|
||||||
'''
|
|
||||||
Tries to sleep for a number of milliseconds in a cross-implementation
|
|
||||||
way. Will raise an ImportError if time is not available on the platform.
|
|
||||||
'''
|
|
||||||
try:
|
|
||||||
import time
|
|
||||||
time.sleep_ms(ms)
|
|
||||||
except AttributeError:
|
|
||||||
import time
|
|
||||||
time.sleep(ms / 1000)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user