
Dim CTS_Flag0 As Integer            ' flags showing foot switch was pressed
Dim CTS_Flag1 As Integer

' this subroutine receives control when there is an event on the
' MS Comm control. This specifically deals with the CTS input which
' activates when the test box foot switch is activated. This response
' routine will set a global variable flag indicating that the CTS was
' detected pressed. A subsequent timer event will note if the flag is
' set is the CTS still in the same state. If so the CTS is deemed to be
' "debounced" and logic from the timer routine will launch the equivalent
' of the "NEXT" key for the calibrate screen.

Private Sub MSComm_OnComm()

  Select Case MSComm.CommEvent

    Case comEvCTS   ' Change in the CTS line.

      If MSComm.CTSHolding = False Then
         CTS_Flag0 = 1           ' foot switch seen pressed
      Else
         CTS_Flag0 = 0           ' foot switch not seen pressed
         CTS_Flag1 = 0           ' so clear both of the flags
      End If
      
  End Select

End Sub

' timer response routine that supports the "debounce" of the
' foot switch input on the CTS line. The first notification of
' the foot switch comes from the MSComm event processing routine.

Private Sub Comm_Timer_Timer()

  ' check if to see a "debounced" foot switch has been detected.
  If CTS_Flag0 <> 0 Then
    
    If CTS_Flag1 <> 0 Then
    
      ' If the Learn Control Button is enabled the invoke its
      ' click via the foot switch from CTS!!
      If MainForm.LearnCtl.Enabled = True Then
        Call MainForm.LearnCtl_Click
      End If
      
      CTS_Flag0 = 0
      CTS_Flag1 = 0
    End If

    If MSComm.CTSHolding = False Then
      CTS_Flag1 = 1
    End If
    
  End If
  
End Sub
