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



            




        endif
        
        
        
        
        
        
        
        if (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
    !     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(Notifications%operation_IrSafetyValveLed == v) return
#endif
        Notifications%operation_IrSafetyValveLed = v
#ifdef deb
	    print*, 'operation_IrSafetyValveLed=', Notifications%operation_IrSafetyValveLed
#endif
    end subroutine
    
    subroutine ButtonPress_IrSafetyValve()
        implicit none
        
        
        
        
        if (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 (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