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


Option Explicit
'*****************************************************************************
' Module:
'       WDT
'-----------------------------------------------------------------------------
' Description:
'        This file contains functions for generating code for the
'        module 'WDT'.
'
'-----------------------------------------------------------------------------
' History:
'
'        Rev. Author         Date        Description
'        ---------------------------------------------------------------------
'        0.1  Radhish        27-10-04    initial version
'        0.2  Radhish        27-11-04    changes made in the range of slowdown clock
'        0.3  radhish        27-12-04    Module name appended before register names
'        0.4  Ashish        05.12.06    WDT enable /disable options added,WDT enable/disable functions added
'*****************************************************************************

'*****************************************************************************
' Constants
'*****************************************************************************

Const TOOLTIP_WDT_NOT_USED = "the watchdog timer is not enabled"

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

    OnLoad = False

    If (Not OnLoadPageControl(ps)) Then Exit Function
    If (Not OnLoadPageFunctions(ps)) Then Exit Function
    If (Not OnLoadPageParameters(ps)) Then Exit Function
    If (Not OnLoadPageNotes(ps)) Then Exit Function
        ' call function to initialize the menu
    If (Not InitMenu(ps, "WDT\Dialog")) Then Exit Function

    OnLoad = True
    Exit Function

OnLoadError:
    Exit Function
End Function

Function OnChangingPage(ps As Peripherals, Page As Integer, Pagename As String) As Boolean
    On Error GoTo OnChangingPageError

    OnChangingPage = False
    
    If (Not OnChangingPageControl(ps, Pagename)) Then Exit Function
    If (Not OnChangingPageFunctions(ps, Pagename)) Then Exit Function
    If (Not OnChangingPageParameters(ps, Pagename)) Then Exit Function
    If (Not OnChangingPageNotes(ps, Pagename, "WDT")) Then Exit Function

    OnChangingPage = True
    Exit Function

OnChangingPageError:
    Exit Function
End Function

Function OnShow(ps As Peripherals, Controlname As String, v() As Variant, Page As Integer, Pagename As String) As Boolean
    On Error Resume Next
    OnShow = False

    If (Not OnShowPageControl(ps, Controlname, Pagename, v)) Then Exit Function
    If (Not OnShowPageFunctions(ps, Controlname, Pagename, v)) Then Exit Function
    If (Not OnShowPageParameters(ps, Controlname, Pagename, v)) Then Exit Function
    If (Not OnShowPageNotes(ps, Controlname, Pagename, "WDT", v)) Then Exit Function

    OnShow = True
'OnShowError:
   ' Errorbox "Can not show page.", Err.Description
  '  Exit Function
End Function

Function OnClick(ps As Peripherals, Controlname As String) As Boolean
    On Error GoTo OnClickError

    OnClick = False
    ' no buttons implemented
    OnClick = True
    Exit Function

OnClickError:
    Errorbox "Can not process the click", Err.Description
    Exit Function
End Function

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
 
Public Function OnLoadPageControl(ps As Peripherals) As Boolean
  On Error Resume Next
  OnLoadPageControl = False

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

  OnLoadPageControl = True
End Function

