Attribute VB_Name = "Module1"
'#Uses "..\classes\FunctionClass.cls"
'#Uses "..\classes\ParameterClass.cls"
'#Uses "..\include\Const.inc"
'#Uses "..\include\Format.inc"
'#Uses "..\include\Global.inc"
'#Uses "..\include\Pages.inc"
'#Uses "Include.inc"

Option Explicit

'*****************************************************************************
' Module:
'        WDT
'-----------------------------------------------------------------------------
' Description:
'        This file contains functions which are create controls for the
'        module 'WDT'.
'        Furthermore it contains functions for the event handling of
'        these controls.
'
'-----------------------------------------------------------------------------
' History:
'
'        Rev. Author         Date        Description
'        ---------------------------------------------------------------------
'        1.0   ahe         14.02.00     final version for C165UTAH
'
'        ---------------------------------------------------------------------
'        2.0   ahe         14.06.00     final version for C167CS, C161CS/JC/JI
'
'        ---------------------------------------------------------------------
'        2.1   ahe         02.11.00     final version for C167CS, C161CS/JC/JI
'
'        ---------------------------------------------------------------------
'        4.0   ahe         24.04.01     final version for Pegasus
'                                       - for input frequency selection is
'                                         only bitfild WDTIN
'        4.1   ste         06.01.03     no changes
'
'*****************************************************************************

Const DISABLED_WDT = "the watchdog timer is diabled"

'*****************************************************************************
'Description:
'        This function is called from DAvE just before the Peripherals
'        window is shown.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnLoad(ps As Peripherals) As Boolean
    On Error GoTo OnLoadError

    OnLoad = False

    '-------------------------------------------------------------------------
    ' page: WDT
    '-------------------------------------------------------------------------
    If (Not OnLoadPageControl(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Functions
    '-------------------------------------------------------------------------
    If (Not OnLoadPageFunctions(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Parameters
    '-------------------------------------------------------------------------
    If (Not OnLoadPageParameters(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Notes
    '-------------------------------------------------------------------------
    If (Not OnLoadPageNotes(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' end of pages
    '-------------------------------------------------------------------------
    
    '-------------------------------------------------------------------------
    ' call function to initialize the menu
    '-------------------------------------------------------------------------
    If (Not InitMenu(ps, "WDT\Dialog")) Then Exit Function

    OnLoad = True
    Exit Function

OnLoadError:
    Exit Function
End Function


'*****************************************************************************
'Description:
'        This function is called from DAvE just before a page
'        is shown.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Page            no. of the page (starts with 1)
'        Pagename        name of the page
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnChangingPage(ps As Peripherals, Page As Integer, Pagename As String) As Boolean
    On Error GoTo OnChangingPageError
    Dim sVarPre As String
    sVarPre = "WDT"

    OnChangingPage = False

    
    '-------------------------------------------------------------------------
    'page: WDT
    '-------------------------------------------------------------------------
    If (Not OnChangingPageControl(ps, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: Functions
    '-------------------------------------------------------------------------
    If (Not OnChangingPageFunctions(ps, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: Parameters
    '-------------------------------------------------------------------------
    If (Not OnChangingPageParameters(ps, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: Notes
    '-------------------------------------------------------------------------
    If (Not OnChangingPageNotes(ps, Pagename, sVarPre)) Then Exit Function


    OnChangingPage = True
    Exit Function

OnChangingPageError:
    Exit Function
End Function


'*****************************************************************************
'Description:
'        This function is called from DAvE in two cases:
'
'        1.
'            The contents of the peripherals window must be refreshed.
'            In this case the 'Controlname' parameter is a empty string
'            and the values array 'v()' contains nothing.
'
'        2.
'            A control on the peripherals has been changed.
'            In this case the 'Controlname' parameter contains the name
'            of the changed control and the values array 'v()' contains the
'            changed value(s).
'
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     name of the changed control (for case 2)
'        v()             array with the changed values (for case 2)
'        Page            no. of the page (starts with 1)
'        Pagename        name of the page
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnShow(ps As Peripherals, Controlname As String, v() As Variant, Page As Integer, Pagename As String) As Boolean
    On Error GoTo OnShowError
    Dim sVarPre As String
    sVarPre = "WDT"

    OnShow = False

    '-------------------------------------------------------------------------
    ' page: WDT
    '-------------------------------------------------------------------------
    If (Not OnShowPageControl(ps, Controlname, Pagename, v)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Functions
    '-------------------------------------------------------------------------
    If (Not OnShowPageFunctions(ps, Controlname, Pagename, v)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Parameters
    '-------------------------------------------------------------------------
    If (Not OnShowPageParameters(ps, Controlname, Pagename, v)) Then Exit Function
       
    '-------------------------------------------------------------------------
    ' page: Notes
    '-------------------------------------------------------------------------
    If (Not OnShowPageNotes(ps, Controlname, Pagename, sVarPre, v)) Then Exit Function


    OnShow = True
    Exit Function

OnShowError:
    Errorbox "Can not show page.", Err.Description
    Exit Function
End Function


'*****************************************************************************
'Description:
'        This function is called from DAvE if the user clicks on a button.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     name of the button
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnClick(ps As Peripherals, Controlname As String) As Boolean
    On Error GoTo OnClickError

    OnClick = False

    Dim np As Peripherals

    '-------------------------------------------------------------------------
    ' buttons: PEC
    '-------------------------------------------------------------------------
    If (Not OnClickPagePEC(ps, Controlname)) Then Exit Function


    OnClick = True
    Exit Function

OnClickError:
    Errorbox "Can not Text in OnClick.", Err.Description
    Exit Function
End Function


'*****************************************************************************
'Description:
'        This function is called from DAvE if the user clicks on a menu entry.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Toolname        name of the entry
'        ToolId          id of the entry
'        Tooltext        additional text of the entry
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnMenuClick(ps As Peripherals, Toolname As String, ToolId As Long, Tooltext As String) As Boolean
    On Error GoTo OnMenuClickError

    OnMenuClick = False

    If (Not MenuClick(ps, Toolname, ToolId, Tooltext, "WDT\Dialog")) Then Exit Function

    OnMenuClick = True
    Exit Function

OnMenuClickError:
    Exit Function
End Function
    

'-----------------------------------------------------------------------------
' local functions
'-----------------------------------------------------------------------------

'*****************************************************************************
'Description:
'        This function is called from the OnLoad function of the associated
'        module in order to add a page.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageControl(ps As Object) As Boolean
  On Error Resume Next

  OnLoadPageControl = False

  If (Not ps.AddPage("Control")) Then Exit Function

  OnLoadPageControl = True
End Function


'*****************************************************************************
'Description:
'        This function is called from the OnChangingPage function of the
'        associated module in order load all controls for the requested page
'        if they are not already loaded.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'        Pagename         requested page name
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnChangingPageControl(ps As Object, Pagename As String) As Boolean
  On Error Resume Next

  OnChangingPageControl = False
  
  If (Not ps.ExtenderCollection("Control").Loaded) And (Pagename = "Control") Then
    ps.ExtenderCollection("Control").Loaded = True
  

    '-------------------------------
    ' frame: frmWDT_Fkt
    '-------------------------------
    If (Not ps.AddFrame("frmWDT_Fkt", 100, 100, 4150, 1000, "Watchdog Function")) Then Exit Function
        If (Not ps.AddCheck("chkWDT_Fkt", 200, 400, 3100, 300, "Disable the watchdog timer")) Then Exit Function

    '-------------------------------
    ' frame: frmWDTIN
    '-------------------------------
    If (Not ps.AddFrame("frmWDTIN", 100, 1250, 4150, 1900, "Input Frequency Selection (WDTIN)")) Then Exit Function
        If (Not ps.AddOption("optPR_0", 200, 300, 3100, 300, "Input frequency is Fpd / 2")) Then Exit Function
        If (Not ps.AddOption("optPR_2", 200, 700, 3100, 300, "Input frequency is Fpd / 4")) Then Exit Function
        If (Not ps.AddOption("optPR_1", 200, 1100, 3100, 300, "Input frequency is Fpd / 128")) Then Exit Function
        If (Not ps.AddOption("optPR_3", 200, 1500, 3100, 300, "Input frequency is Fpd / 256")) Then Exit Function

    '-------------------------------
    ' frame: frmWDTREL
    '-------------------------------
    If (Not ps.AddFrame("frmWDTREL", 100, 3300, 4150, 1650, "Timer Reload Value (WDTREL)")) Then Exit Function
        If (Not ps.AddText("txtWDTREL", 1500, 400, 900, 315)) Then Exit Function
        If (Not ps.AddLabel("lblWDTREL", 0, 200, 450, 1200, 300, "Reload value")) Then Exit Function
        If (Not ps.AddLabel("lbl_box_Time", 1, 1500, 1000, 900, 320, "")) Then Exit Function
        If (Not ps.AddLabel("lbl_txt_Time", 0, 200, 1050, 1175, 300, "Periode [ms]")) Then Exit Function

  End If
  OnChangingPageControl = True
End Function


'*****************************************************************************
'Description:
'        This function is called from the OnShow function of the associated
'        module. See the description for the OnShow function of the
'        associated module for details.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name
'        Pagename        current page name
'        v()             value array
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnShowPageControl(ps As Object, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageControlError

  OnShowPageControl = False

  Dim r         As ProjectData
  Dim c         As Object
  Dim e         As Object
  Dim i         As Integer
  Dim bDisabled As Boolean
  Dim sVarPre   As String
  Dim uTime     As UnitType
  Dim lValue    As Long

  sVarPre = "WDT"

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection

  If (Pagename = "Control") Then
    '-------------------------------------------------------------------------
    ' page: Control (action)
    '-------------------------------------------------------------------------
    Select Case (Controlname)
        '---------------------------------------------------------------------
        ' control: chkWDT_Fkt (action)
        '---------------------------------------------------------------------
        Case "chkWDT_Fkt"
             r.v(sVarPre & "_Disable") = v(1)
             If (v(1) = 1) Then
               r.v(sVarPre & "_USE_Init") = 0
               r.v(sVarPre & "_USE_TriggerWDT") = 0
             End If

        '---------------------------------------------------------------------
        ' control: txtWDTREL (action)
        '---------------------------------------------------------------------
        Case "txtWDTREL"
             If (IsInputFormatOK(v(1), "H2", c("lblWDTREL").Caption, 0, 255)) Then
               r.l(sVarPre & "CON_WDTREL") = v(1)
             Else
                 Exit Function
             End If


        '---------------------------------------------------------------------
        ' control: optPR_0 (action)
        '---------------------------------------------------------------------
        Case "optPR_0"
             r.v(sVarPre & "CON_WDTIN") = 0

        '---------------------------------------------------------------------
        ' control: optWDTIN_1 (action)
        '---------------------------------------------------------------------
        Case "optPR_1"
             r.v(sVarPre & "CON_WDTIN") = 1

        '---------------------------------------------------------------------
        ' control: optPR_2 (action)
        '---------------------------------------------------------------------
        Case "optPR_2"
             r.v(sVarPre & "CON_WDTIN") = 2

        '---------------------------------------------------------------------
        ' control: optPR_3 (action)
        '---------------------------------------------------------------------
        Case "optPR_3"
             r.v(sVarPre & "CON_WDTIN") = 3

      Case Else
    End Select

    '-------------------------------------------------------------------------
    ' page: Control (show)
    '-------------------------------------------------------------------------

    '-------------------------------------------------------------------------
    ' control: chkWDT_Fkt (show)
    '-------------------------------------------------------------------------
    With c("chkWDT_Fkt")
      bDisabled = False
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(sVarPre & "_Disable") = 1)
    End With

    With e("chkWDT_Fkt")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("")
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: txtWDTREL (show)
    '-------------------------------------------------------------------------
    With c("txtWDTREL")
      bDisabled = (r.v(sVarPre & "_Disable") = 1)
      .Enabled = Not (bDisabled)
      .Text = FormatTextOutput(r.v(sVarPre & "CON_WDTREL"), "H2")
    End With

    With e("txtWDTREL")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (r.v(sVarPre & "_Disable") = 1) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(DISABLED_WDT)
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: lblWDTREL (show)
    '-------------------------------------------------------------------------
    With c("lblWDTREL")
      bDisabled = (r.v(sVarPre & "_Disable") = 1)
      .Enabled = Not (bDisabled)
    End With

    With e("lblWDTREL")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (r.v(sVarPre & "_Disable") = 1) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(DISABLED_WDT)
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: lbl_box_Time (show)
    '-------------------------------------------------------------------------
    With c("lbl_box_Time")
      bDisabled = (r.v(sVarPre & "_Disable") = 1)
      .Enabled = Not (bDisabled)
      If (r.v(sVarPre & "CON_WDTIN") = 0) Then
          lValue = 2
      ElseIf (r.v(sVarPre & "CON_WDTIN") = 1) Then
          lValue = 128
      ElseIf (r.v(sVarPre & "CON_WDTIN") = 2) Then
          lValue = 4
      ElseIf (r.v(sVarPre & "CON_WDTIN") = 3) Then
          lValue = 256
      End If
      uTime = ConvertTime((2 ^ 16 - r.v(sVarPre & "CON_WDTREL") * 2 ^ 8) * lValue / GetPeripheralClock(r))
      .Caption = Format(uTime.dValue, "0.000")
      c("lbl_txt_Time").Caption = "Period [" & uTime.sUnit & "]"
    End With

    With e("lbl_box_Time")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (r.v(sVarPre & "_Disable") = 1) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(DISABLED_WDT)
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: lbl_txt_Time (show)
    '-------------------------------------------------------------------------
    With c("lbl_txt_Time")
      bDisabled = (r.v(sVarPre & "_Disable") = 1)
      .Enabled = Not (bDisabled)
    End With

    With e("lbl_txt_Time")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (r.v(sVarPre & "_Disable") = 1) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(DISABLED_WDT)
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optPR_0 (show)
    '-------------------------------------------------------------------------
    With c("optPR_0")
      bDisabled = (r.v(sVarPre & "_Disable") = 1)
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(sVarPre & "CON_WDTIN") = 0)
    End With

    With e("optPR_0")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (r.v(sVarPre & "_Disable") = 1) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(DISABLED_WDT)
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optPR_1 (show)
    '-------------------------------------------------------------------------
    With c("optPR_1")
      bDisabled = (r.v(sVarPre & "_Disable") = 1)
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(sVarPre & "CON_WDTIN") = 1)
    End With

    With e("optPR_1")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (r.v(sVarPre & "_Disable") = 1) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(DISABLED_WDT)
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optPR_2 (show)
    '-------------------------------------------------------------------------
    With c("optPR_2")
      bDisabled = (r.v(sVarPre & "_Disable") = 1)
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(sVarPre & "CON_WDTIN") = 2)
    End With

    With e("optPR_2")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (r.v(sVarPre & "_Disable") = 1) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(DISABLED_WDT)
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optPR_3 (show)
    '-------------------------------------------------------------------------
    With c("optPR_3")
      bDisabled = (r.v(sVarPre & "_Disable") = 1)
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(sVarPre & "CON_WDTIN") = 3)
    End With

    With e("optPR_3")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (r.v(sVarPre & "_Disable") = 1) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(DISABLED_WDT)
        End If
      End If
    End With

  End If

  OnShowPageControl = True
  Exit Function

OnShowPageControlError:
  Errorbox "Can not show page.", Err.Description
  Exit Function
End Function


'*****************************************************************************
'Description:
'        This function is called from the OnLoad function of the associated
'        module in order to add a page.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageFunctions(ps As Peripherals) As Boolean
  On Error Resume Next
  OnLoadPageFunctions = False

  If (Not ps.AddPage("Functions")) Then Exit Function

  OnLoadPageFunctions = True
End Function


'*****************************************************************************
'Description:
'        This function is called from the OnChangingPage function of the
'        associated module in order load all controls for the requested page
'        if they are not already loaded.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'        Pagename         requested page name
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnChangingPageFunctions(ps As Peripherals, Pagename As String) As Boolean
  On Error Resume Next

  OnChangingPageFunctions = False

  Dim i As Integer
  Dim aFunctions(1 To 16) As String


  If (Not ps.ExtenderCollection("Functions").Loaded) And (Pagename = "Functions") Then
    ps.ExtenderCollection("Functions").Loaded = True

    '-------------------------------
    ' frame: fra_Init
    '-------------------------------
    If (Not ps.AddFrame("fra_Init", 100, 100, 4150, 700, CAPTION_FRA_USE_INIT)) Then Exit Function
      If (Not ps.AddCheck("chk_Init", 150, 275, 200, 275, "")) Then Exit Function
      If (Not ps.AddText("txt_Init", 400, 250, 3600, 325)) Then Exit Function

    '-------------------------------
    ' frame: fra_CFile
    '-------------------------------
    If (Not ps.AddFrame("fra_CFile", 4400, 100, 4150, 700, CAPTION_FRA_CFILE)) Then Exit Function
      If (Not ps.AddText("txt_CFile", 1475, 250, 2500, 325)) Then Exit Function
      If (Not ps.AddLabel("lbl_CFile", 0, 200, 300, 1250, 275, CAPTION_LBL_CFILE)) Then Exit Function


    '-------------------------------
    ' frame: fraLibrary1
    '-------------------------------
    ' initialize the array
    For i = LBound(aFunctions) To UBound(aFunctions)
      aFunctions(i) = ""
    Next i

    ' Functions and Macros
    i = LBound(aFunctions)

    aFunctions(i) = "TriggerWDT"
    i = i + 1


    If (Not ps.AddFrame("fraLibrary1", 100, 900, 4150, 4400, CAPTION_FRA_LIBRARY1)) Then Exit Function
      For i = LBound(aFunctions) To UBound(aFunctions)
        If Not (aFunctions(i) = "") Then
          If (Not ps.AddCheck("chk_" & aFunctions(i), 150, 325 + (300 * (i - 1)), 200, 275, "")) Then Exit Function
          If (Not ps.AddText("txt_" & aFunctions(i), 400, 300 + (300 * (i - 1)), 3600, 325)) Then Exit Function
        End If
      Next i


  End If

  OnChangingPageFunctions = True
End Function


'*****************************************************************************
'Description:
'        This function is called from the OnShow function of the associated
'        module. See the description for the OnShow function of the
'        associated module for details.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name
'        Pagename        current page name
'        v()             value array
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnShowPageFunctions(ps As Peripherals, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageFunctionsError

  OnShowPageFunctions = False
    
  Dim r         As ProjectData
  Dim c         As Collection
  Dim e         As Collection
  Dim bDisabled As Boolean
  Dim func      As FunctionClass
  Dim sName     As String
  Dim sRegPre   As String
  Dim sVarPre   As String
  Dim vIndex    As Variant
  Dim d         As String

  sRegPre = "WDT"
  sVarPre = "WDT"

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection
  Set func = New FunctionClass

  If (Pagename = "Functions") Then
    '-------------------------------------------------------------------------
    ' page: Functions (action)
    '-------------------------------------------------------------------------
    RefreshFunctionDescriptions(vIndex, func, r)

    If (Not UpdateFunction(sVarPre, ps, func, Controlname, v)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Functions (show)
    '-------------------------------------------------------------------------
    Set func = New FunctionClass
    RefreshFunctionDescriptions(vIndex, func, r)

    sName = sVarPre & "_NAME_Init"
    ' disable condition
    func.Disabled(sName) = (r.v("WDT_Disable") = 1)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v("WDT_Disable") = 1) Then
      d = d & FormatDisabledToolTip(DISABLED_WDT)
    End If
    func.DisabledToolTip(sName) = d

    sName = sVarPre & "_NAME_TriggerWDT"
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    If (Not ShowFunction(sVarPre, ps, func, v)) Then Exit Function


  End If         ' if Pagename

  OnShowPageFunctions = True
  Exit Function

OnShowPageFunctionsError:
  Errorbox "Can not show page", Err.Description
  Exit Function
End Function


'*****************************************************************************
'Description:
'        This function is called from the OnLoad function of the associated
'        module in order to add a page.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageParameters(ps As Peripherals) As Boolean
  On Error Resume Next
  OnLoadPageParameters = False

  If (Not ps.AddPage("Parameters")) Then Exit Function

  OnLoadPageParameters = True
End Function


'*****************************************************************************
'Description:
'        This function is called from the OnChangingPage function of the
'        associated module in order load all controls for the requested page
'        if they are not already loaded.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'        Pagename         requested page name
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnChangingPageParameters(ps As Peripherals, Pagename As String) As Boolean
  On Error Resume Next

  OnChangingPageParameters = False

  If (Not ps.ExtenderCollection("Parameters").Loaded) And (Pagename = "Parameters") Then
    ps.ExtenderCollection("Parameters").Loaded = True

    '-------------------------------------------------------------------------
    ' frame: frmCAPCOMx_HFile
    '-------------------------------------------------------------------------
    If (Not ps.AddFrame("fra_HFile", 100, 100, 4150, 700, CAPTION_FRA_HFILE)) Then Exit Function
      If (Not ps.AddText("txt_HFile", 1475, 250, 2500, 325)) Then Exit Function
      If (Not ps.AddLabel("lbl_HFile", 0, 200, 300, 1250, 300, CAPTION_LBL_HFILE)) Then Exit Function
    

  End If

  OnChangingPageParameters = True
End Function


'*****************************************************************************
'Description:
'        This function is called from the OnShow function of the associated
'        module. See the description for the OnShow function of the
'        associated module for details.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name
'        Pagename        current page name
'        v()             value array
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnShowPageParameters(ps As Peripherals, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageParametersError
  OnShowPageParameters = False
    
  Dim r       As ProjectData
  Dim c       As Collection
  Dim e       As Collection
  Dim para    As ParameterClass
  Dim vIndex  As Variant
  Dim sVarPre As String
  Dim sRegPre As String
  Dim sName   As String
  Dim d       As String
  Dim i       As Integer

  vIndex = ps.Parameters.v("x")
  sVarPre = "WDT" & vIndex
  sRegPre = sVarPre & "_"

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection
  Set para = New ParameterClass


  If (Pagename = "Parameters") Then

    '-------------------------------------------------------------------------
    ' page: Parameters (action)
    '-------------------------------------------------------------------------
    RefreshParameterDescriptions(vIndex, para, r)

    If (Not UpdateParameter(sVarPre, ps, para, Controlname, v)) Then Exit Function


    '-------------------------------------------------------------------------
    ' page: Parameters (show)
    '-------------------------------------------------------------------------

    Set para = New ParameterClass
    RefreshParameterDescriptions(vIndex, para, r)

'    sName = sIndex & "_PARA_T2"
'    ' disable condition
'    para.Disabled(sName) = True
'    ' tooltip if control is disabled
'    d = FormatDisabledTooltip("Fred ...")
'    para.DisabledToolTip(sName) = d

    If (Not ShowParameter(sVarPre, ps, para, v)) Then Exit Function

  End If         ' if Pagename

  OnShowPageParameters = True
  Exit Function

OnShowPageParametersError:
    Errorbox "Can not show page", Err.Description
    Exit Function
End Function



