def setup(self): # setup ble libmetawear.mbl_mw_settings_set_connection_parameters( self.device.board, 7.5, 7.5, 0, 6000) sleep(1.5) # setup event e = Event() # processor callback fxn def processor_created(context, pointer): self.processor = pointer e.set() fn_wrapper = cbindings.FnVoid_VoidP_VoidP(processor_created) # get acc signal acc = libmetawear.mbl_mw_acc_get_acceleration_data_signal( self.device.board) # create acc averager (averages 4 consecutive acc data entriess) libmetawear.mbl_mw_dataprocessor_average_create( acc, 4, None, fn_wrapper) # wait for averager to be created e.wait() # subscribe to signal libmetawear.mbl_mw_datasignal_subscribe(self.processor, None, self.callback)
def setup(self): libmetawear.mbl_mw_settings_set_connection_parameters( self.device.board, 7.5, 7.5, 0, 6000) sleep(1.5) e = Event() def processor_created(context, pointer): self.processor = pointer e.set() fn_wrapper = cbindings.FnVoid_VoidP_VoidP(processor_created) acc = libmetawear.mbl_mw_acc_get_acceleration_data_signal( self.device.board) libmetawear.mbl_mw_dataprocessor_average_create( acc, 4, None, fn_wrapper) e.wait() libmetawear.mbl_mw_datasignal_subscribe(self.processor, None, self.callback)
device = MetaWear(sys.argv[1]) device.connect() print("Connected to " + device.address) e = Event() print("Configuring device") accel_signal = libmetawear.mbl_mw_acc_get_acceleration_data_signal( device.board) libmetawear.mbl_mw_macro_record(device.board, 1) rss = create_voidp(lambda fn: libmetawear.mbl_mw_dataprocessor_rss_create( accel_signal, None, fn), resource="rss", event=e) avg = create_voidp(lambda fn: libmetawear.mbl_mw_dataprocessor_average_create( rss, 4, None, fn), resource="avg", event=e) threshold = create_voidp( lambda fn: libmetawear.mbl_mw_dataprocessor_threshold_create( avg, ThresholdMode.BINARY, 0.5, 0.0, None, fn), resource="threhsold", event=e) ths_below = create_voidp( lambda fn: libmetawear.mbl_mw_dataprocessor_comparator_create( threshold, ComparatorOperation.EQ, -1.0, None, fn), resource="ths_below", event=e) ths_above = create_voidp( lambda fn: libmetawear.mbl_mw_dataprocessor_comparator_create( threshold, ComparatorOperation.EQ, 1.0, None, fn),
libmetawear.mbl_mw_acc_bmi160_set_odr(d.board, AccBmi160Odr._50Hz) libmetawear.mbl_mw_acc_set_range(d.board, 2.0) libmetawear.mbl_mw_acc_write_acceleration_config(d.board) # start to setup rms->avg->thresh->log chain acc_signal = libmetawear.mbl_mw_acc_get_acceleration_data_signal(d.board) # create RMS - root mean square of acc X,Y,Z rms = create_voidp( lambda fn: libmetawear.mbl_mw_dataprocessor_rms_create( acc_signal, None, fn), "RMS") print("RMS created") # setup averager - averages over 8 RMS samples @ 50Hz avg = create_voidp( lambda fn: libmetawear.mbl_mw_dataprocessor_average_create( rms, 8, None, fn), "averager") print("Averager created") # setup event on avg - reset averager libmetawear.mbl_mw_event_record_commands(avg) libmetawear.mbl_mw_dataprocessor_average_reset(avg) end_event_record(avg) # setup threshold detector - detect anything above 1 ths = create_voidp( lambda fn: libmetawear.mbl_mw_dataprocessor_threshold_create( avg, ThresholdMode.BINARY, 1.0, 0.0, None, fn), "threshold detector") print("Threshold detector created") # setup logger - log the final signal of the averaged data