Public Function OnChangingPageControl(ps As Peripherals, 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

    If (Not ps.AddFrame("fraWDTUsed", 120, 120, 3600, 1160, "WDT Control")) Then Exit Function
    If (Not ps.AddOption("chkWdtUsed", 240, 260, 3000, 380, "Enable watchdog timer in initialisation.")) Then Exit Function
    If (Not ps.AddOption("chkWdtNotUsed", 240, 600, 3000, 380, "Disable watchdog timer in initialisation.")) Then Exit Function

    If (Not ps.AddFrame("fraWDInputF", 120, 1400, 3600, 1520, "Input Frequency select(WDTIN)")) Then Exit Function
    If (Not ps.AddOption("optWDTIN_0", 240, 360, 920, 380, "fSYS / 2")) Then Exit Function
    If (Not ps.AddOption("optWDTIN_1", 240, 720, 1100, 380, "fSYS / 128")) Then Exit Function

    If (Not ps.AddFrame("fraWDtime", 120, 3040, 3600, 1560, "Timeout")) Then Exit Function
    If (Not ps.AddText("txtReloadValue", 2280, 480, 900, 315)) Then Exit Function
    If (Not ps.AddLabel("lblReloadValue", 0, 240, 480, 1920, 390, "Reload Value (WDTREL)")) Then Exit Function
    If (Not ps.AddText("txtPeriod", 2280, 1080, 900, 315)) Then Exit Function
    If (Not ps.AddLabel("lblPeriod", 0, 240, 1080, 1920, 360, "Timeout Period [ms]")) Then Exit Function
    
    If (Not ps.AddFrame("fraWinEna", 4000, 120, 4550, 1160, "Window Boundary")) Then Exit Function
        If (Not ps.AddCheck("chkWinEna", 200, 300, 2150, 380, "Enable Window boundary")) Then Exit Function
    
    If (Not ps.AddFrame("fraWinSet", 4000, 1400, 4550, 1520, "Window Boundary Settings")) Then Exit Function
        If (Not ps.AddLabel("lblWinVal", 0, 200, 500, 2500, 380, "Window boundary Value:")) Then Exit Function
        If (Not ps.AddText("txtWinVal", 2800, 450, 1000, 315)) Then Exit Function

  End If
  OnChangingPageControl = True
End Function

Public Function OnShowPageControl(ps As Peripherals, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowError

  OnShowPageControl = False
  
  Dim r As ProjectData
  Dim c As Collection
  Dim e As Collection
  Dim bDisabled As Boolean
  Dim iTemp As Integer

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

  If (Pagename = "Control") Then
    '-------------------------------------------------------------------------
    ' page: Control (action)
    '-------------------------------------------------------------------------
    Select Case Controlname
        Case "chkWdtUsed"
       r.v("GEN_UserDef1") = 0
       If (v(1) = 1) Then
        r.v(WDT_PREFIX & "WDTCON_WDTEN") = 1
        ElseIf (v(1) = 0) Then
        r.v(WDT_PREFIX & "WDTCON_WDTEN") = 0
        End If
          
          
''            If (v(1) = 0) Then
''                ' take reset values when WDT is not used:
''                r.l(WDT_PREFIX & "WDTCON_WDTIN") = 0
''                r.l(WDT_PREFIX & "WDTCON_WINBEN") = 0
''                r.l(WDT_PREFIX & "WDTREL_WDTREL") = 0
''                r.d("WDT_WDTPeriod") = Format(WdtTimeoutPeriod(r, r.l(WDT_PREFIX & "WDTREL_WDTREL")), "0.0000")  'adjust the timeout period
''                r.v("WDT_USE_Init") = 0  ' deselect function
''                r.v("WDT_USE_Refresh") = 0   ' deselect function
''                r.v("WDT_USE_Reset") = 0  ' deselect function
''                r.v("WDT_USE_Windowb") = 0  ' deselect function
''
''            End If

      Case "chkWdtNotUsed"
      r.v("GEN_UserDef1") = 1
      
        If (v(1) = 1) Then
        r.v(WDT_PREFIX & "WDTCON_WDTEN") = 0
        ElseIf (v(1) = 0) Then
        r.v(WDT_PREFIX & "WDTCON_WDTEN") = 1
        End If
        
       
''            If (v(1) = 0) Then
''                ' take reset values when WDT is not used:
''                r.l(WDT_PREFIX & "WDTCON_WDTIN") = 0
''                r.l(WDT_PREFIX & "WDTCON_WINBEN") = 0
''                r.l(WDT_PREFIX & "WDTREL_WDTREL") = 0
''                r.d("WDT_WDTPeriod") = Format(WdtTimeoutPeriod(r, r.l(WDT_PREFIX & "WDTREL_WDTREL")), "0.0000")  'adjust the timeout period
''                r.v("WDT_USE_Init") = 0  ' deselect function
''                r.v("WDT_USE_Refresh") = 0   ' deselect function
''                r.v("WDT_USE_Reset") = 0  ' deselect function
''                r.v("WDT_USE_Windowb") = 0  ' deselect function
''
''            End If

        Case "optWDTIN_0"
               r.l(WDT_PREFIX & "WDTCON_WDTIN") = 0
               r.d("WDT_WDTPeriod") = Format(WdtTimeoutPeriod(r, r.l(WDT_PREFIX & "WDTREL_WDTREL")), "0.0000") 'adjust the timeout period'

        Case "optWDTIN_1"
               r.l(WDT_PREFIX & "WDTCON_WDTIN") = 1
               r.d("WDT_WDTPeriod") = Format(WdtTimeoutPeriod(r, r.l(WDT_PREFIX & "WDTREL_WDTREL")), "0.0000") 'adjust the timeout period'

        Case "txtReloadValue"
            If (IsInputFormatOK(v(1), "", c("lblReloadValue").Caption, &H0, &HFF)) Then
                r.l(WDT_PREFIX & "WDTREL_WDTREL") = v(1)
                r.d("WDT_WDTPeriod") = Format(WdtTimeoutPeriod(r, r.l(WDT_PREFIX & "WDTREL_WDTREL")), "0.0000") 'adjust the timeout period'
          
            Else
                Exit Function
            End If
                    
        Case "txtPeriod"
            If (IsInputFormatOK(v(1), "F", c("lblPeriod").Caption, WdtTimeoutPeriod(r, &HFF), WdtTimeoutPeriod(r, &H0))) Then
                r.d("WDT_WDTPeriod") = v(1)
                r.l(WDT_PREFIX & "WDTREL_WDTREL") = WdtReloadValue(r, r.d("WDT_WDTPeriod"))
            Else
                Exit Function
            End If
            
         
         Case "chkWinEna"
            r.v(WDT_PREFIX & "WDTCON_WINBEN") = v(1)
            If (v(1) = 0) Then
              r.l(WDT_PREFIX & "WDTWINB_WDTWINB") = 0
            End If
           
           Case "txtWinVal"
           If (IsInputFormatOK(v(1), "", c("lblWinVal").Caption, &H0, &HFF)) Then
               r.l(WDT_PREFIX & "WDTWINB_WDTWINB") = v(1)
            
            End If
                
        
    End Select     ' case Controlname

    '-------------------------------------------------------------------------
    ' page: Control (show)
    '-------------------------------------------------------------------------
    With c("chkWdtUsed")
   .Value = -CInt(r.v("GEN_UserDef1") = 0)
    bDisabled = False
   .Enabled = Not (bDisabled)
    End With

  With c("chkWdtNotUsed")
  .Value = -CInt(r.v("GEN_UserDef1") = 1)
   bDisabled = False
 .Enabled = Not (bDisabled)
  End With
    With c("optWDTIN_0")
        'bDisabled = (r.v(WDT_PREFIX & "WDTCON_WDTEN") = 0)
        '.Enabled = Not bDisabled
        .Value = r.v(WDT_PREFIX & "WDTCON_WDTIN") = 0
    End With
    With e("optWDTIN_0")
           'If (bDisabled) Then
            '    .DisabledTooltipText = TOOLTIP_DISABLED_IF
            '.DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_WDT_NOT_USED)
             '   End If
    End With


    With c("optWDTIN_1")
        'bDisabled = (r.v(WDT_PREFIX & "WDTCON_WDTEN") = 0)
        '.Enabled = Not bDisabled
        .Value = r.v(WDT_PREFIX & "WDTCON_WDTIN") = 1
    End With
    With e("optWDTIN_1")
               ' If (bDisabled) Then
                '.DisabledTooltipText = TOOLTIP_DISABLED_IF
            '.DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_WDT_NOT_USED)
               ' End If
    End With


    With c("txtReloadValue")
        'bDisabled = (r.v(WDT_PREFIX & "WDTCON_WDTEN") = 0)
        '.Enabled = Not bDisabled
       r.l(WDT_PREFIX & "WDTREL_WDTREL") = WdtReloadValue(r, r.d("WDT_WDTPeriod"))

        .Text = FormatTextOutput(r.v(WDT_PREFIX & "WDTREL_WDTREL"), "H2")
    End With
    With e("txtReloadValue")
                'If (bDisabled) Then
            '.DisabledTooltipText = TOOLTIP_DISABLED_IF
            '.DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_WDT_NOT_USED)
             '   End If
    End With
    'c("lblReloadValue").Enabled = Not bDisabled


    With c("txtPeriod")
        'bDisabled = (r.v(WDT_PREFIX & "WDTCON_WDTEN") = 0)
        '.Enabled = Not bDisabled
        .Text = FormatTextOutput(r.v("WDT_WDTPeriod"), "F")
    End With
    With e("txtPeriod")
                'If (bDisabled) Then
               ' .DisabledTooltipText = TOOLTIP_DISABLED_IF
            '.DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_WDT_NOT_USED)
              '  End If
    End With
    c("lblPeriod").Enabled = Not bDisabled

 With c("chkWinEna")
         'bDisabled = (r.v(WDT_PREFIX & "WDTCON_WDTEN") = 0)
        '.Enabled = Not bDisabled
        .Value = -CInt(r.v(WDT_PREFIX & "WDTCON_WINBEN") = 1)
    End With
    With e("chkWinEna")
                'If (bDisabled) Then
               ' .DisabledTooltipText = TOOLTIP_DISABLED_IF
               ' .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_WDT_NOT_USED)
               ' End If
 
        
    End With

 With c("txtWinVal")
       ' bDisabled = (r.v(WDT_PREFIX & "WDTCON_WINBEN") = 0)
        '.Enabled = Not bDisabled
        .Text = FormatTextOutput(r.v(WDT_PREFIX & "WDTWINB_WDTWINB"), "H2")
    End With
    With e("txtWinVal")
               ' If (bDisabled) Then
               ' .DisabledTooltipText = TOOLTIP_DISABLED_IF
               ' .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_WDT_NOT_USED)
               ' End If
    End With
    'c("lblWinVal").Enabled = Not bDisabled


  End If         ' if Pagename

  
  OnShowPageControl = True
  Exit Function

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

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

Public Function OnChangingPageFunctions(ps As Peripherals, Pagename As String) As Boolean
  On Error Resume Next

  OnChangingPageFunctions = False

  Dim pos As Long

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

    If (Not ps.AddFrame("fraWDT_USE_Init", 100, 100, 4150, 700, "Initialization Function")) Then Exit Function
    If (Not ps.AddCheck("chkWDT_USE_Init", 200, 270, 1080, 380, "WDT_vInit")) Then Exit Function
    If (Not ps.AddText("txtWDT_NAME_Init", 2150, 300, 1900, 315)) Then Exit Function

    If (Not ps.AddFrame("fraWDT_CFile", 4400, 100, 4150, 700, "Source File")) Then Exit Function
    If (Not ps.AddText("txtWDT_CFile", 1500, 300, 2550, 315)) Then Exit Function
    If (Not ps.AddLabel("lblWDT_CFile", 0, 200, 300, 1575, 380, "File name")) Then Exit Function

    If (Not ps.AddFrame("fraLibrary1", 100, 900, 4150, 4400, "Function Library")) Then Exit Function
    pos = 0
    ' Functions and Macros
    If (Not ps.AddCheck("chkWDT_USE_Enable", 200, 270 + pos * 300, 1425, 380, "WDT_vEnable")) Then Exit Function
    If (Not ps.AddText("txtWDT_NAME_Enable", 2150, 300 + pos * 300, 1900, 315)) Then Exit Function
    pos = pos + 1
    
    If (Not ps.AddCheck("chkWDT_USE_Disable", 200, 270 + pos * 300, 1425, 380, "WDT_vDisable")) Then Exit Function
    If (Not ps.AddText("txtWDT_NAME_Disable", 2150, 300 + pos * 300, 1900, 315)) Then Exit Function
    pos = pos + 1
    If (Not ps.AddCheck("chkWDT_USE_Refresh", 200, 270 + pos * 300, 1425, 380, "WDT_vRefresh")) Then Exit Function
    If (Not ps.AddText("txtWDT_NAME_Refresh", 2150, 300 + pos * 300, 1900, 315)) Then Exit Function
    pos = pos + 1

    If (Not ps.AddCheck("chkWDT_USE_Reset", 200, 270 + pos * 300, 1800, 380, "WDT_bWDTReset")) Then Exit Function
    If (Not ps.AddText("txtWDT_NAME_Reset", 2150, 300 + pos * 300, 1900, 315)) Then Exit Function
    pos = pos + 1

    If (Not ps.AddCheck("chkWDT_USE_Windowb", 200, 270 + pos * 300, 1450, 380, "WDT_Windowb")) Then Exit Function
    If (Not ps.AddText("txtWDT_NAME_Windowb", 2150, 300 + pos * 300, 1900, 315)) Then Exit Function
    
   
  End If

  OnChangingPageFunctions = True
End Function

Public Function OnShowPageFunctions(ps As Peripherals, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowError

  OnShowPageFunctions = False
    
  Dim r As ProjectData
  Dim c As Collection
  Dim e As Collection
  Dim bDisabled As Boolean
  Dim func As FunctionClass

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

  If (Pagename = "Functions") Then
    '-------------------------------------------------------------------------
    ' page: Functions (action)
    '-------------------------------------------------------------------------
    Select Case Controlname
        Case "chkWDT_USE_Init"
             r.v("WDT_USE_Init") = v(1)
    
        Case "txtWDT_NAME_Init"
             If (IsInputFormatOK(v(1), FORMAT_FUNCTIONS, c("chkWDT_USE_Init").Caption)) Then
                r.v("WDT_NAME_Init") = v(1)
             End If
    
        Case "txtWDT_CFile"
             If (IsInputFormatOK(v(1), FORMAT_FILES, c("lblWDT_CFile").Caption)) Then
                r.v("WDT_CFile") = v(1)
             End If
    End Select     ' case Controlname
    If (Not UpdateFunction(ps, Controlname, v, "Enable")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "Disable")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "Refresh")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "Reset")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "Windowb")) Then Exit Function
   
 '-------------------------------------------------------------------------
    ' page: Functions (show)
    '-------------------------------------------------------------------------
    Call RefreshFunctionDescriptions(func, r)

    '-------------------------------------------------------------------------
    ' control: chkWDT_USE_Init (show)
    '-------------------------------------------------------------------------
    With c("chkWDT_USE_Init")
    'bDisabled = (r.v(WDT_PREFIX & "WDTCON_WDTEN") = 0)
    ' .Enabled = Not bDisabled
    .Value = -CInt(r.v("WDT_USE_Init") = 1)
    End With
   With e("chkWDT_USE_Init")
   If (bDisabled) Then
            .DisabledTooltipText = FormatNormalToolTip(TOOLTIP_WDT_NOT_USED)
        End If
   .EnabledTooltipText = FormatFunctionToolTip(r, func, "WDT_NAME_Init")
End With
    '-------------------------------------------------------------------------
    ' control: txtWDT_NAME_Init (show)
    '-------------------------------------------------------------------------
    With c("txtWDT_NAME_Init")
        bDisabled = r.v("WDT_USE_Init") = 0
        .Enabled = Not bDisabled
        .Text = FormatTextOutput(r.v("WDT_NAME_Init"), "S")
    End With

    With e("txtWDT_NAME_Init")
        If (bDisabled) Then
            .DisabledTooltipText = FormatNormalToolTip(TOOLTIP_DISABLED_FUNC_NAME)
        End If
    End With
    If (Not ShowFunction(ps, v, func, "Enable")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "Disable")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "Refresh")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "Reset")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "Windowb")) Then Exit Function
   
  
   '-------------------------------------------------------------------------
    ' control: lblWDT_CFile (show)
    '-------------------------------------------------------------------------
    With c("lblWDT_CFile")
        bDisabled = r.v("WDT_USE_Init") = 0
        .Enabled = Not bDisabled
    End With

    With e("lblWDT_CFile")
        If (bDisabled) Then
            .DisabledTooltipText = FormatNormalToolTip(TOOLTIP_DISABLED_CFILE_NAME)
        End If
    End With
 With c("txtWDT_CFile")
        bDisabled = (r.v("WDT_USE_Init") = 0)
        .Enabled = Not bDisabled
        .Text = FormatTextOutput(r.v("WDT_CFile"), "S")
    End With
    With e("txtWDT_CFile")
        If (bDisabled) Then
            .DisabledTooltipText = FormatNormalToolTip(TOOLTIP_DISABLED_CFILE_NAME)
        End If
    End With
   
  End If         ' if Pagename

  OnShowPageFunctions = True
  Exit Function

