예제 #1
0
    def _setup_timer(self):
        e = Event()
        result = [None]

        def timer_handler(ctx, pointer):
            result[0] = RuntimeError("Could not create timer") if pointer == None else pointer
            e.set()
        fn_wrapper = FnVoid_VoidP_VoidP(timer_handler)

        libmetawear.mbl_mw_timer_create_indefinite(self.device.board, 1000, 0, None, fn_wrapper)
        e.wait()

        if (result[0] is RuntimeError):
            raise result[0]

        return result[0]
예제 #2
0
def createTimer(mmr):
    mmr.parameters = I2cReadParameters(device_addr=AD7745_ADDR,
                                       register_addr=REG_CAP_DATA)

    e = Event()

    mmr.timer = create_voidp(
        lambda fn: libmetawear.mbl_mw_timer_create_indefinite(
            mmr.device.board, 11, 0, None, fn),
        resource="timer",
        event=e)
    libmetawear.mbl_mw_event_record_commands(mmr.timer)
    libmetawear.mbl_mw_datasignal_read_with_parameters(mmr.i2c_signal,
                                                       byref(mmr.parameters))
    create_voidp_int(
        lambda fn: libmetawear.mbl_mw_event_end_record(mmr.timer, None, fn),
        event=e)
    print(mmr.timer)
    mmr.timer_id = libmetawear.mbl_mw_timer_get_id(mmr.timer)
    print("id" + str(mmr.timer_id))
예제 #3
0
print("Searching for device...")
d = MetaWear(sys.argv[1])
d.connect()
print("Connected to " + d.address)

try:
    # setup events
    e = Event()
    print("Configuring device")
    
    # get temp signal and setup logger
    signal = libmetawear.mbl_mw_multi_chnl_temp_get_temperature_data_signal(d.board, MetaWearRProChannel.ON_BOARD_THERMISTOR)
    logger = create_voidp(lambda fn: libmetawear.mbl_mw_datasignal_log(signal, None, fn), resource = "temp_logger", event = e)
    
    # create a timer
    timer = create_voidp(lambda fn: libmetawear.mbl_mw_timer_create_indefinite(d.board, 1000, 0, None, fn), resource = "timer", event = e)
    
    # record an event
    libmetawear.mbl_mw_event_record_commands(timer)
    
    # event is to read temp signal
    libmetawear.mbl_mw_datasignal_read(signal)
    create_voidp_int(lambda fn: libmetawear.mbl_mw_event_end_record(timer, None, fn), event = e)
    
    # start logging
    libmetawear.mbl_mw_logging_start(d.board, 0)
    
    # start timer
    libmetawear.mbl_mw_timer_start(timer)
    
    # log 10s
예제 #4
0
e = Event()

# create callback
callback = FnVoid_VoidP_DataP(lambda ctx, p: print("{epoch: %d, value: %s}" % (
    p.contents.epoch, parse_value(p))))

# get temp signal
print("Configuring device")
signal = libmetawear.mbl_mw_multi_chnl_temp_get_temperature_data_signal(
    d.board, MetaWearRProChannel.ON_BOARD_THERMISTOR)

# subscribe to temp signal
libmetawear.mbl_mw_datasignal_subscribe(signal, None, callback)

# create timer - fires ever 1000ms
timer = create_voidp(lambda fn: libmetawear.mbl_mw_timer_create_indefinite(
    d.board, 1000, 0, None, fn),
                     resource="timer",
                     event=e)

# create event based on timer - read temp when timer fires
libmetawear.mbl_mw_event_record_commands(timer)
libmetawear.mbl_mw_datasignal_read(signal)
create_voidp_int(
    lambda fn: libmetawear.mbl_mw_event_end_record(timer, None, fn), event=e)

# start timer
libmetawear.mbl_mw_timer_start(timer)

# wait 5s
print("Stream temp data for 5s")
sleep(5.0)
def timer_setup(device):

    # Setup timer to read battery level
    libmetawear.mbl_mw_timer_create_indefinite(device.board, 5000, 0,
                                               timer_created_fn)