Exemplo n.º 1
0
    def setup_darwin(self):
        """
        Setup for headset on the OS X platform.
        Receives packets from headset and sends them to a Queue to be processed
        by the crypto greenlet.
        """

        # Set this to True if the OS is performing the encryption of the packets
        _os_decryption = False
        # Change these values to the hex equivalent from the output of hid_enumerate. If they are incorrect.
        # Current values = VendorID: 8609 ProductID: 1
        #hidraw = hid.device(0x31a1, 0x2001)
        hidraw = hid.device(0x1234,0xed02)

        hidraw.open(0x1234, 0xed02)
        self.serial_number = 'SN20120229000290'
        if not hidraw:
            hidraw = hid.device(0x21a1, 0x1234)
        if not hidraw:
                hidraw = hid.device(0xed02, 0x1234)
        if not hidraw:
            print "Device not found. Uncomment the code in setup_darwin and modify hid.device(vendor_id, product_id)"
            raise ValueError
        if self.serial_number == "":
            print "Serial number needs to be specified manually in __init__()."
            raise ValueError
        print "Serial number:" + self.serial_number
        crypto = gevent.spawn(self.setup_crypto, self.serial_number)
        console_updater = gevent.spawn(self.update_console)
        zero = 0
        while self.running:
            try:
                # Doesn't seem to matter how big we make the buffer 32 returned every time, 33 for other platforms
                data = hidraw.read(34,10)
                #data = [48]*32
                if len(data) == 32:
                    # Most of the time the 0 is truncated? That's ok we'll add it...
                    data = [zero] + data
                if data != "":
                    if _os_decryption:
                        self.packets.put_nowait(EmotivPacket(data))
                    else:
                        #Queue it!
                        print ('Queuing package:'+len(data))
                        tasks.put_nowait(''.join(map(chr, data[1:])))
                        self.packets_received += 1

                    print ('Waiting...')
                    gevent.sleep(0.01)
                else:
                    # No new data from the device; yield
                    # We cannot sleep(0) here because that would go 100% CPU if both queues are empty.
                    gevent.sleep(DEVICE_POLL_INTERVAL)
            except KeyboardInterrupt:
                self.running = False
        hidraw.close()
        gevent.kill(crypto, KeyboardInterrupt)
        gevent.kill(console_updater, KeyboardInterrupt)
Exemplo n.º 2
0
 def setup_darwin(self):
     """
     Setup for headset on the OS X platform.
     Receives packets from headset and sends them to a Queue to be processed
     by the crypto greenlet.
     """
     _os_decryption = False
     # Change these values to the hex equivalent from the output of hid_enumerate. If they are incorrect.
     # Current values = VendorID: 8609 ProductID: 1
     hidraw = hid.device(0x21a1, 0x0001)
     if not hidraw:
         hidraw = hid.device(0x21a1, 0x1234)
     if not hidraw:
         hidraw = hid.device(0xed02, 0x1234)
     if not hidraw:
         print "Device not found. Uncomment the code in setup_darwin and modify hid.device(vendor_id, product_id)"
         raise ValueError
     if self.serial_number == "":
         print "Serial number needs to be specified manually in __init__()."
         raise ValueError
     else:
         print "Serial number is specified! LMAOOO!"
     crypto = gevent.spawn(self.setup_crypto, self.serial_number)
     console_updater = gevent.spawn(self.update_console)
     zero = 0
     while self.running:
         try:
             # Doesn't seem to matter how big we make the buffer 32 returned
             # every time, 33 for other platforms
             data = hidraw.read(34)
             if len(data) == 32:
                 # Most of the time the 0 is truncated? That's ok we'll add
                 # it...
                 data = [zero] + data
             if data != "":
                 if _os_decryption:
                     self.packets.put_nowait(EmotivPacket(data))
                 else:
                     # Queue it!
                     tasks.put_nowait(''.join(map(chr, data[1:])))
                     self.packets_received += 1
                 gevent.sleep(0)
             else:
                 # No new data from the device; yield
                 # We cannot sleep(0) here because that would go 100% CPU if
                 # both queues are empty.
                 gevent.sleep(DEVICE_POLL_INTERVAL)
         except KeyboardInterrupt:
             self.running = False
     hidraw.close()
     gevent.kill(crypto, KeyboardInterrupt)
     gevent.kill(console_updater, KeyboardInterrupt)
