# Path: plugins/io_base.py
# class IOBase:
#     def __init__(self, bus):
#         self.bus = bus
#         self.bus.subscribe(self.process_event, thread=False)
#         self.write_queue = Queue(10)
#         self.reader = threading.Thread(target=self.reader_thread)
#         self.reader.daemon = True
#         self.reader.start()
#         self.writer = threading.Thread(target=self.writer_thread)
#         self.writer.daemon = True
#         self.writer.start()
# 
#     def reader_thread(self):
#         raise NotImplementedError()
# 
#     def writer_thread(self):
#         raise NotImplementedError()
# 
#     def convert_data(self, data):
#         return data
# 
#     def process_event(self, ev):
#         try:
#             if ev.name == "leds_enabled":
#                 data = self.convert_data(ev.data)
#                 self.write_queue.put_nowait(data)
#         except queue.Full:
#             #TODO alert somehow without flooding?
#             pass


from .io_base import IOBase
from select import select
import evdev
import logging
            return len(a_keys) > 0
        
        return list(filter(hasAKey, devices))


    def handle_key(self, code, keystate):
        if keystate == evdev.events.KeyEvent.key_hold:
            return
        
        state = "down" if keystate == evdev.events.KeyEvent.key_down else "up"
        
        if code in self.key_map:
            btn = self.key_map[code]

            event_data = {'source': 'keyboard', 'btn': btn, 'state': state}
            self.bus.notify('button_event', event_data)

        if code in self.goal_map and state == "down":
            team = self.goal_map[code]
            self.bus.notify('goal_event', {'source': 'keyboard', 'team': team})
            
        if code == 'KEY_DOT':  # PERIOD
            self.bus.notify('quit')

    def reader_thread(self):
        # A mapping of file descriptors (integers) to InputDevice instances.
        devices = {dev.fd: dev for dev in self.devices}

        while True:
            r, w, x = select(devices, [], [])

# Path: plugins/io_base.py
# class IOBase:
#     def __init__(self, bus):
#         self.bus = bus
#         self.bus.subscribe(self.process_event, thread=False)
#         self.write_queue = Queue(10)
#         self.reader = threading.Thread(target=self.reader_thread)
#         self.reader.daemon = True
#         self.reader.start()
#         self.writer = threading.Thread(target=self.writer_thread)
#         self.writer.daemon = True
#         self.writer.start()
# 
#     def reader_thread(self):
#         raise NotImplementedError()
# 
#     def writer_thread(self):
#         raise NotImplementedError()
# 
#     def convert_data(self, data):
#         return data
# 
#     def process_event(self, ev):
#         try:
#             if ev.name == "leds_enabled":
#                 data = self.convert_data(ev.data)
#                 self.write_queue.put_nowait(data)
#         except queue.Full:
#             #TODO alert somehow without flooding?
#             pass


# Path: plugins/io_evdev_keyboard.py
from .io_base import IOBase
from select import select
import evdev
import logging

            return len(a_keys) > 0
        
        return list(filter(hasAKey, devices))


    def handle_key(self, code, keystate):
        if keystate == evdev.events.KeyEvent.key_hold:
            return
        
        state = "down" if keystate == evdev.events.KeyEvent.key_down else "up"
        
        if code in self.key_map:
            btn = self.key_map[code]

            event_data = {'source': 'keyboard', 'btn': btn, 'state': state}
            self.bus.notify('button_event', event_data)

        if code in self.goal_map and state == "down":
            team = self.goal_map[code]
            self.bus.notify('goal_event', {'source': 'keyboard', 'team': team})
            
        if code == 'KEY_DOT':  # PERIOD
            self.bus.notify('quit')

    def reader_thread(self):
        # A mapping of file descriptors (integers) to InputDevice instances.
        devices = {dev.fd: dev for dev in self.devices}

        while True:
            r, w, x = select(devices, [], [])

            for fd in r: