コード例 #1
0
class MuseConnector(Connector):
    def __init__(self,
                 publishers,
                 buffer_size,
                 step_size,
                 device_name='muse',
                 device_port='9090',
                 device_mac=None):
        super(MuseConnector,
              self).__init__(publishers, buffer_size, step_size, device_name,
                             device_port, device_mac)

    def connect_device(self):

        connect_muse(port=self.device_port)

        # callback functions to handle the sample for that metric (each metric has a specific number of channels)
        cb_functions = {
            metric:
            self.callback_factory(metric,
                                  get_num_channels(self.device_name, metric))
            for metric in self.metrics
        }

        self.device = MuseOSC(self.device_port, cb_functions)

    def start(self):
        try:
            self.device.start()
            while 1:
                time.sleep(1)
        except KeyboardInterrupt:
            sys.exit()

    def callback_factory(self, metric_name, num_args):
        """
    Callback function generator for Muse metrics
    :return: callback function
    """
        def callback(raw_sample):
            """
      Handle muse samples for that metrics
      :param raw_sample: the muse sample to handle
      """
            sample = json.loads(raw_sample)
            data = sample[1]
            message = {"channel_%s" % i: data[i] for i in xrange(num_args)}
            message['timestamp'] = int(time.time() * 1000000)  # micro seconds

            self.buffers[metric_name].write(message)

        return callback
コード例 #2
0
ファイル: MuseConnector.py プロジェクト: zaybiz/cloudbrain
    def connect_device(self):

        connect_muse(port=self.device_port)

        # callback functions to handle the sample for that metric (each metric has a specific number of channels)
        cb_functions = {
            metric:
            self.callback_factory(metric,
                                  get_num_channels(self.device_name, metric))
            for metric in self.metrics
        }

        self.device = MuseOSC(self.device_port, cb_functions)
コード例 #3
0
  def connect_device(self):

    connect_muse(port=self.device_port)

    # callback functions to handle the sample for that metric (each metric has a specific number of channels)
    cb_functions = {metric: self.callback_factory(metric, get_num_channels(self.device_name, metric))
                    for metric in self.metrics}

    self.device = MuseOSC(self.device_port, cb_functions)
コード例 #4
0
class MuseConnector(Connector):
  def __init__(self, publishers, buffer_size, step_size, device_name='muse', device_port='9090', device_mac=None):
    super(MuseConnector, self).__init__(publishers, buffer_size, step_size, device_name, device_port, device_mac)

  def connect_device(self):

    connect_muse(port=self.device_port)

    # callback functions to handle the sample for that metric (each metric has a specific number of channels)
    cb_functions = {metric: self.callback_factory(metric, get_num_channels(self.device_name, metric))
                    for metric in self.metrics}

    self.device = MuseOSC(self.device_port, cb_functions)

  def start(self):
    try:
      self.device.start()
      while 1:
        time.sleep(1)
    except KeyboardInterrupt:
      sys.exit()


  def callback_factory(self, metric_name, num_args):
    """
    Callback function generator for Muse metrics
    :return: callback function
    """
    def callback(raw_sample):
      """
      Handle muse samples for that metrics
      :param raw_sample: the muse sample to handle
      """
      sample = json.loads(raw_sample)
      data = sample[1]
      message = {"channel_%s" % i: data[i] for i in xrange(num_args)}
      message['timestamp'] = int(time.time() * 1000000) # micro seconds

      self.buffers[metric_name].write(message)

    return callback