OnShowError:
  Errorbox "Can not show page", Err.Description
  Exit Function
End Function
  
 
'*****************************************************************************
'Description:
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the Project Data Object
'        Controlname     control name
'        v()             value array
'        sName           function keyword
'-----------------------------------------------------------------------------
'Returns:
'        True            on successful operation
'        False           else
'*****************************************************************************
Function UpdateFunction(ps As Peripherals, Controlname As String, v() As Variant, sName As String) As Boolean
  On Error GoTo ExitLabel
  UpdateFunction = False

  Dim r As ProjectData
  Dim c As Collection

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

  '---------------------------------------------------------------------
  ' control: chkWDT_USE_.. (action)
  '---------------------------------------------------------------------
  If (Controlname = "chkWDT_USE_" & sName) Then
        If (sName = "Enable") Then
          r.v("WDT_PARA_CLR_BIT") = v(1)
          ElseIf (sName = "Disable") Then
           r.v("WDT_PARA_NO_CLR_BIT") = v(1)
          Else
          r.v("WDT_USE_" & sName) = v(1)
        End If
  End If

  '---------------------------------------------------------------------
  ' control: txtWDT_NAME_.. (action)
  '---------------------------------------------------------------------
  If (Controlname = "txtWDT_NAME_" & sName) Then
    If (IsInputFormatOK(v(1), FORMAT_FUNCTIONS, c("chkWDT_USE_" & sName).Caption)) Then
             If (sName = "Enable") Then
               r.v("WDT_WinEna") = v(1)
             ElseIf (sName = "Disable") Then
              r.v("GEN_UserDef0") = v(1)
              Else
            r.v("WDT_NAME_" & sName) = v(1)
            End If
    Else
        Exit Function
    End If
  End If

  UpdateFunction = True
