from wecg400 import *
import numpy as np
import matplotlib.pyplot as plot


def outpout_sine(Amp, freq, time_s, sample):
    return Amp * np.sin(np.linspace(0, freq * time_s * 2 * np.pi , sample* time_s))

raw_data = PLAY_RAW_DATA()
ac = []
dc = []

device = WECG400(get_lib_path())
if not device.connect(-1, 5000):
    print('Error: device is not connected')
    device.free()
    sys.exit()

print('play raw data ...', end='')
sys.stdout.flush()

device.reset()

raw_data.SampleRate = 1000
raw_data.Size = 1000
sin_time = np.arange (0, 1, 0.001)
ac = outpout_sine(5, 5, 1, 1000)
dc = [200] * 1000

raw_data.AC = ctypes.cast((ctypes.c_double * len(ac))(*ac), ctypes.c_void_p)
raw_data.DC = ctypes.cast((ctypes.c_double * len(dc))(*dc), ctypes.c_void_p)


print (device.load_raw_data(pointer(raw_data)))

device.set_output_lead(OutputDut.DUT1.value, OutputLead.Lead_RA.value)
device.set_output_function(OutputFunction.Output_RawData.value)

time.sleep(10)
device.set_output_function(OutputFunction.Output_Off.value)  # stop output
device.free()

print('done')


