module CCloseSafetyValveLedNotification
    use OperationScenariosModule
    implicit none
    contains
    
    subroutine Evaluate_CloseSafetyValveLed()
        implicit none
        
        
!        if (DriveType == TopDrive_DriveType) then
!#ifdef OST
!            print*, 'Evaluate_CloseSafetyValveLed=TopDrive'
!#endif
!        endif
!        
!        
!        
!        
!        
!        
!        
!        
!        
!        if (DriveType == Kelly_DriveType) then
!#ifdef OST
!            print*, 'Evaluate_CloseSafetyValveLed=Kelly'
!#endif
!        endif
        
        
    end subroutine
    
    ! subroutine Subscribe_CloseSafetyValveLed()
    !     use CDrillingConsoleVariables
!@    use ConfigurationVariables
!@    use ConfigurationVariables
    !     implicit none
    !     call OnCloseSafetyValvePress%Add(ButtonPress_CloseSafetyValve)
    !     call OnOperationConditionChangeInt%Add(Set_Operation_CloseSafetyValveLed)
    ! end subroutine
    
    subroutine Set_Operation_CloseSafetyValveLed(v)
        implicit none
        integer , intent(in) :: v
#ifdef ExcludeExtraChanges
        if(data%State%notifications%operation_CloseSafetyValveLed == v) return
#endif
        data%State%notifications%operation_CloseSafetyValveLed = v
#ifdef deb
	    print*, 'operation_CloseSafetyValveLed=', data%State%notifications%operation_CloseSafetyValveLed
#endif
    end subroutine
    
    subroutine ButtonPress_CloseSafetyValve()
        implicit none
        
        
        
        
        if (data%Configuration%Hoisting%DriveType == TopDrive_DriveType) then
#ifdef OST
            print*, 'Evaluate_CloseSafetyValveLed=TopDrive'
#endif


            !TOPDRIVE-CODE=57
            if (Get_SafetyValveHeight() >= 3.0 .and. Get_SafetyValveHeight() <= 12.0 .and.&
                Get_CloseSafetyValveLed() == .false. .and.&
                Get_OpenSafetyValveLed()) then
            
                call Set_OpenSafetyValveLed(.false.)
                call Set_CloseSafetyValveLed(.true.)
                return
            end if


        endif
        
        
        
        
        
        
        
        
        
        if (data%Configuration%Hoisting%DriveType == Kelly_DriveType) then
#ifdef OST
            print*, 'Evaluate_CloseSafetyValveLed=Kelly'
#endif
        
            !OPERATION-CODE=59
            if (Get_SafetyValveHeight() >= 3.0 .and. Get_SafetyValveHeight() <= 12.0 .and.&
                Get_CloseSafetyValveLed() == .false. .and.&
                Get_OpenSafetyValveLed()) then
                call Set_OpenSafetyValveLed(.false.)
                call Set_CloseSafetyValveLed(.true.)
                return
            end if


        endif
        
        
        
        
        
        
    end subroutine
    
end module CCloseSafetyValveLedNotification