Beispiel #1
0
    def poll_buffered(self, buffer_time: float) -> states_tuple:
        pushed: Set[int] = set()
        released: Set[int] = set()
        break_on = 0

        rounds = max(int(buffer_time / 0.01), 1)

        for i in range(rounds):
            time.sleep(0.01)
            events = self.poll_raw()
            if not any([events, pushed, released]):
                break
            state = self.to_state(events)
            released |= state.released
            pushed |= state.pushed
            if state.released:
                if not break_on:
                    break_on = i + 4
            if break_on and break_on == i:
                break

        clicks = pushed & released
        self.held |= pushed - released
        self.held -= released

        self.released |= released
        released_now = self.released - pushed
        self.released -= released_now

        return states_tuple(*[frozenset(f) for f in [clicks, released_now, self.held]])
Beispiel #2
0
def test_controls():
    j = Joystick(None, backend=StubJoystick)
    e1 = event_tuple(123, EventTypes.push)
    e2 = event_tuple(123, EventTypes.release)
    e3 = event_tuple(100, EventTypes.push)
    state = frozenset([123]), frozenset(), frozenset([100])

    assert j.postprocess([e1, e2, e2, e3]) == states_tuple(*state)
Beispiel #3
0
    def postprocess(self, events):  # TODO: this is cancer :3

        pushed, released, held = self.to_states_sets(events)
        self.held |= pushed
        self.held -= released
        self.released |= released

        held |= self.held
        pushed -= held

        released |= self.released
        released -= pushed
        self.released -= released

        return states_tuple(*map(frozenset, [pushed, released, held]))
Beispiel #4
0
 def to_state(cls, events):
     pushed, released, held = cls.to_states_sets(events)
     return states_tuple(*map(frozenset, [pushed, released, held]))