from ctypes import *
from aecg100 import *
import sys
import time

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

print('device is connected... ({} / {})'.format(
    device.get_serial_number(),
    device.get_ppg_serial_number()))
sys.stdout.flush()

time.sleep(5)

sys.stdout.flush()

ppg_waveform1 = device.get_default_ppg_ch1_waveform()
ppg_waveform2 = device.get_default_ppg_ch2_waveform()
ppg_waveform1.VolSP = 8
ppg_waveform1.VolDN = 4.5
ppg_waveform1.VolDP = 5.1
ppg_waveform2.VolSP = 10
ppg_waveform2.VolDN = 5.6
ppg_waveform2.VolDP = 6.4

# must be called before outputting PPG
device.enable_dynamic_led_length(True)

device.output_ppg_ex(pointer(ppg_waveform1), pointer(ppg_waveform2), OutputSignalCallback(0), OutputSignalCallback(0))

# configure the transmission rate after outputting PPG
device.configure_transmission_rate(5)

pause()

device.stop_output()
device.free()
