Exemple #1
0
        bt.ble_close()  # Try to close the BLE connection cleanly (may fail)
    print("Ran cleanup")


"""
This is where the main code starts
"""
while True:
    try:
        # Take care of some initializations
        initialize_buffers()
        initialize_ble()

        # Instantiate filters
        lowpass_filt = Filter(sampling_frequency=sampling_freq,
                              filter_frequency=4,
                              filter_type='low')
        highpass_filt = Filter(sampling_frequency=sampling_freq,
                               filter_frequency=0.5,
                               filter_type='high')

        # Instantiate Hr class
        hr_calc = Hr(train_file="../Objective1/ir_data_train.csv", plot=False)

        # If we are plotting our data
        # Call the animation with our update_data() function
        # This will call our function repeatedly and plot the results
        if live_plot:
            # create animation object
            # Plot about 1/5 of the data in the buffer
            an = AnimatedFigure(update_data, plot_samples=200, debug=False)
    # Plot two graphs: (sensor data vs time) and (filtered data vs time)
    return [(data_buffer[0], data_buffer[1]), (data_buffer[0], data_buffer[2])]
    # This format [(x1, y1), (x2, y2), (x3, y3)] is expected by the animation module


"""
This is where the main code starts
"""
try:
    # Take care of some initializations
    initialize_buffers()
    # Take care of some initializations
    initialize_ble()
    # Create the filter *
    filter = Filter(sampling_frequency=sampling_freq,
                    filter_frequency=4,
                    filter_type='low')
    filter1 = Filter(sampling_frequency=sampling_freq,
                     filter_frequency=0.5,
                     filter_type='high')

    # Monitor for any text received over BLE
    count = 0
    if (write_flag1): f1 = open("Heartrate_test_HPF.csv", "w")
    if (read_flag):
        f = open("Heartrate_test.csv", "r")
        f.readline()
    # If we are plotting our data
    # Call the animation with our update_data() function
    # This will call our function repeatedly and plot the results
    if live_plot: