module CSlipsEnum
    use OperationScenariosModule
    implicit none
    contains
    
    subroutine Evaluate_Slips()
        implicit none
        
!        if (DriveType == TopDrive_DriveType) then
!#ifdef OST
!            print*, 'Evaluate_Slips=TopDrive'
!#endif
!        endif
!        
!        
!        
!        
!        
!        
!        
!        
!        if (DriveType == Kelly_DriveType) then
!#ifdef OST
!            print*, 'Evaluate_Slips=Kelly'
!#endif
!        endif
        
    end subroutine
    
    ! subroutine Subscribe_Slips()
    !     use CDrillingConsoleVariables
    !     use ConfigurationVariables
    !     use ConfigurationVariables
    !     implicit none
        
    !     !call Set_Slips(SLIPS_SET)
        
    !     call OnSlipsPress%Add(ButtonPress_Slips)
    ! end subroutine
    
    subroutine ButtonPress_Slips()
        use UnitySignalsModule
        use NotificationModule
        use CUnityOutputs
        use UnitySignalsModule !for CTdsConnectionModesEnum
        implicit none
        
        
        
        
        
        if (data%Configuration%Hoisting%DriveType == TopDrive_DriveType) then
#ifdef OST
            print*, 'ButtonPress_Slips=TopDrive'
#endif


            !TOPDRIVE-CODE=30
            if (Get_Slips() == SLIPS_UNSET_END .and.&
                Get_SlipsNotification()) then
            
                call Set_Slips(SLIPS_SET_BEGIN)
                return
            end if

                
                
                
                

            !TOPDRIVE-CODE=31
            if (Get_TdsConnectionModes() == TDS_CONNECTION_STRING .and.&
                Get_Slips() == SLIPS_SET_END .and.&
                Get_SlipsNotification()) then
            
                call Set_Slips(SLIPS_UNSET_BEGIN)
                return
            end if
                
                
                
                
                

            !TOPDRIVE-CODE=32
            if (Get_TdsElevatorModes() == TDS_ELEVATOR_CONNECTION_STRING .and.&
                Get_Slips() == SLIPS_SET_END .and.&
                Get_SlipsNotification()) then
            
                call Set_Slips(SLIPS_UNSET_BEGIN)
                return
            end if



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

            !OPERATION-CODE=19
            if (Get_Slips() == SLIPS_UNSET_END .and.&
                Get_SlipsNotification()) then
            
                call Set_Slips(SLIPS_SET_BEGIN)
                return
            end if
            
            !OPERATION-CODE=20
            if (Get_OperationCondition() == OPERATION_DRILL .and.&
                Get_KellyConnection() == KELLY_CONNECTION_STRING .and.&
                GetRotaryRpm() == 0.0d0 .and.&
                Get_SlipsNotification() .and.&
                Get_Slips() == SLIPS_SET_END) then
            
                call Set_Slips(SLIPS_UNSET_BEGIN)
                return
            end if
            
            
            !OPERATION-CODE=21
            if (Get_OperationCondition() == OPERATION_TRIP .and.&
                Get_ElevatorConnection() == ELEVATOR_CONNECTION_STRING .and.&
                GetRotaryRpm() == 0.0d0 .and.&
                Get_SlipsNotification() .and.&
                Get_Slips() == SLIPS_SET_END) then
            
                call Set_Slips(SLIPS_UNSET_BEGIN)
                return
            end if
                
                
                
                
                
                
        endif
        
        
        
        
        
        
        
        
        
    end subroutine
    
end module CSlipsEnum