'This will start a loop that catches all keyboard events, parse barcode
sequences and put them on a timestamped queue that can be consumed by
the point of sale\'s requests for barcode events'

def run(self):

    self.barcodes = Queue()
    barcode = []
    shift = False
    devices = None
    while True:
        devices = self.get_devices()
        try:
            while True:
                (r, w, x) = select({dev.fd: dev for dev in [d.evdev for d in devices]}, [], [], 5)
                if (len(r) == 0):
                    break
                for fd in r:
                    device = self._get_open_device_by_fd(fd)
                    if (not evdev.util.is_device(device.evdev.fn)):
                        _logger.info('%s    disconnected', str(device.evdev))
                        self.release_device(device)
                        break
                    events = device.evdev.read()
                    for event in events:
                        if (event.type == evdev.ecodes.EV_KEY):
                            if (event.value == 1):
                                if (event.code in self.keymap):
                                    if device.shift:
                                        device.barcode.append(self.keymap[event.code][1])
                                    else:
                                        device.barcode.append(self.keymap[event.code][0])
                                elif ((event.code == 42) or (event.code == 54)):
                                    device.shift = True
                                elif (event.code == 28):
                                    _logger.debug('pushing    barcode    %s    from    %s', ''.join(device.barcode), str(device.evdev))
                                    self.barcodes.put((time.time(), ''.join(device.barcode)))
                                    device.barcode = []
                            elif (event.value == 0):
                                if ((event.code == 42) or (event.code == 54)):
                                    device.shift = False
        except Exception as e:
            self.set_status('error', str(e))