ExitLabel:
End Function
'Description:
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        v()             value array
'        func            reference to the function object
'        sName           function keyword
'-----------------------------------------------------------------------------
'Returns:
'        True            on successful operation
'        False           else
'*****************************************************************************
Function ShowFunction(ps As Peripherals, v() As Variant, func As FunctionClass, sName As String) As Boolean
  On Error GoTo ExitLabel
  ShowFunction = False
    
  Dim r As ProjectData
  Dim c As Collection
  Dim e As Collection
  Dim bDisabled As Boolean

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

  '-------------------------------------------------------------------------
  ' control: chkWDT_USE_.. (show)
  '-------------------------------------------------------------------------
  With c("chkWDT_USE_" & sName)
    Select Case sName

        Case "Refresh", "Reset", "Windowb", "Enable", "Disable"
            bDisabled = (r.v("WDT_USE_Init") = 0) Or (r.v("WDT_WDTUsed") = 0)
       End Select
   .Enabled = Not bDisabled
    If (sName = "Enable") Then
      .Value = -CInt((r.v("WDT_USE_Init") = 1) And (r.v("WDT_PARA_CLR_BIT") = 1))
    ElseIf (sName = "Disable") Then
      .Value = -CInt((r.v("WDT_USE_Init") = 1) And (r.v("WDT_PARA_NO_CLR_BIT") = 1))
      Else
    .Value = -CInt((r.v("WDT_USE_Init") = 1) And (r.v("WDT_USE_" & sName) = 1))
    End If
  End With


  With e("chkWDT_USE_" & sName)
    If (bDisabled) Then
        ' tooltip if control is disabled
        Select Case sName
           Case "Enable"
              .DisabledTooltipText = GetDisabledFunctionTooltipEntry(func, "WDT_WinEna")
                If (r.v("WDT_USE_Init") = 0) Then
                .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
                End If

                If (r.v("WDT_WDTUsed") = 0) Then
                  .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_WDT_NOT_USED)
                 End If
              
           
           Case "Disable"
                .DisabledTooltipText = GetDisabledFunctionTooltipEntry(func, "GEN_UserDef0")
                    If (r.v("WDT_USE_Init") = 0) Then
                    .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
                    End If

                     If (r.v("WDT_WDTUsed") = 0) Then
                      .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_WDT_NOT_USED)
                     End If
               

            Case "Refresh", "Reset", "Windowb"
                .DisabledTooltipText = GetDisabledFunctionTooltipEntry(func, "WDT_NAME_" & sName)
                If (r.v("WDT_USE_Init") = 0) Then
                    .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
                End If
                If (r.v("WDT_WDTUsed") = 0) Then
                    .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_WDT_NOT_USED)
                End If

            
            Case Else
                If (sName = "Enable") Then
                .DisabledTooltipText = GetDisabledFunctionTooltipEntry(func, "WDT_WinEna")
                .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
                ElseIf (sName = "Disable") Then
                .DisabledTooltipText = GetDisabledFunctionTooltipEntry(func, "GEN_UserDef0")
                .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
                
                Else
                .DisabledTooltipText = GetDisabledFunctionTooltipEntry(func, "WDT_NAME_" & sName)
                .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
               End If
        End Select
    Else
        ' tooltip if control is enabled
        If (sName = "Enable") Then
        .EnabledTooltipText = FormatFunctionToolTip(r, func, "WDT_WinEna")
        ElseIf (sName = "Disable") Then
        .EnabledTooltipText = FormatFunctionToolTip(r, func, "GEN_UserDef0")
        Else
        .EnabledTooltipText = FormatFunctionToolTip(r, func, "WDT_NAME_" & sName)
        End If
    End If
  End With

  '-------------------------------------------------------------------------
  ' control: txtWDT_NAME_... (show)
  '-------------------------------------------------------------------------
  With c("txtWDT_NAME_" & sName)
  If (sName = "Enable") Then
    bDisabled = c("chkWDT_USE_Enable").Value = 0
    .Enabled = Not bDisabled
    .Text = FormatTextOutput(r.s("WDT_WinEna"), "S")
  ElseIf (sName = "Disable") Then
    bDisabled = c("chkWDT_USE_Disable").Value = 0
    .Enabled = Not bDisabled
    .Text = FormatTextOutput(r.s("GEN_UserDef0"), "S")
  Else
  
    bDisabled = c("chkWDT_USE_" & sName).Value = 0
    .Enabled = Not bDisabled
    .Text = FormatTextOutput(r.s("WDT_NAME_" & sName), "S")
    End If
  End With

  With e("txtWDT_NAME_" & sName)
    If (bDisabled) Then
        .DisabledTooltipText = FormatNormalToolTip(TOOLTIP_DISABLED_FUNC_NAME)
    End If
  End With

  ShowFunction = True
