Example #1
0
    def __init__(self,
                 file_name=None,
                 mode="hid",
                 hid=None,
                 file=None,
                 new_format=False,
                 **kwargs):
        self.mode = mode
        self.file = file
        self.file_name = file_name
        self.hid = hid
        self.new_format = new_format
        self.platform = system_platform
        self.serial_number = None
        self.lock = Lock()
        if self.platform != "Windows":
            hidapi.hid_init()
        self.setup_platform = {
            'Windows': self.setup_windows,
            'Darwin': self.setup_not_windows,
            'Linux': self.setup_not_windows,
            'Reader': self.setup_reader,
        }
        if self.mode == "csv":
            if file_name is None:
                raise ValueError(
                    "CSV file name must be specified when initializing an EmotivReader class using mode "
                    "'csv'.")

            if sys.version_info >= (3, 0):
                self.file = open(file_name, 'r')
            else:
                self.file = open(file_name, 'rb')
            contents = self.file.read().split('\n')
            self.reader = read_csv(contents)
            self.platform = "Reader"
        elif self.mode == 'hid':
            self.reader = None
        else:
            self.reader = None
        self.data = Queue()
        self.setup_platform[self.platform]()
        self.running = False
        self.stopped = True
        if self.reader is not None:
            self.thread = Thread(target=self.run,
                                 kwargs={'source': self.reader})
        else:
            self.thread = Thread(target=self.run, kwargs={'source': self.hid})
        self.thread.setDaemon(True)
        self._stop_signal = False
# v0.8, 2019-05-23, jw  Support usb.core on windows via libusb-win32
# v0.9, 2019-07-17, jw  Support 48x12 configuration too.
# v0.10, 2019-09-09, jw Support for loading monochrome images. Typos fixed.
# v0.11, 2019-09-29, jw New option --brightness added.
# v0.12, 2019-12-27, jw hint at pip3 -- as discussed in https://github.com/jnweiger/led-name-badge-ls32/issues/19

import sys, os, re, time, argparse
from datetime import datetime
from array import array
try:
    if sys.version_info[0] < 3:
        raise Exception(
            "prefer usb.core with python-2.x because of https://github.com/jnweiger/led-badge-ls32/issues/9"
        )
    import pyhidapi
    pyhidapi.hid_init()
    have_pyhidapi = True
except:
    have_pyhidapi = False
    try:
        import usb.core
    except:
        print("ERROR: Need the pyhidapi or usb.core module.")
        if sys.platform == "darwin":
            print("""Please try
  pip3 install pyhidapi
  pip install pyhidapi
  brew install hidapi""")
        elif sys.platform == "linux":
            print("""Please try
  sudo pip3 install pyhidapi
Example #3
0
def test_func():
    pyhidapi.hid_init()
    devs = pyhidapi.hid_enumerate()
    for dev in devs:
        print('---')
        print(dev.description())