Exemplo n.º 3
0
 def start_capture(self):
     """Begin listening for output from the stenotype machine."""
     try:
         if hasattr(hid.device, 'open'):
             self._machine = hid.device()
             self._machine.open(VENDOR_ID, 1)
         else:
             self._machine = hid.device(VENDOR_ID, 1)
         self._machine.set_nonblocking(0)
     except IOError as e:
         log.info('Treal device not found: %s', str(e))
         log.warning('Treal is not connected')
         self._error()
         return
     super(Stenotype, self).start_capture()
Exemplo n.º 4
0
    def open(self) -> int:
        """
        Opens the device
        :return: <0 err; >0 ok
        """
        # Windows: pywinusb
        if os.name == 'nt':
            target_vendor_id = SARK110_VENDOR_ID
            target_product_id = SARK110_PRODUCT_ID
            hid_filter = hid.HidDeviceFilter(vendor_id=target_vendor_id,
                                             product_id=target_product_id)
            try:
                self._handler = hid_filter.get_devices()[0]
                if not self._handler:
                    return -1
                else:
                    self._handler.open()
                    self._handler.set_raw_data_handler(self._rx_handler)
                    return 1
            except:
                return -2

        # Linux: hidapi
        else:
            self._handler = hid.device()
            try:
                self._handler.open(SARK110_VENDOR_ID, SARK110_PRODUCT_ID)
                self._handler.set_nonblocking(0)
                return 1
            except IOError as ex:
                return -1
Exemplo n.º 5
0
 def start_capture(self):
     """Begin listening for output from the stenotype machine."""
     try:
         self._machine = hid.device(VENDOR_ID, 1)
         self._machine.set_nonblocking(1)
     except IOError as e:
         self._error()
         return
     return ThreadedStenotypeBase.start_capture(self)
Exemplo n.º 6
0
 def start_capture(self):
     """Begin listening for output from the stenotype machine."""
     try:
         self._machine = hid.device(VENDOR_ID, 1)
         self._machine.set_nonblocking(1)
     except IOError as e:
         self._error()
         return
     return ThreadedStenotypeBase.start_capture(self)
Exemplo n.º 7
0
Arquivo: treal.py Projeto: gcr/plover
 def start_capture(self):
     """Begin listening for output from the stenotype machine."""
     try:
         self._machine = hid.device(3526, 1)
         self._machine.set_nonblocking(1)
     except IOError as e:
         # TODO(hesky): Figure out what to do here. Maybe start_capture should return a bool or error or raise an exception.
         raise e
     super(type(self), self).start_capture()
Exemplo n.º 8
0
 def start_capture(self):
     """Begin listening for output from the stenotype machine."""
     try:
         self._machine = hid.device(VENDOR_ID, 1)
         self._machine.set_nonblocking(1)
     except IOError as e:
         log.info('Treal device not found: %s', str(e))
         log.warning('Treal is not connected')
         self._error()
         return
     return ThreadedStenotypeBase.start_capture(self)
Exemplo n.º 9
0
 def open(self, device=None):
     if device is None:
         try:
             self.hid_device = hid.device(0x2047, 0x200)
          
         except IndexError:
             raise ValueError('USB VID:PID 2047:0200 not found (not in BSL mode? or try --device)')
     else:
         #~ ... by serial number?
         raise ValueError("don't (yet) know how to handle --device")
     self.logger.info('Opening HID device %r' % (self.hid_device,))
Exemplo n.º 10
0
 def start_capture(self):
     """Begin listening for output from the stenotype machine."""
     try:
         self._machine = hid.device(VENDOR_ID, 1)
         self._machine.set_nonblocking(1)
     except IOError as e:
         log.info('Treal device not found: %s', str(e))
         log.warning('Treal is not connected')
         self._error()
         return
     return ThreadedStenotypeBase.start_capture(self)
        def open(self, device=None):
            if device is None:
                try:
                    self.hid_device = hid.device(0x2047, 0x200)

                except IndexError:
                    raise ValueError(
                        'USB VID:PID 2047:0200 not found (not in BSL mode? or try --device)'
                    )
            else:
                #~ ... by serial number?
                raise ValueError("don't (yet) know how to handle --device")
            self.logger.info('Opening HID device %r' % (self.hid_device, ))