ExitLabel:
End Function



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

Public Function OnChangingPageParameters(ps As Peripherals, Pagename As String) As Boolean
  On Error Resume Next

  Dim iPar As Integer
  Dim sName As String

  OnChangingPageParameters = False

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

    If (Not ps.AddFrame("fraWDT_HFile", 100, 100, 8450, 700, "Header File")) Then Exit Function
    If (Not ps.AddText("txtWDT_HFile", 1825, 250, 5000, 315)) Then Exit Function
    If (Not ps.AddLabel("lblWDT_HFile", 0, 200, 300, 1575, 380, "File Name")) Then Exit Function

 End If

  OnChangingPageParameters = True
End Function

Public Function OnShowPageParameters(ps As Peripherals, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowError

  OnShowPageParameters = False
       
  Dim r As ProjectData
  Dim c As Collection
  Dim e As Collection
  Dim bDisabled As Boolean
  Dim sName As String
  Dim iPar As Integer

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


  If (Pagename = "Parameters") Then
    '-------------------------------------------------------------------------
    ' page: Parameters (action)
    '-------------------------------------------------------------------------
    Select Case Controlname
        Case "txtWDT_HFile"
            If (IsInputFormatOK(v(1), FORMAT_FILES, c("lblWDT_HFile").Caption)) Then
                r.v("WDT_HFile") = v(1)
            Else
                Exit Function
            End If
     

    End Select

    '-------------------------------------------------------------------------
    ' page: Parameters (show)
    '-------------------------------------------------------------------------
    With c("lblWDT_HFile")
        bDisabled = (r.v("WDT_USE_Init") = 0)
        .Enabled = Not bDisabled
    End With
    With e("lblWDT_HFile")
        If (bDisabled) Then
            .DisabledTooltipText = FormatNormalToolTip(TOOLTIP_DISABLED_HFILE_NAME)
        End If
    End With

    With c("txtWDT_HFile")
        bDisabled = (r.v("WDT_USE_Init") = 0)
        .Enabled = Not bDisabled
        .Text = FormatTextOutput(r.v("WDT_HFile"), "S")
    End With
    With e("txtWDT_HFile")
        If (bDisabled) Then
            .DisabledTooltipText = FormatNormalToolTip(TOOLTIP_DISABLED_HFILE_NAME)
        End If
    End With

   

  End If         ' if Pagename
  
  OnShowPageParameters = True
  Exit Function

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


