def set_sample_delay(self, data_source, delay=None, differential=False): """ Change the delay between samples using the onboard time processor module to change the effective sampling rate of a specific data source. :param data_source: A data source from sensor.SensorFusion :param delay: The delay in ms between samples, or None to reset to default :param differential: Set Time Preprocessor mode to differential, instead of the default, absolute """ if self._data_source_signals[data_source] is None: log.debug("Getting data signal for data source {0}".format( data_source )) self._data_source_signals[data_source] = \ libmetawear.mbl_mw_sensor_fusion_get_data_signal( self.board, data_source ) if delay is not None: mode = TimeMode.DIFFERENTIAL if differential else \ TimeMode.ABSOLUTE log.debug("Creating time dataprocessor for signal {0}".format( self._data_source_signals[data_source] )) _done = Event() def _processor_set(context, processor): """ Set global variables as the libmetawear callback can't handle the self parameter of instance methods. :param context: Pointer to additional data for the callback function :param processor: The processor that was created """ self._data_source_signals[data_source] = processor _done.set() processor_set_func = FnVoid_VoidP_VoidP(_processor_set) libmetawear.mbl_mw_dataprocessor_time_create( self._data_source_signals[data_source], mode, delay, None, processor_set_func) _done.wait(timeout=PROCESSOR_SET_WAIT_TIME) if self._data_source_signals[data_source] is None: raise PyMetaWearException("Can't set data processor!") else: data_signal = libmetawear.mbl_mw_sensor_fusion_get_data_signal( self.board, data_source) if self._data_source_signals[data_source] != data_signal: libmetawear.mbl_mw_dataprocessor_remove( self._data_source_signals[data_source] ) self._data_source_signals[data_source] = data_signal
def set_sample_delay(self, data_source, delay=None, differential=False): """ Change the delay between samples using the onboard time processor module to change the effective sampling rate of a specific data source. :param data_source: A data source from sensor.SensorFusion :param delay: The delay in ms between samples, or None to reset to default :param differential: Set Time Preprocessor mode to differential, instead of the default, absolute """ global current_processor global waiting_for_processor if self._data_source_signals[data_source] is None: log.debug("Getting data signal for data source {0}".format( data_source )) self._data_source_signals[data_source] = \ libmetawear.mbl_mw_sensor_fusion_get_data_signal( self.board, data_source ) if delay is not None: mode = processor.Time.MODE_DIFFERENTIAL if differential else \ processor.Time.MODE_ABSOLUTE waiting_for_processor = True log.debug("Creating time dataprocessor for signal {0}".format( self._data_source_signals[data_source] )) libmetawear.mbl_mw_dataprocessor_time_create( self._data_source_signals[data_source], mode, delay, Fn_VoidPtr(processor_set)) wait_time = 0 while waiting_for_processor and wait_time < max_processor_wait_time: sleeptime = 0.1 time.sleep(sleeptime) wait_time += sleeptime if current_processor is not None: self._data_source_signals[data_source] = current_processor current_processor = None else: raise PyMetaWearException("Can't set data processor!") else: data_signal = libmetawear.mbl_mw_sensor_fusion_get_data_signal( self.board, data_source) if self._data_source_signals[data_source] != data_signal: libmetawear.mbl_mw_dataprocessor_remove( self._data_source_signals[data_source] ) self._data_source_signals[data_source] = data_signal
def set_sample_delay(self, data_source, delay=None, differential=False): """ Change the delay between samples using the onboard time processor module to change the effective sampling rate of a specific data source. :param data_source: A data source from sensor.SensorFusion :param delay: The delay in ms between samples, or None to reset to default :param differential: Set Time Preprocessor mode to differential, instead of the default, absolute """ if self._data_source_signals[data_source] is None: log.debug("Getting data signal for data source {0}".format( data_source )) self._data_source_signals[data_source] = \ libmetawear.mbl_mw_sensor_fusion_get_data_signal( self.board, data_source ) if delay is not None: mode = TimeMode.DIFFERENTIAL if differential else \ TimeMode.ABSOLUTE log.debug("Creating time dataprocessor for signal {0}".format( self._data_source_signals[data_source] )) _done = Event() def _processor_set(processor): """ Set global variables as the libmetawear callback can't handle the self parameter of instance methods. :param processor: The processor that was created """ self._data_source_signals[data_source] = processor _done.set() libmetawear.mbl_mw_dataprocessor_time_create( self._data_source_signals[data_source], mode, delay, FnVoid_VoidP(_processor_set)) _done.wait(timeout=PROCESSOR_SET_WAIT_TIME) if self._data_source_signals[data_source] is None: raise PyMetaWearException("Can't set data processor!") else: data_signal = libmetawear.mbl_mw_sensor_fusion_get_data_signal( self.board, data_source) if self._data_source_signals[data_source] != data_signal: libmetawear.mbl_mw_dataprocessor_remove( self._data_source_signals[data_source] ) self._data_source_signals[data_source] = data_signal