Macros - Logger Start with Button Press

I am working on a script that would write a macro to my MMS that would start the logger (acc and gyro) when the device boots. I can get sections of this code to work, but I cant get it all to work at the same time. @Laura or @Matt - any suggestions?

connect

device = MetaWear('E3:12:38:77:65:EF')
device.connect()
e=Event()

print("Connected to " + device.address + " over " + ("USB" if device.usb.is_connected else "BLE"))

Remove Previous Macros

libmetawear.mbl_mw_macro_erase_all(device.board)
libmetawear.mbl_mw_debug_reset_after_gc(device.board)

Configure Signals

libmetawear.mbl_mw_gyro_bmi160_set_range(device.board, GyroBoschRange._500dps)
libmetawear.mbl_mw_gyro_bmi160_set_odr(device.board, GyroBoschOdr._200Hz)
libmetawear.mbl_mw_gyro_bmi160_write_config(device.board)
libmetawear.mbl_mw_acc_set_odr(device.board, 200.0)
libmetawear.mbl_mw_acc_set_range(device.board, 16.0)
libmetawear.mbl_mw_acc_write_acceleration_config(device.board)

Get Signals

acc=libmetawear.mbl_mw_acc_get_acceleration_data_signal(device.board)
gyro=libmetawear.mbl_mw_gyro_bmi160_get_rotation_data_signal(device.board)

Create Loggers

acc_logger=create_voidp(lambda fn: libmetawear.mbl_mw_datasignal_log(acc, None, fn), resource = "acc_logger")
gyro_logger=create_voidp(lambda fn: libmetawear.mbl_mw_datasignal_log(gyro, None, fn), resource = "gyro_logger")

Start Macro

libmetawear.mbl_mw_macro_record(device.board,1) #Starts on Boot
libmetawear.mbl_mw_logging_start(device.board,0) #if non-0 older entries will be overwritten
libmetawear.mbl_mw_acc_enable_acceleration_sampling(device.board)
libmetawear.mbl_mw_acc_start(device.board)
libmetawear.mbl_mw_gyro_bmi160_enable_rotation_sampling(device.board)
libmetawear.mbl_mw_gyro_bmi160_start(device.board)

Led Indicator

pattern= LedPattern(repeat_count= Const.LED_REPEAT_INDEFINITELY)
libmetawear.mbl_mw_led_load_preset_pattern(byref(pattern), LedPreset.BLINK)
libmetawear.mbl_mw_led_write_pattern(device.board, byref(pattern), LedColor.GREEN)
libmetawear.mbl_mw_led_play(device.board)
sleep(2)
libmetawear.mbl_mw_led_stop_and_clear(device.board)
create_voidp_int(lambda fn: libmetawear.mbl_mw_macro_end_record(device.board, None, fn), event = e)

Send device to power saving mode and disconnect

libmetawear.mbl_mw_debug_enable_power_save(device.board)
device.disconnect()

Sign In or Register to comment.