Пример #1
0
 def psleep(self):
     '''
     Sleeps longer and longer to save power the more time in between updates.
     '''
     if ticks_diff(ticks_ms(), self._powersave_start) <= 60000:
         sleep_ms(8)
     elif ticks_diff(ticks_ms(), self._powersave_start) >= 240000:
         sleep_ms(180)
     return
Пример #2
0
def tt_released(key, state, *args, **kwargs):
    if (state.start_time['tt'] is None or ticks_diff(
            ticks_ms(), state.start_time['tt']) >= state.config.tap_time):
        # On first press, works like MO. On second press, does nothing unless let up within
        # time window, then acts like TG.
        state.start_time['tt'] = None
        return mo_released(key, state, *args, **kwargs)

    return state
Пример #3
0
def lt_released(key, state, *args, **kwargs):
    # On keyup, check timer, and press key if needed.
    if state.start_time['lt'] and (ticks_diff(
            ticks_ms(), state.start_time['lt']) < state.config.tap_time):
        state.hid_pending = True
        state.tap_key(key.meta.kc)

    mo_released(key, state, *args, **kwargs)
    state.start_time['lt'] = None
    return state
Пример #4
0
def mt_released(key, state, *args, **kwargs):
    # On keyup, check timer, and press key if needed.
    state.keys_pressed.discard(key.meta.mods)
    timer_name = 'mod_tap'
    if state.start_time[timer_name] and (ticks_diff(
            ticks_ms(), state.start_time[timer_name]) < state.config.tap_time):
        state.hid_pending = True
        state.tap_key(key.meta.kc)

    state.start_time[timer_name] = None
    return state
Пример #5
0
def tt_pressed(key, state, *args, **kwargs):
    """Momentarily activates layer if held, toggles it if tapped repeatedly"""
    # TODO Make this work with tap dance to function more correctly, but technically works.
    if state.start_time['tt'] is None:
        # Sets the timer start and acts like MO otherwise
        state.start_time['tt'] = ticks_ms()
        return mo_pressed(key, state, *args, **kwargs)
    elif ticks_diff(ticks_ms(),
                    state.start_time['tt']) < state.config.tap_time:
        state.start_time['tt'] = None
        return tg_pressed(key, state, *args, **kwargs)
Пример #6
0
    def _process_timeouts(self):
        if not self._timeouts:
            return self

        # Copy timeout keys to a temporary list to allow sorting.
        # Prevent net timeouts set during handling from running on the current
        # cycle by setting a flag `_processing_timeouts`.
        current_time = ticks_ms()
        timeout_keys = []
        self._processing_timeouts = True

        for k in self._timeouts.keys():
            if ticks_diff(k, current_time) <= 0:
                timeout_keys.append(k)

        for k in sorted(timeout_keys):
            for callback in self._timeouts[k]:
                if callback:
                    callback()
            del self._timeouts[k]

        self._processing_timeouts = False

        return self
Пример #7
0
 def ble_rescan_timer(self):
     '''If true, the rescan timer is up'''
     return bool(ticks_diff(ticks_ms(), self._ble_last_scan) > 5000)
Пример #8
0
 def usb_rescan_timer(self):
     return bool(ticks_diff(ticks_ms(), self._usb_last_scan) > 5000)