module CIrSafetyValveLedNotification
    use OperationScenariosModule
    !use UnitySignalsModuleVariables
    implicit none
    contains
    
    subroutine Evaluate_IrSafetyValveLed()
        implicit none
        
        
        
        
        
        if (data%Configuration%Hoisting%DriveType == TopDrive_DriveType) then
#ifdef OST
            print*, 'Evaluate_IrSafetyValveLed=TopDrive'
#endif



            




        endif
        
        
        
        
        
        
        
        if (data%Configuration%Hoisting%DriveType == Kelly_DriveType) then
#ifdef OST
            print*, 'Evaluate_IrSafetyValveLed=Kelly'
#endif

            !OPERATION-CODE=56
            if (Get_OperationCondition() == OPERATION_DRILL) then
                call Set_IrSafetyValveLed(.true.)
                return
            end if
        
        
        
        
            !call Set_IrSafetyValveLed(.false.)
        
        endif
        
        
        
        
        
        
        
        
        
        
        
        
    end subroutine
        
    ! subroutine Subscribe_IrSafetyValveLed()
    !     use CDrillingConsoleVariables
!@    use ConfigurationVariables
!@    use ConfigurationVariables
    !     implicit none
    !     call OnIRSafetyValvePress%Add(ButtonPress_IrSafetyValve)
    !     call OnOperationConditionChangeInt%Add(Set_Operation_IrSafetyValveLed)
    ! end subroutine
    
    subroutine Set_Operation_IrSafetyValveLed(v)
        implicit none
        integer , intent(in) :: v
#ifdef ExcludeExtraChanges
        if(data%State%notifications%operation_IrSafetyValveLed == v) return
#endif
        data%State%notifications%operation_IrSafetyValveLed = v
#ifdef deb
	    print*, 'operation_IrSafetyValveLed=', data%State%notifications%operation_IrSafetyValveLed
#endif
    end subroutine
    
    subroutine ButtonPress_IrSafetyValve()
        implicit none
        
        
        
        
        if (data%Configuration%Hoisting%DriveType == TopDrive_DriveType) then
#ifdef OST
            print*, 'Evaluate_IrSafetyValveLed=TopDrive'
#endif



            !TOPDRIVE-CODE=53
            if (Get_IrSafetyValvePermission() .and.&
                Get_IrSafetyValveLed()) then
            
                call Set_IrSafetyValveLed(.false.)
                return
            end if








            !TOPDRIVE-CODE=54
            if (Get_IrSafetyValvePermission() .and.&
                Get_IrSafetyValveLed() == .false.) then
            
                call Set_IrSafetyValveLed(.true.)
                return
            end if


        endif
        
        
        
        
        
        
        
        if (data%Configuration%Hoisting%DriveType == Kelly_DriveType) then
#ifdef OST
            print*, 'Evaluate_IrSafetyValveLed=Kelly'
#endif

            !OPERATION-CODE=54
            if (Get_OperationCondition() == OPERATION_TRIP .and.&
                Get_IrSafetyValvePermission() .and.&
                Get_IrSafetyValveLed()) then
                call Set_IrSafetyValveLed(.false.)
                return
            end if
            
            
            !OPERATION-CODE=55
            if (Get_OperationCondition() == OPERATION_TRIP .and.&
                Get_IrSafetyValvePermission() .and.&
                Get_IrSafetyValveLed() == .false. ) then
                call Set_IrSafetyValveLed(.true.)
                return
            end if

        endif
        
        
        
        
        
        
         
        
    end subroutine
    
end module CIrSafetyValveLedNotification