Beispiel #1
0
def read(headset):

    while True:
        data = hidapi.hid_read_timeout(
            headset['device'], 34,
            500)  # Have a timeout to make things responsive to interrupts
        if len(data) > 0:
            yield data
Beispiel #2
0
def read_non_windows(source, new_format=False):
    """
    Read from Emotiv hid device.
    :param source: Emotiv hid device
    :param new_format: Read more data?
    :return: Next encrypted packet from Emotiv device.
    """
    # Doesn't seem to matter how big we make the buffer 32 returned every time, 33 for other platforms
    # Set timeout for 1 second, to help with thread shutdown.
    if new_format:
        data = validate_data(hidapi.hid_read_timeout(source, 64, 1000),
                             new_format)
    else:
        data = validate_data(hidapi.hid_read_timeout(source, 34, 1000),
                             new_format)
    if data is not None:
        return ''.join(map(chr, data[1:]))
Beispiel #3
0
    def rx(self, handle, numBytes=0x10):
        in_data = bytes()
        while True:
            ret = hidapi.hid_read_timeout(handle, numBytes, 1000)
            if len(ret) == 0:
                break
            in_data += ret

        return in_data
Beispiel #4
0
def read_non_windows(source):
    """
    Read from Emotiv hid device.
    :param source: Emotiv hid device
    :return: Next encrypted packet from Emotiv device.
    """
    # Doesn't seem to matter how big we make the buffer 32 returned every time, 33 for other platforms
    # Set timeout for 1 second, to help with thread shutdown.
    data = validate_data(hidapi.hid_read_timeout(source, 34, 1000))
    if data is not None:
        return ''.join(map(chr, data[1:]))
Beispiel #5
0
    def cor_nb(self, timeout=100) -> bool:
        """
        [RX] Detects if there's a signal from the Radio.

        Non-blocking, returns after a timeout even if there's no signal from
        the Radio.
        """
        cor_status: bool = False

        hid_read = hidapi.hid_read_timeout(self.hid_device, roip.READ_SIZE,
                                           timeout)
        self._logger.debug('read="%s"', hid_read)

        if roip.COR_START in hid_read:
            cor_status = True
        elif roip.COR_STOP in hid_read:
            cor_status = False

        self._logger.debug('cor_status="%s"', cor_status)
        return cor_status
Beispiel #6
0
    def run(self):
        while not self.finish:
            line = hidapi.hid_read_timeout(self.device, 32, 3000)

            if not len(line):
                continue

            fields = [c for c in line]
            if fields[0] == 0xaa:
                length = fields[1]
                message_id = fields[2]
                if message_id in self.pending_requests:
                    deferred = self.pending_requests[message_id]
                    deferred.resolve(fields[3:length + 2])
                    del self.pending_requests[message_id]
                else:
                    self.unknown_message(line)
            elif fields[0] == 0xab:
                self.notifyObservers()
            else:
                self.unknown_message(line)
Beispiel #7
0
def read(headset):
    
    while True:
        data = hidapi.hid_read_timeout(headset['device'], 34, 500) # Have a timeout to make things responsive to interrupts
        if len(data) > 0:
            yield data
Beispiel #8
0
def rx(handle, numBytes=0x10):
    return hidapi.hid_read_timeout(handle, numBytes, 1000)