Exemplo n.º 12
0
 def setup_darwin(self):
     """
     Setup for headset on the OS X platform.
     Receives packets from headset and sends them to a Queue to be processed
     by the crypto greenlet.
     """
     _os_decryption = False
     # Change these values to the hex equivalent from the output of hid_enumerate. If they are incorrect.
     # Current values = VendorID: 8609 ProductID: 1
     # You can see yours by opening /Applications/Utilities/System Information and navigating to
     # Hardware -> USB -> Receiver Dongle L01
     try:
         hidraw = hid.device(0x21A1, 0x0001)
     except IOError:
         print "You need to specify correct ProductID and VendorID in setup_darwin()"
         exit()
     if self.serial_number == "":
         print "Serial number needs to be specified manually in __init__()."
         raise ValueError
     crypto = gevent.spawn(self.setup_crypto, self.serial_number)
     console_updater = gevent.spawn(self.update_console)
     zero = 0
     while self.running:
         try:
             # Doesn't seem to matter how big we make the buffer 32 returned every time, 33 for other platforms
             data = hidraw.read(34)
             if len(data) == 32:
                 # Most of the time the 0 is truncated? That's ok we'll add it...
                 data = [zero] + data
             if data != "":
                 if _os_decryption:
                     self.packets.put_nowait(EmotivPacket(data))
                 else:
                     # Queue it!
                     tasks.put_nowait("".join(map(chr, data[1:])))
                     self.packets_received += 1
                 gevent.sleep(0)
             else:
                 # No new data from the device; yield
                 # We cannot sleep(0) here because that would go 100% CPU if both queues are empty.
                 gevent.sleep(DEVICE_POLL_INTERVAL)
         except KeyboardInterrupt:
             self.running = False
     hidraw.close()
     gevent.kill(crypto, KeyboardInterrupt)
     gevent.kill(console_updater, KeyboardInterrupt)
Exemplo n.º 13
0
            sys.exit(0)

        # Open device
        print "Mooltipass device found"
        device = hid_device[0]
        device.open()
        device.set_raw_data_handler(data_handler)
        report = device.find_output_reports()

        # Set data sending object
        data_sending_object = report[0]
        data_receiving_object = None
    else:
        # Look for our device and open it
        try:
            hid_device = hid.device(vendor_id=0x16d0, product_id=0x09a0)
            hid_device.open(vendor_id=0x16d0, product_id=0x09a0)
        except IOError, ex:
            print ex
            sys.exit(0)

        print "Device Found and Opened"
        print "Manufacturer: %s" % hid_device.get_manufacturer_string()
        print "Product: %s" % hid_device.get_product_string()
        print "Serial No: %s" % hid_device.get_serial_number_string()
        print ""

        # Set data sending object
        data_sending_object = hid_device
        data_receiving_object = hid_device
Exemplo n.º 14
0
def mini_check_lut(test_lut, dead_keys):
    global data_receiving_object
    global data_sending_object

    # Main function
    print("")
    print("Mooltipass Keyboard LUT Generation Tool")

    if using_pywinusb:
        # Look for our device
        filter = hid.HidDeviceFilter(vendor_id=0x16d0, product_id=0x09a0)
        hid_device = filter.get_devices()

        if len(hid_device) == 0:
            print("Mooltipass device not found")
            sys.exit(0)

        # Open device
        print("Mooltipass device found")
        device = hid_device[0]
        device.open()
        device.set_raw_data_handler(data_handler)
        report = device.find_output_reports()

        # Set data sending object
        data_sending_object = report[0]
        data_receiving_object = None
    else:
        # Look for our device and open it
        try:
            hid_device = hid.device(vendor_id=0x16d0, product_id=0x09a0)
            hid_device.open(vendor_id=0x16d0, product_id=0x09a0)
        except IOError as ex:
            print(ex)
            sys.exit(0)

        print("Device Found and Opened")
        print("Manufacturer: %s" % hid_device.get_manufacturer_string())
        print("Product: %s" % hid_device.get_product_string())
        print("Serial No: %s" % hid_device.get_serial_number_string())
        print("")

        # Set data sending object
        data_sending_object = hid_device
        data_receiving_object = hid_device

    sendHidPacket(CMD_PING, 4, [0, 1, 2, 3])
    if receiveHidPacket()[CMD_INDEX] == CMD_PING:
        print("Device responded to our ping")
    else:
        print("Bad answer to ping")
        sys.exit(0)

    #keyboardTest(data_sending_object)
    return_val = keyboardCheck(test_lut, dead_keys)

    # Close device
    if not using_pywinusb:
        data_sending_object.close()
    else:
        device.close()

    return return_val