from artiq.experiment import *
from pyLIAF.artiq.controllers import UrukulCh
from time import sleep

class TurnOnLasers(EnvExperiment):
    """Turn on IR and UV lasers and Hold"""
    def build(self):
        self.setattr_device("core")
        self.setattr_device("scheduler")

        self.laserUV = UrukulCh(self, ch=2, freq=110.0, amp=0.3, name="UV") #corresponde a 0.7 Vpp
        self.laserIR = UrukulCh(self, ch=1, freq=208.0, amp=0.35, name="IR") #corresponde a 0.8 Vpp

    def run(self):
        try:
            self.turn_on()
            while True:
                self.scheduler.pause() # posible punto de pausa del programa
                sleep(0.5)
        except TerminationRequested:
            print("LIBERO LASERES")

    # Para testear, sin el artiq
    # def turn_on(self):
    #     print("PRENDO LASERES")

    @kernel
    def turn_on(self):
        self.core.break_realtime()
        self.laserUV.on()
        self.laserIR.on()
